-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdirsx.go
259 lines (185 loc) · 6.5 KB
/
dirsx.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package main
import (
"os"
"fmt"
"time"
"path"
"strings"
"strconv"
"path/filepath"
"dirsx/common/logger"
"dirsx/common/httpx"
"github.com/jessevdk/go-flags"
"dirsx/common"
S "dirsx/common/format"
)
// init logger
var Logger = logger.Logger {}
var opts common.Options
var MAX_RESPONE int = 1024*1024
// node all results
var ALL_RESULTS strings.Builder
var banner string = fmt.Sprintf(`
██████╗ ██╗██████╗ ███████╗██╗ ██╗
██╔══██╗██║██╔══██╗██╔════╝╚██╗██╔╝
██║ ██║██║██████╔╝███████╗ ╚███╔╝
██║ ██║██║██╔══██╗╚════██║ ██╔██╗
██████╔╝██║██║ ██║███████║██╔╝ ██╗
╚═════╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
%s
xboy@遥遥领先
`, "1.2.1")
var InfoFormat string = `
-----------------------------------------------------------
Target Num | {0}
Threads | {1}
Wordlist | {2}
Status Code | [{3}]
Current Time | {4}
-----------------------------------------------------------
`
func PrintScanInfo(tgnum int, wordlist string, threads int) {
code := Logger.Suc("200").Str(",").War("301,302,307").Str(",400,404,501,502,503").Msg("")
_, filename := path.Split(wordlist)
fmt.Println(
S.F(
strings.TrimLeft(InfoFormat,"\n"),
tgnum, threads, filename, code,
time.Now().Format("2006-01-02 15:04:05"),
),
)
}
func ListAndSelectDicts(rootpath string) ([]string, string) {
dictspath := filepath.Join(filepath.Dir(rootpath), "dicts")
Logger.War("[+] You have not appoint payloads, so you can select from the list: ").Msgf("")
var (
idxs [] string
selnum string
paths []string
options string
)
idxs, options = common.FormatDictsOptions(dictspath)
fmt.Println(options)
for {
fmt.Printf("[+] Select payloads with number: ")
fmt.Scan(&selnum)
selnums := strings.Split(selnum, ",")
for _, sn := range selnums {
idx, err := strconv.Atoi(sn)
if err != nil {
Logger.ERR().Msgf("Number error! No this selectioin! Please input again!")
os.Exit(0)
}
if idx >= len(idxs) {
Logger.ERR().Msgf("Number error! No this selectioin! Please input again!")
os.Exit(0)
}
paths = append(paths, filepath.Join(dictspath, idxs[idx]))
}
return paths, selnum
}
}
func LoadUrls() []string {
var urls [] string
if opts.Url == "" && opts.List == "" {
Logger.WAR().Msgf("Please input the url or[url file]")
os.Exit(0)
}
if opts.Url != "" {
urls = []string {opts.Url}
} else {
urls = common.ReadFile(opts.List)
}
return common.SplitUrlPath(urls, opts.IsSplit)
}
func LoadPayloads(rootpath string) ([]string, string){
var wordlist [] string
var wordname string = "payload list-> "
if opts.Wordlist != "" {
wordlist = common.ReadFile(opts.Wordlist)
wordname = filepath.Base(opts.Wordlist)
} else {
paths, selnums := ListAndSelectDicts(rootpath)
for _, path := range paths {
wlist := common.ReadFile(path)
wordlist = append(wordlist, wlist...)
}
wordname = wordname + selnums
}
return common.RemoveDuplicates(wordlist), wordname
}
func GenerateTargets(url string, wordlist []string) []string {
var targets, exts []string
// adding backup wordlist and removing extensions
wordlist = common.RemoveExtensions(
common.GenerateBackupWords(url, wordlist, opts.Isbak),
opts.RemoveExt,
)
if opts.Ext != "" {
exts = strings.Split(strings.Trim(opts.Ext, ","), ",")
opts.Suffix = opts.Suffix + "."
} else {
exts = [] string {""}
}
for _, word := range wordlist {
for _, ext := range exts {
// remove %ext% of dirsearch wordlist
if strings.Contains(word, "%EXT%") {
continue
}
word = common.FormatWords(word, opts.UpperTitle, opts.UpperAll)
targets = append(targets, common.JoinUrlAndWord(url, word, opts.Prefix, opts.Suffix, ext))
}
}
// unique targets
return common.RemoveDuplicates(targets)
}
func DirScan(urls []string, wordlist []string, headers map[string]string) {
for index, url := range urls {
httpx := httpx.Httpx {
Targets: make(chan string),
Method: opts.Method,
Headers: headers,
Timeout: opts.Timeout,
MaxRespone: MAX_RESPONE,
TitleLen: opts.TitleLen,
Threads: opts.Threads,
Excodes: strings.Split(opts.Excodes, ","),
Proxy: opts.Proxy,
Smart: !opts.Unsmart,
}
// unique targets
targets := GenerateTargets(url, wordlist)
// fmt.Println(targets)
Logger.INF().Msgf(S.F("Start Scanning Target {0} -> {1}", index+1, url))
results := httpx.Reset().Runner(url, targets)
consoleText, fileText := common.HandleScanResults(url, results, "")
ALL_RESULTS.WriteString(fileText)
fmt.Println(consoleText)
}
if opts.Output != "" {
common.OutputResultsToFile(opts.Output, ALL_RESULTS.String())
}
}
func ScanRunner(rootpath string) {
urls := LoadUrls()
wordlist, wordname := LoadPayloads(rootpath)
PrintScanInfo(len(urls), wordname, opts.Threads)
headers := common.HandleHttpHeaders(opts.Cookie, opts.Headers, opts.HeadersFile)
DirScan(urls, wordlist, headers)
}
func main() {
fmt.Printf(banner)
var rootpath, err = os.Executable()
if err != nil {
Logger.WAR().Msgf("No permission to read dirsx directory, Please check ...")
return
}
start := time.Now()
if _, err := flags.Parse(&opts); err != nil {
// fmt.Println(err)
return
}
ScanRunner(rootpath)
Logger.INF().Str(S.F("Scanning {0} targets completed [{1}]", 1, time.Since(start))).Msgf("")
}