-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
219 lines (182 loc) · 5.16 KB
/
main.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
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
)
var showsuccess bool = false
var successlist []string
func main() {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
address := flag.String("url", "", "url address https://google.com")
showsuccessresult := flag.Bool("v", false, "show success result only")
flag.Parse()
if *showsuccessresult {
showsuccess = true
}
if *address == "" {
println("Please Set url via --url or -h for help")
return
}
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
file, err := os.Open(exPath + "/backup_finder_list.txt")
if err != nil {
fmt.Printf("%s", err)
return
}
list := readToDisplayUsingFile1(file)
addreswithouthttp := strings.ReplaceAll(*address, "https://", "")
addreswithouthttp = strings.ReplaceAll(addreswithouthttp, "http://", "")
subanddomain := strings.Split(addreswithouthttp, ".")
for i := 0; i < len(subanddomain)-1; i++ {
list = append(list, "/"+subanddomain[i])
}
newlist := append(list, "/"+addreswithouthttp)
newlistwithcurl := pathinurl(*address)
uniqelistwithurl := Unique(newlistwithcurl)
extentions := [...]string{".zip", ".tar", ".tar.gz", ".rar", ".sql"}
for _, str := range uniqelistwithurl {
newlist = append(newlist, str)
}
defer file.Close()
for _, url := range newlist {
for _, ext := range extentions {
if url != "" {
checkurl(*address + url + ext)
}
}
}
fmt.Printf("%d %s\n", len(successlist), "Found")
for _, v := range successlist {
println(v)
}
}
func Unique(slice []string) []string {
// create a map with all the values as key
uniqMap := make(map[string]struct{})
for _, v := range slice {
uniqMap[v] = struct{}{}
}
// turn the map keys into a slice
uniqSlice := make([]string, 0, len(uniqMap))
for v := range uniqMap {
uniqSlice = append(uniqSlice, v)
}
return uniqSlice
}
func pathinurl(urlrecive string) (list []string) {
response, err := http.Get(urlrecive)
if err != nil {
if strings.Contains(err.Error(), "http: server gave HTTP response to HTTPS clien") {
os.Exit(3)
}
return nil
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
responseString := string(responseData)
re := regexp.MustCompile("href=[\"'](.*?)[\"']")
var patharray []string
found := re.FindAllStringSubmatch(responseString, -1)
addresuri, _ := url.Parse(urlrecive)
for _, fou := range found {
perfix := ""
if strings.Contains(strings.ToLower(fou[1]), "http") {
perfix = fou[1]
} else {
if !strings.HasPrefix(fou[1], "/") {
perfix = urlrecive + "/" + fou[1]
} else {
perfix = urlrecive + fou[1]
}
}
checkuri, err := url.Parse(perfix)
if err != nil {
fmt.Printf("\n url is problem : %s \n ", fou[1])
continue
}
if len(checkuri.Path) > 3 {
if strings.Contains(addresuri.Host, checkuri.Host) {
pathurispli := strings.Split(checkuri.Path, "/")
pathcomplate := ""
for i := 1; i < len(pathurispli); i++ {
tolowers := strings.ToLower(pathurispli[i])
if strings.TrimSpace(tolowers) != "" {
if strings.Contains(tolowers, ".png") || strings.Contains(tolowers, ".jpg") ||
strings.Contains(tolowers, ".svg") || strings.Contains(tolowers, ".gif") ||
strings.Contains(tolowers, ".css") || strings.Contains(tolowers, ".js") ||
strings.Contains(tolowers, ".ttf") || strings.Contains(tolowers, ".ico") ||
strings.Contains(tolowers, ".otf") || strings.Contains(tolowers, ".woff") ||
strings.Contains(tolowers, ".woff2") || strings.Contains(tolowers, ".ico") {
} else {
if strings.Contains(tolowers, "?") {
splitqus := strings.Split(pathurispli[i], "?")
pathcomplate += "/" + splitqus[0]
} else {
pathcomplate += "/" + pathurispli[i]
}
}
}
}
//patharray = append(patharray, pathcomplate)
patharray = append(patharray, pathcomplate) // here
for i := len(pathurispli) - 1; 1 < i; i-- {
//fmt.Println("beginlop" + pathurispli[i])
lastpath := ""
for ii := 0; ii < i; ii++ {
lastpath += pathurispli[ii] + "/"
}
//fmt.Println("afterlop : " + lastpath)
patharray = append(patharray, strings.TrimRight(lastpath, "/"))
}
}
}
}
defer response.Body.Close()
return patharray
}
func readToDisplayUsingFile1(f *os.File) (line []string) {
defer f.Close()
reader := bufio.NewReader(f)
contents, _ := ioutil.ReadAll(reader)
lines := strings.Split(string(contents), "\n")
return lines
}
func checkurl(url string) {
resp, err := http.Head(url)
if err != nil {
if strings.Contains(err.Error(), "http: server gave HTTP response to HTTPS clien") {
os.Exit(3)
}
//fmt.Printf("%s", err.Error())
}
if err == nil {
if !showsuccess {
println(url + " " + resp.Status)
}
if resp.StatusCode == 200 {
if resp.Header.Get("Content-Type") != "" {
if resp.Header.Get("Content-Type") == "application/zip" || resp.Header.Get("Content-Type") == "application/octet-stream" {
fmt.Println(url)
successlist = append(successlist, url)
}
}
} else {
}
}
}