songining
article thumbnail
gdb ์‚ฌ์šฉ๋ฒ• ์ตํžˆ๊ธฐ
Hacking/System Hacking 2022. 3. 28. 20:49

gdb๋Š” ๋ฆฌ๋ˆ…์Šค์˜ ๋Œ€ํ‘œ์ ์ธ ๋””๋ฒ„๊ฑฐ์ค‘ ํ•˜๋‚˜! ELF - ๋ฆฌ๋ˆ…์Šค ์‹คํ–‰ ํŒŒ์ผ ํ˜•์‹ - ํฌ๊ฒŒ ํ—ค๋”์™€ ์—ฌ๋Ÿฌ ํ˜•์‹์œผ๋กœ ์ด๋ฃจ์–ด์ง --> ELF ์˜ ํ—ค๋”์— ์ง„์ž…์ (EP) ํ•„๋“œ ์กด์žฌ (OS๋Š” ELF๋ฅผ ์‹คํ–‰ํ•  ๋•Œ EP๋ถ€ํ„ฐ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰) //ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ง„์ž…์  ํ™•์ธ ๊ฐ€๋Šฅ //entry point address readelf -h debugee(ํŒŒ์ผ๋ช…) entry point address : 0x1060 gdb์—์„œ start ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ง„์ž…์  ์ฃผ์†Œ๋ฅผ rip๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. gdb (gdb) start 1. registers : ๋ ˆ์ง€์Šคํ„ฐ์˜ ์ƒํƒœ๋ฅผ ๋ณด์—ฌ์คŒ 2. disasm : rip๋ถ€ํ„ฐ ์—ฌ๋Ÿฌ์ค„์— ๊ฑธ์ณ ๋””์Šค์–ด์…ˆ๋ธ”(๊ธฐ๊ณ„์–ด -> ์–ด์…ˆ๋ธ”๋ฆฌ)๋œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์คŒ 3. stack : rsp๋ถ€ํ„ฐ ์—ฌ๋Ÿฌ์ค„์— ๊ฑธ์ณ..

[์‹œ์Šคํ…œ] ์–ด์…ˆ๋ธ”๋ฆฌ์–ด, GDB
Hacking/System Hacking 2020. 8. 2. 16:40

์–ด์…ˆ๋ธ”๋ฆฌ์–ด ๊ธฐ๊ณ„์–ด์™€ ์ผ๋Œ€์ผ ๋Œ€์‘๋˜๋Š” ์–ธ์–ด. ์‹คํ–‰ํŒŒ์ผ๋งŒ ์žˆ์–ด๋„ ์–ด์…ˆ๋ธ”๋ฆฌ ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ด์ง„์ˆ˜๋กœ ๋œ ๊ธฐ๊ณ„์–ด๋ฅผ "๋””์ปดํŒŒ์ผ๋Ÿฌ" ๋ฅผ ์ด์šฉํ•˜์—ฌ ์–ด์…ˆ๋ธ”๋ฆฌ์–ด๋กœ ๋œ ์ฝ”๋“œ๋ฅผ ์–ป์–ด๋‚ด๊ณ , ์ด๋ฅผ ๋ถ„์„ํ•œ๋‹ค. ๋””๋ฒ„๊ฑฐ GDB(GNU Debugger) C, C++ ๋“ฑ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์‹คํ–‰ ํŒŒ์ผ์„ ๋””๋ฒ„๊น…ํ•˜๋Š” ๋„๊ตฌ 1. ์‹œ์ž‘/์ข…๋ฃŒ ์‹œ์ž‘: gdb [ํ”„๋กœ๊ทธ๋žจ๋ช…] ์ข…๋ฃŒ: quit or q 2. ๋ฌธ๋ฒ• ๋ณ€๊ฒฝ set disassembly-flavor intel 3. ๋ถ„์„ ํ•ด๋‹น ํ•จ์ˆ˜ ์ฝ”๋“œ: disas [ํ•จ์ˆ˜์ด๋ฆ„] ์‹คํ–‰ : run or r ๋ธŒ๋ ˆ์ดํฌ ํฌ์ธํŠธ : b [์ง€์ ] ๋ธŒ๋ ˆ์ดํฌ ํฌ์ธํŠธ ๊ฑธ๋ฆฐ ์œ„์น˜ ์ฝ”๋“œ : disas ๋ธŒ๋ ˆ์ดํฌ ํฌ์ธํŠธ ๋‹ค ์ง€์šฐ๊ธฐ: d or dis ๋‹ค์Œ ๋ช…๋ น์–ด : ni ์ง„ํ–‰ : c ๊ฐ•์ œ ์ ํ”„ : jump [์œ„์น˜] -> ํ•จ์ˆ˜, ํ–‰, ๋ฉ”๋ชจ..