-
Notifications
You must be signed in to change notification settings - Fork 309
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
Ecubit/fix false positives #262
Changes from 8 commits
5208cc5
d3e2899
b68e503
e663226
3d4e783
1316e56
8f645d6
e4218eb
532a496
d6c83fd
734fdca
7754d3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
// Scanner for POP3 protocol | ||
// https://www.ietf.org/rfc/rfc1939.txt | ||
|
||
package pop3 | ||
|
||
import ( | ||
"net" | ||
"regexp" | ||
"errors" | ||
"strings" | ||
"io" | ||
|
||
"github.com/zmap/zgrab2" | ||
) | ||
|
@@ -17,15 +23,28 @@ type Connection struct { | |
Conn net.Conn | ||
} | ||
|
||
// Verifies that a POP3 banner begins with a valid status indicator | ||
func VerifyPOP3Contents(n int, ret []byte) (string, error) { | ||
s := string(ret[0:n]) | ||
if strings.HasPrefix(s, "+OK "){ | ||
return s, nil | ||
} | ||
if strings.HasPrefix(s, "+ERR "){ | ||
return s, zgrab2.NewScanError(zgrab2.SCAN_APPLICATION_ERROR, errors.New("POP3 Reported Error")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment as for imap; this is actually a success case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the contents of the modbus scanner, it seems that SCAN_APPLICATION_ERROR is a success case - indicating that a valid response was received but the server reported back an error in the final ScanResult There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though I just realized that string should be "-ERR" regardless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For example, from banner, err := conn.ReadResponse()
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
} |
||
} | ||
return s, zgrab2.NewScanError(zgrab2.SCAN_PROTOCOL_ERROR, errors.New("Invalid response for POP3")) | ||
} | ||
|
||
// ReadResponse reads from the connection until it matches the pop3EndRegex. Copied from the original zgrab. | ||
// TODO: Catch corner cases, parse out success/error character. | ||
// TODO: Catch corner cases | ||
func (conn *Connection) ReadResponse() (string, error) { | ||
ret := make([]byte, readBufferSize) | ||
n, err := zgrab2.ReadUntilRegex(conn.Conn, ret, pop3EndRegex) | ||
if err != nil { | ||
return "", nil | ||
// Don't quit for timeouts since we might have gotten relevant data still | ||
if err != nil && err != io.EOF && !zgrab2.IsTimeoutError(err) { | ||
return "", err | ||
} | ||
return string(ret[0:n]), nil | ||
return VerifyPOP3Contents(n, ret) | ||
} | ||
|
||
// SendCommand sends a command, followed by a CRLF, then wait for / read the server's response. | ||
|
@@ -34,4 +53,4 @@ func (conn *Connection) SendCommand(cmd string) (string, error) { | |
return "", err | ||
} | ||
return conn.ReadResponse() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package smtp | |
import ( | ||
"net" | ||
"regexp" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/zmap/zgrab2" | ||
) | ||
|
@@ -18,15 +20,28 @@ type Connection struct { | |
Conn net.Conn | ||
} | ||
|
||
// Verify that an SMTP code was returned, and that it is a successful one! | ||
func VerifySMTPContents(n int, ret []byte) (string, error){ | ||
s := string(ret[:n]) | ||
code, err := getSMTPCode(s) | ||
if err != nil { | ||
return s, err | ||
} | ||
if code < 200 || code >= 300 { | ||
return s, zgrab2.NewScanError(zgrab2.SCAN_APPLICATION_ERROR, fmt.Errorf("SMTP returned error code %d", code)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment; if we wanted to vet that it is a valid code, anything returned as a code from the SMTP RFC would qualify as success. However, I wonder if we even need to be that strict (in case there are non-standard extensions out there)? |
||
} | ||
return s, nil | ||
} | ||
|
||
// ReadResponse reads from the connection until it matches the smtpEndRegex. Copied from the original zgrab. | ||
// TODO: Catch corner cases, parse out response code. | ||
// TODO: Catch corner cases | ||
func (conn *Connection) ReadResponse() (string, error) { | ||
ret := make([]byte, readBufferSize) | ||
n, err := zgrab2.ReadUntilRegex(conn.Conn, ret, smtpEndRegex) | ||
if err != nil { | ||
return "", nil | ||
if err != nil && err != io.EOF && !zgrab2.IsTimeoutError(err) { | ||
return "", err | ||
} | ||
return string(ret[0:n]), nil | ||
return VerifySMTPContents(n, ret) | ||
} | ||
|
||
// SendCommand sends a command, followed by a CRLF, then wait for / read the server's response. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually an error, at least for us. Since the goal of zgrab2 is to identify services, receiving a well-formed error response is a good thing, as it is a positive indication that (in this case) we are talking to an imap server. (This also applies to the
* BAD
case, as well).There is also
* PREAUTH
and* BYE