-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDNSKiller.go
245 lines (213 loc) · 5.4 KB
/
DNSKiller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
DNSKiller - github.com/n0nexist
DNS top and sub level domain bruteforcer
*/
package main
import (
"fmt"
"net"
"os"
"bufio"
"strconv"
"sync"
)
var (
doesnotexist = ""
currentloadingstatus = "-"
currentdomain = ""
currentcolor = ""
currentfilename = ""
alreadyfound = []string {}
purple = "\033[0;35m"
boldpurple = "\033[1;35m"
cyan = "\033[0;36m"
boldcyan = "\033[1;36m"
blue = "\033[0;34m"
boldblue = "\033[1;34m"
reset = "\033[0;0m"
)
func checkInList(elemento string) bool {
/*
checks if an element is present
on a list of strings
*/
for _, item := range alreadyfound {
if item == elemento {
return true
}
}
return false
}
func tryDomainName(domain string) {
/*
checks if the given domain is valid
*/
ips, err := net.LookupIP(domain)
if err == nil {
currentcolor = cyan
if checkInList(ips[0].String()) {
currentcolor = boldblue+"(already found) "
}else{
alreadyfound = append(alreadyfound, ips[0].String())
}
if ips[0].String() != doesnotexist {
currentstr := fmt.Sprintf("%s>%s Found %s%s%s -> %s%s%s%s\n",purple,reset,cyan,domain,reset,currentcolor,cyan,ips[0].String(),reset)
fmt.Print(currentstr)
appendToFile(fmt.Sprintf("> Found %s -> %s",domain,ips[0].String()))
}
}
}
func getInvalidDomain(domain string) string {
/*
gets the response of an invalid domain name
that will be confronted with next responses
*/
ips, err := net.LookupIP(domain)
if err != nil {
return "*no*"
}
return ips[0].String()
}
func appendToFile(content string){
/*
writes to the file path
indicated by the global variable currentfilename
(in append mode) and writes the content inside of the content variable
*/
if currentfilename != "" {
f, err := os.OpenFile(currentfilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {}
defer f.Close()
if _, err = f.WriteString(content+"\n"); err != nil {}
}
}
func slideloading(){
/*
changes the loading animation
*/
switch currentloadingstatus {
case "-":
currentloadingstatus = "/"
break;
case "/":
currentloadingstatus = "\\"
break;
case "\\":
currentloadingstatus = "-"
break;
}
}
func logo(){
/*
prints the logo
*/
fmt.Printf(`%s .__ . . __.. . ..
| \|\ |(__ |_/ *|| _ ._.
%s |__/| \|.__)| \|||(/,[
%s%s`,purple,boldpurple,reset,"\n")
}
func showcredits(){
/*
prints the credits and quit
*/
fmt.Printf("%s>%s DNSKiller was developed by %sn0nexist %s(%shttps://www.n0nexist.github.io%s)%s\n\n",purple,reset,boldpurple,boldcyan,blue,boldcyan,reset)
os.Exit(0)
}
func showhelp(){
/*
shows help menu
*/
fmt.Printf(`
%sUsage%s: %s%s %s(%sdomain%s) (%ssubdomain-wordlist-path%s) (%stopleveldomain-wordlist-path%s) (%sthreads%s) (%soutput file [OPTIONAL]%s)
%sExample%s: %s%s %sgoogle wordlists/sub.txt wordlist/top.txt 200
`,boldpurple,purple,blue,os.Args[0],boldblue,cyan,boldblue,cyan,boldblue,cyan,boldblue,cyan,boldblue,cyan,boldblue,boldpurple,purple,blue,os.Args[0],cyan)
showcredits()
}
func getlines(filename string) int {
/*
gets the number of lines
in a file
*/
count := 0
readFile, err := os.Open(filename)
if err != nil{
showhelp()
}
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
count += 1
}
readFile.Close()
return count
}
func worker(mycurrentline chan string, wg *sync.WaitGroup) {
/*
a single task
*/
defer wg.Done()
for line := range mycurrentline {
tryDomainName(line)
}
}
func main() {
/*
DNSKiller starts here
*/
doesnotexist = getInvalidDomain("domain_that_does_not_exist.blablabla")
logo()
if len(os.Args) < 5 {
showhelp()
}
target := os.Args[1]
subpath := os.Args[2]
toppath := os.Args[3]
tempthreadcount := os.Args[4]
threadcount, convertingerror := strconv.Atoi(tempthreadcount)
if convertingerror != nil {
showhelp()
}
if len(os.Args) >= 6 {
currentfilename = os.Args[5]
appendToFile("[ github.com/n0nexist/DNSKiller ]")
appendToFile(fmt.Sprintf("[ target = %s ]",target))
}
totaltries := getlines(subpath)*getlines(toppath)
fmt.Printf("%s>%s Starting to resolve possible valid domains for %s'%s%s%s'\n",purple,reset,boldpurple,blue,target,boldpurple)
fmt.Printf("%s>%s Calculated that the total possibilities are %d\n\n",purple,reset,totaltries)
subdomain_file, err := os.Open(subpath)
if err != nil {
showhelp()
}
topdomain_file, errtwo := os.Open(toppath)
if errtwo != nil {
showhelp()
}
subdomain_file_scanner := bufio.NewScanner(subdomain_file)
subdomain_file_scanner.Split(bufio.ScanLines)
var wg sync.WaitGroup
mycurrentline := make(chan string)
for i := 0; i < threadcount; i++ {
wg.Add(1)
go worker(mycurrentline, &wg)
}
for subdomain_file_scanner.Scan() {
topdomain_file, errtwo := os.Open(toppath)
if errtwo != nil {
showhelp()
}
topdomain_file_scanner := bufio.NewScanner(topdomain_file)
topdomain_file_scanner.Split(bufio.ScanLines)
for topdomain_file_scanner.Scan() {
fmt.Printf("%s[%s%s%s]%s Trying %s.%s.%s \r",boldpurple,blue,currentloadingstatus,boldpurple,reset,subdomain_file_scanner.Text(), target, topdomain_file_scanner.Text())
slideloading()
currentdomain = fmt.Sprintf("%s.%s.%s", subdomain_file_scanner.Text(), target, topdomain_file_scanner.Text())
mycurrentline <- currentdomain
}
topdomain_file.Close()
}
close(mycurrentline)
wg.Wait()
subdomain_file.Close()
topdomain_file.Close()
}