增加两个设置,可以自定义ASR混淆概率和字典文件
This commit is contained in:
parent
b61861cb67
commit
3fe77430f2
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/" {
|
||||
return nil, fmt.Errorf("not an asr request")
|
||||
}
|
||||
if !shouldApplyASRReplacement(replacePercentage) {
|
||||
return nil, nil
|
||||
}
|
||||
obj := SpeechRecognitionResponse{}
|
||||
err := obj.FromJSON(string(body))
|
||||
if err != nil {
|
||||
@ -133,3 +136,13 @@ func asrResultObfuscate(r *http.Request, body []byte) ([]byte, error) {
|
||||
}
|
||||
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.Dump.OutputDir = "traffic_dumps"
|
||||
config.Dump.DOIDir = "interest_dumps"
|
||||
config.DictFile = "dict.txt"
|
||||
config.ASR.ReplacePercentage = 100
|
||||
|
||||
// Parse the TOML file
|
||||
_, 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)
|
||||
}
|
||||
|
||||
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
|
||||
if err := createDumpDirectories(config); err != nil {
|
||||
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 {
|
||||
return fmt.Sprintf("Config{DomainsOfInterest: %v, Proxy: {Port: %d}, Dump: {OutputDir: %s, DOI_dir: %s}}",
|
||||
c.DomainsOfInterest, c.Proxy.Port, c.Dump.OutputDir, c.Dump.DOIDir)
|
||||
return fmt.Sprintf("Config{DomainsOfInterest: %v, DictFile: %s, Proxy: {Port: %d}, Dump: {OutputDir: %s, DOI_dir: %s}, ASR: {ReplacePercentage: %d}}",
|
||||
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"
|
||||
]
|
||||
|
||||
dict_file = "dict.txt"
|
||||
|
||||
# Proxy server configuration
|
||||
[proxy]
|
||||
port = 8080
|
||||
@ -12,3 +14,7 @@ port = 8080
|
||||
[dump]
|
||||
output_dir = "traffic_dumps"
|
||||
DOI_dir = "interest_dumps"
|
||||
|
||||
# ASR obfuscation configuration
|
||||
[asr]
|
||||
replace_percentage = 100
|
||||
|
||||
24
main.go
24
main.go
@ -28,6 +28,7 @@ import (
|
||||
|
||||
type Config struct {
|
||||
DomainsOfInterest []string `toml:"domains_of_interest"`
|
||||
DictFile string `toml:"dict_file"`
|
||||
Proxy struct {
|
||||
Port int `toml:"port"`
|
||||
} `toml:"proxy"`
|
||||
@ -35,6 +36,9 @@ type Config struct {
|
||||
OutputDir string `toml:"output_dir"`
|
||||
DOIDir string `toml:"DOI_dir"`
|
||||
} `toml:"dump"`
|
||||
ASR struct {
|
||||
ReplacePercentage int `toml:"replace_percentage"`
|
||||
} `toml:"asr"`
|
||||
}
|
||||
|
||||
type UserData struct {
|
||||
@ -66,8 +70,15 @@ func main() {
|
||||
|
||||
fmt.Println("MITM Proxy Server v1.4")
|
||||
|
||||
fmt.Println("Reading dictionary...")
|
||||
dict, err := NewChineseDict("dict.txt")
|
||||
// Load configuration
|
||||
config, err := loadConfig("config.toml")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
@ -76,13 +87,6 @@ func main() {
|
||||
|
||||
fmt.Println("Starting MITM proxy server...")
|
||||
|
||||
// Load configuration
|
||||
config, err := loadConfig("config.toml")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
log.Println(config.String())
|
||||
|
||||
// Create output directories
|
||||
if err := os.MkdirAll(config.Dump.OutputDir, 0755); err != nil {
|
||||
log.Fatalf("Failed to create output directory: %v", err)
|
||||
@ -241,7 +245,7 @@ func (p *ProxyServer) setupHandlers() {
|
||||
var newReqBody []byte = nil
|
||||
|
||||
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" {
|
||||
log.Printf("Failed to obfuscate request body: %v", err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user