Compare commits
3 Commits
7f1f9eb1f8
...
3fe77430f2
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fe77430f2 | |||
| b61861cb67 | |||
| a0cb2a7ca6 |
15
asr.go
15
asr.go
@ -113,10 +113,13 @@ func (s *SpeechRecognitionResponse) asrReplaceRandom() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func asrResultObfuscate(r *http.Request, body []byte) ([]byte, error) {
|
func asrResultObfuscate(r *http.Request, body []byte, replacePercentage int) ([]byte, error) {
|
||||||
if r.URL.Path != "/webcast/review/client_ai/upload_asr_result/" {
|
if r.URL.Path != "/webcast/review/client_ai/upload_asr_result/" {
|
||||||
return nil, fmt.Errorf("not an asr request")
|
return nil, fmt.Errorf("not an asr request")
|
||||||
}
|
}
|
||||||
|
if !shouldApplyASRReplacement(replacePercentage) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
obj := SpeechRecognitionResponse{}
|
obj := SpeechRecognitionResponse{}
|
||||||
err := obj.FromJSON(string(body))
|
err := obj.FromJSON(string(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,3 +136,13 @@ func asrResultObfuscate(r *http.Request, body []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
return jsonData, nil
|
return jsonData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldApplyASRReplacement(replacePercentage int) bool {
|
||||||
|
if replacePercentage <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if replacePercentage >= 100 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return rand.Intn(100) < replacePercentage
|
||||||
|
}
|
||||||
|
|||||||
16
config.go
16
config.go
@ -17,6 +17,8 @@ func parseConfig(filename string) (*Config, error) {
|
|||||||
config.Proxy.Port = 8080
|
config.Proxy.Port = 8080
|
||||||
config.Dump.OutputDir = "traffic_dumps"
|
config.Dump.OutputDir = "traffic_dumps"
|
||||||
config.Dump.DOIDir = "interest_dumps"
|
config.Dump.DOIDir = "interest_dumps"
|
||||||
|
config.DictFile = "dict.txt"
|
||||||
|
config.ASR.ReplacePercentage = 100
|
||||||
|
|
||||||
// Parse the TOML file
|
// Parse the TOML file
|
||||||
_, err := toml.DecodeFile(filename, config)
|
_, err := toml.DecodeFile(filename, config)
|
||||||
@ -24,6 +26,16 @@ func parseConfig(filename string) (*Config, error) {
|
|||||||
return nil, fmt.Errorf("failed to parse config file %s: %v", filename, err)
|
return nil, fmt.Errorf("failed to parse config file %s: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.DictFile == "" {
|
||||||
|
config.DictFile = "dict.txt"
|
||||||
|
}
|
||||||
|
if config.ASR.ReplacePercentage < 0 {
|
||||||
|
config.ASR.ReplacePercentage = 0
|
||||||
|
}
|
||||||
|
if config.ASR.ReplacePercentage > 100 {
|
||||||
|
config.ASR.ReplacePercentage = 100
|
||||||
|
}
|
||||||
|
|
||||||
// Create dump directories if they don't exist
|
// Create dump directories if they don't exist
|
||||||
if err := createDumpDirectories(config); err != nil {
|
if err := createDumpDirectories(config); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create dump directories: %v", err)
|
return nil, fmt.Errorf("failed to create dump directories: %v", err)
|
||||||
@ -51,6 +63,6 @@ func createDumpDirectories(config *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) String() string {
|
func (c *Config) String() string {
|
||||||
return fmt.Sprintf("Config{DomainsOfInterest: %v, Proxy: {Port: %d}, Dump: {OutputDir: %s, DOI_dir: %s}}",
|
return fmt.Sprintf("Config{DomainsOfInterest: %v, DictFile: %s, Proxy: {Port: %d}, Dump: {OutputDir: %s, DOI_dir: %s}, ASR: {ReplacePercentage: %d}}",
|
||||||
c.DomainsOfInterest, c.Proxy.Port, c.Dump.OutputDir, c.Dump.DOIDir)
|
c.DomainsOfInterest, c.DictFile, c.Proxy.Port, c.Dump.OutputDir, c.Dump.DOIDir, c.ASR.ReplacePercentage)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ domains_of_interest = [
|
|||||||
"amemv.com"
|
"amemv.com"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
dict_file = "dict.txt"
|
||||||
|
|
||||||
# Proxy server configuration
|
# Proxy server configuration
|
||||||
[proxy]
|
[proxy]
|
||||||
port = 8080
|
port = 8080
|
||||||
@ -11,4 +13,8 @@ port = 8080
|
|||||||
# Traffic dump configuration
|
# Traffic dump configuration
|
||||||
[dump]
|
[dump]
|
||||||
output_dir = "traffic_dumps"
|
output_dir = "traffic_dumps"
|
||||||
DOI_dir = "interest_dumps"
|
DOI_dir = "interest_dumps"
|
||||||
|
|
||||||
|
# ASR obfuscation configuration
|
||||||
|
[asr]
|
||||||
|
replace_percentage = 100
|
||||||
|
|||||||
5
dict.txt
5
dict.txt
@ -1,6 +1,7 @@
|
|||||||
大家好大家好,家人们晚上好,欢迎来到我们的服饰专场直播间,今天不啰嗦,干货铺满、福利装满、好物塞满
|
大家好大家好,家人们晚上好,欢迎来到我们的服饰专场直播间,今天不啰嗦,干货铺满、福利装满、好物塞满
|
||||||
先点点关注不迷路,点个小红心、点个赞,直播间流量走一走,待会儿抽奖不迷糊
|
先点点关注不迷路,点个小红心、点个赞,直播间流量走一走,待会儿抽奖不迷糊
|
||||||
哥哥姐姐们,手机横过来更清楚,清屏看细节,今天所有款式都是我们反复打样、反复试穿、反复挑面料的选品,穿上身的那一刻,只想说:太值了
|
哥哥姐姐们,手机横过来更清楚,清屏看细节,
|
||||||
|
今天所有款式都是我们反复打样、反复试穿、反复挑面料的选品,穿上身的那一刻,只想说:太值了
|
||||||
家人们,先把省钱公式记下来
|
家人们,先把省钱公式记下来
|
||||||
直播间专属价加跨店满减加店铺券加前二百名红包加评论区口令,再叠加神秘福利,怎么叠
|
直播间专属价加跨店满减加店铺券加前二百名红包加评论区口令,再叠加神秘福利,怎么叠
|
||||||
等我口令一喊,评论区清一色刷屏就有
|
等我口令一喊,评论区清一色刷屏就有
|
||||||
@ -182,8 +183,6 @@ A字廓形,显瘦
|
|||||||
前二百名再送小礼物,已经拍的老铁我也补,后台统一备注,老铁吃肉
|
前二百名再送小礼物,已经拍的老铁我也补,后台统一备注,老铁吃肉
|
||||||
链接开二十分钟,过时就真关,想要的抓紧
|
链接开二十分钟,过时就真关,想要的抓紧
|
||||||
补货来了补货来了,白色S再来五零件,手慢了真的没了
|
补货来了补货来了,白色S再来五零件,手慢了真的没了
|
||||||
家人们,今晚五小时不间断,我们从基础百搭,到通勤气质,再到运动居家、秋冬预备、配饰收官,福利一波接一波,感谢一直陪到现在的每一位
|
|
||||||
没抢到的,私信给我,我去沟通能不能再给大家争取一小批补货
|
没抢到的,私信给我,我去沟通能不能再给大家争取一小批补货
|
||||||
已经下单的,放心睡,明早统一打单发货
|
已经下单的,放心睡,明早统一打单发货
|
||||||
还有没关注的点一点关注,明天同一时间我们继续服饰专场,更多新品首发价,只在直播间
|
|
||||||
最后再送一波福利,刷今晚真香,我抽五位送神秘礼品
|
最后再送一波福利,刷今晚真香,我抽五位送神秘礼品
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func TestDictE2E(t *testing.T) {
|
|||||||
t.Fatalf("NewChineseDict failed: %v", err)
|
t.Fatalf("NewChineseDict failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for range 100 {
|
for range 1000 {
|
||||||
char := dict.GetRandomCharacter()
|
char := dict.GetRandomCharacter()
|
||||||
fmt.Printf("%c", char)
|
fmt.Printf("%c", char)
|
||||||
if char == 0 {
|
if char == 0 {
|
||||||
|
|||||||
28
main.go
28
main.go
@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DomainsOfInterest []string `toml:"domains_of_interest"`
|
DomainsOfInterest []string `toml:"domains_of_interest"`
|
||||||
|
DictFile string `toml:"dict_file"`
|
||||||
Proxy struct {
|
Proxy struct {
|
||||||
Port int `toml:"port"`
|
Port int `toml:"port"`
|
||||||
} `toml:"proxy"`
|
} `toml:"proxy"`
|
||||||
@ -35,6 +36,9 @@ type Config struct {
|
|||||||
OutputDir string `toml:"output_dir"`
|
OutputDir string `toml:"output_dir"`
|
||||||
DOIDir string `toml:"DOI_dir"`
|
DOIDir string `toml:"DOI_dir"`
|
||||||
} `toml:"dump"`
|
} `toml:"dump"`
|
||||||
|
ASR struct {
|
||||||
|
ReplacePercentage int `toml:"replace_percentage"`
|
||||||
|
} `toml:"asr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserData struct {
|
type UserData struct {
|
||||||
@ -64,17 +68,7 @@ func main() {
|
|||||||
setConsoleUTF8()
|
setConsoleUTF8()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("MITM Proxy Server v1.3")
|
fmt.Println("MITM Proxy Server v1.4")
|
||||||
|
|
||||||
fmt.Println("Reading dictionary...")
|
|
||||||
dict, err := NewChineseDict("dict.txt")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to load dictionary: %v", err)
|
|
||||||
}
|
|
||||||
Dict = dict
|
|
||||||
fmt.Printf("Dictionary loaded successfully, size=%d\n", Dict.GetCharacterCount())
|
|
||||||
|
|
||||||
fmt.Println("Starting MITM proxy server...")
|
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
config, err := loadConfig("config.toml")
|
config, err := loadConfig("config.toml")
|
||||||
@ -83,6 +77,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println(config.String())
|
log.Println(config.String())
|
||||||
|
|
||||||
|
fmt.Printf("Reading dictionary from %s...\n", config.DictFile)
|
||||||
|
dict, err := NewChineseDict(config.DictFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to load dictionary: %v", err)
|
||||||
|
}
|
||||||
|
Dict = dict
|
||||||
|
fmt.Printf("Dictionary loaded successfully, size=%d\n", Dict.GetCharacterCount())
|
||||||
|
|
||||||
|
fmt.Println("Starting MITM proxy server...")
|
||||||
|
|
||||||
// Create output directories
|
// Create output directories
|
||||||
if err := os.MkdirAll(config.Dump.OutputDir, 0755); err != nil {
|
if err := os.MkdirAll(config.Dump.OutputDir, 0755); err != nil {
|
||||||
log.Fatalf("Failed to create output directory: %v", err)
|
log.Fatalf("Failed to create output directory: %v", err)
|
||||||
@ -241,7 +245,7 @@ func (p *ProxyServer) setupHandlers() {
|
|||||||
var newReqBody []byte = nil
|
var newReqBody []byte = nil
|
||||||
|
|
||||||
if p.isDomainOfInterest(r.Host) {
|
if p.isDomainOfInterest(r.Host) {
|
||||||
newReqBody, err = asrResultObfuscate(r, reqBody)
|
newReqBody, err = asrResultObfuscate(r, reqBody, p.config.ASR.ReplacePercentage)
|
||||||
if err != nil && err.Error() != "not an asr request" {
|
if err != nil && err.Error() != "not an asr request" {
|
||||||
log.Printf("Failed to obfuscate request body: %v", err)
|
log.Printf("Failed to obfuscate request body: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user