scan

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: BSD-3-Clause Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scan computes the JA4TScan value of a host by an active TCP scan.

JA4TScan is the one FoxIO method that sends packets. The scanner sends one TCP SYN to each target, and it reads the SYN-ACK of the target and every retransmission of it. The value describes how the TCP stack of the target answers and how it retransmits. FoxIO publishes the scanner at `https://github.com/FoxIO-LLC/ja4tscan`, and this project reads commit `d01bfec4`.

**The package is opt-in and separate.** No passive fingerprinter and no `Processor` imports it, so a capture read sends no packet. `internal/repocheck` holds that boundary. The maintainer ruled it on 2026-09-30, and `Crank-Git/ja4plus#775` holds the ruling.

**The package changes no firewall state.** FirewallRules returns the rules that the operator adds, so that the kernel of the scanning host sends no RST for the SYN-ACK of a target. The package never applies them.

The package reads IPv4 alone. OpenNetwork sends through the link-layer handle of `internal/capture`, and the maintainer ruled that placement on 2026-10-01 in #796. A build for macOS needs the `libpcap` build tag for that handle.

The package writes nothing to standard output and nothing to standard error. Each warning reaches the OnWarning function of Config, and `cmd/ja4plus` prints it.

Index

Constants

View Source
const MaxTargets = 10000

MaxTargets is the largest count of targets that the state table of a Scanner holds. The FoxIO module holds the same count at `ja4tscan/module_ja4tscan.c:169`, and FR-active-scan-18 of the port states it.

View Source
const NoRetransmitWait = 8 * time.Second

NoRetransmitWait is the wait when the scan reads the first response alone. It is the zmap default that the same rule records.

View Source
const ResetValue = "0_rst-ack"

ResetValue is the value of a target whose first response carries RST.

The FoxIO wrapper publishes this value at `ja4tscan/ja4tscan.py:44-45`, and the maintainer ruled it for every such target on 2026-09-30.

View Source
const RetransmitWait = 120 * time.Second

RetransmitWait is the wait after the SYN of a target for its later responses. S13 of the port's `docs/specs/foxio/JA4TScan.md` at tag `v1.3.0` records the cooldown of 120 seconds that the FoxIO wrapper passes to zmap.

Variables

This section is empty.

Functions

func FirewallRules

func FirewallRules(goos string) string

FirewallRules returns the firewall rules that the operator adds before a scan, as lines of text, for the operating system that goos names.

The maintainer ruled on 2026-09-30 that the scanner states the rules and never applies them. Linux gets the four `iptables` rules of the FoxIO wrapper and their four removals. Every other system gets the four pf rules.

func ParseTargets

func ParseTargets(text string) (iter.Seq[netip.Addr], error)

ParseTargets returns the IPv4 targets that one target argument names.

FR-active-scan-14 of the port names three forms: one address, one network in CIDR form, or a file that holds one address on each line. A network names every address it holds, as zmap does, and the sequence holds no list in memory. A file names each address once.

It returns an error before the first SYN in three cases.

  • The argument names an IPv6 target, or a file line holds one.
  • A file line holds no IPv4 address. The error names the line.
  • The argument is no address, no network and no readable file.

func Value

func Value(responses []Response) (string, bool)

Value returns the JA4TScan value of one target, and false when the responses hold none.

The responses answer the SYN of the target, in arrival order. A first response that carries RST produces ResetValue. Otherwise part a to part d come from the first SYN-ACK, and each later SYN-ACK adds one delay to part e. A RST after a SYN-ACK ends the value. A response that carries neither SYN and ACK nor RST adds nothing.

The maintainer ruled on 2026-09-30 that the value uses the JA4TS form, at `Crank-Git/ja4plus#775`. So Value gives the responses to a JA4TS fingerprinter and keeps its last value, and one rule writes both methods. A scan value and the passive JA4TS value of the same responses are equal.

Types

type Config

type Config struct {
	// Port is the TCP port of every target. It is above zero.
	Port uint16
	// Rate is the SYN count for each second. It is above zero, and one second divided by it
	// fits a time.Duration.
	Rate float64
	// Retransmit is true to read every retransmission for RetransmitWait. False reads the
	// first response alone for NoRetransmitWait.
	Retransmit bool
	// Network sends each SYN and receives each response.
	Network Network
	// Clock returns the time that the wait reads. Nil reads time.Now.
	Clock func() time.Time
	// OnResult takes each result. Nil drops it.
	OnResult func(Result)
	// OnWarning takes each warning line. Nil drops it.
	OnWarning func(string)
	// Rand supplies the source port and the sequence number of each SYN. Nil reads the
	// global source of `math/rand/v2`.
	Rand *rand.Rand
}

Config states what NewScanner needs.

type Network

type Network interface {
	// Send sends one SYN to the target from the source port, with the sequence number.
	// It returns the source address of the SYN, and false when it sent nothing. An error
	// states a socket failure, and it stops the scan.
	Send(target netip.Addr, srcPort uint16, sequence uint32) (netip.Addr, bool, error)
	// Receive waits at most the timeout for one Ethernet frame. It returns the frame and
	// its receive time, and false when no frame arrived. An error states a socket
	// failure, and it stops the scan.
	Receive(timeout time.Duration) ([]byte, time.Time, bool, error)
	// Close releases the network.
	Close() error
}

Network sends the SYN of each target and receives the frames that answer it.

OpenNetwork returns the network of the host. A test passes a fake network, so a scan runs with no packet and no socket.

**One Network serves one goroutine.** The Scanner that holds it makes every call from the goroutine that runs Scanner.Run, so an implementation needs no lock. A caller that shares one Network between two goroutines guards each call itself. The network of OpenNetwork is not safe for concurrent use.

func OpenNetwork

func OpenNetwork(port uint16, first netip.Addr, warn func(string)) (Network, error)

OpenNetwork returns the network of this host for a scan of the port. The route to the first target names the interface, and every SYN leaves through that interface.

The SYN leaves as an Ethernet frame, as zmap writes it. The send primitive lives in `internal/capture`, and the maintainer ruled that placement on 2026-10-01 in #796. Each warning reaches the warn function.

It returns an error when the first target routes through a loopback interface, when the interface holds no Ethernet address, and when the host refuses the link. `capture.PermissionDenied` reads a refused privilege. A macOS build without the `libpcap` build tag returns an error that names the tag.

**The returned Network serves one goroutine, and it is not safe for concurrent use.** It holds a next-hop cache and a list of pending frames, and no lock guards either one. The goroutine that runs the Scanner makes every call, and that goroutine calls Close after the scan. `.claude/rules/concurrency.md` states the shard pattern for one `Processor`, and one network for each Scanner is the same pattern. OpenNetwork itself holds no shared state, so two goroutines can each open a network of their own.

type Response

type Response struct {
	// Time is the receive time of the response.
	Time time.Time
	// Header holds the TCP header as received, from the source port to the last option
	// byte. It holds no payload.
	Header []byte
}

Response holds one TCP response of a target that the value reads.

type Result

type Result struct {
	// Value is the JA4TScan value.
	Value string
	// Target is the address of the target.
	Target netip.Addr
	// TargetPort is the scanned port.
	TargetPort uint16
	// Scanner is the address of the scanning host.
	Scanner netip.Addr
	// ScannerPort is the source port of the SYN.
	ScannerPort uint16
	// Time is the receive time of the last response that the value reads.
	Time time.Time
}

Result holds the value of one target and the endpoints of its responses.

The target sent the responses that the value reads, so the target is the source. `ja4tscan/module_ja4tscan.c:153` records the same address as `ip_src_num`.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner sends one SYN to each target and writes one result for each target that answers.

The state table holds each target from its SYN until its wait ends, in send order. It holds at most MaxTargets entries, and no entry outlives its wait. The scanner sends no SYN while the table is full, so no target loses its wait.

**One Scanner serves one goroutine.** It holds a state table that no lock guards, and it owns its Network for the whole scan. Run one Scanner for each scan. No SyncProcessor pattern applies, because the scan path is not the packet path of `Processor`.

func NewScanner

func NewScanner(config Config) (*Scanner, error)

NewScanner returns a Scanner for the configuration. It returns an error in four cases.

  • The port is zero.
  • The rate is not a finite number above zero.
  • The interval of the rate does not fit a time.Duration.
  • The configuration names no network.

func (*Scanner) Flush

func (s *Scanner) Flush()

Flush ends the wait of every target now, and it writes each result. A caller runs it after an interrupt, so each target writes what it already sent.

func (*Scanner) Run

func (s *Scanner) Run(targets iter.Seq[netip.Addr]) error

Run sends one SYN to each target, and it returns when the wait of the last target ends.

A target that the table already holds gets no second SYN. Run returns the first error of the network, and the results that it wrote before that error stay written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL