feature: MITM
This commit is contained in:
@ -19,6 +19,7 @@ const (
|
||||
Direct AdapterType = iota
|
||||
Reject
|
||||
Compatible
|
||||
Mitm
|
||||
Pass
|
||||
|
||||
Relay
|
||||
@ -182,6 +183,8 @@ func (at AdapterType) String() string {
|
||||
return "Compatible"
|
||||
case Pass:
|
||||
return "Pass"
|
||||
case Mitm:
|
||||
return "Mitm"
|
||||
case Shadowsocks:
|
||||
return "Shadowsocks"
|
||||
case ShadowsocksR:
|
||||
|
@ -31,6 +31,7 @@ const (
|
||||
TUN
|
||||
TUIC
|
||||
INNER
|
||||
MITM
|
||||
)
|
||||
|
||||
type NetWork int
|
||||
@ -80,6 +81,8 @@ func (t Type) String() string {
|
||||
return "Tuic"
|
||||
case INNER:
|
||||
return "Inner"
|
||||
case MITM:
|
||||
return "Mitm"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
@ -144,6 +147,8 @@ type Metadata struct {
|
||||
RemoteDst string `json:"remoteDestination"`
|
||||
// Only domain rule
|
||||
SniffHost string `json:"sniffHost"`
|
||||
// Only Mitm rule
|
||||
UserAgent string `json:"userAgent"`
|
||||
}
|
||||
|
||||
func (m *Metadata) RemoteAddress() string {
|
||||
|
@ -148,8 +148,12 @@ func (p *path) GeoSite() string {
|
||||
return P.Join(p.homeDir, "GeoSite.dat")
|
||||
}
|
||||
|
||||
func (p *path) GetAssetLocation(file string) string {
|
||||
return P.Join(p.homeDir, file)
|
||||
func (p *path) RootCA() string {
|
||||
return p.Resolve("mitm_ca.crt")
|
||||
}
|
||||
|
||||
func (p *path) CAKey() string {
|
||||
return p.Resolve("mitm_ca.key")
|
||||
}
|
||||
|
||||
func (p *path) GetExecutableFullPath() string {
|
||||
|
82
constant/rewrite.go
Normal file
82
constant/rewrite.go
Normal file
@ -0,0 +1,82 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var RewriteTypeMapping = map[string]RewriteType{
|
||||
MitmReject.String(): MitmReject,
|
||||
MitmReject200.String(): MitmReject200,
|
||||
MitmRejectImg.String(): MitmRejectImg,
|
||||
MitmRejectDict.String(): MitmRejectDict,
|
||||
MitmRejectArray.String(): MitmRejectArray,
|
||||
Mitm302.String(): Mitm302,
|
||||
Mitm307.String(): Mitm307,
|
||||
MitmRequestHeader.String(): MitmRequestHeader,
|
||||
MitmRequestBody.String(): MitmRequestBody,
|
||||
MitmResponseHeader.String(): MitmResponseHeader,
|
||||
MitmResponseBody.String(): MitmResponseBody,
|
||||
}
|
||||
|
||||
const (
|
||||
MitmReject RewriteType = iota
|
||||
MitmReject200
|
||||
MitmRejectImg
|
||||
MitmRejectDict
|
||||
MitmRejectArray
|
||||
|
||||
Mitm302
|
||||
Mitm307
|
||||
|
||||
MitmRequestHeader
|
||||
MitmRequestBody
|
||||
|
||||
MitmResponseHeader
|
||||
MitmResponseBody
|
||||
)
|
||||
|
||||
type RewriteType int
|
||||
|
||||
func (rt RewriteType) String() string {
|
||||
switch rt {
|
||||
case MitmReject:
|
||||
return "reject" // 404
|
||||
case MitmReject200:
|
||||
return "reject-200"
|
||||
case MitmRejectImg:
|
||||
return "reject-img"
|
||||
case MitmRejectDict:
|
||||
return "reject-dict"
|
||||
case MitmRejectArray:
|
||||
return "reject-array"
|
||||
case Mitm302:
|
||||
return "302"
|
||||
case Mitm307:
|
||||
return "307"
|
||||
case MitmRequestHeader:
|
||||
return "request-header"
|
||||
case MitmRequestBody:
|
||||
return "request-body"
|
||||
case MitmResponseHeader:
|
||||
return "response-header"
|
||||
case MitmResponseBody:
|
||||
return "response-body"
|
||||
default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
type Rewrite interface {
|
||||
ID() string
|
||||
URLRegx() *regexp.Regexp
|
||||
RuleType() RewriteType
|
||||
RuleRegx() *regexp.Regexp
|
||||
RulePayload() string
|
||||
ReplaceURLPayload([]string) string
|
||||
ReplaceSubPayload(string) string
|
||||
}
|
||||
|
||||
type RewriteRule interface {
|
||||
SearchInRequest(func(Rewrite) bool) bool
|
||||
SearchInResponse(func(Rewrite) bool) bool
|
||||
}
|
@ -23,6 +23,7 @@ const (
|
||||
Network
|
||||
Uid
|
||||
SubRules
|
||||
UserAgent
|
||||
MATCH
|
||||
AND
|
||||
OR
|
||||
@ -67,6 +68,8 @@ func (rt RuleType) String() string {
|
||||
return "Process"
|
||||
case ProcessPath:
|
||||
return "ProcessPath"
|
||||
case UserAgent:
|
||||
return "UserAgent"
|
||||
case MATCH:
|
||||
return "Match"
|
||||
case RuleSet:
|
||||
|
Reference in New Issue
Block a user