Skip to content

Commit

Permalink
cover dns resolution failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Jan 3, 2022
1 parent 6ea74a1 commit 05ccae7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ syn-flood can be customized with several command line arguments:
--floodDurationSeconds int64 Provide the duration of the attack in seconds, -1 for no limit, defaults to -1
```

> To be able to run **syn-flood** with unlimited time range, you should also increase your operating system open file
> limits, you can refer [here](https://www.tecmint.com/increase-set-open-file-limits-in-linux/) about how to do that.
## Download
### Binary
Binary can be downloaded from [Releases](https://github.com/bilalcaliskan/syn-flood/releases) page.
Expand Down
7 changes: 5 additions & 2 deletions internal/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ func StartFlooding(destinationHost string, destinationPort, payloadLength int, f
err error
)

destinationHost = resolveHost(destinationHost)
destinationHost, err = resolveHost(destinationHost)
if err != nil {
return err
}

description := fmt.Sprintf("Flood is in progress, target=%s:%d, floodType=%s, payloadLength=%d\n",
description := fmt.Sprintf("Flood is in progress, target=%s:%d, floodType=%s, payloadLength=%d",
destinationHost, destinationPort, floodType, payloadLength)
bar := progressbar.DefaultBytes(-1, description)

Expand Down
9 changes: 6 additions & 3 deletions internal/raw/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ func isIP(host string) bool {
}

// 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 {
func resolveHost(host string) (string, error) {
if !isIP(host) && isDNS(host) {
log.Printf("%s is a DNS record, making DNS lookup\n", host)
ipRecords, err := net.DefaultResolver.LookupIP(context.Background(), "ip4", host)
if err != nil {
log.Fatalf("an error occured on dns lookup: %s", err.Error())
log.Printf("an error occured on dns lookup: %s\n", err.Error())
return "", err
}

log.Printf("dns lookup succeeded, found %s for %s\n", ipRecords[0].String(), host)
host = ipRecords[0].String()
} else {
log.Printf("%s is already an IP address, skipping DNS resolution\n", host)
}

return host
return host, nil
}
10 changes: 8 additions & 2 deletions internal/raw/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ func TestResolveHost(t *testing.T) {
}{
{"case1", "example.com"},
{"case2", "93.184.216.34"},
{"case3", "nonexisteddns.com"},
}

for _, tc := range cases {
t.Run(tc.caseName, func(t *testing.T) {
res := resolveHost(tc.host)
assert.NotNil(t, res)
_, err := resolveHost(tc.host)
assert.NotNil(t, err)
})
}
}

func TestResolvHostFailure(t *testing.T) {
_, err := resolveHost("nonexisteddns.com")
assert.NotNil(t, err)
}

func TestIsDNS(t *testing.T) {
cases := []struct {
caseName string
Expand Down

0 comments on commit 05ccae7

Please sign in to comment.