gdb - physics-sec/pwnable GitHub Wiki

GDB CheatSheet

Iniciar

gdb <ejecutable> [core dump] --- Start GDB (with optional core dump).
gdb --args <program> <args...> - Start GDB and pass arguments
gdb --pid <pid> ---------------- Start GDB and attach to process.
set args <args...> ------------- Set arguments to pass to program to be debugged.
run ---------------------------- Run the program to be debugged.
kill --------------------------- Kill the running program

ver codigo de funcion

dissasemble funcion (disas)

Stepping

step ----- Go to next instruction (source line), diving into function.
next ----- Go to next instruction (source line) but donʻt dive into functions.
finish --- Continue until the current function returns.
continue - Continue normal execution.

Variables and memory

print/format <what> -------- Print content of variable/memory location/register.
display/format <what> ------ Like „print“, but print the information after each stepping instruction.
undisplay <display#> ------- Remove the „display“ with the given number.
enable display <display#>
disable display <display#> - En- or disable the „display“ with the given number.

Examining the stack

backtrace [full]
where [full] ---- Show call stack.
frame <frame#> -- Select the stack frame to operate on.

correr el programa

run (r)
start -> igual que run pero se detiene en la primera instrucción

ver los registros

info registers

setear un break point

break *0x.....

back-trace

bt

Informations

disassemble <where> -- Disassemble the current function or given location.
info args ------------ Print the arguments to the function of the current stack frame.
info breakpoints ----- Print informations about the break and watchpoints.
info display --------- Print informations about the „displays“.
info locals ---------- Print the local variables in the currently selected stack frame.
info sharedlibrary --- List loaded shared libraries.
info signals --------- List all signals and how they are currently handled.
info threads --------- List all threads.
show directories ----- Print all directories in which GDB searches for source files.
show listsize -------- Print how many are shown in the „list“ command.
whatis variable_name - Print type of named variable.

continuar dsp de un break point

continue (c)

avanzar una instruccion

si (entra en funciones)
ni (no entra en funciones)

ver 20 registros del stack A en hexadecimal

x/20x $esp

escribir en un registro

set $eax=0

info donde esta el stack y el heap

info proc mappings

borrar todos los breakpoints

del

definir algo que deberia mostrar gdb en cada break

define hook-stop
x/24wx $esp
x/2i $eip
end

definir algo que deberia ejecutar gdb en cada break

command
...
end

ver funciones en el proceess linckage table

info functions @plt

objectdump -d -> te muestra cosas raras

objerctdump -t -> info de todos los simbolos

objectdump -x archivo | less -> muestra info del archivo intersante

print system -> donde esta system (que pasa si es aleatorio?)

print *auth -> te muestra la estructura auth en el heap, es una var globa, es una var global

.gdbinit -> pones los comandos que queres que se ejecuten al iniciar

echo 'set disassembly-flavor intel' >> ~/.gdbinit
echo 'set pagination off' >> ~/.gdbinit

gdb -p 1234 -> abris gdb con el proceso de pid 1234

set follow-fork-mode child -> si le proceso forkea seguis al hijo

⚠️ **GitHub.com Fallback** ⚠️