๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿด‍โ˜ ๏ธ CTF ๐Ÿด‍โ˜ ๏ธ/๋ฆฌ๋ฒ„์‹ฑ

[Dream Hack - Reversing] Simple Patch me

๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ํ•ด์„

main ํ•จ์ˆ˜

dword_40404C ๊ฐ’์ด 0 ์œผ๋กœ ์‹œ์ž‘ํ•ด์„œ 0x2237๊นŒ์ง€ ์ฆ๊ฐ€ํ•˜๋ฉด์„œ while๋ฌธ์ด ๋™์ž‘ํ•˜๊ณ  ์žˆ๋‹ค. sleep(0xE10u) ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•œ๋ฒˆ ์ฆ๊ฐ€ํ• ๋•Œ๋งˆ๋‹ค 1์‹œ๊ฐ„์”ฉ ๊ฑธ๋ฆฌ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ์ง„ํ–‰ํ•˜๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.

 

  1. dword_40404C์— 0x2237๋ณด๋‹ค ํฐ ๊ฐ’์„ ๋„ฃ๋Š” ๋ฐฉ๋ฒ•
  2. sleep ํ•จ์ˆ˜์— 0์„ ๋„ฃ๋Š” ๋ฐฉ๋ฒ•

๋ฐฉ๋ฒ• ์„ ํƒ์„ ์œ„ํ•ด sub_401196 ํ•จ์ˆ˜๋ฅผ ์‚ดํŽด๋ณด์ž

 

 

sub_401196

 

  1. dword_40404C = 0x2238 ๋กœ ์„ธํŒ…ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ๋„ ๊ฐ€๋Šฅํ•ด ๋ณด์ธ๋‹ค.
  2. sleep(0) ์„ ์„ค์ •ํ•˜๋Š”๊ฒŒ ๊ฐ„๋‹จํ•ด ๋ณด์—ฌ ์ด ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค.

 

ํ’€์ด ๋ฐฉ๋ฒ• a) dword_40404C = 0x2238 ์„ธํŒ…

ELF ํŒŒ์ผ ํฌ๋งท์ด๋ฏ€๋กœ Linux ํ™˜๊ฒฝ์—์„œ pwndbg๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

##  ํŒŒ์ผ ์‹คํ–‰

$ gdb ./simple_patch_me
$ break *0x401376
$ run

## dword_40404C ์—…๋ฐ์ดํŠธ
$ set {int}0x40404C = 0x2238
$ continue

 

ํ’€์ด ๋ฐฉ๋ฒ• b) sleep(0) ์„ธํŒ…

sleep ํ•จ์ˆ˜ ์ธ์ž ๊ฐ’์„ ๋„ฃ๋Š” ๋ถ€๋ถ„์— break point ์„ค์ •

##  ํŒŒ์ผ ์‹คํ–‰

$ gdb ./simple_patch_me
$ break *0x4012a1
$ run

 

 

0xe10 ์„ 0์œผ๋กœ ๋ณ€๊ฒฝ

$ x/x 0x4012a1
$ set {int}0x4012a1=0x000000bf

 

 

๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•œ ํ›„ break point๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์‹คํ–‰ํ•ด์ค€๋‹ค.

$ info break
$ delete 1
$ continue

๋น ๋ฅด๊ฒŒ 365์ผ์ด ํ๋ฅด๊ณ  flag๊ฐ€ ์ถœ๋ ฅ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋ฐ˜์‘ํ˜•

'๐Ÿดโ€โ˜ ๏ธ CTF ๐Ÿดโ€โ˜ ๏ธ > ๋ฆฌ๋ฒ„์‹ฑ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dream Hack - Reversing] Simple Counter  (0) 2024.08.22