-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip_obfuscator.py
More file actions
1642 lines (1374 loc) · 64 KB
/
Copy pathip_obfuscator.py
File metadata and controls
1642 lines (1374 loc) · 64 KB
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
IP Address Obfuscation Tool
"""
import ipaddress
import json
import random
import sys
import urllib.parse
from typing import Dict, Optional
class IPObfuscator:
"""Generate all known obfuscated representations of an IPv4 address."""
def __init__(self, ip_str: str):
"""Initialize with a standard IPv4 address string."""
self.ip = ipaddress.IPv4Address(ip_str)
self.octets = list(self.ip.packed)
self.integer = int(self.ip)
# =========================================================================
# STANDARD FORMATS
# =========================================================================
def standard_dotted_decimal(self) -> str:
"""Standard format: 192.168.1.1"""
return str(self.ip)
# =========================================================================
# INTEGER/DWORD FORMATS
# =========================================================================
def decimal_dword(self) -> str:
"""
Single 32-bit decimal integer (DWORD).
Example: 192.168.1.1 -> 3232235777
Used by: SMOKELOADER, phishing campaigns
Source: Mandiant, Zscaler, Trustwave
"""
return str(self.integer)
def hex_dword(self) -> str:
"""
Single hexadecimal integer with 0x prefix.
Example: 192.168.1.1 -> 0xC0A80101
Source: Trustwave SpiderLabs
"""
return f"0x{self.integer:08X}"
def hex_dword_lowercase(self) -> str:
"""Lowercase hex: 0xc0a80101"""
return f"0x{self.integer:08x}"
def octal_dword(self) -> str:
"""
Single 32-bit octal integer (DWORD).
Example: 192.168.1.1 -> 030052000401
Leading 0 indicates octal notation.
Works in: curl, Chrome, Safari, Firefox
Source: inet_aton() man page
"""
return f"0{self.integer:o}"
# =========================================================================
# DOTTED NOTATION VARIANTS
# =========================================================================
def dotted_hex(self) -> str:
"""
Each octet as hex with 0x prefix.
Example: 192.168.1.1 -> 0xC0.0xA8.0x1.0x1
Used in: Bank phishing, PayPal scams
Source: Eric Conrad, SANS
"""
return '.'.join(f'0x{o:X}' for o in self.octets)
def dotted_hex_lowercase(self) -> str:
"""Lowercase dotted hex: 0xc0.0xa8.0x1.0x1"""
return '.'.join(f'0x{o:x}' for o in self.octets)
def dotted_hex_padded(self) -> str:
"""
Padded dotted hex (2 digits per octet).
Example: 192.168.1.1 -> 0xC0.0xA8.0x01.0x01
"""
return '.'.join(f'0x{o:02X}' for o in self.octets)
def dotted_hex_long_padded(self) -> str:
"""
Extra padded hex (used in real phishing).
Example: 0x000000C0.0x000000A8.0x00000001.0x00000001
Source: Eric Conrad - MSN phishing example
"""
return '.'.join(f'0x{o:08X}' for o in self.octets)
def dotted_octal(self) -> str:
"""
Each octet as octal with leading 0.
Example: 192.168.1.1 -> 0300.0250.01.01
Used by: Emotet malware
Source: McAfee, Trend Micro
"""
return '.'.join(f'0{o:o}' for o in self.octets)
def dotted_octal_padded(self) -> str:
"""
Padded octal (3 digits minimum).
Example: 192.168.1.1 -> 0300.0250.0001.0001
"""
return '.'.join(f'0{o:03o}' for o in self.octets)
def dotted_octal_long_padded(self) -> str:
"""
Extra padded octal.
Example: 0000000300.0000000250.0000000001.0000000001
"""
return '.'.join(f'0{o:09o}' for o in self.octets)
# =========================================================================
# MIXED NOTATION (DIFFERENT BASES)
# =========================================================================
def mixed_hex_decimal(self) -> str:
"""
Mix of hex and decimal.
Example: 0xC0.168.0x1.1
"""
return f"0x{self.octets[0]:X}.{self.octets[1]}.0x{self.octets[2]:X}.{self.octets[3]}"
def mixed_octal_decimal(self) -> str:
"""
Mix of octal and decimal.
Example: 0300.168.01.1
"""
return f"0{self.octets[0]:o}.{self.octets[1]}.0{self.octets[2]:o}.{self.octets[3]}"
def mixed_all_bases(self) -> str:
"""
Mix of decimal, hex, and octal.
Example: 192.0xa8.01.0x1
"""
return f"{self.octets[0]}.0x{self.octets[1]:x}.0{self.octets[2]:o}.0x{self.octets[3]:x}"
def random_mixed(self) -> str:
"""Randomly mix bases for each octet."""
result = []
for o in self.octets:
fmt = random.choice(['dec', 'hex', 'oct'])
if fmt == 'dec':
result.append(str(o))
elif fmt == 'hex':
result.append(f'0x{o:x}')
else:
result.append(f'0{o:o}')
return '.'.join(result)
# =========================================================================
# PARTIAL HEX CONVERSIONS (first N or last N octets)
# =========================================================================
def hex_first_3(self) -> str:
"""First 3 octets as hex, last as decimal."""
return f"0x{self.octets[0]:X}.0x{self.octets[1]:X}.0x{self.octets[2]:X}.{self.octets[3]}"
def hex_first_2(self) -> str:
"""First 2 octets as hex, last 2 as decimal."""
return f"0x{self.octets[0]:X}.0x{self.octets[1]:X}.{self.octets[2]}.{self.octets[3]}"
def hex_first_1(self) -> str:
"""First octet as hex, rest as decimal."""
return f"0x{self.octets[0]:X}.{self.octets[1]}.{self.octets[2]}.{self.octets[3]}"
def hex_last_3(self) -> str:
"""First as decimal, last 3 as hex."""
return f"{self.octets[0]}.0x{self.octets[1]:X}.0x{self.octets[2]:X}.0x{self.octets[3]:X}"
def hex_last_2(self) -> str:
"""First 2 as decimal, last 2 as hex."""
return f"{self.octets[0]}.{self.octets[1]}.0x{self.octets[2]:X}.0x{self.octets[3]:X}"
def hex_last_1(self) -> str:
"""First 3 as decimal, last as hex."""
return f"{self.octets[0]}.{self.octets[1]}.{self.octets[2]}.0x{self.octets[3]:X}"
# =========================================================================
# PARTIAL OCTAL CONVERSIONS (first N or last N octets)
# =========================================================================
def octal_first_3(self) -> str:
"""First 3 octets as octal, last as decimal."""
return f"0{self.octets[0]:o}.0{self.octets[1]:o}.0{self.octets[2]:o}.{self.octets[3]}"
def octal_first_2(self) -> str:
"""First 2 octets as octal, last 2 as decimal."""
return f"0{self.octets[0]:o}.0{self.octets[1]:o}.{self.octets[2]}.{self.octets[3]}"
def octal_first_1(self) -> str:
"""First octet as octal, rest as decimal."""
return f"0{self.octets[0]:o}.{self.octets[1]}.{self.octets[2]}.{self.octets[3]}"
def octal_last_3(self) -> str:
"""First as decimal, last 3 as octal."""
return f"{self.octets[0]}.0{self.octets[1]:o}.0{self.octets[2]:o}.0{self.octets[3]:o}"
def octal_last_2(self) -> str:
"""First 2 as decimal, last 2 as octal."""
return f"{self.octets[0]}.{self.octets[1]}.0{self.octets[2]:o}.0{self.octets[3]:o}"
def octal_last_1(self) -> str:
"""First 3 as decimal, last as octal."""
return f"{self.octets[0]}.{self.octets[1]}.{self.octets[2]}.0{self.octets[3]:o}"
# =========================================================================
# PARTIAL HEX WITH LONG PADDING
# =========================================================================
def hex_padded_first_3(self) -> str:
"""First 3 octets as padded hex (8 digits), last as decimal."""
return f"0x{self.octets[0]:08X}.0x{self.octets[1]:08X}.0x{self.octets[2]:08X}.{self.octets[3]}"
def hex_padded_first_2(self) -> str:
"""First 2 octets as padded hex, last 2 as decimal."""
return f"0x{self.octets[0]:08X}.0x{self.octets[1]:08X}.{self.octets[2]}.{self.octets[3]}"
def hex_padded_first_1(self) -> str:
"""First octet as padded hex, rest as decimal."""
return f"0x{self.octets[0]:08X}.{self.octets[1]}.{self.octets[2]}.{self.octets[3]}"
# =========================================================================
# PARTIAL OCTAL WITH LONG PADDING
# =========================================================================
def octal_padded_first_3(self) -> str:
"""First 3 octets as padded octal (8 digits), last as decimal."""
return f"0{self.octets[0]:08o}.0{self.octets[1]:08o}.0{self.octets[2]:08o}.{self.octets[3]}"
def octal_padded_first_2(self) -> str:
"""First 2 octets as padded octal, last 2 as decimal."""
return f"0{self.octets[0]:08o}.0{self.octets[1]:08o}.{self.octets[2]}.{self.octets[3]}"
def octal_padded_first_1(self) -> str:
"""First octet as padded octal, rest as decimal."""
return f"0{self.octets[0]:08o}.{self.octets[1]}.{self.octets[2]}.{self.octets[3]}"
# =========================================================================
# THREE-WAY BASE MIXING (hex, octal, decimal permutations)
# =========================================================================
def mix_hex_oct_dec_dec(self) -> str:
"""hex.oct.dec.dec"""
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.{self.octets[2]}.{self.octets[3]}"
def mix_hex_dec_oct_dec(self) -> str:
"""hex.dec.oct.dec"""
return f"0x{self.octets[0]:X}.{self.octets[1]}.0{self.octets[2]:o}.{self.octets[3]}"
def mix_hex_dec_dec_oct(self) -> str:
"""hex.dec.dec.oct"""
return f"0x{self.octets[0]:X}.{self.octets[1]}.{self.octets[2]}.0{self.octets[3]:o}"
def mix_hex_oct_oct_dec(self) -> str:
"""hex.oct.oct.dec"""
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.0{self.octets[2]:o}.{self.octets[3]}"
def mix_hex_oct_dec_oct(self) -> str:
"""hex.oct.dec.oct"""
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.{self.octets[2]}.0{self.octets[3]:o}"
def mix_hex_dec_oct_oct(self) -> str:
"""hex.dec.oct.oct"""
return f"0x{self.octets[0]:X}.{self.octets[1]}.0{self.octets[2]:o}.0{self.octets[3]:o}"
def mix_oct_hex_dec_dec(self) -> str:
"""oct.hex.dec.dec"""
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.{self.octets[2]}.{self.octets[3]}"
def mix_oct_dec_hex_dec(self) -> str:
"""oct.dec.hex.dec"""
return f"0{self.octets[0]:o}.{self.octets[1]}.0x{self.octets[2]:X}.{self.octets[3]}"
def mix_oct_dec_dec_hex(self) -> str:
"""oct.dec.dec.hex"""
return f"0{self.octets[0]:o}.{self.octets[1]}.{self.octets[2]}.0x{self.octets[3]:X}"
def mix_oct_hex_hex_dec(self) -> str:
"""oct.hex.hex.dec"""
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.0x{self.octets[2]:X}.{self.octets[3]}"
def mix_oct_hex_dec_hex(self) -> str:
"""oct.hex.dec.hex"""
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.{self.octets[2]}.0x{self.octets[3]:X}"
def mix_oct_dec_hex_hex(self) -> str:
"""oct.dec.hex.hex"""
return f"0{self.octets[0]:o}.{self.octets[1]}.0x{self.octets[2]:X}.0x{self.octets[3]:X}"
def mix_dec_hex_oct_dec(self) -> str:
"""dec.hex.oct.dec"""
return f"{self.octets[0]}.0x{self.octets[1]:X}.0{self.octets[2]:o}.{self.octets[3]}"
def mix_dec_hex_dec_oct(self) -> str:
"""dec.hex.dec.oct"""
return f"{self.octets[0]}.0x{self.octets[1]:X}.{self.octets[2]}.0{self.octets[3]:o}"
def mix_dec_oct_hex_dec(self) -> str:
"""dec.oct.hex.dec"""
return f"{self.octets[0]}.0{self.octets[1]:o}.0x{self.octets[2]:X}.{self.octets[3]}"
def mix_dec_oct_dec_hex(self) -> str:
"""dec.oct.dec.hex"""
return f"{self.octets[0]}.0{self.octets[1]:o}.{self.octets[2]}.0x{self.octets[3]:X}"
def mix_dec_dec_hex_oct(self) -> str:
"""dec.dec.hex.oct"""
return f"{self.octets[0]}.{self.octets[1]}.0x{self.octets[2]:X}.0{self.octets[3]:o}"
def mix_dec_dec_oct_hex(self) -> str:
"""dec.dec.oct.hex"""
return f"{self.octets[0]}.{self.octets[1]}.0{self.octets[2]:o}.0x{self.octets[3]:X}"
def mix_dec_hex_oct_oct(self) -> str:
"""dec.hex.oct.oct"""
return f"{self.octets[0]}.0x{self.octets[1]:X}.0{self.octets[2]:o}.0{self.octets[3]:o}"
def mix_dec_oct_hex_hex(self) -> str:
"""dec.oct.hex.hex"""
return f"{self.octets[0]}.0{self.octets[1]:o}.0x{self.octets[2]:X}.0x{self.octets[3]:X}"
def mix_dec_oct_oct_hex(self) -> str:
"""dec.oct.oct.hex"""
return f"{self.octets[0]}.0{self.octets[1]:o}.0{self.octets[2]:o}.0x{self.octets[3]:X}"
def mix_dec_hex_hex_oct(self) -> str:
"""dec.hex.hex.oct"""
return f"{self.octets[0]}.0x{self.octets[1]:X}.0x{self.octets[2]:X}.0{self.octets[3]:o}"
def mix_hex_oct_hex_dec(self) -> str:
"""hex.oct.hex.dec"""
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.0x{self.octets[2]:X}.{self.octets[3]}"
def mix_hex_dec_hex_oct(self) -> str:
"""hex.dec.hex.oct"""
return f"0x{self.octets[0]:X}.{self.octets[1]}.0x{self.octets[2]:X}.0{self.octets[3]:o}"
def mix_oct_hex_oct_dec(self) -> str:
"""oct.hex.oct.dec"""
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.0{self.octets[2]:o}.{self.octets[3]}"
def mix_oct_dec_oct_hex(self) -> str:
"""oct.dec.oct.hex"""
return f"0{self.octets[0]:o}.{self.octets[1]}.0{self.octets[2]:o}.0x{self.octets[3]:X}"
# =========================================================================
# RANDOM PADDING TECHNIQUES
# =========================================================================
def random_hex_padding(self) -> str:
"""Each octet as hex with random padding (1-8 zeros)."""
result = []
for o in self.octets:
padding = random.randint(1, 8)
result.append(f"0x{'0' * padding}{o:X}")
return '.'.join(result)
def random_octal_padding(self) -> str:
"""Each octet as octal with random padding (1-8 zeros)."""
result = []
for o in self.octets:
padding = random.randint(1, 8)
result.append(f"{'0' * padding}{o:o}")
return '.'.join(result)
def random_mixed_padding(self) -> str:
"""Mix of bases with random padding."""
result = []
for o in self.octets:
fmt = random.choice(['dec', 'hex', 'oct'])
padding = random.randint(0, 6)
if fmt == 'dec':
result.append(str(o))
elif fmt == 'hex':
result.append(f"0x{'0' * padding}{o:x}")
else:
result.append(f"{'0' * padding}{o:o}")
return '.'.join(result)
# =========================================================================
# MIXED CLASS SHORTHAND WITH HEX/OCTAL PREFIX
# =========================================================================
def hex_class_c(self) -> str:
"""Hex first 2 octets + Class C merge (16-bit).
Example: 0xC0.0xA8.16898"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0x{self.octets[0]:X}.0x{self.octets[1]:X}.{merged}"
def hex_class_b(self) -> str:
"""Hex first octet + Class B merge (24-bit).
Example: 0xC0.11026946"""
merged = (self.octets[1] << 16) | (self.octets[2] << 8) | self.octets[3]
return f"0x{self.octets[0]:X}.{merged}"
def octal_class_c(self) -> str:
"""Octal first 2 octets + Class C merge (16-bit).
Example: 0300.0250.16898"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0{self.octets[0]:o}.0{self.octets[1]:o}.{merged}"
def octal_class_b(self) -> str:
"""Octal first octet + Class B merge (24-bit).
Example: 0300.11026946"""
merged = (self.octets[1] << 16) | (self.octets[2] << 8) | self.octets[3]
return f"0{self.octets[0]:o}.{merged}"
def hex_octal_class_c(self) -> str:
"""Hex first, octal second + Class C merge.
Example: 0xC0.0250.16898"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.{merged}"
def octal_hex_class_c(self) -> str:
"""Octal first, hex second + Class C merge.
Example: 0300.0xA8.16898"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.{merged}"
# =========================================================================
# MIXED BASE WITH MERGED OCTETS
# =========================================================================
def hex_oct_merged_dec(self) -> str:
"""hex.oct.merged-decimal
Example: 0xC0.0250.16898"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0x{self.octets[0]:X}.0{self.octets[1]:o}.{merged}"
def hex_dec_merged_hex(self) -> str:
"""hex.dec.merged-hex
Example: 0xC0.168.0x4202"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0x{self.octets[0]:X}.{self.octets[1]}.0x{merged:X}"
def oct_hex_merged_oct(self) -> str:
"""oct.hex.merged-octal
Example: 0300.0xA8.0102002"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0{self.octets[0]:o}.0x{self.octets[1]:X}.0{merged:o}"
def dec_oct_merged_hex(self) -> str:
"""dec.oct.merged-hex
Example: 192.0250.0x4202"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"{self.octets[0]}.0{self.octets[1]:o}.0x{merged:X}"
def dec_hex_merged_oct(self) -> str:
"""dec.hex.merged-octal
Example: 192.0xA8.0102002"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"{self.octets[0]}.0x{self.octets[1]:X}.0{merged:o}"
def oct_dec_merged_hex(self) -> str:
"""oct.dec.merged-hex
Example: 0300.168.0x4202"""
merged = (self.octets[2] << 8) | self.octets[3]
return f"0{self.octets[0]:o}.{self.octets[1]}.0x{merged:X}"
# =========================================================================
# CLASS-BASED SHORTHAND (inet_aton compatibility)
# =========================================================================
def class_a_format(self) -> str:
"""
Single value (Class A style).
a -> a.0.0.0 expanded, but here we use full integer.
Example: 3232235777
Source: inet_aton() man page, BSD sockets
"""
return str(self.integer)
def class_b_format(self) -> str:
"""
Two-part notation: a.b (a = first octet, b = 24-bit value).
Example: 192.168.1.1 -> 192.11010305
inet_aton interprets: a.b where b is 24-bit
Source: inet_aton() man page
"""
a = self.octets[0]
b = (self.octets[1] << 16) | (self.octets[2] << 8) | self.octets[3]
return f"{a}.{b}"
def class_c_format(self) -> str:
"""
Three-part notation: a.b.c (c = 16-bit value).
Example: 192.168.1.1 -> 192.168.257
inet_aton interprets: a.b.c where c is 16-bit
Source: inet_aton() man page
"""
a = self.octets[0]
b = self.octets[1]
c = (self.octets[2] << 8) | self.octets[3]
return f"{a}.{b}.{c}"
# =========================================================================
# IPv6 MAPPED FORMATS
# =========================================================================
def ipv6_mapped(self) -> str:
"""
IPv4-mapped IPv6 address (dotted decimal).
Example: 192.168.1.1 -> ::ffff:192.168.1.1
Source: SANS ISC diary 30466
"""
return f"::ffff:{self.ip}"
def ipv6_mapped_hex(self) -> str:
"""
IPv4-mapped IPv6 address (hexadecimal).
Example: 192.168.1.1 -> ::ffff:c0a8:0101
Used for: URL obfuscation, firewall bypass
Source: SANS ISC, Cloudflare bug report
"""
high = (self.octets[0] << 8) | self.octets[1]
low = (self.octets[2] << 8) | self.octets[3]
return f"::ffff:{high:x}:{low:x}"
def ipv6_mapped_hex_full(self) -> str:
"""
Full IPv6 format with mapped address.
Example: 0000:0000:0000:0000:0000:ffff:c0a8:0101
"""
high = (self.octets[0] << 8) | self.octets[1]
low = (self.octets[2] << 8) | self.octets[3]
return f"0000:0000:0000:0000:0000:ffff:{high:04x}:{low:04x}"
def ipv6_compatible(self) -> str:
"""
IPv4-compatible IPv6 address (deprecated but may work).
Example: 192.168.1.1 -> ::192.168.1.1
"""
return f"::{self.ip}"
def ipv6_compatible_hex(self) -> str:
"""
IPv4-compatible IPv6 in hex.
Example: ::c0a8:0101
"""
high = (self.octets[0] << 8) | self.octets[1]
low = (self.octets[2] << 8) | self.octets[3]
return f"::{high:x}:{low:x}"
# =========================================================================
# OVERFLOW / WRAPAROUND TECHNIQUES
# =========================================================================
def overflow_dword(self) -> str:
"""
Add 2^32 to create overflow (may work in some parsers).
Example: 192.168.1.1 -> 7527203073 (3232235777 + 4294967296)
Source: Webroot (Koobface analysis)
"""
return str(self.integer + (256 ** 4))
def overflow_octets(self) -> str:
"""
Add 256 to octets (overflow each byte).
Example: 192.168.1.1 -> 448.424.257.257
Note: May not work in modern browsers
"""
return '.'.join(str(o + 256) for o in self.octets)
# =========================================================================
# URL ENCODING TECHNIQUES
# =========================================================================
def url_encoded_decimal(self) -> str:
"""
URL/percent encode the dotted decimal (all characters).
Example: 192.168.1.1 -> %31%39%32%2E%31%36%38%2E%31%2E%31
"""
return ''.join(f'%{ord(c):02X}' for c in str(self.ip))
def url_encoded_dots_only(self) -> str:
"""
URL encode only the dots (%2E).
Example: 192.168.1.1 -> 192%2E168%2E66%2E2
"""
return str(self.ip).replace('.', '%2E')
def url_encoded_random(self) -> str:
"""
Randomly URL encode some characters.
Example: 1%39%32.16%38.%36%36.2
"""
result = []
for c in str(self.ip):
if c.isdigit() and random.random() > 0.5:
result.append(f'%{ord(c):02X}')
else:
result.append(c)
return ''.join(result)
def url_double_encoded(self) -> str:
"""
Double URL encoding (for WAF bypass).
Example: 192%252E168%252E66%252E2 (%25 = encoded %)
"""
# First encode dots, then encode the % sign
return str(self.ip).replace('.', '%252E')
def url_unicode_encoded(self) -> str:
"""
Unicode URL encoding (%u format, legacy IIS).
Example: 192%u002E168%u002E66%u002E2
"""
return str(self.ip).replace('.', '%u002E')
def url_encoded_colons(self) -> str:
"""
Replace dots with URL-encoded colons (%3A).
Example: 192%3A168%3A66%3A2
Note: May work in some parsers that accept : as separator.
"""
return str(self.ip).replace('.', '%3A')
# =========================================================================
# URL SCHEMA ABUSE (@ symbol trick)
# =========================================================================
def url_with_fake_auth(self, fake_domain: str = "google.com") -> str:
"""
URL with fake authentication section.
Example: http://google.com@3232235777
The part before @ is ignored by browsers.
Used by: SMOKELOADER, various phishing
Source: Mandiant "URL Schema Obfuscation"
"""
return f"http://{fake_domain}@{self.integer}"
def url_with_fake_auth_hex(self, fake_domain: str = "google.com") -> str:
"""With hex DWORD instead of decimal."""
return f"http://{fake_domain}@0x{self.integer:x}"
def url_with_fake_auth_octal(self, fake_domain: str = "google.com") -> str:
"""With octal DWORD instead of decimal."""
return f"http://{fake_domain}@{self.octal_dword()}"
def url_with_fake_auth_ipv6(self, fake_domain: str = "google.com") -> str:
"""With IPv6 mapped address."""
return f"http://{fake_domain}@[{self.ipv6_mapped_hex()}]"
def url_multi_at(self, fake_domain: str = "google.com", extra: str = "accounts") -> str:
"""
Multiple @ signs (some parsers take last @).
Example: http://google.com@accounts@3232235777
Source: Cuteit
"""
return f"http://{fake_domain}@{extra}@{self.integer}"
def url_plus_trick(self, fake_domain: str = "facebook.com", path_fake: str = "settings") -> str:
"""
Plus sign trick in fake auth.
Example: https://facebook.com+settings@3232235777
Source: Cuteit
"""
return f"https://{fake_domain}+{path_fake}@{self.integer}"
def url_with_userpass(self, fake_domain: str = "google.com", user: str = "admin", passwd: str = "secure") -> str:
"""
Full user:pass@host format.
Example: http://admin:secure@3232235777
"""
return f"http://{user}:{passwd}@{self.integer}"
def url_encoded_at(self, fake_domain: str = "google.com") -> str:
"""
URL-encoded @ symbol (%40).
Example: http://google.com%403232235777
Note: Some parsers may not recognize this as auth separator.
"""
return f"http://{fake_domain}%40{self.integer}"
# =========================================================================
# LEADING ZEROS PADDING
# =========================================================================
def decimal_padded(self) -> str:
"""
Decimal with leading zeros (treated as octal by some parsers!)
Example: 192.168.001.001
WARNING: Leading zeros = OCTAL in inet_aton!
Source: SANS ISC
"""
return '.'.join(f'{o:03d}' for o in self.octets)
def decimal_heavy_padded(self) -> str:
"""Extra heavy zero padding."""
return '.'.join(f'{o:010d}' for o in self.octets)
# =========================================================================
# BRACKET FORMATS (for URLs)
# =========================================================================
def bracketed_ipv6_mapped(self) -> str:
"""
Bracketed IPv6 for URL use.
Example: [::ffff:c0a8:0101]
"""
return f"[{self.ipv6_mapped_hex()}]"
def bracketed_ipv6_mapped_decimal(self) -> str:
"""Bracketed with decimal IPv4 portion."""
return f"[::ffff:{self.ip}]"
def bracketed_ipv6_full(self) -> str:
"""Bracketed full IPv6."""
return f"[{self.ipv6_mapped_hex_full()}]"
def bracketed_url_encoded(self) -> str:
"""
URL-encoded brackets around IPv6.
Example: %5B::ffff:c0a8:4202%5D
"""
return f"%5B{self.ipv6_mapped_hex()}%5D"
# =========================================================================
# ADDITIONAL IPv6 FORMATS
# =========================================================================
def ipv6_short_zeros(self) -> str:
"""
IPv6 with explicit zeros (not collapsed).
Example: 0:0:0:0:0:ffff:c0a8:4202
"""
high = (self.octets[0] << 8) | self.octets[1]
low = (self.octets[2] << 8) | self.octets[3]
return f"0:0:0:0:0:ffff:{high:x}:{low:x}"
def ipv6_mapped_dword(self) -> str:
"""
IPv6-mapped with merged DWORD for IPv4 portion.
Example: ::ffff:c0a84202 (without colon in IPv4 part)
"""
return f"::ffff:{self.integer:x}"
# =========================================================================
# HEX DWORD VARIANTS
# =========================================================================
def hex_dword_uppercase_prefix(self) -> str:
"""
Hex DWORD with uppercase 0X prefix.
Example: 0XC0A84202
"""
return f"0X{self.integer:08X}"
# =========================================================================
# GENERATE ALL FORMATS
# =========================================================================
def generate_all(self) -> Dict[str, str]:
"""Generate all obfuscation formats."""
return {
# Standard
"Standard Dotted Decimal": self.standard_dotted_decimal(),
# Integer/DWORD
"Decimal DWORD": self.decimal_dword(),
"Hex DWORD (uppercase)": self.hex_dword(),
"Hex DWORD (lowercase)": self.hex_dword_lowercase(),
"Hex DWORD (0X prefix)": self.hex_dword_uppercase_prefix(),
"Octal DWORD": self.octal_dword(),
# Dotted variants
"Dotted Hex": self.dotted_hex(),
"Dotted Hex (lowercase)": self.dotted_hex_lowercase(),
"Dotted Hex (padded)": self.dotted_hex_padded(),
"Dotted Hex (long padded)": self.dotted_hex_long_padded(),
"Dotted Octal": self.dotted_octal(),
"Dotted Octal (padded)": self.dotted_octal_padded(),
"Dotted Octal (long padded)": self.dotted_octal_long_padded(),
# Mixed bases (legacy)
"Mixed Hex/Decimal": self.mixed_hex_decimal(),
"Mixed Octal/Decimal": self.mixed_octal_decimal(),
"Mixed All Bases": self.mixed_all_bases(),
"Random Mixed": self.random_mixed(),
# Partial hex conversions
"Hex First 3": self.hex_first_3(),
"Hex First 2": self.hex_first_2(),
"Hex First 1": self.hex_first_1(),
"Hex Last 3": self.hex_last_3(),
"Hex Last 2": self.hex_last_2(),
"Hex Last 1": self.hex_last_1(),
# Partial octal conversions
"Octal First 3": self.octal_first_3(),
"Octal First 2": self.octal_first_2(),
"Octal First 1": self.octal_first_1(),
"Octal Last 3": self.octal_last_3(),
"Octal Last 2": self.octal_last_2(),
"Octal Last 1": self.octal_last_1(),
# Partial hex with long padding
"Hex Padded First 3": self.hex_padded_first_3(),
"Hex Padded First 2": self.hex_padded_first_2(),
"Hex Padded First 1": self.hex_padded_first_1(),
# Partial octal with long padding
"Octal Padded First 3": self.octal_padded_first_3(),
"Octal Padded First 2": self.octal_padded_first_2(),
"Octal Padded First 1": self.octal_padded_first_1(),
# Three-way base mixing
"Mix hex.oct.dec.dec": self.mix_hex_oct_dec_dec(),
"Mix hex.dec.oct.dec": self.mix_hex_dec_oct_dec(),
"Mix hex.dec.dec.oct": self.mix_hex_dec_dec_oct(),
"Mix hex.oct.oct.dec": self.mix_hex_oct_oct_dec(),
"Mix hex.oct.dec.oct": self.mix_hex_oct_dec_oct(),
"Mix hex.dec.oct.oct": self.mix_hex_dec_oct_oct(),
"Mix oct.hex.dec.dec": self.mix_oct_hex_dec_dec(),
"Mix oct.dec.hex.dec": self.mix_oct_dec_hex_dec(),
"Mix oct.dec.dec.hex": self.mix_oct_dec_dec_hex(),
"Mix oct.hex.hex.dec": self.mix_oct_hex_hex_dec(),
"Mix oct.hex.dec.hex": self.mix_oct_hex_dec_hex(),
"Mix oct.dec.hex.hex": self.mix_oct_dec_hex_hex(),
"Mix dec.hex.oct.dec": self.mix_dec_hex_oct_dec(),
"Mix dec.hex.dec.oct": self.mix_dec_hex_dec_oct(),
"Mix dec.oct.hex.dec": self.mix_dec_oct_hex_dec(),
"Mix dec.oct.dec.hex": self.mix_dec_oct_dec_hex(),
"Mix dec.dec.hex.oct": self.mix_dec_dec_hex_oct(),
"Mix dec.dec.oct.hex": self.mix_dec_dec_oct_hex(),
"Mix dec.hex.oct.oct": self.mix_dec_hex_oct_oct(),
"Mix dec.oct.hex.hex": self.mix_dec_oct_hex_hex(),
"Mix dec.oct.oct.hex": self.mix_dec_oct_oct_hex(),
"Mix dec.hex.hex.oct": self.mix_dec_hex_hex_oct(),
"Mix hex.oct.hex.dec": self.mix_hex_oct_hex_dec(),
"Mix hex.dec.hex.oct": self.mix_hex_dec_hex_oct(),
"Mix oct.hex.oct.dec": self.mix_oct_hex_oct_dec(),
"Mix oct.dec.oct.hex": self.mix_oct_dec_oct_hex(),
# Random padding
"Random Hex Padding": self.random_hex_padding(),
"Random Octal Padding": self.random_octal_padding(),
"Random Mixed Padding": self.random_mixed_padding(),
# Mixed Class shorthand with hex/octal
"Hex + Class C": self.hex_class_c(),
"Hex + Class B": self.hex_class_b(),
"Octal + Class C": self.octal_class_c(),
"Octal + Class B": self.octal_class_b(),
"Hex.Octal + Class C": self.hex_octal_class_c(),
"Octal.Hex + Class C": self.octal_hex_class_c(),
# Mixed base with merged octets
"Hex.Oct.Merged-Dec": self.hex_oct_merged_dec(),
"Hex.Dec.Merged-Hex": self.hex_dec_merged_hex(),
"Oct.Hex.Merged-Oct": self.oct_hex_merged_oct(),
"Dec.Oct.Merged-Hex": self.dec_oct_merged_hex(),
"Dec.Hex.Merged-Oct": self.dec_hex_merged_oct(),
"Oct.Dec.Merged-Hex": self.oct_dec_merged_hex(),
# Class-based shorthand
"Class B Format (a.bbb)": self.class_b_format(),
"Class C Format (a.b.cc)": self.class_c_format(),
# IPv6 mapped
"IPv6 Mapped (decimal)": self.ipv6_mapped(),
"IPv6 Mapped (hex)": self.ipv6_mapped_hex(),
"IPv6 Mapped (full)": self.ipv6_mapped_hex_full(),
"IPv6 Short Zeros": self.ipv6_short_zeros(),
"IPv6 Mapped DWORD": self.ipv6_mapped_dword(),
"IPv6 Compatible": self.ipv6_compatible(),
"IPv6 Compatible (hex)": self.ipv6_compatible_hex(),
# Overflow
"Overflow DWORD (+2^32)": self.overflow_dword(),
"Overflow Octets (+256)": self.overflow_octets(),
# URL encoding
"URL Encoded (full)": self.url_encoded_decimal(),
"URL Encoded (dots only)": self.url_encoded_dots_only(),
"URL Encoded (random)": self.url_encoded_random(),
"URL Double Encoded": self.url_double_encoded(),
"URL Unicode Encoded": self.url_unicode_encoded(),
"URL Encoded Colons": self.url_encoded_colons(),
# URL schema abuse
"URL Fake Auth (decimal)": self.url_with_fake_auth(),
"URL Fake Auth (hex)": self.url_with_fake_auth_hex(),
"URL Fake Auth (octal)": self.url_with_fake_auth_octal(),
"URL Fake Auth (IPv6)": self.url_with_fake_auth_ipv6(),
"URL Multi-@": self.url_multi_at(),
"URL Plus Trick": self.url_plus_trick(),
"URL User:Pass@Host": self.url_with_userpass(),
"URL Encoded @": self.url_encoded_at(),
# Leading zeros
"Decimal Padded (caution: octal!)": self.decimal_padded(),
"Decimal Heavy Padded": self.decimal_heavy_padded(),
# Bracketed
"Bracketed IPv6 Mapped": self.bracketed_ipv6_mapped(),
"Bracketed IPv6 Decimal": self.bracketed_ipv6_mapped_decimal(),
"Bracketed IPv6 Full": self.bracketed_ipv6_full(),
"Bracketed URL Encoded": self.bracketed_url_encoded(),
}
def generate_urls(self, path: str = "/") -> Dict[str, str]:
"""Generate URL versions of all formats."""
urls = {}
formats = self.generate_all()
for name, value in formats.items():
if value.startswith("http"):
urls[name] = value + path
elif value.startswith("["):
urls[name] = f"http://{value}{path}"
elif "::" in value:
urls[name] = f"http://[{value}]{path}"
else:
urls[name] = f"http://{value}{path}"
return urls
def generate_obfuscated_urls(
ip: str,
fake_domain: str = "google.com",
path: str = "/",
port: Optional[int] = None,
fake_password: Optional[str] = None,
use_https: bool = False,
) -> Dict[str, str]:
"""
Generate all possible obfuscated URL combinations.
Args:
ip: Target IPv4 address (e.g., "193.24.210.101")
fake_domain: Fake domain to show before @ (e.g., "secure.bank.com")
path: Path to request on target server (e.g., "/account/login")
port: Optional port number (e.g., 8080)
fake_password: Optional fake password for user:pass@host format
use_https: Use HTTPS instead of HTTP
Returns:
Dictionary of technique names to obfuscated URLs
"""
obf = IPObfuscator(ip)
urls = {}
proto = "https" if use_https else "http"
# Ensure path starts with /
if not path.startswith("/"):
path = "/" + path
# Build port string
port_str = f":{port}" if port else ""
# Build auth string
if fake_password:
auth = f"{fake_domain}:{fake_password}@"
else:
auth = f"{fake_domain}@"
# =========================================================================
# NO OBFUSCATION (baseline)
# =========================================================================
urls["Standard (no obfuscation)"] = f"{proto}://{ip}{port_str}{path}"
# =========================================================================
# IP-ONLY OBFUSCATION (no fake auth)
# =========================================================================
# Integer/DWORD formats
urls["Decimal DWORD"] = f"{proto}://{obf.decimal_dword()}{port_str}{path}"
urls["Hex DWORD"] = f"{proto}://{obf.hex_dword()}{port_str}{path}"
urls["Hex DWORD (lowercase)"] = f"{proto}://{obf.hex_dword_lowercase()}{port_str}{path}"
urls["Hex DWORD (0X prefix)"] = f"{proto}://{obf.hex_dword_uppercase_prefix()}{port_str}{path}"
urls["Octal DWORD"] = f"{proto}://{obf.octal_dword()}{port_str}{path}"