-
Notifications
You must be signed in to change notification settings - Fork 0
/
string-mangler.py
112 lines (96 loc) · 3.07 KB
/
string-mangler.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
#!/usr/bin/env python
"""This script will encode/decode strings."""
import codecs
import base64
import argparse
import urllib
import hashlib
from sys import argv, exit
from binascii import hexlify
parser = argparse.ArgumentParser(
description="This script will encode/decode strings")
parser.add_argument("input_string", help="Input String")
first_group = parser.add_mutually_exclusive_group()
first_group.add_argument(
"-e", "--encode", help="Encode String", action="store_true")
first_group.add_argument(
"-d", "--decode", help="Decode String", action="store_true")
second_group = parser.add_mutually_exclusive_group()
second_group.add_argument(
"--base64", help="Base64", action="store_true")
second_group.add_argument(
"--md5", help="MD5", action="store_true")
second_group.add_argument(
"--ntlm", help="NTLM", action="store_true")
second_group.add_argument(
"--rot13", help="ROT13", action="store_true")
second_group.add_argument(
"--psh", help="PowerShell Base64 (Unicode)", action="store_true")
second_group.add_argument(
"--url", help="URL", action="store_true")
if len(argv) < 4:
parser.print_help()
exit()
args = parser.parse_args()
class Str:
"""Input string class."""
def __init__(self, input_string, e):
"""Initialize Str class."""
self.input_string = input_string
self.e = e
def base64(self):
"""Encode/decode in base64."""
if self.e:
return base64.b64encode(self.input_string)
else:
return base64.b64decode(self.input_string)
def rot13(self):
"""Encode/decode in ROT13."""
if self.e:
return codecs.encode(self.input_string, 'rot13')
else:
return codecs.decode(self.input_string, 'rot13')
def url(self):
"""Encode/decode in URL."""
if self.e:
return urllib.quote_plus(self.input_string)
else:
return urllib.unquote(self.input_string)
def md5(self):
"""Encode in MD5."""
if self.e:
h = hashlib.md5()
h.update(self.input_string)
return h.hexdigest()
else:
return "https://hashkiller.co.uk/md5-decrypter.aspx"
def ntlm(self):
"""Encode in NTLM."""
if self.e:
h = self.input_string.encode('utf-16le')
h = hashlib.new('md4', h).digest()
return hexlify(h)
else:
return "https://hashkiller.co.uk/ntlm-decrypter.aspx"
def psh(self):
"""Encode/decode in base64 for PowerShell (Unicode)."""
if self.e:
return base64.b64encode(self.input_string.encode('utf-16le'))
else:
return base64.b64decode(self.input_string).decode('utf-16le')
if args.encode:
str_object = Str(args.input_string, 1)
else:
str_object = Str(args.input_string, 0)
if args.base64:
print str_object.base64()
elif args.rot13:
print str_object.rot13()
elif args.url:
print str_object.url()
elif args.md5:
print str_object.md5()
elif args.ntlm:
print str_object.ntlm()
elif args.psh:
print str_object.psh()