Skip to content

Commit

Permalink
finished first check and output
Browse files Browse the repository at this point in the history
  • Loading branch information
5amu committed Jul 5, 2022
1 parent e9871ba commit b65f0f0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
26 changes: 13 additions & 13 deletions cmd/dnshunter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func banner() {
common.Banner("")
common.Banner(" ·▄▄▄▄ ▐ ▄ .▄▄ · ▄ .▄▄• ▄▌ ▐ ▄ ▄▄▄▄▄▄▄▄ .▄▄▄ ")
common.Banner(" ██▪ ██ •█▌▐█▐█ ▀. ██▪▐██▪██▌•█▌▐█•██ ▀▄.▀·▀▄ █· ")
common.Banner(" ▐█· ▐█▌▐█▐▐▌▄▀▀▀█▄██▀▐██▌▐█▌▐█▐▐▌ ▐█.▪▐▀▀▪▄▐▀▀▄ ")
common.Banner(" ██. ██ ██▐█▌▐█▄▪▐███▌▐▀▐█▄█▌██▐█▌ ▐█▌·▐█▄▄▌▐█•█▌ ")
common.Banner(" ▀▀▀▀▀• ▀▀ █▪ ▀▀▀▀ ▀▀▀ · ▀▀▀ ▀▀ █▪ ▀▀▀ ▀▀▀ .▀ ▀ ")
common.Banner(" -by 5amu (https://github.com/5amu)")
common.Banner("")
fmt.Println("")
fmt.Println(common.Banner(" ·▄▄▄▄ ▐ ▄ .▄▄ · ▄ .▄▄• ▄▌ ▐ ▄ ▄▄▄▄▄▄▄▄ .▄▄▄ "))
fmt.Println(common.Banner(" ██▪ ██ •█▌▐█▐█ ▀. ██▪▐██▪██▌•█▌▐█•██ ▀▄.▀·▀▄ █· "))
fmt.Println(common.Banner(" ▐█· ▐█▌▐█▐▐▌▄▀▀▀█▄██▀▐██▌▐█▌▐█▐▐▌ ▐█.▪▐▀▀▪▄▐▀▀▄ "))
fmt.Println(common.Banner(" ██. ██ ██▐█▌▐█▄▪▐███▌▐▀▐█▄█▌██▐█▌ ▐█▌·▐█▄▄▌▐█•█▌ "))
fmt.Println(common.Banner(" ▀▀▀▀▀• ▀▀ █▪ ▀▀▀▀ ▀▀▀ · ▀▀▀ ▀▀ █▪ ▀▀▀ ▀▀▀ .▀ ▀ "))
fmt.Println(common.Banner(" -by 5amu (https://github.com/5amu)"))
fmt.Println("")
}

func usage() {
Expand Down Expand Up @@ -50,13 +50,13 @@ func main() {
banner()

if err := mainFlagSet.Parse(os.Args[1:]); err != nil {
fmt.Println(err)
common.Error(fmt.Sprintf("%v", err))
os.Exit(1)
}

if len(os.Args) < 2 {
usage()
fmt.Println("not enough arguments")
common.Error("not enough arguments")
os.Exit(1)
}

Expand All @@ -66,19 +66,19 @@ func main() {
}

if vers1 || vers2 {
fmt.Printf("version %v\n", common.DNSHunterVersion)
common.Error(fmt.Sprintf("version %v\n", common.DNSHunterVersion))
os.Exit(0)
}

if len(mainFlagSet.Args()) != 1 {
usage()
fmt.Println("please, specify a target domain")
common.Error("please, specify a target domain")
os.Exit(1)
}

domain := mainFlagSet.Arg(0)
if err := run(outfile, nsfile, domain); err != nil {
fmt.Println(err)
common.Error(fmt.Sprintf("%v", err))
os.Exit(1)
}
}
12 changes: 10 additions & 2 deletions cmd/dnshunter/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ func run(outfile string, nsfile string, domain string) error {
if err != nil {
return err
}
common.Info(fmt.Sprintf("Using nameservers: %v\n", nameservers))

initialInfo := common.Info(fmt.Sprintf("scanning domain : %v\n", domain))
initialInfo += common.Info(fmt.Sprintf("using nameservers : %v\n", nameservers))
if outfile != "" {
initialInfo += common.Info(fmt.Sprintf("saving output to : %v\n", outfile))
} else {
initialInfo += common.Info("saving output to : /dev/null\n")
}
fmt.Println(initialInfo)

var results []*output.CheckOutput
for _, check := range internal.CheckList {
Expand All @@ -36,7 +44,7 @@ func run(outfile string, nsfile string, domain string) error {
if data, err := json.Marshal(results); err != nil {
return err
} else {
if err := os.WriteFile(outfile, data, os.ModeAppend); err != nil {
if err := os.WriteFile(outfile, data, 0644); err != nil {
return err
}
}
Expand Down
24 changes: 12 additions & 12 deletions internal/common/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ var colors = map[string]string{
"reset": "\033[0m", // reset
}

func generic(s string, color string) {
fmt.Printf("%v%v%v\n", color, s, colors[Reset])
func generic(s string, color string) string {
return fmt.Sprintf("%v%v%v", color, s, colors[Reset])
}

func Banner(s string) {
generic(s, colors[BannerLevel])
func Banner(s string) string {
return generic(s, colors[BannerLevel])
}

func Info(s string) {
generic(s, colors[InfoLevel])
func Info(s string) string {
return generic(s, colors[InfoLevel])
}

func Warn(s string) {
generic(fmt.Sprintf("[WARNING]: %v", s), colors[WarnLevel])
func Warn(s string) string {
return generic(fmt.Sprintf("[WARNING]: %v", s), colors[WarnLevel])
}

func Header(s string) {
generic(fmt.Sprintf("[!] %v [!]", s), colors[HeaderLevel])
func Header(s string) string {
return generic(fmt.Sprintf("[!] %v [!]", s), colors[HeaderLevel])
}

func Error(s string) {
generic(fmt.Sprintf("[ERROR]: %v", s), colors[ErrorLevel])
func Error(s string) string {
return generic(fmt.Sprintf("[ERROR]: %v", s), colors[ErrorLevel])
}
12 changes: 8 additions & 4 deletions internal/dnschecks/soainfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,35 @@ func parseSOA(soa string) (isVuln bool, message string) {
dummyUpper, _ := time.Parse("%s", fmt.Sprintf("%v", time.Now().Unix()))

if serialDate.After(dummyUpper) || serialDate.Before(dummyLower) {
message += fmt.Sprintf("[WARNING] Serial number: %v - should follow standards (RIPE-203)\n", part)
message += common.Warn(fmt.Sprintf("Serial number: %v - should follow standards (RIPE-203)\n", part))
isVuln = true
} else {
message += fmt.Sprintf("Serial number: %v\n", part)
}
case SOARefresh:
refresh, _ := time.ParseDuration(fmt.Sprintf("%vs", part))

if refresh < (24 * time.Hour) {
message += fmt.Sprintf("[WARNING] Refresh: %v - should follow standards (RIPE-203)\n", part)
message += common.Warn(fmt.Sprintf("Refresh: %v - should follow standards (RIPE-203)\n", part))
isVuln = true
} else {
message += fmt.Sprintf("Refresh: %v\n", part)
}
case SOARetry:
retry, _ := time.ParseDuration(fmt.Sprintf("%vs", part))

if retry < (2 * time.Hour) {
message += fmt.Sprintf("[WARNING] Retry: %v - should follow standards (RIPE-203)\n", part)
message += common.Warn(fmt.Sprintf("Retry: %v - should follow standards (RIPE-203)\n", part))
isVuln = true
} else {
message += fmt.Sprintf("Retry: %v\n", part)
}
case SOAExpire:
expire, _ := time.ParseDuration(fmt.Sprintf("%vs", part))

if expire < (1000 * time.Hour) {
message += fmt.Sprintf("[WARNING] Expire: %v - should follow standards (RIPE-203)\n", part)
message += common.Warn(fmt.Sprintf("Expire: %v - should follow standards (RIPE-203)\n", part))
isVuln = true
} else {
message += fmt.Sprintf("Expire: %v\n", part)
}
Expand Down
13 changes: 8 additions & 5 deletions internal/output/output.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package output

import "fmt"
import (
"fmt"

"github.com/5amu/dnshunter/internal/common"
)

type CheckOutput struct {
Name string `json:"name"`
Expand All @@ -11,8 +15,7 @@ type CheckOutput struct {
}

func (o *CheckOutput) String() string {
// TODO: make colored output
s := "[!] Check: %v - vulnerable: %v\n"
s += "%v\n"
return fmt.Sprintf(s, o.Name, o.Vulnerable, o.Message)
s := common.Header(fmt.Sprintf("Check: %v - vulnerable: %v", o.Name, o.Vulnerable))
s += o.Message
return s
}

0 comments on commit b65f0f0

Please sign in to comment.