-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaa0a57
commit 85852ed
Showing
9 changed files
with
303 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
|
||
"github.com/google/gopacket/layers" | ||
"github.com/spf13/cobra" | ||
"github.com/v-byte-cpu/sx/pkg/scan/tcp" | ||
) | ||
|
||
func init() { | ||
tcpCmd.AddCommand(tcpsynCmd) | ||
} | ||
|
||
var tcpsynCmd = &cobra.Command{ | ||
Use: "syn [flags] subnet", | ||
Example: strings.Join([]string{"tcp syn -p 22 192.168.0.1/24", "tcp syn -p 22-4567 10.0.0.1"}, "\n"), | ||
Short: "Perform TCP SYN 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) { | ||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) | ||
defer cancel() | ||
return startTCPSYNScan(ctx, args[0], cliPortsFlag) | ||
}, | ||
} | ||
|
||
func startTCPSYNScan(ctx context.Context, subnet, ports string) (err error) { | ||
scanName := tcp.SYNScanType | ||
|
||
var conf *scanConfig | ||
if conf, err = parseScanConfig(scanName, subnet, ports); err != nil { | ||
return | ||
} | ||
|
||
m := newTCPScanMethod(ctx, conf, | ||
withTCPScanName(scanName), | ||
withTCPPacketFiller(tcp.NewPacketFiller(tcp.WithSYN())), | ||
withTCPPacketFilterFunc(func(pkt *layers.TCP) bool { | ||
// port is open | ||
return pkt.SYN && pkt.ACK | ||
}), | ||
withTCPPacketFlags(tcp.EmptyFlags), | ||
) | ||
|
||
return startEngine(ctx, &engineConfig{ | ||
logger: conf.logger, | ||
scanRange: conf.scanRange, | ||
scanMethod: m, | ||
// TODO SYN,ACK filter | ||
bpfFilter: tcp.BPFFilter, | ||
}) | ||
} |
Oops, something went wrong.