Documentation
¶
Overview ¶
Package portscan probes TCP ports. Phase 1 ships only the TCP connect scanner against a single (addr, port) pair. The SYN scanner and the worker-pool wiring land in Phase 2 / Phase 6.
Index ¶
- Constants
- Variables
- func ParsePorts(spec string) ([]uint16, error)
- func Scan(ctx context.Context, it *target.Iterator, cfg Config) <-chan HostResult
- func SynScan(_ context.Context, _ *target.Iterator, _ Config) (<-chan HostResult, error)
- func Top100() []uint16
- func Top1000() []uint16
- type Config
- type HostResult
- type Result
- type ScriptFinding
- type State
Constants ¶
const SYNAvailable = false
SYNAvailable reports whether this build of scry includes the raw-socket SYN scanner. Default builds return false; builds with `-tags rawsock` return true.
Variables ¶
"SYN scanning is not compiled into this binary; rebuild with `-tags rawsock` and install libpcap (Linux) or Npcap (Windows)")
ErrSYNUnavailable is returned by the CLI when --syn is requested on a default build.
Functions ¶
func ParsePorts ¶
ParsePorts parses the -p flag into a deduplicated, order-preserving slice of ports.
Supported forms (comma-separated, mixable):
22 single port 22,80,443 list 1-1024 range (inclusive) - all ports 1..65535 (-p-) top100 / top1000 bundled shortlists (see top.go)
func Scan ¶
Scan iterates addresses from it and probes each Config.Ports (or runs TCP ping when Config.PingOnly is set). Results stream on the returned channel; the channel closes when iteration and in-flight work finish or when ctx is cancelled.
Types ¶
type Config ¶
type Config struct {
Ports []uint16 // required unless PingOnly
Timeout time.Duration // per-probe dial timeout (default 500ms)
Retries int // retries on filtered (default 0)
Concurrency int // max sockets in flight (default 2000)
HostParall int // max hosts in flight (default 100)
// PingOnly skips the port scan and runs TCP ping discovery only (-sn).
PingOnly bool
// Banner enables a passive banner grab on every open port.
Banner bool
// Progress receives one Tick per host completed. SetTotal is called
// once up front using target.Iterator.Total(). nil → progress.NewNoop.
Progress progress.Reporter
// Resolver enables reverse DNS enrichment. nil disables it (equivalent
// to --no-dns at the CLI level).
Resolver *resolver.Cache
// ScriptEngine runs Lua scripts against each open port. nil disables.
ScriptEngine *script.Engine
// Rate bounds SYN packet emission (packets-per-second). 0 disables
// rate limiting. TCP-connect mode ignores this; the socket semaphore
// is the pacer there.
Rate int
// Adaptive enables the adaptive rate limiter: the SYN sender starts
// at max(Rate/4, 100) pps and scales up/down based on the observed
// probe error rate. Ignored when Rate is 0 or when the scan is
// TCP-connect (not --syn).
Adaptive bool
}
Config tunes a Scan run. Defaults are speed-first: short timeout, no retries, generous concurrency. Raise Timeout + Retries for accuracy on WAN or lossy links.
type HostResult ¶
type HostResult struct {
Addr netip.Addr
Hostname string // populated when Config.Resolver was set and PTR succeeded
Started time.Time
Elapsed time.Duration
Results []Result
Discovery *discovery.Result // populated in PingOnly mode
}
HostResult aggregates all port results for a single host, plus any reverse-DNS and discovery metadata collected in parallel with the scan.
func (HostResult) OpenPorts ¶
func (h HostResult) OpenPorts() []uint16
OpenPorts returns the list of open ports (as found, not sorted).
func (HostResult) Up ¶
func (h HostResult) Up() bool
Up reports whether any probe returned StateOpen, or (in PingOnly mode) whether discovery reached the host.
type Result ¶
type Result struct {
Addr netip.Addr
Port uint16
State State
RTT time.Duration
Err error // populated for StateError
Banner string // populated when banner grab is enabled and data was received
Findings []ScriptFinding // populated when Config.ScriptEngine is set
}
Result is the outcome of a single probe.
func TCPConnect ¶
TCPConnect performs one TCP-connect probe against addr:port using the supplied timeout. State classification:
open — TCP handshake completed closed — received RST / ECONNREFUSED filtered — timeout reached with no response error — some other error (unreachable host, too many open files, …)
type ScriptFinding ¶
ScriptFinding is one output line produced by a user Lua script.