$ sudo apt install binutils gdb
One of the commmon categories in CTFs is Reverse Engineering, which involves using a dissassembler and other tools to figure out how an executable file works. For your first real reversing challenge, here is an ELF file. Head over to /problems/rev1/ on the shell server to try it out, and once you have the input right, get the flag!
$ chmod u+x ./rev1_32 $ ./rev1_32 Welcome to your first Reverse Engineering challenge! What is the password to this file? Enter password here: aaa Sorry, the password isn't aaa. Try again!
$ objdump -M intel -d ./rev1_32 ...ずらずら...
<main>
というのはmain関数に対応するアセンブラであることを示しています__libc_start_main
とかあるけどそれは調べてみてください(楽しいよ)080485db <main>: 80485db: 8d 4c 24 04 lea ecx,[esp+0x4] 80485df: 83 e4 f0 and esp,0xfffffff0 80485e2: ff 71 fc push DWORD PTR [ecx-0x4] 80485e5: 55 push ebp 80485e6: 89 e5 mov ebp,esp 80485e8: 51 push ecx 80485e9: 83 ec 64 sub esp,0x64 80485ec: 89 c8 mov eax,ecx 80485ee: 8b 40 04 mov eax,DWORD PTR [eax+0x4] 80485f1: 89 45 a4 mov DWORD PTR [ebp-0x5c],eax 80485f4: 65 a1 14 00 00 00 mov eax,gs:0x14 80485fa: 89 45 f4 mov DWORD PTR [ebp-0xc],eax 80485fd: 31 c0 xor eax,eax 80485ff: 83 ec 0c sub esp,0xc 8048602: 68 60 87 04 08 push 0x8048760 8048607: e8 74 fe ff ff call 8048480 <[email protected]> 804860c: 83 c4 10 add esp,0x10 804860f: 83 ec 0c sub esp,0xc 8048612: 68 98 87 04 08 push 0x8048798 8048617: e8 24 fe ff ff call 8048440 <[email protected]> 804861c: 83 c4 10 add esp,0x10 804861f: c7 45 ac d1 87 04 08 mov DWORD PTR [ebp-0x54],0x80487d1 8048626: a1 40 a0 04 08 mov eax,ds:0x804a040 804862b: 83 ec 04 sub esp,0x4 804862e: 50 push eax 804862f: 6a 40 push 0x40 8048631: 8d 45 b4 lea eax,[ebp-0x4c] 8048634: 50 push eax 8048635: e8 16 fe ff ff call 8048450 <[email protected]> 804863a: 83 c4 10 add esp,0x10 804863d: 83 ec 0c sub esp,0xc 8048640: 8d 45 b4 lea eax,[ebp-0x4c] 8048643: 50 push eax 8048644: e8 57 fe ff ff call 80484a0 <[email protected]> 8048649: 83 c4 10 add esp,0x10 804864c: 83 e8 01 sub eax,0x1 804864f: c6 44 05 b4 00 mov BYTE PTR [ebp+eax*1-0x4c],0x0 8048654: 83 ec 08 sub esp,0x8 8048657: 8d 45 b4 lea eax,[ebp-0x4c] 804865a: 50 push eax 804865b: ff 75 ac push DWORD PTR [ebp-0x54] 804865e: e8 cd fd ff ff call 8048430 <[email protected]> 8048663: 83 c4 10 add esp,0x10 8048666: 85 c0 test eax,eax 8048668: 74 16 je 8048680 <main+0xa5> 804866a: 83 ec 08 sub esp,0x8 804866d: 8d 45 b4 lea eax,[ebp-0x4c] 8048670: 50 push eax 8048671: 68 e4 87 04 08 push 0x80487e4 8048676: e8 c5 fd ff ff call 8048440 <[email protected]> 804867b: 83 c4 10 add esp,0x10 804867e: eb 3c jmp 80486bc <main+0xe1> 8048680: 83 ec 0c sub esp,0xc 8048683: 68 10 88 04 08 push 0x8048810 8048688: e8 f3 fd ff ff call 8048480 <[email protected]> 804868d: 83 c4 10 add esp,0x10 8048690: e8 db fd ff ff call 8048470 <[email protected]> 8048695: 89 45 b0 mov DWORD PTR [ebp-0x50],eax 8048698: 83 ec 04 sub esp,0x4 804869b: ff 75 b0 push DWORD PTR [ebp-0x50] 804869e: ff 75 b0 push DWORD PTR [ebp-0x50] 80486a1: ff 75 b0 push DWORD PTR [ebp-0x50] 80486a4: e8 17 fe ff ff call 80484c0 <[email protected]> 80486a9: 83 c4 10 add esp,0x10 80486ac: 83 ec 0c sub esp,0xc 80486af: 68 39 88 04 08 push 0x8048839 80486b4: e8 d7 fd ff ff call 8048490 <[email protected]> 80486b9: 83 c4 10 add esp,0x10 80486bc: b8 00 00 00 00 mov eax,0x0 80486c1: 8b 55 f4 mov edx,DWORD PTR [ebp-0xc] 80486c4: 65 33 15 14 00 00 00 xor edx,DWORD PTR gs:0x14 80486cb: 74 05 je 80486d2 <main+0xf7> 80486cd: e8 8e fd ff ff call 8048460 <[email protected]> 80486d2: 8b 4d fc mov ecx,DWORD PTR [ebp-0x4] 80486d5: c9 leave 80486d6: 8d 61 fc lea esp,[ecx-0x4] 80486d9: c3 ret 80486da: 66 90 xchg ax,ax 80486dc: 66 90 xchg ax,ax 80486de: 66 90 xchg ax,ax
$ gdb -q ./rev1_32 (gdb) x/s 0x8048760 0x8048760: "Welcome to your first Reverse Engineering challenge!" (gdb) x/s 0x8048798 0x8048798: "What is the password to this file? Enter password here: " gdb-peda$ x/32x 0x80487e4 0x80487e4: 0x53 0x6f 0x72 0x72 0x79 0x2c 0x20 0x74 0x80487ec: 0x68 0x65 0x20 0x70 0x61 0x73 0x73 0x77 0x80487f4: 0x6f 0x72 0x64 0x20 0x69 0x73 0x6e 0x27 0x80487fc: 0x74 0x20 0x25 0x73 0x2e 0x20 0x54 0x72
... 8048657: 8d 45 b4 lea eax,[ebp-0x4c] 804865a: 50 push eax 804865b: ff 75 ac push DWORD PTR [ebp-0x54] 804865e: e8 cd fd ff ff call 8048430 <strcmp@plt>
test eax, eax je 0xdeadbeef => eaxが0ならジャンプする
$ strings ./rev1_32