Skip to content

Commit

Permalink
Add TLS support for fox (#403)
Browse files Browse the repository at this point in the history
* Add TLS support for fox module

* Add TLS to the schema

---------

Co-authored-by: Raymond Nook <[email protected]>
  • Loading branch information
Seanstoppable and developStorm committed May 22, 2024
1 parent 6106c1a commit ab1db71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/fox/log.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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 +62,6 @@ type FoxLog struct {

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

TLSLog *zgrab2.TLSLog `json:"tls,omitempty"`
}
29 changes: 28 additions & 1 deletion modules/fox/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
log "github.com/sirupsen/logrus"
"github.com/zmap/zgrab2"
"net"
)

// Flags holds the command-line configuration for the fox scan module.
Expand All @@ -17,6 +18,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,12 +101,36 @@ 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
)

conn, err = target.Open(&scanner.config.BaseFlags)
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
} else {
conn, err = target.Open(&scanner.config.BaseFlags)
}

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

defer conn.Close()
result := new(FoxLog)
if tlsConn != nil {
result.TLSLog = tlsConn.GetLog()
}

err = GetFoxBanner(result, conn)
if !result.IsFox {
Expand Down
1 change: 1 addition & 0 deletions zgrab2_schemas/zgrab2/fox.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"brand_id": String(),
"sys_info": String(),
"agent_auth_type": String(),
"tls": zgrab2.tls_log,
}
)
},
Expand Down

0 comments on commit ab1db71

Please sign in to comment.