-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathxorpass.py
130 lines (105 loc) · 5.85 KB
/
xorpass.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
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
#!/usr/bin/python3
try:
import argparse
import string
import random
import re
from colorama import Fore
from builtins import ImportError
except ImportError:
print ("\
Error: Install required libraries\n\
pip3 install argparse string random re colorama builtins")
exit()
def banner():
print ("\n" +
Fore.WHITE + " |-------____ \n" +
Fore.WHITE + " | | \___ __ _____ ____ \n" +
Fore.WHITE + " ---------| \ \ \/ / _ \| _ \ " + Fore.RED + "_ __ __ _ ___ ___ \n" +
Fore.WHITE + " | | \_______ \ / | | | |_) " + Fore.RED + "| '_ \ / _` / __/ __| \n" +
Fore.WHITE + " | | / / \ |_| | _ <" + Fore.RED + "| |_) | (_| \__ \__ \ \n" +
Fore.WHITE + " ---------| ___/ /_/\_\___/|_| \_\ " + Fore.RED + ".__/ \__,_|___/___/ \n" +
Fore.WHITE + " | | ____/ " + Fore.RED + "|_| \n" +
Fore.WHITE + " |------- @devploit \n" )
class XORpass():
DEFAULT_CHARSET = string.ascii_letters + string.digits
SEPARATORS = '()[]{}:;+-/ "' # type: Any
def _calc_xor_char(self, payload_char, charset=DEFAULT_CHARSET, randomize=True):
for first_char in (charset if not randomize else "".join(random.sample(charset, len(charset)))):
for second_char in (charset if not randomize else "".join(random.sample(charset, len(charset)))):
third_char = chr(ord(first_char) ^ ord(second_char) ^ ord(payload_char))
if third_char != payload_char and third_char in charset:
return [first_char, second_char, third_char]
raise Exception("Charset not valid for this payload. char=%c charset=%s" % (payload_char, charset))
def _calc_xor_string(self, payload, charset=DEFAULT_CHARSET, randomize=True):
if payload[0] == '"':
payload = payload[1:-1]
result = ["", "", ""]
for c in payload:
xored_chars = self._calc_xor_char(c, charset=charset, randomize=randomize)
for i in range(3):
result[i] += xored_chars[i]
return result
def encode(self, payload, charset=DEFAULT_CHARSET, randomize=True, badchars=""):
charset = "".join([x if x not in badchars else "" for x in charset])
payload_array = re.split(r'(\"[\w\- ]+\")|([\w\.]+)', payload)
result = ""
for word in payload_array:
if word == None: continue
if word == "" or word in self.SEPARATORS:
result += word
continue
xored_words = self._calc_xor_string(word, charset=charset, randomize=randomize)
xored_words = ['"' + x + '"' for x in xored_words]
result += "(" + "^".join(xored_words) + ")"
while True:
match = re.search(r'(\(\([\^\w\"]+)\)\)', result)
if not match: break
result = result.replace(match.group(0), match.group(0)[1:-1])
return result
def _decode_string(self, payload_string):
parts = payload_string.split("^")
parts = [p.strip('"') for p in parts]
result = ""
for a, b, c in zip(*parts):
result += chr(ord(a) ^ ord(b) ^ ord(c))
if 1 in [c in self.SEPARATORS for c in result]:
result = '"' + result + '"'
return result
def decode(self, payload):
parts = re.split(r'([\^\w\"]+)', payload)
result = ""
for p in parts:
if "^" in p:
result += self._decode_string(p)
else:
result += p
return result
def main():
banner()
parser = argparse.ArgumentParser(description="Encoder to bypass WAF filters using XOR operations.")
grouped = parser.add_mutually_exclusive_group(required=True)
grouped.add_argument("--encode", "-e", help="Encode the payload")
grouped.add_argument("--decode", "-d", help="Decode the payload")
parser.add_argument("--number", "-n", default=1, type=int, help="Number of encoded results")
groupcb = parser.add_mutually_exclusive_group()
groupcb.add_argument("--charset", "-c", default=string.ascii_letters + string.digits,
help="Select specific charset for encoding")
groupcb.add_argument("--badchars", "-b", default="", help="Select specific badchars for encoding")
args = parser.parse_args()
if args.encode is not None:
print(Fore.CYAN + "[" + Fore.WHITE + "+" + Fore.CYAN + "] Charset: " + Fore.WHITE + str(args.charset))
print(Fore.YELLOW + "[" + Fore.WHITE + "-" + Fore.YELLOW + "] Badchars: " + Fore.WHITE + str(args.badchars))
print(Fore.BLUE + "[" + Fore.WHITE + "*" + Fore.BLUE + "] Payload: " + Fore.WHITE + str(args.encode))
try:
for _ in range(args.number):
result = XORpass().encode(args.encode, charset=args.charset, badchars=args.badchars)
print(Fore.GREEN + "[" + Fore.WHITE + "#" + Fore.GREEN + "] Encoded Payload: " + Fore.WHITE + result)
except Exception as ex:
print("Error encoding the payload: ", ex)
if args.decode is not None:
print(Fore.BLUE + "[" + Fore.WHITE + "*" + Fore.BLUE + "] Encoded Payload: " + Fore.WHITE + str(args.decode))
result = XORpass().decode(args.decode)
print(Fore.GREEN + "[" + Fore.WHITE + "#" + Fore.GREEN + "] Decoded Payload: " + Fore.WHITE + result)
if __name__ == "__main__":
main()