forked from blackhatethicalhacking/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory_search.go
140 lines (124 loc) · 3.75 KB
/
directory_search.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
package directory_search
import (
"bufio"
"net/http"
"os"
"strconv"
"strings"
"github.com/graniet/operative-framework/session"
)
type DirectorySearchModule struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushModuleDirectorySearch(s *session.Session) *DirectorySearchModule {
mod := DirectorySearchModule{
sess: s,
Stream: &s.Stream,
}
mod.CreateNewParam("TARGET", "website target", "", true, session.STRING)
mod.CreateNewParam("WORDLIST", "WORDLIST e.g: operative-framwork-default/directory_search/lists.txt", "", true, session.STRING)
return &mod
}
func (module *DirectorySearchModule) Name() string {
return "directory_search"
}
func (module *DirectorySearchModule) Author() string {
return "Tristan Granier"
}
func (module *DirectorySearchModule) Description() string {
return "Try to bust hidden directory"
}
func (module *DirectorySearchModule) GetType() string {
return "website"
}
func (module *DirectorySearchModule) GetInformation() session.ModuleInformation {
information := session.ModuleInformation{
Name: module.Name(),
Description: module.Description(),
Author: module.Author(),
Type: module.GetType(),
Parameters: module.Parameters,
}
return information
}
func (module *DirectorySearchModule) Start() {
trg, err := module.GetParameter("TARGET")
if err != nil {
module.Stream.Error(err.Error())
return
}
target, err := module.sess.GetTarget(trg.Value)
if err != nil {
module.Stream.Error(err.Error())
return
}
if strings.Contains(target.GetName(), "://") {
expProto := strings.Split(target.GetName(), "://")
proto := expProto[0]
expURL := ""
if strings.Contains(target.GetName(), "/") {
expURL = strings.Split(expProto[1], "/")[0]
target.Name = proto + "://" + expURL + "/"
}
} else {
if strings.Contains(target.GetName(), "/") {
expURL := strings.Split(target.GetName(), "/")[0]
target.Name = "https://" + expURL + "/"
}
}
wordList, err := module.GetParameter("WORDLIST")
if err != nil {
module.Stream.Error(err.Error())
return
}
file, errPath := os.Open(wordList.Value)
if errPath != nil {
module.Stream.Error(errPath.Error())
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
client := http.Client{}
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
url := target.GetName() + line
req, err := http.NewRequest("GET", url, nil)
if err != nil {
continue
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
res, err := client.Do(req)
if err != nil {
module.Stream.Error(err.Error())
} else {
if res.StatusCode == 200 {
result := session.TargetResults{
Header: "URL" + target.GetSeparator() + "STATUS",
Value: url + target.GetSeparator() + strconv.Itoa(res.StatusCode),
}
module.Results = append(module.Results, url)
target.Save(module, result)
module.sess.Stream.Success(url + " : " + strconv.Itoa(res.StatusCode))
} else if res.StatusCode == 404 {
result := session.TargetResults{
Header: "URL" + target.GetSeparator() + "STATUS",
Value: url + target.GetSeparator() + strconv.Itoa(res.StatusCode),
}
module.Results = append(module.Results, url)
target.Save(module, result)
module.sess.Stream.Standard(url + " : " + strconv.Itoa(res.StatusCode))
} else {
result := session.TargetResults{
Header: "URL" + target.GetSeparator() + "STATUS",
Value: url + target.GetSeparator() + strconv.Itoa(res.StatusCode),
}
module.Results = append(module.Results, url)
target.Save(module, result)
module.sess.Stream.Warning(url + " : " + strconv.Itoa(res.StatusCode))
}
}
}
return
}