diff --git a/cmd/root.go b/cmd/root.go index 1dfe80d..3ea31b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,6 +61,7 @@ func Execute() { } } +// init function initializes the cmd module func init() { opts := options.GetSynFloodOptions() diff --git a/internal/raw/raw_test.go b/internal/raw/raw_test.go index bae1d30..b9ebf0c 100644 --- a/internal/raw/raw_test.go +++ b/internal/raw/raw_test.go @@ -22,7 +22,6 @@ func TestStartFlooding(t *testing.T) { {"500byte_syn", "syn", 500, srcPorts[rand.Intn(len(srcPorts))], 443, 100, srcIps[rand.Intn(len(srcIps))], "213.238.175.187", macAddrs[rand.Intn(len(macAddrs))], macAddrs[rand.Intn(len(macAddrs))]}, - // TODO: other cases like floodType=ack, floodType=synAck. think a solution to "too many open files" error ;) } for _, tc := range cases { diff --git a/internal/raw/utils.go b/internal/raw/utils.go index 3c5128f..9e940d0 100644 --- a/internal/raw/utils.go +++ b/internal/raw/utils.go @@ -9,12 +9,14 @@ import ( "regexp" ) +// getRandomPayload returns a byte slice to spoof ip packets with random payload in specified length func getRandomPayload(length int) []byte { payload := make([]byte, length) rand.Read(payload) return payload } +// getIps returns a string slice to spoof ip packets with dummy source ip addresses func getIps() []string { ips := make([]string, 0) for i := 0; i < 20; i++ { @@ -25,6 +27,7 @@ func getIps() []string { return ips } +// getPorts returns an int slice to spoof ip packets with dummy source ports func getPorts() []int { ports := make([]int, 0) for i := 1024; i <= 65535; i++ { @@ -34,6 +37,7 @@ func getPorts() []int { return ports } +// getMacAddrs returns a byte slice to spoof ip packets with dummy MAC addresses func getMacAddrs() [][]byte { macAddrs := make([][]byte, 0) for i := 0; i <= 50; i++ { @@ -49,6 +53,7 @@ func getMacAddrs() [][]byte { return macAddrs } +// isDNS returns a boolean which indicates host parameter is a DNS record or not func isDNS(host string) bool { var ( res bool @@ -62,6 +67,7 @@ func isDNS(host string) bool { return res } +// isIP returns a boolean which indicates host parameter is an IP address or not func isIP(host string) bool { var ( res bool @@ -75,6 +81,7 @@ func isIP(host string) bool { return res } +// resolveHost function gets a string and returns the ip address while deciding it is an ip address already or DNS record func resolveHost(host string) string { if !isIP(host) && isDNS(host) { log.Printf("%s is a DNS record, making DNS lookup\n", host)