-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellcode.py
More file actions
87 lines (77 loc) · 2.7 KB
/
shellcode.py
File metadata and controls
87 lines (77 loc) · 2.7 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
# -*- coding: utf-8 -*-
# @Time : 2017/5/13 11:36
# @Author : set3rnal
# @Site :
# @File : shellcode.py
# @Software: PyCharm
'''
This is ascii <-> shellcode encode / decoder tool
programmer : gunslinger_ <yudha.gunslinger[at]gmail.com>
This was written for educational purpose only. or fucking messing around...
i.e how to use encode mode :
--------------------------------------------------------------
gunslinger@localhost:~/shellcode$ ./shellcodeencdec.py
shellcode hex encode decoder
programmer : gunslinger_
what do you want to do ? encode / decode
=> encode
Please input data : /bin
shellcode => \x2f\x62\x69\x6e
gunslinger@localhost:~/shellcode$
--------------------------------------------------------------
i.e how to use decode mode :
"\x68\x2f\x2f\x73\x68" // push $0x68732f2f
"\x68\x2f\x62\x69\x6e" // push $0x6e69622f
we know 'x68' is push, so drop it...
"\x2f\x2f\x73\x68" $0x68732f2f
"\x2f\x62\x69\x6e" $0x6e69622f
--------------------------------------------------------------
gunslinger@localhost:~/shellcode$ ./shellcodeencdec.py
shellcode hex encode decoder
programmer : gunslinger_
what do you want to do ? encode / decode
=> decode
Please input data : \x2f\x2f\x73\x68
hex => 2f2f7368
plaintext => //sh
gunslinger@localhost:~/shellcode$ ./shellcodeencdec.py
shellcode hex encode decoder
programmer : gunslinger_
what do you want to do ? encode / decode
=> decode
Please input data : \x2f\x62\x69\x6e
hex => 2f62696e
plaintext => /bin
gunslinger@localhost:~/shellcode$
--------------------------------------------------------------
and we got that is "/bin//sh"
warning ! this is not disassemble tool !
'''
import binascii, sys, time
RED = '\033[31m'
WHITE = '\033[37m'
RESET = '\033[0;0m'
def main():
print "shellcode hex encode decoder"
print "programmer : gunslinger_ <yudha.gunslinger[at]gmail.com>"
print "what do you want to do ? %sencode%s / %sdecode%s" % (RED, RESET, WHITE, RESET)
q = raw_input("=> ")
if q == "encode":
inputtype = raw_input("Please input data : ")
print "shellcode => ",
for encoded in inputtype:
print "\b\\x" + encoded.encode("hex"),
sys.stdout.flush()
time.sleep(0.5)
print RESET
elif q == "decode":
inputtype = raw_input("Please input data : ")
cleaninput = inputtype.replace("\\x", "")
print "hex => ", cleaninput
print "plaintext => ",
print "\b" + cleaninput.decode("hex")
else:
print "wrong answer ! your choice is %sencode%s or %sdecode%s" % (RED, RESET, WHITE, RESET)
sys.exit(1)
if __name__ == '__main__':
main()