728x90

[๋ฌธ์ œ]

https://dreamhack.io/wargame/challenges/16

 

rev-basic-2

Reversing Basic Challenge #2 ์ด ๋ฌธ์ œ๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ •ํ•ด์ง„ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž…๋ ฅ๊ฐ’์„ ๊ฒ€์ฆํ•˜์—ฌ correct ๋˜๋Š” wrong์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ๋ถ„์„ํ•˜์—ฌ correct๋ฅผ ์ถœ

dreamhack.io

 


[๋ฌธ์ œ ํ’€์ด]

  • ๋จผ์ €, ํŒŒ์ผ์„ x64dbg๋กœ ์—ด์–ด correct ๋ฌธ์ž์—ด๋กœ ํ•„ํ„ฐ๋งํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด ๋ณด๋‹ˆ call chall2.7FF7A38B1186์—์„œ ์ž…๋ ฅ๋œ ๊ฐ’์— ๋Œ€ํ•ด ๊ฒ€์ฆ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์ด ํ•จ์ˆ˜๊ฐ€ ๋ฆฌํ„ดํ•˜๋Š” ๊ฐ’์— ๋”ฐ๋ผ ์ž…๋ ฅ์ด ์˜ฌ๋ฐ”๋ฅธ์ง€ ์•„๋‹Œ์ง€๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.

  • ํ•ด๋‹น ํ•จ์ˆ˜๋กœ ๋”ฐ๋ผ๊ฐ€์„œ ์ฝ”๋“œ๋ฅผ ํ•˜๋‚˜ํ•˜๋‚˜ ๋ถ„์„ํ•ด ๋ดค์Šต๋‹ˆ๋‹ค.
mov qword ptr ss:[rsp+8],rcx       rcx์˜ ๊ฐ’์„ ์Šคํƒ์˜ [rsp+8] ์œ„์น˜์— ์ €์žฅ            
sub rsp,18                         rsp์—์„œ 0x18(24)๋งŒํผ ์Šคํƒ์„ ํ• ๋‹น             
mov dword ptr ss:[rsp],0           ์Šคํƒ์˜ [rsp]์— 0์„ ์ €์žฅํ•˜์—ฌ, ๋ฃจํ”„์—์„œ ์‚ฌ์šฉํ•  ์นด์šดํ„ฐ ์—ญํ• ์„ ํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™”              
jmp chall2.7FF7A38B101A            chall2.7FF7A38B101A๋กœ ๋ฐ”๋กœ ์ ํ”„              
mov eax,dword ptr ss:[rsp]         [rsp]์— ์ €์žฅ๋œ ๊ฐ’์„ eax๋กœ ๋กœ๋“œ              
inc eax                            eax๋ฅผ 1 ์ฆ๊ฐ€              
mov dword ptr ss:[rsp],eax         ๋‹ค์‹œ [rsp]์— ์ €์žฅ              
movsxd rax,dword ptr ss:[rsp]      [rsp]์˜ ๊ฐ’์„ rax์— ๋ถ€ํ˜ธ ํ™•์žฅํ•˜์—ฌ ๋กœ๋“œ              
cmp rax,12                         rax๋ฅผ 12์™€ ๋น„๊ต              
jae chall2.7FF7A38B1048            rax๊ฐ€ 12 ์ด์ƒ์ด๋ฉด ๋ฃจํ”„๋ฅผ ๋ฒ—์–ด๋‚œ๋‹ค.              
movsxd rax,dword ptr ss:[rsp]      [rsp]์˜ ์นด์šดํ„ฐ ๊ฐ’์„ rax์™€ rdx์— ๋ถ€ํ˜ธ ํ™•์žฅํ•˜์—ฌ ๊ฐ๊ฐ ๋กœ๋“œ              
lea rcx,qword ptr ds:[7FF7A38B3000]rcx๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ 7FF7A38B3000์„ ๊ฐ€๋ฆฌํ‚ค๋„๋ก ์„ค์ •              
movsxd rdx,dword ptr ss:[rsp]                    
mov r8,qword ptr ss:[rsp+20]       [rsp+20]์— ์žˆ๋Š” ๊ฐ’(r8)์—์„œ rdx(์นด์šดํ„ฐ์˜ ๊ฐ’)์— ํ•ด๋‹นํ•˜๋Š” ์˜คํ”„์…‹์„ ๊ฐ€์ ธ์™€              
movzx edx,byte ptr ds:[r8+rdx]     edx์— ์ €์žฅ              
cmp dword ptr ds:[rcx+rax*4],edx   rcx๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ฐฐ์—ด [7FF7A38B3000 + rax*4]์—์„œ edx์™€ ๋น„๊ต              
je chall2.7FF7A38B1046                           
xor eax,eax                                      
jmp chall2.7FF7A38B104D                          
jmp chall2.7FF7A38B1012                          
mov eax,1                                        
add rsp,18                                       
ret
  • ์ด ์ฝ”๋“œ๋Š” ์ฃผ์–ด์ง„ ์ž…๋ ฅ(r8์ด ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ฐ์ดํ„ฐ)๊ณผ ๋ฉ”๋ชจ๋ฆฌ ์œ„์น˜(7FF7A38B3000์— ์ €์žฅ๋œ ๊ฐ’)๋ฅผ ๋น„๊ตํ•˜์—ฌ ํŒจํ„ด์ด ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฃจํ”„์ž…๋‹ˆ๋‹ค. ๋ฃจํ”„๊ฐ€ 12๋ฒˆ ๋ฐ˜๋ณต๋˜๋ฉฐ, ๋ชจ๋“  ๋น„๊ต๊ฐ€ ์„ฑ๊ณตํ•˜๋ฉด eax = 1๋กœ ์„ค์ •๋˜์–ด ์„ฑ๊ณต ์‹ ํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ถ„์„์„ ํ†ตํ•ด ๋ฉ”๋ชจ๋ฆฌ ์œ„์น˜(7FF7A38B3000์— ์ €์žฅ๋œ ๊ฐ’) ์ฃผ์†Œ๋ฅผ ๋”ฐ๋ผ๊ฐ€ ๊ฐ’์„ ํ™•์ธํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

  • ๋”ฐ๋ผ๊ฐ€ ๋ณด๋‹ˆ "Comp4re_the_arr4y" ํ”Œ๋ž˜๊ทธ๋ฅผ ๋ฐœ๊ฒฌํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
  • ๋งˆ์ง€๋ง‰์œผ๋กœ ์ž…๋ ฅํ•ด์„œ ๋‹ต์ด ๋งž๋Š”์ง€ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

+ Recent posts