반응형

GDB는 리눅스에서 개발시 디버깅을 하기 위한 기본적인 도구 입니다. 보통은 실행될 바이너리에 자기 자신을 직접 attach 한다. 다시말해 GDB는 바이너리가 실행되는 동안 자세한 정보를 관할 수 있도록 바이너리를 특수한 위치 시킨다. 테스팅 목적으로 포함 되는 디버깅 정보를 이용하면 프로그램의 의미를 좀더 쉽게 이해 할 수 있습니다. 그렇지만 대부분의 바이너리은 디버깅 플래그를 설정 하지 않고 컴파일 된것이 기 때문에 이를 이용해서 더비깅 해서 리버싱을 하는 방법도 알아 두면 좋을 것 같습니다.


gdb [바이너리]


gdb ./bash


choi@choi:~$ gdb ./bash

GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git

Copyright (C) 2018 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-linux-gnu".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:

<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

Reading symbols from ./bash...(no debugging symbols found)...done.

(gdb)  


run 명령을 명령을 이용해 실행 파일 인자를 지정할 수 있습니다.

(gdb) run --version

Starting program: /home/choi/bash --version

GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)

Copyright (C) 2016 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


This is free software; you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

[Inferior 1 (process 13232) exited normally]

(gdb)


브레이킹 포인트를 설정하기 위해서는 우선 해당 코드의 주소를 알아야 되어야 한다.


우선 main 함수의 주소를 알기 위해서는 dissaemble main을 이용하거나 objdump를 이용하면 됩니다.


(gdb) run --version

Starting program: /home/choi/bash --version

GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)

Copyright (C) 2016 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


This is free software; you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

[Inferior 1 (process 13232) exited normally]

(gdb)


choi@choi:~$ objdump --disassemble-all --start-address=0x000000  ./bash |grep \<main*Base\>
000000000002fdb0 <main@@Base>:


다음으로 해당 주소에 브레이크주소를 거는 방법을 보도록 합니다.


(gdb) b main

Breakpoint 2 at 0x2fdb0

(gdb) b *0x000000000002fdb0

Note: breakpoint 2 also set at pc 0x2fdb0.

Breakpoint 3 at 0x2fdb0


또한 watch point를 사용하여 특정변수에 대한 감시를 할 수 있다.


(gdb)  eval "watch -location *0x%x", $rsp

Hardware watchpoint 4: -location *0xffffe3e8


반응형

+ Recent posts