upx packing 이라는 개념을 몰랐어서 라업을 보고 푼 문제입니다.
실행하면 다음과 같이 나옵니다.
I will malloc() and strcpy the flag there. take it.
gdb로 보면 심볼이 없다고 나옵니다.
다음과 같은 명령어로 upx 패킹이 되어 있다는 것을 알 수 있다고 합니다.
$ strings flag | grep packed
$Info: This file is packed with the UPX executable packer http://upx.sf.net $
이걸 다음과 같은 명령어로 언패킹할 수 있습니다.
$ upx -d ./flag
이제 disassemble 해보면 다음과 같습니다.
gdb-peda$ disassemble main
Dump of assembler code for function main:
0x0000000000401164 <+0>: push rbp
0x0000000000401165 <+1>: mov rbp,rsp
0x0000000000401168 <+4>: sub rsp,0x10
0x000000000040116c <+8>: mov edi,0x496658
0x0000000000401171 <+13>: call 0x402080 <puts>
0x0000000000401176 <+18>: mov edi,0x64
0x000000000040117b <+23>: call 0x4099d0 <malloc>
0x0000000000401180 <+28>: mov QWORD PTR [rbp-0x8],rax
0x0000000000401184 <+32>: mov rdx,QWORD PTR [rip+0x2c0ee5] # 0x6c2070 <flag>
0x000000000040118b <+39>: mov rax,QWORD PTR [rbp-0x8]
0x000000000040118f <+43>: mov rsi,rdx
0x0000000000401192 <+46>: mov rdi,rax
0x0000000000401195 <+49>: call 0x400320
0x000000000040119a <+54>: mov eax,0x0
0x000000000040119f <+59>: leave
0x00000000004011a0 <+60>: ret
End of assembler dump.
malloc을 호출 한 뒤 0x400320 함수로 플래그를 작성하는 것으로 보입니다.
gdb-peda$ x/gx $rbp-8
0x7fffffffdf38: 0x00000000006c96b0
malloc으로 할당된 주소는 0x6c96b0입니다.
main+49까지 실행된 후 해당 주소를 읽어보면 플래그가 나옵니다.
gdb-peda$ x/s 0x00000000006c96b0
0x6c96b0: "UPX...? sounds like a delivery service :)"
레퍼런스
https://jaimelightfoot.com/blog/pwnable-kr-flag-walkthrough/
'write-up(pwn) > pwnable.kr' 카테고리의 다른 글
[pwnable.kr] passcode write-up (0) | 2023.06.14 |
---|---|
[pwnable.kr] bof write-up (0) | 2023.05.01 |
[pwnable.kr] collision write-up (0) | 2023.05.01 |
[pwnable.kr] fd write-up (0) | 2023.04.29 |