Skip to content

Commit

Permalink
added tls support to fox protocol (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
lz-censys authored Feb 18, 2024
1 parent 61b9e47 commit 8333a12
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/fox/log.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fox

import "github.com/zmap/zgrab2"

// FoxLog is the struct returned to the caller.
type FoxLog struct {
// IsFox should always be true (otherwise, the result should have been nil).
Expand Down Expand Up @@ -58,4 +60,7 @@ type FoxLog struct {

// AuthAgentType corresponds to the "authAgentTypeSpecs" field.
AuthAgentType string `json:"auth_agent_type,omitempty"`

// TLSLog is the standard TLS log for the connection, if used.
TLSLog *zgrab2.TLSLog `json:"tls,omitempty"`
}
39 changes: 38 additions & 1 deletion modules/fox/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package fox

import (
"errors"
"net"

log "github.com/sirupsen/logrus"
"github.com/zmap/zgrab2"
)
Expand All @@ -17,6 +19,8 @@ type Flags struct {
zgrab2.BaseFlags

Verbose bool `long:"verbose" description:"More verbose logging, include debug fields in the scan results"`
UseTLS bool `long:"use-tls" description:"Sends probe with a TLS connection. Loads TLS module command options."`
zgrab2.TLSFlags
}

// Module implements the zgrab2.Module interface.
Expand Down Expand Up @@ -98,10 +102,38 @@ func (scanner *Scanner) Protocol() string {
// 4. If the response has the Fox response prefix, mark the scan as having detected the service.
// 5. Attempt to read any / all of the data fields from the Log struct
func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{}, error) {
conn, err := target.Open(&scanner.config.BaseFlags)
var (
conn net.Conn
tlsConn *zgrab2.TLSConnection
err error
)

isSSL := false
conn, err = target.Open(&scanner.config.BaseFlags)
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
}

if scanner.config.UseTLS {
tlsConn, err = scanner.config.TLSFlags.GetTLSConnection(conn)
if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
}

if err := tlsConn.Handshake(); err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
}

conn = tlsConn
isSSL = true
} else {
conn, err = target.Open(&scanner.config.BaseFlags)
}

if err != nil {
return zgrab2.TryGetScanStatus(err), nil, err
}

defer conn.Close()
result := new(FoxLog)

Expand All @@ -113,5 +145,10 @@ func (scanner *Scanner) Scan(target zgrab2.ScanTarget) (zgrab2.ScanStatus, inter
Status: zgrab2.SCAN_PROTOCOL_ERROR,
}
}

if isSSL {
result.TLSLog = conn.(*zgrab2.TLSConnection).GetLog()
}

return zgrab2.TryGetScanStatus(err), result, err
}

0 comments on commit 8333a12

Please sign in to comment.