-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
186 lines (158 loc) · 3.85 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
package main
import (
"fmt"
"bufio"
"flag"
"os"
"sync"
"crypto/tls"
"net"
"net/http"
"net/url"
"time"
"strings"
"io/ioutil"
"regexp"
)
func init() {
flag.Usage = func() {
h := []string{
"",
"Urlive (Check url is live *HTTP status code \"200 ok\" only)",
"",
"By : viloid [Sec7or - Surabaya Hacker Link]",
"",
"Basic Usage :",
" ▶ echo http://domain.com/path/file.extparam=value | urlive",
" ▶ cat listurls.txt | urlive -c 50",
"",
"Options :",
" -H, --header Add Header to the request",
" -c, --concurrency Increase concurrency level (*default 20)",
" -x, --proxy Add HTTP proxy",
" -m, --match Add match specific string (*Sensitive Case)",
" -o, --output Output to file",
"",
"",
}
fmt.Fprintf(os.Stderr, strings.Join(h, "\n"))
}
}
func main() {
var headers headerArgs
flag.Var(&headers, "header", "")
flag.Var(&headers, "H", "")
var concurrency int
flag.IntVar(&concurrency, "concurrency", 20, "Concurrency level")
flag.IntVar(&concurrency, "c", 20, "Concurrency level")
var proxy string
flag.StringVar(&proxy, "proxy", "", "")
flag.StringVar(&proxy, "x", "", "")
var match string
flag.StringVar(&match, "match", "", "")
flag.StringVar(&match, "m", "", "")
var outputFile string
flag.StringVar(&outputFile, "output", "", "")
flag.StringVar(&outputFile, "o", "", "")
flag.Parse()
client := newClient(proxy)
jobs := make(chan string)
var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
for u := range jobs {
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return
}
if headers == nil {
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; urlive/0.1; +https://github.com/vsec7/urlive)")
}
// add headers to the request
for _, h := range headers {
parts := strings.SplitN(h, ":", 2)
if len(parts) != 2 {
continue
}
req.Header.Set(parts[0], parts[1])
}
// send the request
resp, err := client.Do(req)
if err != nil {
continue
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
if match != "" {
data, _ := ioutil.ReadAll(resp.Body)
var re, _ = regexp.Compile(match)
if re.MatchString(string(data)) == true {
if outputFile != "" {
file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Printf("[!] Failed Creating File: %s", err)
}
buf := bufio.NewWriter(file)
buf.WriteString(u+"\n")
buf.Flush()
file.Close()
}
fmt.Printf("%s\n", u)
}
} else {
if outputFile != "" {
file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Printf("[!] Failed Creating File: %s", err)
}
buf := bufio.NewWriter(file)
buf.WriteString(u+"\n")
buf.Flush()
file.Close()
}
fmt.Printf("%s\n", u)
}
}
}
wg.Done()
}()
}
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
jobs <- sc.Text()
}
close(jobs)
wg.Wait()
}
func newClient(proxy string) *http.Client {
tr := &http.Transport{
MaxIdleConns: 30,
IdleConnTimeout: time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: time.Second * 5,
}).DialContext,
}
if proxy != "" {
if p, err := url.Parse(proxy); err == nil {
tr.Proxy = http.ProxyURL(p)
}
}
re := func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
return &http.Client{
Transport: tr,
CheckRedirect: re,
Timeout: time.Second * 5,
}
}
type headerArgs []string
func (h *headerArgs) Set(val string) error {
*h = append(*h, val)
return nil
}
func (h headerArgs) String() string {
return "string"
}