Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for udp payload #1051

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions v2/pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Options struct {
ScanAllIPS bool // Scan all the ips
IPVersion goflags.StringSlice // IP Version to use while resolving hostnames
ScanType string // Scan Type
ConnectPayload string // Payload to use with CONNECT scan types
Proxy string // Socks5 proxy
ProxyAuth string // Socks5 proxy authentication (username:password)
Resolvers string // Resolvers (comma separated or file)
Expand Down Expand Up @@ -144,6 +145,7 @@ func ParseOptions() *Options {
flagSet.BoolVarP(&options.ScanAllIPS, "sa", "scan-all-ips", false, "scan all the IP's associated with DNS record"),
flagSet.StringSliceVarP(&options.IPVersion, "iv", "ip-version", []string{scan.IPv4}, "ip version to scan of hostname (4,6) - (default 4)", goflags.NormalizedStringSliceOptions),
flagSet.StringVarP(&options.ScanType, "s", "scan-type", SynScan, "type of port scan (SYN/CONNECT)"),
flagSet.StringVarP(&options.ConnectPayload, "cp", "connect-payload", "", "payload to send in CONNECT scans (optional)"),
flagSet.StringVar(&options.SourceIP, "source-ip", "", "source ip and port (x.x.x.x:yyy)"),
flagSet.BoolVarP(&options.InterfacesList, "il", "interface-list", false, "list available interfaces and public ip"),
flagSet.StringVarP(&options.Interface, "i", "interface", "", "network Interface to use for port scan"),
Expand Down
12 changes: 6 additions & 6 deletions v2/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (r *Runner) RunEnumeration(pctx context.Context) error {
return nil
}
}

payload := r.options.ConnectPayload
switch {
case r.options.Stream && !r.options.Passive: // stream active
showNetworkCapabilities(r.options)
Expand All @@ -354,7 +354,7 @@ func (r *Runner) RunEnumeration(pctx context.Context) error {
r.RawSocketEnumeration(ctx, target, port)
} else {
r.wgscan.Add()
go r.handleHostPort(ctx, target, port)
go r.handleHostPort(ctx, target, payload, port)
}
return true
}
Expand Down Expand Up @@ -547,7 +547,7 @@ func (r *Runner) RunEnumeration(pctx context.Context) error {
r.RawSocketEnumeration(ctx, ip, port)
} else {
r.wgscan.Add()
go r.handleHostPort(ctx, ip, port)
go r.handleHostPort(ctx, ip, payload, port)
}
if r.options.EnableProgressBar {
r.stats.IncrementCounter("packets", 1)
Expand Down Expand Up @@ -578,7 +578,7 @@ func (r *Runner) RunEnumeration(pctx context.Context) error {
r.RawSocketEnumeration(ctx, ip, &portWithMetadata)
} else {
r.wgscan.Add()
go r.handleHostPort(ctx, ip, &portWithMetadata)
go r.handleHostPort(ctx, ip, payload, &portWithMetadata)
}
if r.options.EnableProgressBar {
r.stats.IncrementCounter("packets", 1)
Expand Down Expand Up @@ -778,7 +778,7 @@ func (r *Runner) canIScanIfCDN(host string, port *port.Port) bool {
return port.Port == 80 || port.Port == 443
}

func (r *Runner) handleHostPort(ctx context.Context, host string, p *port.Port) {
func (r *Runner) handleHostPort(ctx context.Context, host, payload string, p *port.Port) {
defer r.wgscan.Done()

select {
Expand All @@ -796,7 +796,7 @@ func (r *Runner) handleHostPort(ctx context.Context, host string, p *port.Port)
}

r.limiter.Take()
open, err := r.scanner.ConnectPort(host, p, time.Duration(r.options.Timeout)*time.Millisecond)
open, err := r.scanner.ConnectPort(host, payload, p, time.Duration(r.options.Timeout)*time.Millisecond)
if open && err == nil {
r.scanner.ScanResults.AddPort(host, p)
if r.scanner.OnReceive != nil {
Expand Down
4 changes: 4 additions & 0 deletions v2/pkg/runner/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (options *Options) ValidateOptions() error {
options.ScanType = ConnectScan
}

if options.ConnectPayload != "" && options.ScanType != ConnectScan {
return errors.New("connect payload can only be used with connect scan")
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions v2/pkg/runner/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ func TestOptions(t *testing.T) {

options.Resolvers = "aaabbbccc"
assert.NotNil(t, options.ValidateOptions())

options.Rate = 2
options.ConnectPayload = "aabbcc"
options.ScanType = SynScan
assert.EqualError(t, options.ValidateOptions(), "connect payload can only be used with connect scan")
}
4 changes: 2 additions & 2 deletions v2/pkg/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func GetInterfaceFromIP(ip net.IP) (*net.Interface, error) {
}

// ConnectPort a single host and port
func (s *Scanner) ConnectPort(host string, p *port.Port, timeout time.Duration) (bool, error) {
func (s *Scanner) ConnectPort(host, payload string, p *port.Port, timeout time.Duration) (bool, error) {
hostport := net.JoinHostPort(host, fmt.Sprint(p.Port))
var (
err error
Expand Down Expand Up @@ -395,7 +395,7 @@ func (s *Scanner) ConnectPort(host string, p *port.Port, timeout time.Duration)
if err := conn.SetWriteDeadline(time.Now().Add(timeout)); err != nil {
return false, err
}
if _, err := conn.Write(nil); err != nil {
if _, err := conn.Write([]byte(payload)); err != nil {
return false, err
}
if err := conn.SetReadDeadline(time.Now().Add(timeout)); err != nil {
Expand Down
Loading