From 79681657fe82c4ad724c9e96e238c54c3b06cfa6 Mon Sep 17 00:00:00 2001 From: Andrew LeFevre Date: Sat, 14 Jul 2018 00:47:19 -0400 Subject: [PATCH] Remove edge case where IP wasn't actually obfuscated --- src/obfuscators.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/obfuscators.py b/src/obfuscators.py index 03381e1..f79723c 100644 --- a/src/obfuscators.py +++ b/src/obfuscators.py @@ -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]