|
|
@ -13,33 +13,29 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
type Config struct {
|
|
|
|
debug int
|
|
|
|
Version bool // show version
|
|
|
|
version bool
|
|
|
|
Addr string // proxy listen addr
|
|
|
|
certPath string
|
|
|
|
WebAddr string // web interface listen addr
|
|
|
|
|
|
|
|
SslInsecure bool // not verify upstream server SSL/TLS certificates.
|
|
|
|
addr string
|
|
|
|
IgnoreHosts []string // a list of ignore hosts
|
|
|
|
webAddr string
|
|
|
|
AllowHosts []string // a list of allow hosts
|
|
|
|
sslInsecure bool
|
|
|
|
CertPath string // path of generate cert files
|
|
|
|
|
|
|
|
Debug int // debug mode: 1 - print debug log, 2 - show debug from
|
|
|
|
dump string // dump filename
|
|
|
|
Dump string // dump filename
|
|
|
|
dumpLevel int // dump level
|
|
|
|
DumpLevel int // dump level: 0 - header, 1 - header + body
|
|
|
|
|
|
|
|
MapperDir string // mapper files dirpath
|
|
|
|
mapperDir string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ignoreHosts []string
|
|
|
|
|
|
|
|
allowHosts []string
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
config := loadConfig()
|
|
|
|
config := loadConfig()
|
|
|
|
|
|
|
|
|
|
|
|
if config.debug > 0 {
|
|
|
|
if config.Debug > 0 {
|
|
|
|
rawLog.SetFlags(rawLog.LstdFlags | rawLog.Lshortfile)
|
|
|
|
rawLog.SetFlags(rawLog.LstdFlags | rawLog.Lshortfile)
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if config.debug == 2 {
|
|
|
|
if config.Debug == 2 {
|
|
|
|
log.SetReportCaller(true)
|
|
|
|
log.SetReportCaller(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.SetOutput(os.Stdout)
|
|
|
|
log.SetOutput(os.Stdout)
|
|
|
@ -48,11 +44,11 @@ func main() {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
opts := &proxy.Options{
|
|
|
|
opts := &proxy.Options{
|
|
|
|
Debug: config.debug,
|
|
|
|
Debug: config.Debug,
|
|
|
|
Addr: config.addr,
|
|
|
|
Addr: config.Addr,
|
|
|
|
StreamLargeBodies: 1024 * 1024 * 5,
|
|
|
|
StreamLargeBodies: 1024 * 1024 * 5,
|
|
|
|
SslInsecure: config.sslInsecure,
|
|
|
|
SslInsecure: config.SslInsecure,
|
|
|
|
CaRootPath: config.certPath,
|
|
|
|
CaRootPath: config.CertPath,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p, err := proxy.NewProxy(opts)
|
|
|
|
p, err := proxy.NewProxy(opts)
|
|
|
@ -60,34 +56,34 @@ func main() {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if config.version {
|
|
|
|
if config.Version {
|
|
|
|
fmt.Println("go-mitmproxy: " + p.Version)
|
|
|
|
fmt.Println("go-mitmproxy: " + p.Version)
|
|
|
|
os.Exit(0)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Infof("go-mitmproxy version %v\n", p.Version)
|
|
|
|
log.Infof("go-mitmproxy version %v\n", p.Version)
|
|
|
|
|
|
|
|
|
|
|
|
if len(config.ignoreHosts) > 0 {
|
|
|
|
if len(config.IgnoreHosts) > 0 {
|
|
|
|
p.SetShouldInterceptRule(func(address string) bool {
|
|
|
|
p.SetShouldInterceptRule(func(address string) bool {
|
|
|
|
return !matchHost(address, config.ignoreHosts)
|
|
|
|
return !matchHost(address, config.IgnoreHosts)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(config.allowHosts) > 0 {
|
|
|
|
if len(config.AllowHosts) > 0 {
|
|
|
|
p.SetShouldInterceptRule(func(address string) bool {
|
|
|
|
p.SetShouldInterceptRule(func(address string) bool {
|
|
|
|
return matchHost(address, config.allowHosts)
|
|
|
|
return matchHost(address, config.AllowHosts)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p.AddAddon(&proxy.LogAddon{})
|
|
|
|
p.AddAddon(&proxy.LogAddon{})
|
|
|
|
p.AddAddon(web.NewWebAddon(config.webAddr))
|
|
|
|
p.AddAddon(web.NewWebAddon(config.WebAddr))
|
|
|
|
|
|
|
|
|
|
|
|
if config.dump != "" {
|
|
|
|
if config.Dump != "" {
|
|
|
|
dumper := addon.NewDumperWithFilename(config.dump, config.dumpLevel)
|
|
|
|
dumper := addon.NewDumperWithFilename(config.Dump, config.DumpLevel)
|
|
|
|
p.AddAddon(dumper)
|
|
|
|
p.AddAddon(dumper)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if config.mapperDir != "" {
|
|
|
|
if config.MapperDir != "" {
|
|
|
|
mapper := addon.NewMapper(config.mapperDir)
|
|
|
|
mapper := addon.NewMapper(config.MapperDir)
|
|
|
|
p.AddAddon(mapper)
|
|
|
|
p.AddAddon(mapper)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|