-
Notifications
You must be signed in to change notification settings - Fork 24
/
xortools.py
71 lines (61 loc) · 1.42 KB
/
xortools.py
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
#!/usr/bin/python
import struct
def single_byte_xor(buf, key):
out = ''
for i in buf:
out += chr(ord(i) ^ key)
return out
def single_byte_brute_xor(buf, plntxt, start=None, end=None):
for key in range (1,255):
out = ''
for i in buf:
out += chr(ord(i) ^ key)
if out[start:end].find(plntxt) != -1:
return (key, out)
return (None,None)
def get_xor_permutations(buf):
out = []
for key in range(1,255):
out.append(single_byte_xor(buf, key))
return out
def two_byte_xor(buf, key):
out = ''
for i in range(0,len(buf)/2):
c = struct.unpack("=H", buf[(i*2):(i*2)+2])[0]
c ^= key
out += struct.pack("=H", c)
return out
def four_byte_xor(buf, key):
out = ''
for i in range(0,len(buf)/4):
c = struct.unpack("=I", buf[(i*4):(i*4)+4])[0]
c ^= key
out += struct.pack("=I", c)
return out
def rolling_xor(buf, key):
out = ''
k = 0
for i in buf:
if k == len(key):
k = 0
out += chr(ord(i) ^ ord(key[k]))
k += 1
return out
def yaratize(rule, vals):
n = 0
strs = []
for val in vals:
s = ' $_%d = { ' % n
for c in val:
s += "%2.2x " % ord(c)
s += '}'
strs.append(s)
n += 1
return """
rule %s
{
strings:
%s
condition:
any of them
}""" % (rule,'\n'.join(strs))