forked from shekkbuilder/Shellcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASMtoShellcode.py
More file actions
67 lines (61 loc) · 2.08 KB
/
Copy pathASMtoShellcode.py
File metadata and controls
67 lines (61 loc) · 2.08 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 os
import sys
import commands
class complier(object):
#Author : B3mB4m
#Greetz : Bomberman
#This script directly convert asm files to shellcode.
#Stay tuned !
def __init__(self):
self.target = sys.argv[1]
self.command1 = "nasm -f elf %s" % sys.argv[1]
self.filename = sys.argv[1].split(".")[0]
self.temporaryfile = "%s.o" % self.filename
self.command2 = "ld -s -o %s %s.o" % (self.filename,self.filename)
self.shellcode = command2 = r'''for i in $(objdump -d %s |grep "^ " |cut -f2); do echo -n '\x'$i; done; echo''' % (self.filename)
self.getme = [self.command1, self.command2, self.shellcode]
self.complie()
def complie(self):
if "NASM version" not in commands.getoutput("nasm -v"):
print "You must install nasm complier .."
print "Install command : apt-get install nasm"
print "Please wait .."
command = 'apt-get install nasm'
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True).stdout.read()
if "NASM version" not in process.strip():
print "Install failed.Please install it manual."
sys.exit()
else:
print "Nasm installed.Process continues .. "
self.justincase()
coutme = 0
for i in self.getme:
commands.getoutput(i)
if coutme == 2:
if "x00" in commands.getstatusoutput(i)[1]:
print "\n#WARNING : NULL BYTES HERE !#\n";
print "\n%s\n" % commands.getstatusoutput(i)[1]
else:
print "\n%s\n" % (commands.getstatusoutput(i)[1])
newout = ""
for i in out:
append = "0x%s," % str(i.strip())
if append != "0x,":
newout += append
print newout[0:len(newout)-1] + "\n\n"
coutme += 1
self.justincase()
def justincase(self):
if os.path.exists(self.filename) or os.path.exists(self.temporaryfile):
try:
os.remove(self.filename)
os.remove(self.temporaryfile)
except Exception as errorlog:
print errorlog.message
sys.exit()
if __name__ == '__main__':
if os.getuid() != 0:
sys.exit("You need to have root privileges to run this script.")
#Because as you can see that script using terminal commands ..
else:
complier()