-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobfuscator.py
More file actions
67 lines (55 loc) · 1.67 KB
/
obfuscator.py
File metadata and controls
67 lines (55 loc) · 1.67 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
import sys
from random import randint, random
import re
class Obfuscator:
def __init__(
self,
min_length: int,
max_length: int,
) -> None:
self.min_length = min_length
self.max_length = max_length
def obfuscate(
self,
command: str
) -> str:
obfuscations = []
length = randint(self.min_length, self.max_length)
for _ in range(length):
if random() > 0.5:
obfuscations.append('AND')
obfuscations.append(self._generate_and_clause())
else:
obfuscations.append('OR')
obfuscations.append(self._generate_or_clause())
obfuscations.insert(0, command)
result = ' '.join(obfuscations)
if random() > 0.28:
result = self._mask_integers(result)
return result
def _generate_and_clause(self) -> str:
num = randint(0, 9)
return str(num) + '=' + str(num)
def _generate_or_clause(self) -> str:
left = randint(0, 1000)
right = left + randint(1, 1000)
return str(left) + '=' + str(right)
def _mask_integers(
self,
s: str,
) -> str:
i = re.finditer('\d+', s)
i = list(i)
i.reverse()
for m in i:
start = int(m.start(0))
end = int(m.end(0))
rand = randint(1, 1000)
num = rand + int(s[start:end])
exp = str(num) + '-' + str(rand)
s = s[:start] + exp + s[end:]
return s
if __name__ == '__main__':
obf = Obfuscator(5, 10)
command = sys.argv[1]
print(obf.obfuscate(command))