Skip to content

Commit d25b7ad

Browse files
authored
fix for smtp module (#297)
The SMTP module was matching on "STMP" when verifying the contents of the scan response. This PR fixes the typo and adds a test for the VerifySMTPContents() function.
1 parent d9ed4f1 commit d25b7ad

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

modules/smtp/scanner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func VerifySMTPContents(banner string) (zgrab2.ScanStatus, int) {
214214
case err == nil && (code < 200 || code >= 300):
215215
return zgrab2.SCAN_APPLICATION_ERROR, code
216216
case err == nil,
217-
strings.Contains(banner, "STMP"),
217+
strings.Contains(banner, "SMTP"),
218218
strings.Contains(lowerBanner, "blacklist"),
219219
strings.Contains(lowerBanner, "abuse"),
220220
strings.Contains(lowerBanner, "rbl"),

modules/smtp/scanner_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package smtp
2+
3+
import (
4+
"github.com/zmap/zgrab2"
5+
"testing"
6+
)
7+
8+
func TestVerifySMTPContents(t *testing.T) {
9+
type Test struct {
10+
Banner string
11+
ExpectedStatus zgrab2.ScanStatus
12+
ExpectedCode int
13+
}
14+
testTable := map[string]Test{
15+
"success with code": {
16+
Banner: `220-some.host.com ESMTP Exim 4.93 #2 Thu, 04 Feb 2021 13:34:12 -0500
17+
220-We do not authorize the use of this system to transport unsolicited,
18+
220 and/or bulk e-mail.`,
19+
ExpectedStatus: zgrab2.SCAN_SUCCESS,
20+
ExpectedCode: 0,
21+
},
22+
"success without code": {
23+
Banner: `ESMTP Exim 4.93 #2 Thu, 04 Feb 2021 13:34:12 -0500
24+
220-We do not authorize the use of this system to transport unsolicited,
25+
220 and/or bulk e-mail.`,
26+
ExpectedStatus: zgrab2.SCAN_SUCCESS,
27+
ExpectedCode: 0,
28+
},
29+
"invalid protocol": {
30+
Banner: "gibberish that doesnt match expected response",
31+
ExpectedStatus: zgrab2.SCAN_PROTOCOL_ERROR,
32+
ExpectedCode: 0,
33+
},
34+
"error response": {
35+
Banner: "500-some.host.com ESMTP something went horribly wrong.",
36+
ExpectedStatus: zgrab2.SCAN_APPLICATION_ERROR,
37+
ExpectedCode: 500,
38+
},
39+
}
40+
41+
for name, test := range testTable {
42+
t.Run(name, func(t *testing.T) {
43+
status, code := VerifySMTPContents(test.Banner)
44+
if status != test.ExpectedStatus {
45+
t.Errorf("recieved unexpected status: %s, wanted: %s", status, test.ExpectedStatus)
46+
}
47+
if code != test.ExpectedCode {
48+
t.Errorf("recieved unexpected code: %d, wanted: %d", code, test.ExpectedCode)
49+
}
50+
})
51+
}
52+
53+
}

0 commit comments

Comments
 (0)