Goal: Create a neat shellcode without padded “00” in NASM for exploit bundling
Source: OpenSecurityTraining “Software Exploits”
Attempt I:
; ;;;;;;;;;;;;;;;;;;;;;;;;
basic ‘Hello World’ in nasm
; compile with nasm -f elf hello.asm; ld -o hello hello.o
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .data
; ;;;;;;;;;;;;;;;;;;;;;;;;
msg db ‘Hello World’, 0xa
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .text
; ;;;;;;;;;;;;;;;;;;;;;;;;
global _start
; ;;;;;;;;;;;;;;;;;;;;;;;;
start:
; ;;;;;;;;;;;;;;;;;;;;;;;;
; write(int fd, char *msg, unsigned int len)
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, 8
int 0x80
; ;;;;;;;;;;;;;;;;;;;;;;;;
; exit(int ret)
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov eax, 1
mov ebx, 0
int 0x80
Attempt II (change extended to lower byte register values):
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .data
; ;;;;;;;;;;;;;;;;;;;;;;;;
msg db ‘Hello World’, 0xa
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .text
; ;;;;;;;;;;;;;;;;;;;;;;;;
global _start
; ;;;;;;;;;;;;;;;;;;;;;;;;
start:
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov al, 4
mov bl, 1
mov ecx, msg
mov dl, 8
int 0x80
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov al, 1
mov bl, 0
int 0x80
Attempt III (achieve code independence):
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .text
; ;;;;;;;;;;;;;;;;;;;;;;;;
global _start
; ;;;;;;;;;;;;;;;;;;;;;;;;
_start:
; ;;;;;;;;;;;;;;;;;;;;;;;;
; clear out the registers we need
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
; write(int fd, char *msg, unsigned int len)
mov al, 4
mov bl, 1
; Owned!! = 4f,77,6e,65,64,21,21,0xa
; push \n,!,!,d
push 0x0a212164
; push e,n,w,O
push 0x656e774f
mov dl, 8
int 0x80
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov al, 1
mov bl, 0
int 0x80
Attempt IV (remove 0xa newline):
; ;;;;;;;;;;;;;;;;;;;;;;;;
section .text
; ;;;;;;;;;;;;;;;;;;;;;;;;
global _start
; ;;;;;;;;;;;;;;;;;;;;;;;;
_start:
; ;;;;;;;;;;;;;;;;;;;;;;;;
; clear out the registers we need
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
; write(int fd, char *msg, unsigned int len)
mov al, 4
mov bl, 1
; Owned!! = 4f,77,6e,65,64,21,21,0xa
; push \n,!,!,d
push 0x21212164
; push e,n,w,O
push 0x656e774f
mov dl, 8
int 0x80
; ;;;;;;;;;;;;;;;;;;;;;;;;
mov al, 1
mov bl, 0
int 0x80