-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
256 lines (202 loc) · 5.86 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
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
/*
* Copyright 2019, Travis Biehn
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
package main
import (
"context"
"crypto/tls"
"flag"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"strings"
"sync"
"time"
"github.com/corpix/uarand"
"github.com/texttheater/golang-levenshtein/levenshtein"
)
var e = log.New(os.Stderr, "", 0)
var l = log.New(os.Stdout, "", 0)
var timeout = flag.Duration("timeout", 30*time.Second, "Timeout the check.")
var keepalive = 0 * time.Millisecond
var DefBits = flag.Int("mbits", 500, "Match in the first -mbits.")
var Threshold = flag.Int("perc", 50, "Match at -perc[entage] similarity")
var Threads = flag.Int("threads", 200, "Number of -threads to use.")
var ShowSample = flag.Bool("show", false, "Show sample responses.")
var UserAgent = flag.String("ua", "", "Specify User Agent, otherwise we'll generate one.")
func main() {
e.Print(ban)
reconfile := flag.String("file", "", "read ips from specified -file instead of stdin.")
domain := flag.String("url", "https://example.org", "-url to check.")
flag.Parse()
inputStream := os.Stdin
if strings.EqualFold(*UserAgent, "") {
rand := uarand.Default.GetRandom()
UserAgent = &rand
}
e.Print("[I] Starting on ", *domain, " with UA ", *UserAgent)
if !strings.EqualFold(*reconfile, "") {
var err error
inputStream, err = os.Open(*reconfile)
if err != nil {
e.Println("Could not open specified file", *reconfile)
e.Fatal(err)
}
}
bits, err := ioutil.ReadAll(inputStream)
if err != nil {
e.Println("Could not read all the bits")
e.Fatal(err)
}
testIps := strings.Split(strings.Replace(string(bits), "\r\n", "\n", -1), "\n")
var wg sync.WaitGroup
wg.Add(1)
go test(&wg, *domain, testIps)
wg.Wait()
}
func test(wg *sync.WaitGroup, target string, testIPs []string) {
defer wg.Done()
//Vanilla.
dialer := &net.Dialer{
Timeout: *timeout,
KeepAlive: keepalive,
DualStack: true,
}
transport := &http.Transport{
Dial: dialer.Dial,
}
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
client := http.Client{
Timeout: *timeout,
Transport: transport,
}
req, err := http.NewRequest("GET", target, nil)
req.Header.Set("User-Agent", *UserAgent)
res, err := client.Do(req)
og := ""
if err != nil {
e.Print(err)
} else {
reader := io.LimitReader(res.Body, int64(*DefBits))
bits, err := ioutil.ReadAll(reader)
if err != nil {
e.Print(err)
}
og = string(bits)
}
client.CloseIdleConnections()
transport.CloseIdleConnections()
jobs := make(chan AssessParcel, len(testIPs))
for w := 1; w <= *Threads; w++ {
go assessWorker(w, jobs)
}
var workerGroup sync.WaitGroup
workerGroup.Add(len(testIPs))
for _, ip := range testIPs {
jobs <- AssessParcel{
OriginalContent: og,
Target: target,
TestIP: ip,
Wg: &workerGroup,
}
}
close(jobs)
workerGroup.Wait()
}
type AssessParcel struct {
OriginalContent string
Target string
TestIP string
Wg *sync.WaitGroup
}
func assessWorker(id int, jobs <-chan AssessParcel) {
for j := range jobs {
ip := net.ParseIP(j.TestIP)
if ip != nil {
e.Print("[T@", id, "] Is ", j.Target, " hosted on ", j.TestIP, "?")
assess(j.OriginalContent, j.Target, ip.String())
}
j.Wg.Done()
}
}
func assess(og string, target string, testIP string) {
//Jacked.
jackedDialer := &net.Dialer{
Timeout: *timeout,
KeepAlive: keepalive,
DualStack: true,
}
jackedTransport := &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
// redirect all connections to 127.0.0.1
addr = testIP + addr[strings.LastIndex(addr, ":"):]
return jackedDialer.DialContext(ctx, network, addr)
},
}
jackedTransport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
jackedClient := http.Client{
Timeout: *timeout,
Transport: jackedTransport,
}
req, err := http.NewRequest("GET", target, nil)
req.Header.Set("User-Agent", *UserAgent)
res, err := jackedClient.Do(req)
jacked := ""
if err != nil {
e.Print(err)
} else {
reader := io.LimitReader(res.Body, int64(*DefBits))
bits, err := ioutil.ReadAll(reader)
if err != nil {
e.Print(err)
}
jacked = string(bits)
}
jackedClient.CloseIdleConnections()
jackedTransport.CloseIdleConnections()
matchBits := *DefBits
if len(og) < matchBits || len(jacked) < matchBits {
matchBits = len(og)
if len(jacked) < len(og) {
matchBits = len(jacked)
}
}
if matchBits < 5 {
e.Print("[E] ", testIP, "==", target, " Not enough bytes to be meaningful. len(og): ", len(og), " len(jacked): ", len(jacked))
l.Print("miss ", testIP, " ", target, " ", 0, " percent in ", 0, " bytes")
return
}
distance := levenshtein.DistanceForStrings([]rune(og[:matchBits]), []rune(jacked[:matchBits]), levenshtein.DefaultOptions)
matchy := 100 - int(float32(float32(distance)/float32(matchBits))*100)
e.Print("[I] ", testIP, "==", target, " Similarity in first ", matchBits, " bits computed as: ", matchy, "% @ distance: ", distance)
if *ShowSample {
e.Print("[D] Original Sample:")
e.Print(og[:matchBits])
e.Print("[D] Measurement Sample:")
e.Print(jacked[:matchBits])
}
if matchy > 50 {
l.Print("match ", testIP, " ", target, " ", matchy, " percent in ", matchBits, " bytes")
} else {
l.Print("miss ", testIP, " ", target, " ", matchy, " percent in ", matchBits, " bytes")
}
}
var ban = `
mmm m m mmmmm mmmmm m m mmmmmm mmmmm mm m mmm mmmmmm mmmmm
m" " # # # "# # "# "m m" # # #"m # m" " # # "#
# # # #mmmm" #mmmm" "#" #mmmmm # # #m # # mm #mmmmm #mmmm"
# # # # "m # "m # # # # # # # # # # "m
"mmm" "mmmm" # " # " # # mm#mm # ## "mmm" #mmmmm # "
dualuse.io - FINE DUAL USE TECHNOLOGIES`