forked from shekkbuilder/Shellcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverstackv2.py
More file actions
168 lines (142 loc) · 4.67 KB
/
Copy pathconverstackv2.py
File metadata and controls
168 lines (142 loc) · 4.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import sys
import re
from optparse import OptionParser
#Deprecated since version 2.6
#The commands module has been removed in Python 3. Use the subprocess module instead.
#I'm still using 2.x, so fuck it lol.
try:
from colorama import init,Fore
init()
except:
print "Please, install colorama module!"
print "pip install colorama"
#Author : B3mB4m
#Title : Shellcode Helper(x86 Litle Endian Stack Converter)
#Concat : [email protected]
#Version : v2 Final(I hope)
#Supported AT&T - Intel Syntaxs
#Most boring part shellcoding turning strings to stack but from now on its not !
#https://github.com/b3mb4m/Shellcode/tree/master/Auxiliary/ConverStack
def helper():
print r"""
___ _ ___
| _ ) ___ _ __ | |__ ___ _ _ _ __ __ _ _ _ / __|
| _ \/ _ \ ' \| '_ \/ -_) '_| ' \/ _` | ' \\__ \
|___/\___/_|_|_|_.__/\___|_| |_|_|_\__,_|_||_|___/
Bomberman & B3mB4m & T-Rex
root~/Desktop$ python stack.py --type "AT&T" --target "MyString" or "PATH"
root~/Desktop$ python stack.py --type "Intel" --target "MyString" or "PATH"
""";
sys.exit()
class B3mB4mPusheR(object):
def __init__(self, syntaxtype, target):
self.generate = target
self.syntaxtype = syntaxtype
self.cout = 0
self.fill = "/"
self.newlist = [x for x in range(len(str(self.generate)))]
for i in xrange(0, len(self.generate)):
self.newlist[i] = self.generate[i]
self.cout += 1;
if "/" in self.generate:
self.calculatorifpath( self.generate)
else:
self.calculatorifstring( self.generate)
def calculatorifstring(self, string):
if len(string) == 4:
if self.syntaxtype == "Intel":
stack = "push 0x%s" % (string[::-1].encode('hex'))
elif self.syntaxtype == "AT&T":
stack = "push $0x%s" % (string[::-1].encode('hex'))
print(Fore.GREEN + stack)
sys.exit()
elif len(string) % 4 == 0:
self.splitter( string)
else:
dwordpart = string[0:(len(string)-len(string)%4)]
wordpart = string[(len(string)-len(string)%4):len(string)]
self.splitter( dwordpart)
self.splitter( wordpart, "WordTime")
def calculatorifpath(self, hexme):
#In linux doesnt matter how many / in path.
#So we can use that our purpose.
#Therefore,we dont need convert to words too.
if len(hexme) % 4 == 0:
self.fill = self.fill
if len(hexme) % 4 == 1:
self.fill = self.fill * 4
elif len(hexme) % 4 == 2:
self.fill = self.fill * 3
elif len(hexme) % 4 == 3:
self.fill = self.fill * 2
if self.cout == 4:
if self.syntaxtype == "Intel":
stack = "push 0x%s" % (hexme[::-1].encode('hex'))
elif self.syntaxtype == "AT&T":
stack = "push $0x%s" % (hexme[::-1].encode('hex'))
print(Fore.GREEN + stack)
sys.exit()
elif self.cout > 4:
if len(hexme) % 4 == 0:
self.hextime(self.fill, hexme)
elif len(hexme) % 4 == 1:
self.hextime(self.fill, hexme)
sys.exit()
elif len(hexme) % 4 == 2:
self.hextime(self.fill, hexme)
sys.exit()
elif len(hexme) % 4 == 3:
self.hextime(self.fill, hexme)
sys.exit()
def hextime(self, putmein, hexme):
for i in xrange(0, len(hexme)):
if hexme[i] == "/":
self.newlist[i] = putmein
fixstring = self.complie( self.newlist)
self.splitter(fixstring)
break;
def complie(self, givemethatstring):
compliestring = ""
for i in givemethatstring:
compliestring += i
return compliestring
def splitter(self, hexdump, pushword="None"):
self.mylist = []
if pushword == "None":
fixmesempai = re.findall('....?', hexdump)
for x in fixmesempai[::-1]:
self.syntaxtyper( str(x[::-1].encode("hex")), "dword")
else:
dot = "." * len(hexdump)
fixmesempai = re.findall(dot+'?', hexdump)
for x in fixmesempai[::-1]:
if dot > 2:
self.syntaxtyper( str(x[::-1].encode("hex")), "dword")
else:
self.syntaxtyper( str(x[::-1].encode("hex")), "word")
for x in self.mylist:
print (Fore.GREEN + x)
def syntaxtyper(self, getstring, dwordORword):
if self.syntaxtype == "Intel":
if dwordORword == "dword":
getstring = "push 0x%s" % getstring
self.mylist.append(getstring)
elif dwordORword == "word":
getstring = "push word 0x%s" % getstring
self.mylist.append(getstring)
elif self.syntaxtype == "AT&T":
if dwordORword == "dword":
getstring = "push $0x%s" % getstring
self.mylist.append(getstring)
elif dwordORword == "word":
getstring = "pushw 0x%s" % getstring
self.mylist.append(getstring)
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('--type', action="store")
parser.add_option('--target', action="store")
options, args = parser.parse_args()
if options.type:
B3mB4mPusheR( options.type, options.target)
else:
helper()