r/ExploitDev • • Jan 25 '22

Shellcode to x86, x64 Assembly

Sharing a quick python3 command line tool I made to disassemble shellcode without having to remember the nuances of python2 v python3 strings and writing to a file each time:

https://gitlab.com/stormblest/exploit-dev-tools/-/blob/main/shellcode2asm.py

Includes python unittests in Gitlab.

Example:

$ python3 shellcode2asm.py "\xbb\x90\x50\x90\x50\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x1a\x75\xee\x39\x5a\x04\x75\xe9\xff\xe2" -a 32

shellcode: "\xbb\x90\x50\x90\x50\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x1a\x75\xee\x39\x5a\x04\x75\xe9\xff\xe2"

00000000  BB90509050        mov ebx,0x50905090
00000005  31C9              xor ecx,ecx
00000007  F7E1              mul ecx
00000009  6681CAFF0F        or dx,0xfff
0000000E  42                inc edx
0000000F  60                pusha
00000010  8D5A04            lea ebx,[edx+0x4]
00000013  B021              mov al,0x21
00000015  CD80              int 0x80
00000017  3CF2              cmp al,0xf2
00000019  61                popa
0000001A  74ED              jz 0x9
0000001C  391A              cmp [edx],ebx
0000001E  75EE              jnz 0xe
00000020  395A04            cmp [edx+0x4],ebx
00000023  75E9              jnz 0xe
00000025  FFE2              jmp edx
16 Upvotes

3 comments sorted by

View all comments

0

u/[deleted] Jan 26 '22

[deleted]

2

u/blutitanium Jan 26 '22

For anyone wondering: the full example to do this without an intermediate file follows.

But isn't it annoying to have to look up bash syntax each time or remember the nuances of python2 and python3 string handling? It interrupts your flow.

$ echo -ne "\xbb\x90\x50\x90\x50\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f\x42\x60\x8d\x5a\x04\xb0\x21\xcd\x80\x3c\xf2\x61\x74\xed\x39\x1a\x75\xee\x39\x5a\x04\x75\xe9\xff\xe2" | ndisasm -b 32 -

00000000  BB90509050        mov ebx,0x50905090
00000005  31C9              xor ecx,ecx
00000007  F7E1              mul ecx
00000009  6681CAFF0F        or dx,0xfff
0000000E  42                inc edx
0000000F  60                pusha
00000010  8D5A04            lea ebx,[edx+0x4]
00000013  B021              mov al,0x21
00000015  CD80              int 0x80
00000017  3CF2              cmp al,0xf2
00000019  61                popa
0000001A  74ED              jz 0x9
0000001C  391A              cmp [edx],ebx
0000001E  75EE              jnz 0xe
00000020  395A04            cmp [edx+0x4],ebx
00000023  75E9              jnz 0xe
00000025  FFE2              jmp edx