Debugging – GDB Tutorial Forums 48 – Programming Debugging – GDB Tutorial


Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #43133
    Support @QUE.COM

    You need to know how to debug your program to make it easier to correct any bugs. Here’s a tutorial video using GDB or GNU Debugger tool.

    Support @QUE.COM
    Support @QUE.COM

    Another good tutorial using GDB program.

    NOTE: If this tutorial is not working it is likely that you have aslr enabled. To disable it run the following command in your terminal
    echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
    When you are finished I strongly recommend you turn it back on with the command
    echo 2 | sudo tee /proc/sys/kernel/randomize_va_space

    The 46 byte shellcode (x86*) used in this program is

    # Sample buffer overflow program.
    Save to example.c program

    #include <stdio.h>
    #include <string.h>
    int main(int argc, char *argv[]){
    	char buf[256];
    	strcpy(buf, argv[1]);
    	printf("%s\n", buf);
    	return 0;
    Support @QUE.COM

    1. gcc -o example example.c // compile your program
    2. gdb ./example // run GNU Debug
    3. (gdb) disas main // run disassembly main
    take note of the address, this is for 64bit.

    Now for 32bits compile code.
    gcc -o example -fno-stack-protector -m32 -z execstack example.c // not working
    gcc -o example -m32 example.c
    Command: gcc -m32 geek.c -o geek

    fatal error: bits/predefs.h: No such file or directory
    Then it indicates that a standard library of gcc is been missing. In that case you must install gcc-multlib by using the following command:

    For C language:
    sudo apt-get install gcc-multilib

    alias python=python3 // to set python to python3

    to anyone getting :
    Cannot insert breakpoint 1.
    Cannot access memory at address xxxxxx

    the displayed memory addresses when you run disassemble main at first are not correct .
    to get the correct ones run the commands as follow:

    gdb ./example
    run aaaaawhatever
    disassemble main or disas main

    now you get the correct ones copy it and quit gdb
    gdb ./example
    break *the address you copied

    now running the command (run $(python ……..) will work.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.