Bash

對我的虛擬伺服器的可能攻擊 - 傳出 tcp/ip 連接

  • March 17, 2022

我的 vServer (Centos 7) 出現可疑情況。未知的 bash 腳本正在消耗伺服器的所有記憶體。與“外部”有明顯的聯繫。

不幸的是,我的 Unix 知識有限。

如何禁止使用者 git 與外部的連接?

我怎樣才能弄清楚這個 bash 腳本駐留在哪裡,腳本的內容是什麼?

lsof -p 1577
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 1577 git cwd DIR 182,395665 4096 2 /
bash 1577 git rtd DIR 182,395665 4096 2 /
bash 1577 git txt unknown /proc/1577/exe (readlink: No such file or directory)
bash 1577 git mem REG 182,395665 795648 (deleted)/var/tmp/.ICE-unix/.bash/.bash/bash (stat: No such file or directory)
bash 1577 git 0r FIFO 0,8 0t0 3801753555 pipe
bash 1577 git 1w FIFO 0,8 0t0 3801753556 pipe
bash 1577 git 2w FIFO 0,8 0t0 3801753556 pipe
bash 1577 git 3u REG 182.395665 0 5390 /tmp/.lock
bash 1577 git 4u 0000 0,9 0 4145 [eventpoll]
bash 1577 git 5r FIFO 0,8 0t0 3801755403 pipe
bash 1577 git 6w FIFO 0,8 0t0 3801755403 pipe
bash 1577 git 7r FIFO 0,8 0t0 3801755399 pipe
bash 1577 git 8w FIFO 0,8 0t0 3801755399 pipe
bash 1577 git 9u 0000 0,9 0 4145 [eventfd]
bash 1577 git 10r CHR 1,3 0t0 3801397120 /dev/null
bash 1577 git 11u IPv4 3801755495 0t0 TCP <my server IP>:56542->**blackcat.ro:http** (ESTABLISHED)

根據您現有的防火牆設置,它可能會有所不同。但通常你應該已經iptables安裝了防火牆。

(注意:如果你有firewalld,它不能阻止 IP 地址,請參閱此處禁用它並切換到 iptables)

您需要知道的第一件事是您不能阻止對域的請求,但您可以使用 IP 來阻止。

要查找 IP,請使用nslookup. 說nslookup blackcat.ro。您將獲得 IP 列表,您需要將它們全部阻止。您可能會看到 IPv4 和 IPv6 地址,請使用以下命令之一進行阻止。

iptables -A OUTPUT -p tcp -d <IPv4> -j DROP
ip6tables -A OUTPUT -p tcp -d <IPv6> -j DROP

完成後,保存您目前的配置,以免失去。

/sbin/service iptables save
/sbin/service ip6tables save

引用自:https://serverfault.com/questions/1096370