-q# No show banner-x<file># Auto-execute GDB instructions from here-p<pid># Attach to process
Talimatlar
run# Executestart# Start and break in mainn/next/ni# Execute next instruction (no inside)s/step/si# Execute next instructionc/continue# Continue until next breakpointpsystem# Find the address of the system functionset $eip =0x12345678# Change value of $eiphelp# Get helpquit# exit# Disassembledisassemblemain# Disassemble the function called maindisassemble0x12345678# Disassemble taht addresssetdisassembly-flavorintel# Use intel syntaxsetfollow-fork-modechild/parent# Follow child/parent process# Breakpointsbrfunc# Add breakpoint to functionbr*func+23br*0x12345678del<NUM># Delete that number of breakpointwatchEXPRESSION# Break if the value changes# infoinfofunctions-->Infoabountfunctionsinfofunctionsfunc-->Infoofthefuntioninforegisters-->Valueoftheregistersbt# Backtrace Stackbtfull# Detailed stackprintvariableprint0x87654321-0x12345678# Caculate# x/examineexamine/<num><o/x/d/u/t/i/s/c><b/h/w/g> dir_mem/reg/puntero # Shows content of <num> in <octal/hexa/decimal/unsigned/bin/instruction/ascii/char> where each entry is a <Byte/half word (2B)/Word (4B)/Giant word (8B)>
x/o0xDir_hexx/2x $eip # 2Words from EIPx/2x $eip -4# $eip - 4x/8xb $eip # 8 bytes (b-> byte, h-> 2bytes, w-> 4bytes, g-> 8bytes)ireip# Value of $eipx/wpointer# Value of the pointerx/spointer# String pointed by the pointerx/xw&pointer# Address where the pointer is locatedx/i $eip # Instructions of the EIP
İlginç daha fazla talimat içeren bu GEF çatalını isteğe bağlı olarak kullanabilirsiniz.
helpmemory# Get help on memory commandcanary# Search for canary value in memorychecksec#Check protectionspsystem#Find system function addresssearch-pattern"/bin/sh"#Search in the process memoryvmmap#Get memory mappingsxinfo<addr># Shows page, size, perms, memory area and offset of the addr in the pagememorywatch0x7840000x1000byte#Add a view always showinf this memorygot#Check got tablememorywatch $_got()+0x185#Watch a part of the got table# Vulns detectionformat-string-helper#Detect insecure format stringsheap-analysis-helper#Checks allocation and deallocations of memory chunks:NULL free, UAF,double free, heap overlap#Patternspatterncreate200#Generate length 200 patternpatternsearch"avaaawaa"#Search for the offset of that substringpatternsearch $rsp #Search the offset given the content of $rsp#Shellcodeshellcodesearchx86#Search shellcodesshellcodeget61#Download shellcode number 61#Dump memory to filedumpbinarymemory/tmp/dump.bin0x2000000000x20000c350#Another way to get the offset of to the RIP1-PutabpafterthefunctionthatoverwritestheRIPandsendappaterntoovwerwriteit2-ef➤ifStacklevel0,frameat0x7fffffffddd0:rip=0x400cd3; savedrip=0x6261617762616176calledbyframeat0x7fffffffddd8Arglistat0x7fffffffdcf8,args:Localsat0x7fffffffdcf8,Previousframe's sp is 0x7fffffffddd0Saved registers:rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8gef➤ pattern search 0x6261617762616176[+] Searching for '0x6261617762616176'[+] Found at offset 184 (little-endian search) likely
İpuçları
GDB aynı adresler
Hata ayıklarken GDB, yürütüldüğünde ikili tarafından kullanılan adreslerden biraz farklı olacaktır. GDB'nin aynı adreslere sahip olmasını sağlayabilirsiniz:
unset env LINES
unset env COLUMNS
set env _=<path>İkili dosyanın mutlak yolunu ekleyin
Aynı mutlak yolu kullanarak ikili dosyayı sömürün
GDB'yi kullanırken ve ikili dosyayı sömürürken PWD ve OLDPWD aynı olmalıdır
Çağrılan fonksiyonları bulmak için geri izleme
Statik olarak bağlanmış bir ikiliye sahip olduğunuzda, tüm fonksiyonlar ikiliye ait olacaktır (ve harici kütüphanelere değil). Bu durumda, örneğin kullanıcı girdisi istemek için ikilinin izlediği akışı tanımlamak zor olacaktır.
Bu akışı kolayca tanımlayabilirsiniz gdb ile ikiliyi çalıştırarak, giriş istendiğinde durdurun ve ardından CTRL+C ile durdurun ve bt (geri izleme) komutunu kullanarak çağrılan fonksiyonları görebilirsiniz:
gef➤ bt
#0 0x00000000004498ae in ?? ()
#1 0x0000000000400b90 in ?? ()
#2 0x0000000000400c1d in ?? ()
#3 0x00000000004011a9 in ?? ()
#4 0x0000000000400a5a in ?? ()
GDB sunucusu
gdbserver --multi 0.0.0.0:23947 (IDA'da Linux makinesindeki yürütülebilir dosyanın mutlak yolunu ve Windows makinesindeki yürütülebilir dosyanın mutlak yolunu doldurmanız gerekmektedir)
Ghidra
Yığın ofsetini bulma
Ghidra, **yerel değişkenlerin konumu hakkındaki bilgiler sayesinde bir tampon taşmasının ofsetini bulmak için çok yararlıdır.
Örneğin, aşağıdaki örnekte, local_bc içinde bir tampon taşması, 0xbc ofsetine ihtiyaç duyduğunuzu gösterir. Dahası, local_10 bir canary çerezi ise, local_bc'den üzerine yazmak için 0xac ofseti olduğunu gösterir.
RIP'nin kaydedildiği ilk 0x08'in RBP'ye ait olduğunu unutmayın.
ldd executable | grep libc.so.6 --> Adres (ASLR varsa, bu her seferinde değişir)
for i in `seq 0 20`; do ldd <Ejecutable> | grep libc; done --> Adresin çok değişip değişmediğini görmek için döngü
readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system --> "system"ın ofseti
strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh --> "/bin/sh" ofseti
strace executable --> Yürütülebilir dosya tarafından çağrılan fonksiyonlar
rabin2 -i ejecutable --> Tüm fonksiyonların adresi
Inmunity debugger
!monamodules#Get protections, look for all false except last one (Dll of SO)!monafind-s"\xff\xe4"-mname_unsecure.dll#Search for opcodes insie dll space (JMP ESP)
IDA
Uzaktan linux'ta hata ayıklama
IDA klasörü içinde, bir linux içinde bir ikili dosyayı hata ayıklamak için kullanılabilecek ikili dosyalar bulabilirsiniz. Bunun için linux_server veya linux_server64 ikili dosyasını linux sunucusuna taşıyın ve ikili dosyayı içeren klasörde çalıştırın:
./linux_server64 -Ppass
Sonra, hata ayıklayıcıyı yapılandırın: Hata Ayıklayıcı (linux uzak) --> Proses seçenekleri...:
Şirketinizi HackTricks'te reklamını görmek istiyorsanız veya HackTricks'i PDF olarak indirmek istiyorsanız [ABONELİK PLANLARI]'na göz atın (https://github.com/sponsors/carlospolop)!
[The PEASS Family]'yi (https://opensea.io/collection/the-peass-family) keşfedin, özel [NFT'lerimiz]'i (https://opensea.io/collection/the-peass-family) içeren koleksiyonumuzu