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

refactor: improve and align ftp tls error msg #418

Merged
merged 2 commits into from
Apr 12, 2024
Merged
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
30 changes: 15 additions & 15 deletions modules/ftp/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ func (ftp *Connection) GetFTPSCertificates() error {
ftpsReady, err := ftp.SetupFTPS()

if err != nil {
return err
return fmt.Errorf("error setting up FTPS: %w", err)
}
if !ftpsReady {
return nil
}
var conn *zgrab2.TLSConnection
if conn, err = ftp.config.TLSFlags.GetTLSConnection(ftp.conn); err != nil {
return err
return fmt.Errorf("error setting up TLS connection: %w", err)
}
ftp.results.TLSLog = conn.GetLog()

Expand All @@ -232,25 +232,25 @@ func (ftp *Connection) GetFTPSCertificates() error {
// AUTH TLS succeeds, but the handshake fails, dumping
// "error:1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher"
// to the socket.
return err
return fmt.Errorf("TLS handshake failed: %w", err)
}
ftp.conn = conn
return nil
}

// Scan performs the configured scan on the FTP server, as follows:
// * Read the banner into results.Banner (if it is not a 2XX response, bail)
// * If the FTPAuthTLS flag is not set, finish.
// * Send the AUTH TLS command to the server. If the response is not 2XX, then
// send the AUTH SSL command. If the response is not 2XX, then finish.
// * Perform ths TLS handshake / any configured TLS scans, populating
// results.TLSLog.
// * Return SCAN_SUCCESS, &results, nil
// - Read the banner into results.Banner (if it is not a 2XX response, bail)
// - If the FTPAuthTLS flag is not set, finish.
// - Send the AUTH TLS command to the server. If the response is not 2XX, then
// send the AUTH SSL command. If the response is not 2XX, then finish.
// - Perform ths TLS handshake / any configured TLS scans, populating
// results.TLSLog.
// - Return SCAN_SUCCESS, &results, nil
func (s *Scanner) Scan(t zgrab2.ScanTarget) (status zgrab2.ScanStatus, result interface{}, thrown error) {
var err error
conn, err := t.Open(&s.config.BaseFlags)
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
return zgrab2.TryGetScanStatus(err), nil, fmt.Errorf("error opening connection: %w", err)
}
cn := conn
defer func() {
Expand All @@ -261,25 +261,25 @@ func (s *Scanner) Scan(t zgrab2.ScanTarget) (status zgrab2.ScanStatus, result in
if s.config.ImplicitTLS {
tlsConn, err := s.config.TLSFlags.GetTLSConnection(conn)
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
return zgrab2.TryGetScanStatus(err), nil, fmt.Errorf("error setting up TLS connection: %w", err)
}
results.ImplicitTLS = true
results.TLSLog = tlsConn.GetLog()
err = tlsConn.Handshake()
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
return zgrab2.TryGetScanStatus(err), nil, fmt.Errorf("TLS handshake failed: %w", err)
}
cn = tlsConn
}

ftp := Connection{conn: cn, config: s.config, results: results}
is200Banner, err := ftp.GetFTPBanner()
if err != nil {
return zgrab2.TryGetScanStatus(err), &ftp.results, err
return zgrab2.TryGetScanStatus(err), &ftp.results, fmt.Errorf("error reading FTP banner: %w", err)
}
if s.config.FTPAuthTLS && is200Banner {
if err := ftp.GetFTPSCertificates(); err != nil {
return zgrab2.SCAN_APPLICATION_ERROR, &ftp.results, err
return zgrab2.TryGetScanStatus(err), &ftp.results, fmt.Errorf("error getting FTPS certificates: %w", err)
}
}
return zgrab2.SCAN_SUCCESS, &ftp.results, nil
Expand Down
Loading