Skip to content

Commit

Permalink
Honor port override when composing URL (#233)
Browse files Browse the repository at this point in the history
Commit a38194a added an optional port override as part of the
scan target.  The HTTP and IPP modules, however, still compose
the URL (and select http vs https) by ignoring the override.

This checks for the override, and if present uses the scan target
port.  Otherwise, it falls back to the config port.

#233
  • Loading branch information
codyprime authored and dadrian committed Nov 20, 2019
1 parent 4c1161b commit d12c70e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion modules/http/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,14 @@ func (scanner *Scanner) newHTTPScan(t *zgrab2.ScanTarget) *scan {
if host == "" {
host = t.IP.String()
}
ret.url = getHTTPURL(scanner.config.UseHTTPS, host, uint16(scanner.config.BaseFlags.Port), scanner.config.Endpoint)
// Scanner Target port overrides config flag port
var port uint16
if t.Port != nil {
port = uint16(*t.Port)
} else {
port = uint16(scanner.config.BaseFlags.Port)
}
ret.url = getHTTPURL(scanner.config.UseHTTPS, host, port, scanner.config.Endpoint)

return &ret
}
Expand Down
9 changes: 8 additions & 1 deletion modules/ipp/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,15 @@ func (scanner *Scanner) newIPPScan(target *zgrab2.ScanTarget, tls bool) *scan {
// FIXME: Change this, since ipp uri's cannot contain an IP address. Still valid for HTTP
host = target.IP.String()
}
// Scanner Target port overrides config flag port
var port uint16
if target.Port != nil {
port = uint16(*target.Port)
} else {
port = uint16(scanner.config.BaseFlags.Port)
}
// FIXME: ?Should just use endpoint "/", since we get the same response as "/ipp" on CUPS??
newScan.url = getHTTPURL(tls, host, uint16(scanner.config.BaseFlags.Port), "/ipp")
newScan.url = getHTTPURL(tls, host, port, "/ipp")
return &newScan
}

Expand Down

0 comments on commit d12c70e

Please sign in to comment.