Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trojan analyzer heuristics #107

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions analyzer/tcp/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ccsPattern = []byte{20, 3, 3, 0, 1, 1}
// TrojanAnalyzer uses length-based heuristics to detect Trojan traffic based on
// its "TLS-in-TLS" nature. The heuristics are trained using a decision tree with
// about 2000 samples. This is highly experimental and is known to have significant
// false positives (about 8% false positives & 2% false negatives).
// false positives (about 9% false positives & 3% false negatives).
// We do NOT recommend directly blocking all positive connections, as this is likely
// to break many normal TLS connections.
type TrojanAnalyzer struct{}
Expand All @@ -36,7 +36,7 @@ type trojanStream struct {
first bool
count bool
rev bool
seq [4]int
seq [3]int
seqIndex int
}

Expand Down Expand Up @@ -69,16 +69,15 @@ func (s *trojanStream) Feed(rev, start, end bool, skip int, data []byte) (u *ana
if s.count {
if rev == s.rev {
// Same direction as last time, just update the number
s.seq[s.seqIndex] = len(data)
s.seq[s.seqIndex] += len(data)
} else {
// Different direction, bump the index
s.seqIndex += 1
if s.seqIndex == 4 {
if s.seqIndex == 3 {
// Time to evaluate
yes := s.seq[0] >= 100 &&
s.seq[1] >= 88 &&
s.seq[2] >= 40 &&
s.seq[3] >= 51
yes := s.seq[0] >= 180 &&
s.seq[1] <= 11000 &&
s.seq[2] >= 40
return &analyzer.PropUpdate{
Type: analyzer.PropUpdateReplace,
M: analyzer.PropMap{
Expand All @@ -87,7 +86,7 @@ func (s *trojanStream) Feed(rev, start, end bool, skip int, data []byte) (u *ana
},
}, true
}
s.seq[s.seqIndex] = len(data)
s.seq[s.seqIndex] += len(data)
s.rev = rev
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/Analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Check https://github.com/XTLS/Trojan-killer for more information.
```json
{
"trojan": {
"seq": [170, 282, 167, 470],
"seq": [680, 4514, 293],
"yes": true
}
}
Expand Down
Loading