wargame ๐Ÿด‍โ˜ ๏ธ write-up/pwnable.kr

1. fd

Kortsec1 2022. 2. 15. 00:46

http://pwnable.kr/#

 

http://pwnable.kr/

   there are flag   files corresponding to each challenges (similar to CTF), you need to read it and submit to pwnable.kr to get the corresponding point. in order to read the flag file, you need some skills regarding programming, reverse-engineering, bu

pwnable.kr

 

์ฒซ ๋ฒˆ์งธ ๋ฌธ์ œ fd *.*

intro.png

์—„๋งˆ๋ฅผ ์ฐพ๋Š” ํ•œ ์•„์ด๊ฐ€ ๋งํ•˜๋„ค์š”

"ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ๊ฐ€ ๋ญ์•ผ?? ๋€จ><"

 

ํ•˜์ง€๋งŒ ์—„๋งˆ๋Š” ๋‹ต์ด ์—†๊ณ ...

์šฐ๋ฆฌ๊ฐ€ ์•Œ๋ ค์ค˜์•ผ ํ• ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค

 

conn.png

 

ssh ์ ‘์† ๋ฐฉ๋ฒ•์€ ๋ฌธ์ œ ์†Œ๊ฐœ ๋ถ€๋ถ„์— ์นœ์ ˆํ•˜๊ฒŒ ์ ํ˜€์žˆ์Šต๋‹ˆ๋‹ค. (intro.png)

 

 

 

target.png

fdํŒŒ์ผ์— setuid๊ฐ€ ๊ฑธ๋ ค์žˆ๊ณ , flagํŒŒ์ผ์„ ์ฝ๊ธฐ ์œ„ํ•ด์„  fdํŒŒ์ผ์„ ๊ณต๋žตํ•ด์•ผ ํ•  ๋“ฏํ•˜๋„ค์š”.

 

 

code.png

์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด, buf๋ณ€์ˆ˜์— "LETMEWIN"์ด๋ผ๋Š” ๋ฌธ์ž์—ด์ด ๋“ค์–ด๊ฐ€ ์žˆ์œผ๋ฉด,

flag ํŒŒ์ผ์„ ์ฝ์–ด์˜ฌ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”.

12๋ฒˆ ์ค„์„ ๋ณด๋ฉด read(fd, buf, 32);๋ผ๋Š” ์ฝ”๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์šฐ์„ , read ํ•จ์ˆ˜๋ฅผ ์•Œ์•„์•ผ๊ฒ ์ฃ ?

๊ตฌ๊ธ€๋ง์„ ํ†ตํ•ด ์‰ฝ๊ฒŒ ๋ณผ ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ, ์†Œ๊ฐœํ•ด ๋“œ๋ฆด ๋ฐฉ๋ฒ•์ด ํ•˜๋‚˜ ์ƒ๊ฐ๋‚ฌ๋„ค์š”

๋ฐ”๋กœ linux man page์ž…๋‹ˆ๋‹ค

 

์‰˜์— "man man"์„ ์ž…๋ ฅํ•ด ๋ด…์‹œ๋‹ค.

man_page.png

 

์„ค๋ช… ๋ถ€๋ถ„์„ ๋ณด๋ฉด section ์†Œ๊ฐœ๊ฐ€ ๋‚˜์˜ค์ฃ 

์—ฌ๊ธฐ์„œ ์งˆ๋ฌธ, ์ง€๊ธˆ ๋ˆ„๊ฐ€ ์‚ด์•„๋‚จ์•„ ์žˆ์–ด?  system call์ธ read๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋ ค๋ฉด ๋ช‡ ๋ฒˆ section์„ ์ฐธ์กฐํ•ด์•ผ ํ• ๊นŒ์š”?

 

q๋ฅผ ๋ˆ„๋ฅด๊ณ , ๋‹ค์‹œ ์‰˜๋กœ ๋ณต๊ท€ํ•˜์‹œ์š”๋“ค

์‰˜์— "man 2 read"๋ฅผ ์ž…๋ ฅํ•ด ๋ด…์‹œ๋‹ค

 

man_read.png

์งœ์ข~ ์‚ฌ์‹ค ๊ทธ๋ƒฅ man readํ•ด๋„ ๋จ

 

์ธ์ž๋“ค์„ ํ™•์ธํ•ด ๋ด…์‹œ๋‹ค.

 

์ธ์ž fd buf count
์šฉ๋„ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ์ €์žฅ๋  ๋ณ€์ˆ˜ ํฌ๊ธฐ

 

ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ? ๋ฌธ์ œ intro์—์„œ ๋ณธ๊ฑฐ ๊ฐ™๊ธฐ๋„..?

์œ„ํ‚คํ”ผ๋””์•„๋ฅผ ๋ณด๋ฉฐ๋ˆˆ

 

0 → standard input

1 → standard output

2 → standard error

๋ผ๊ณ  ๋˜์–ด์žˆ๋„ค์š”.

 

์‰ฝ๊ฒŒ ๋งํ•ด์„œ, "0์€ ์ž…๋ ฅ(ํ‚ค๋ณด๋“œ) 1์€ ์ถœ๋ ฅ(๋ชจ๋‹ˆํ„ฐ) 2๋Š” ์—๋Ÿฌ"๋ผ๋Š” ์†Œ๋ฆฌ์ž…๋‹ˆ๋‹ค.

์šฐ๋ฆฌ๋Š” buf ๋ณ€์ˆ˜์— "LETMEWIN"์„ ์ž…๋ ฅํ•ด ๋„ฃ์–ด์•ผ ํ•˜๋‹ˆ, fd๋Š” 0์ด ๋˜์–ด์•ผ๊ฒ ๋„ค์š” ใ…Žใ…Ž

 

๋‹ค์‹œ ์ฝ”๋“œ๋กœ ๋Œ์•„์™€์„œ, 10๋ฒˆ์งธ fd๋ฅผ ์„ธํŒ…ํ•˜๋Š” ๋ผ์ธ์„ ๋ด…์‹œ๋‹ค.

 

10          int fd = atoi( argv [1] ) - 0x1234;

 

atoi๋Š” ๋˜ ๋ญ์—ฌ..

 

man_atoi.png

'str → int' ํ˜• ๋ณ€ํ™˜ ํ•จ์ˆ˜๋„ค์š”^^

 

๊ทธ๋ ‡๋‹ด, fd๊ฐ€ 0์ด ๋˜๊ธฐ ์œ„ํ•ด์„  argv [1]์— 0x1234๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ๊ฒ ๋„ค์š”.

์—ฌ๊ธฐ์„œ ์ฃผ์˜ํ•  ์ ์€ atoi๋Š” 10์ง„์ˆ˜ ํ˜•์‹์œผ๋กœ ๋ฐ”๊ฟ” ์ฃผ๊ธฐ ๋•Œ๋ฌธ์—, "4660"์„ ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ๊ฒ ์ฃ ?

+) 0x1234 == 4660

 

 

๋งˆ์ง€๋ง‰์œผ๋กœ ์šฐ๋ฆฌ๊ฐ€ ์‹คํ–‰ํ•ด์•ผ ํ•  ์ ˆ์ฐจ๋ฅผ ์ •๋ฆฌํ•ด๋ด…์‹œ๋‹ค.

argv [1]์— "4660" ์ž…๋ ฅ "LETMEWIN" ์ž…๋ ฅ

 

 

๋ ˆ์ธ ๊ณ .

solv.png

 

 

๋„ค..? ์ €์š”..? ใ…Žใ…Ž