Skip to content

Commit

Permalink
Remove edge case where IP wasn't actually obfuscated
Browse files Browse the repository at this point in the history
  • Loading branch information
capnspacehook committed Jul 14, 2018
1 parent 5c513c7 commit 7968165
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/obfuscators.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,31 @@ def random_base_ip_gen(parts, smallIP):
octParts.append(oct(int(i)))

randBaseIP = ""
for i in range(0,4):
val = ord(os.urandom(1)) % 3
if val == 0:
# dec
randBaseIP += parts[i] + '.'
elif val == 1:
# hex
if not smallIP:
randBaseIP += hexParts[i].replace('0x', '0x' + '0' * (ord(os.urandom(1)) % 31)) + '.'
baseChoices = []
ip_obfuscated = False
while not ip_obfuscated:
for i in range(0,4):
val = ord(os.urandom(1)) % 3
baseChoices.append(val)
if val == 0:
# dec
randBaseIP += parts[i] + '.'
elif val == 1:
# hex
if not smallIP:
randBaseIP += hexParts[i].replace('0x', '0x' + '0' * (ord(os.urandom(1)) % 31)) + '.'
else:
randBaseIP += hexParts[i] + '.'
else:
randBaseIP += hexParts[i] + '.'
# oct
if not smallIP:
randBaseIP += '0' * (ord(os.urandom(1)) % 31) + octParts[i] + '.'
else:
randBaseIP += octParts[i] + '.'

if sum(baseChoices) > 0:
ip_obfuscated = True
else:
# oct
if not smallIP:
randBaseIP += '0' * (ord(os.urandom(1)) % 31) + octParts[i] + '.'
else:
randBaseIP += octParts[i] + '.'
baseChoices.clear()

return randBaseIP[:-1]

0 comments on commit 7968165

Please sign in to comment.