Skip to content

Commit

Permalink
TCP NULL scan
Browse files Browse the repository at this point in the history
  • Loading branch information
v-byte-cpu committed Mar 22, 2021
1 parent 7299572 commit b17777d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The goal of this project is to create the fastest network scanner with clean and
Features:
* ARP scan
* TCP SYN scan
* TCP FIN scan
* TCP FIN / NULL scans

## Building

Expand Down
2 changes: 1 addition & 1 deletion command/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ func newTCPScanMethod(ctx context.Context, conf *scanConfig, opts ...tcpScanConf
return tcp.NewScanMethod(
c.scanName, psrc, results,
tcp.WithPacketFilterFunc(c.packetFilter),
tcp.WithPacketFlagsFunc(tcp.EmptyFlags))
tcp.WithPacketFlagsFunc(c.packetFlags))
}
51 changes: 51 additions & 0 deletions command/tcp_null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package command

import (
"context"
"errors"
"os"
"os/signal"
"strings"

"github.com/spf13/cobra"
"github.com/v-byte-cpu/sx/pkg/scan/tcp"
)

func init() {
tcpCmd.AddCommand(tcpnullCmd)
}

var tcpnullCmd = &cobra.Command{
Use: "null [flags] subnet",
Example: strings.Join([]string{"tcp null -p 22 192.168.0.1/24", "tcp null -p 22-4567 10.0.0.1"}, "\n"),
Short: "Perform TCP NULL scan",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("requires one ip subnet argument")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
var conf *scanConfig
if conf, err = parseScanConfig(tcp.NULLScanType, args[0], portsFlag); err != nil {
return
}

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

m := newTCPScanMethod(ctx, conf,
withTCPScanName(tcp.NULLScanType),
withTCPPacketFiller(tcp.NewPacketFiller()),
withTCPPacketFilterFunc(tcp.TrueFilter),
withTCPPacketFlags(tcp.AllFlags),
)

return startEngine(ctx, &engineConfig{
logger: conf.logger,
scanRange: conf.scanRange,
scanMethod: m,
bpfFilter: tcp.BPFFilter,
})
},
}
5 changes: 3 additions & 2 deletions pkg/scan/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

const (
SYNScanType = "syn"
FINScanType = "fin"
SYNScanType = "tcpsyn"
FINScanType = "tcpfin"
NULLScanType = "tcpnull"
)

//easyjson:json
Expand Down
2 changes: 1 addition & 1 deletion pkg/scan/tcp/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestProcessPacketData(t *testing.T) {
require.FailNow(t, "results chan is empty")
}
tcpResult := result.(*ScanResult)
assert.Equal(t, "syn", tcpResult.ScanType)
assert.Equal(t, SYNScanType, tcpResult.ScanType)
assert.Equal(t, net.IPv4(192, 168, 0, 2).To4().String(), tcpResult.IP)
assert.Equal(t, uint16(22), tcpResult.Port)

Expand Down

0 comments on commit b17777d

Please sign in to comment.