In computers, debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code or the engineering of a hardware device.Debugging is the Fundamentals part of Exploit Development .When you are writing an exploit you are going to need to be able to execute the code in your target application in a variety of different ways, to give you the appropriate amount of control to monitor the code and memory closely when needed. You may want to run normally at one point, to go step by step through each individual instruction at another, and sometimes to have it run quickly to a particular point allowing you to take control once that point is reached.
Luckily, this is all possible via the use of a debugger by using breakpoints as well as the various methods for stepping through code.In this article will try to describe most common features of GDB.First we will take a simple C program.Compile it, And after that break it with GDB.
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
Start your program, specifying anything that might affect its behavior.
Make your program stop on specified conditions.
Examine what has happened, when your program has stopped.
Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.
After some basic debugging we will use some portable Linux based tools to gather more information about a Linux Executable.
So here we will debug this simple C program using gdb.
#include<stdio.h>
#include<wchar.h>
int my_function(wchar_t *a)
{
return wprintf(a);
}
int main()
{
return my_function(L"Hello World!\n");
}
First of all we will use gcc compiler to compile the C prog.
debasish@debasish-desktop:~$ nano MYprog.c
debasish@debasish-desktop:~$ gcc -o MYprog MYprog.c
MYprog.c:2:18: warning: extra tokens at end of #include directive
debasish@debasish-desktop:~$
debasish@debasish-desktop:~$ ./MYprog
Hello World!
debasish@debasish-desktop:~$ ^C
Now we will debug this program with gdb debugger.We will use following commands.
debasish@debasish-desktop:~$ gdb MYprog
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/debasish/MYprog...(no debugging symbols found)...done.
(gdb)
So now gdb will load the program and at entry point it will pause the execution.
Then we will use the command "start" to start the debugging process.
(gdb) start
Temporary breakpoint 1 at 0x804841a
Starting program: /home/debasish/MYprog
Temporary breakpoint 1, 0x0804841a in main ()
(gdb)
We can see that is showing the break point is at 0x0804841a.
Now we will use the command "layout asm" to see the assembly code in a proper order.
Now you should get a window like this.
0x804841a and $0xfffffff0,%esp
¦0x804841d sub $0x10,%esp
¦0x8048420 movl $0x80484f0,(%esp)
¦0x8048427 call 0x8048404
¦0x804842c leave
¦0x804842d ret
¦0x804842e nop
¦0x804842f nop
¦0x8048430 <__libc_csu_fini> push %ebp
¦0x8048431 <__libc_csu_fini+1> mov %esp,%ebp
¦0x8048433 <__libc_csu_fini+3> pop %ebp
¦0x8048434 <__libc_csu_fini+4> ret
¦0x8048435 lea 0x0(%esi,%eiz,1),%esi
¦0x8048439 lea 0x0(%edi,%eiz,1),%edi
¦0x8048440 <__libc_csu_init> push %ebp
¦0x8048441 <__libc_csu_init+1> mov %esp,%ebp
¦0x8048443 <__libc_csu_init+3> push %edi
¦0x8048444 <__libc_csu_init+4> push %esi
¦0x8048445 <__libc_csu_init+5> push %ebx
Now in extreme left side the address shown, is the virtual address. The ">" sign indicates that the Break point is at 0x804841a.Which is our main function.
The first instruction is
sub $0x10,%esp
This will substructure the 10 from the ESP.
Next move instruction takes the value $0x80484f0 and put it in stack.We all know that Stack grows downward in memory!
Now more interestingly if you look at the 2nd line of the code you can see $0x80484f0 is the starting address of the string Hello World.
To validate that we can use this command.
(gdb) printf "%s\n",0x80484f0
Now it will return the first character of our string that is a H.
One thing to note that GDB cant print wide character to it will just return "H".
Now its obvious that adding 4 with this we will get our next character.
And adding more bytes will give our full string "Hello World"
Now step by step execution of assembly instructions is very important while trying to understand flow of any program.We can do this using "si" command."si" stands for "step into". When si is entered gdb will execute the next instruction just after break point.
Cont is another gdb command which can be used to run rest of the instructions at a time.
Now when playing with debugger its very important that at the same time you look at the status of the stack and registers.In interactive disassembler like Immunity,Olly debug in windows you can just easily monitor them.But for a command line debugger it will be not that easy.
At any point of time when you wanna check any register content you can do this just by using the command "print"
so to check the value at which EAX is pointing we have to enter
"print $eax"
There are more in gdb. Hopefully I will write another article on it.
One other tool that can be very useful for reverse engineering Linux based prog is "hexdump"
Use the hexdump tool with -C option will dump raw hex dump of executable.Which we usually get at the lower left corner in case of Immunity debugger or Ollydebug.
Now if you wanna see first 16 bytes of the executable then you can use the option -n.
For example
hexdump -C -n 16 MYprog
This will print the header part of executable.
The command "file" also can be used to retrieve some useful information about any executable.
readelf -h Myprog
This command will give the header information of this executable in detail.This will also retrieve the program entry pint.
ndisasm is another cool tool comes with Ubuntu using that you can actually disassemble the binary.
ndisasm -u -o 0x[entry-point] -e 0x320 MYprog | less
the option -e will escape fist 320 bytes.Which is nothing but the header part.
But if you notice you can see this is not the code we have just seen in gdb.
The reason is it the entry point.The code present here is used by the application for setting up the stack.
Now after this following instructions when stack is already configured ,if we jump at the address 0x8048358 we can have the assembly code we just saw in gdb.
08048395 51 push ecx
08048396 56 push esi
08048397 6817840408 push dword 0x8048417
0804839C E8B7FFFFFF call dword 0x8048358
Look at the screen shot [red marked]. After the NOP sleds we can see the codes we have just seen in gdb.
It was the most fundamental of debugging linux application.I hope it was helpful.I will try to write more on gdb later on.
Really a awesome blog for the freshers. Thanks for posting the information.
ReplyDeleteBlockchain Training in Chennai
Blockchain certification
german language course
best ielts coaching centre in chennai
spoken english training in chennai
Japanese Language Course in Chennai
Spoken English in Chennai
spanish language classes in chennai
content writing course in chennai
Blockchain course in Tambaram
Blockchain course in Adyar
This comment has been removed by the author.
ReplyDeleteExcellent article for the people who need information about this course.
ReplyDeletepython real time examples
job opportunities after ccna certification
why python is better
career in machine learning
data scientist interview questions and answers
seo interview questions for freshers
Aivivu chuyên vé máy bay, tham khảo
ReplyDeletevé máy bay đi Mỹ tháng nào rẻ nhất
vé máy bay đi quy nhơn tháng 10
vé máy bay giá rẻ thanh hóa sài gòn
vé máy bay đi hà nội
từ mỹ về việt nam được chưa
cho thuê xe đi sân bay nội bài
Combo Nha Trang
Aivivu - đại lý chuyên vé máy bay trong nước và quốc tế
ReplyDeletevé máy bay đi Mỹ giá bao nhiêu
chuyen bay tu my ve vietnam
vé máy bay từ nhật về việt nam 2021
chuyến bay từ đức về hà nội hôm nay
các đường bay từ canada về việt nam
vé máy bay từ hàn quốc sang việt nam
khách sạn cách ly tại tphcm
Hello. This article was extremely fascinating, especially because I was looking for thoughts on this subject last couple of days.
ReplyDelete스포츠토토
토토
안전놀이터
토토사이트
Hi there every one, here every person is sharing these kinds of familiarity, therefore it’s pleasant to read this web site, and I used to go to see this webpage everyday.
ReplyDelete사설토토
카지노
파워볼사이트
온라인카지노
Great post, beautiful weblog with great informational content. This is a really interesting and informative content. 파워볼게임
ReplyDeleteLooking at this article, I miss the time when I didn't wear a mask. 메리트카지노 Hopefully this corona will end soon. My blog is a blog that mainly posts pictures of daily life before Corona and landscapes at that time. If you want to remember that time again, please visit us.
ReplyDeleteI have got much clear idea regarding from this article.I am pleased that I observed this site. 카지노사이트탑
ReplyDeleteHello, I'm happy to see some great articles on your site. Would you like to come to my site later? My site also has posts, comments and communities similar to yours. Please visit and take a look keonhacai
ReplyDeletePretty! This was an incredibly wonderful post.
ReplyDeleteThank you for providing this information. 토토사이트
The assignment submission period was over and I was nervous, 메이저사이트추천 and I am very happy to see your post just in time and it was a great help. Thank you ! Leave your blog address below. Please visit me anytime.
ReplyDeleteLastly something not a junk, 스포츠토토 which we undergo incredibly frequently.
ReplyDeletevery much for sharing this article. It helped me a lot and made me feel a lot. Please feel free to share such good 토토사이트
ReplyDeleteLastly something not a junk part of my day because 토토사이트 you never know how much which we undergo incredibly frequently.
ReplyDeleteExcellent Blog! I would like to thank you for the efforts you have made in writing this post.
ReplyDelete스포츠토토
thank you so much for posting this great and full of informative content good work keep it up 토토사이트
ReplyDeleteI was reading some of your articles on this website and I conceive this web site is very instructive! Retain putting up.
ReplyDelete카지노사이트가이드
You made some great points and I am grateful for for your information! Take care! 카지노사이트
ReplyDeleteI needed several examples to write an article on this subject, and your article was of great help to me
ReplyDelete토토
경마
온라인경마
Thanks for sharing this vast knowledge to us in this single article. I really appreciate your work. You are going well. Keep it up and keep sharing.
ReplyDelete바카라
사설토토
Keep up the good work , I read few blog posts on this internet site and I believe that your site is really interesting and contains lots of fantastic info .
ReplyDeleteoncasinosite
majortotositepro2
totopickpro2
"Basic Reverse Engineering with GDB" offers a concise introduction to using GDB (GNU Debugger) for reverse engineering purposes. It provides practical insights into analyzing and understanding software binaries by utilizing GDB's debugging capabilities. This resource is valuable for beginners seeking to explore reverse engineering techniques through hands-on examples and exercises.Abogado de tráfico Southampton VA
ReplyDeleteI appreciate you after surfing through your educative article. Once more thanks for sharing. Abogado DWI Virginia
ReplyDelete