1 / 9

Linux GDB 를 이용한 Debug

Linux GDB 를 이용한 Debug. 2010.12.01 시스템제어 박정욱. 다음 소스를 실행하면 오른쪽 그림과 같이 마지막에 semantation fault 라는 오류로 프로그램이 끝나게 된다 . Linux gdb 로 이유를 알아 보겠다. #include &quot;HexaView.h&quot; void test(int, int); int main() { int A = 0x12345678; int B = 0xABCDEFBA; printf(&quot;[%08X] : main() address<br>&quot;, main);

coyne
Download Presentation

Linux GDB 를 이용한 Debug

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LinuxGDB를 이용한 Debug 2010.12.01 시스템제어 박정욱

  2. 다음 소스를 실행하면 오른쪽 그림과 같이 마지막에 semantation fault라는 오류로 프로그램이 끝나게 된다. Linuxgdb로 이유를 알아 보겠다. #include "HexaView.h" void test(int, int); int main() { int A = 0x12345678; int B = 0xABCDEFBA; printf("[%08X] : main() address\n", main); test(A, B); return 0; } void test2() { printf("test2\n"); } void test(int a, int b) { int C = 0x11223344; int *p = &C; p = p+2; *p = (int)test2; PrintHexaNAscii(&p, 150); }

  3. 처음 명령 실행시 break point(b)를 main 으로설정하고 run(r) 명령으로 실행 시킨다. 실행 시킨 프로그램은 breakpoint main 에서 멈추게 된다. info frame(i f)을명령으로현재 프로그램 메모리의 세부정보를 알 수 있다. 현재 main의 ebp는 0xffff9fc, esp는 0xbffff9c4 이다

  4. Step(s)명령으로 printf명령까지 진행 시키면 assembly 명령에 의해서 A는 ebp의 주소의 +4의 주소 0xbffff9f4 B는 ebp의 주소의 +8의 주소 0xbffff9f8의 주소에 값이 초기화 된다. B A ebp 다음 진행하면 인자 A,B를 가지는 Test함수가 호출 된다.

  5. test함수를 호출하는 명령에서는 함수의 본체로 넘어가는 명령 전에 인자 A,B의 값을 저장하고, call 명령에서는 test함수가 종료후 돌아갈 test return address를 eip에 저장 후 Jump명령을 실행한다. test Return address test의인자 A,B A B test함수의 ebp주소는 0xbffff9cc, esp 0xbffff9b4이다. eip에는 test 함수가 종료되고 returnaddress인 0x8048479가 들어가 있다.

  6. test 함수에서는 지역변수 C가 선언 및 초기화 되고, *p는 C의 주소값으로 초기화 된다. 변수C는 0xbffff9c8, p는 0xffff9c4의 주소를 가진다. 다음 명령에서 C의값을 가지고 있는 p에 p+2 연산을 해서 p에 있는 c의주소 0xbffff9c8을 0xffff9d0의 값으로 만든다. 주소0xffff9d0는 test return address의 값이 저장된 주소로서 p는 return address를 가리키게 되다 c return address P+2연산으로 변화

  7. 다음 명령에서 p값 즉 return address에 test2의 주소를 대입한다. test의 주소값은 0x8048484이다 위의 그림에서 return address가 test2의 주소로 바뀐것을 볼 수 있다. 다음 실행에서 HexaView함수가 호출 되고 실행된다.

  8. test함수의 실행이 끝나고 test는 main으로 return하여야 하지만 의도한대로 test2로 return하게된다. test2의 ebp는 return address가 있던 0xbffff9d0, esp는 0xbffff9c8이다. 하지만 정상적인 return이 이루어 지지않아 return address를 가지고 있어야 할 eip가 return address의 값 +4의 주소에 저장된 test함수의 인자A의 값 12345678 을가지게 된다. ebp return address

  9. step(s)명령을 실행하면 printf명령이 실행되어 Test2가 출력된 후 test2함수도 종료 하게 된다. 그리고 return address 12345678로 이동 하게 된다. 12345678이라는 주소로 이동하고 메모리에서 오류를 읽으켜 segmentation fault 라는 오류를 출력하고 프로그램이 종료 하게 된다.

More Related