Git Product home page Git Product logo

tunna's Introduction

Tunna

Tunna is a set of tools which will wrap and tunnel any TCP communication over HTTP. It can be used to bypass network restrictions in fully firewalled environments.

v1.1 Alpha version

				  _____                        
				 |_   _|   _ _ __  _ __   __ _ 
				   | || | | | '_ \| '_ \ / _` |
				   | || |_| | | | | | | | (_| |
				   |_| \__,_|_| |_|_| |_|\__,_|	
                                                 

                 Tunna 0.1, for HTTP tunneling TCP connections by Nikos Vassakis
                 http://www.secforce.co.uk	/ nikos.vassakis <at> secforce.com

################################################################################################################

SUMMARY

TLDR: Tunnels TCP connections over HTTP

In a fully firewalled (inbound and outbound connections restricted - except the webserver port)

The webshell can be used to connect to any service on the remote host. This would be a local connection on a local port at the remote host and should be allowed by the firewall.

The webshell will read data from the service port wrap them over HTTP and send it as an HTTP response to the local proxy.

The local proxy will unwrap and write the data to it's local port where the client program would be connected.

When the local proxy receives data on the local port, it will send them over to the webshell as an HTTP Post.

The webshell will read the data from the HTTP Post and put them on the service port

and repeat --^

Only the webserver port needs to be open (typically 80/443) The whole communication (Externally) is done over the HTTP protocol

USAGE

python proxy.py -u <remoteurl> -l <localport> [options]

Options

--help, -h show this help message and exit

--url=URL, -u URL url of the remote webshell

--lport=LOCAL_PORT, -l LOCAL_PORT local listening port

--verbose, -v Verbose (outputs packet size)

--buffer=BUFFERSIZE, -b BUFFERSIZE* HTTP request size (some webshels have limitations on the size)

No SOCKS Options

Options are ignored if SOCKS proxy is used

--no-socks, -n Do not use Socks Proxy

--rport=REMOTE_PORT, -r REMOTE_PORT remote port of service for the webshell to connect to

--addr=REMOTE_IP, -a REMOTE_IP address for remote webshell to connect to (default = 127.0.0.1)

Upstream Proxy Options

Tunnel connection through a local Proxy

--up-proxy=UPPROXY, -x UPPROXY Upstream proxy (http://proxyserver.com:3128)

--auth, -A Upstream proxy requires authentication

Advanced Options

--ping-interval=PING_DELAY, -q PING_DELAY webshprx pinging thread interval (default = 0.5)

--start-ping, -s Start the pinging thread first - some services send data first (eg. SSH)

--cookie, -C Request cookies

--authentication, -t Basic authentication

  • See limitations

example usage: python proxy.py -u http://10.3.3.1/conn.aspx -l 8000 -v

# This will start a Local SOCKS Proxy Server at port 8000
# This connection will be wrapped over HTTP and unwrapped at the remote server

python proxy.py -u http://10.3.3.1/conn.aspx -l 8000 -x https://192.168.1.100:3128 -A -v

# This will start a Local SOCKS Proxy Server at port 8000
# It will connect through a Local Proxy (https://192.168.1.100:3128) that requires authentication
# to the remote Tunna webshell

python proxy.py -u http://10.3.3.1/conn.aspx -l 4444 -r 3389 -b 8192 -v --no-socks

# This will initiate a connection between the webshell and Remote host RDP (3389) service
# The RDP client can connect on localhost port 4444
# This connection will be wrapped over HTTP

Prerequisites

The ability to upload a webshell on the remote server

LIMITATIONS / KNOWN BUGS / HACKS

This is a POC code and might cause DoS of the server.
	All efforts to clean up after execution or on error have been made (no promises)

Based on local tests: 		
	* JSP buffer needs to be limited (buffer option):
			4096 worked in Linux Apache Tomcat
			1024 worked in XAMPP Apache Tomcat (slow)
			* More than that created problems with bytes missing at the remote socket
			eg: ruby proxy.rb -u http://10.3.3.1/conn.jsp -l 4444 -r 3389 -b 1024 -v

	* Sockets not enabled by default:
		php windows (IIS + PHP)
		XAMPP Windows
		php linux (PHP bultin web server/apache + PHP)
	If you have the error Uncaught Error: Call to undefined function socket_create()
	see https://stackoverflow.com/questions/6137823/fatal-error-call-to-undefined-function-socket-create
	
	
	* Return cariages on webshells (outside the code): 
		get sent on responses / get written on local socket --> corrupt the packets

	* PHP webshell for windows: the loop function DoS'es the remote socket: 
		sleep function added -> works but a bit slow 
	* PHP webshell needs new line characters removed at the end of the file (after "?>")
		as these will get send in every response and confuse Tunna 

FILES

Webshells:
	conn.jsp	Tested on Apache Tomcat (windows + linux)
	conn.aspx	Tested on IIS 6+8 (windows server 2003/2012) 
	conn.php	Tested on LAMP + XAMPP + IIS (windows + linux)

WebServer:
	webserver.py	Tested with Python 2.6.5

Proxies:
	proxy.py	Tested with Python 2.6.5

Technical Details

Architecture descisions

Data is sent raw in the HTTP Post Body (no post variable)

Instructions / configuration is sent to the webshell as URL parameters (HTTP Get)
Data is sent in the HTTP body (HTTP Post)

Websockets not used: Not supported by default by most of webservers
Asyncronous HTTP responses not really possible
	Proxy queries the server constantly (default 0.5 seconds)

INITIATION PHASE

1st packet initiates a session with the webshell - gets a cookie back eg: http://webserver/conn.ext?proxy

2nd packet sends connection configuration options to the webshell eg: http://webserver/conn.ext?proxy&port=4444&ip=127.0.0.1

IP and port for the webshell to connect to
This is a threaded request:
	In php this request will go into an infinate loop 
	to keep the webshell socket connection alive
	In other webshells [OK] is received back

TUNNA CLIENT

A local socket is going to get created where the client program is going to connect to Once the client is connected the pinging thread is initiated and execution starts. Any data on the socket (from the client) get read and get sent as a HTTP Post request Any data on the webshell socket get sent as a response to the POST request

PINGING THREAD

Because HTTP responses cannot be asyncronous. This thread will do HTTP Get requests on the webshell based on an interval (default 0.5 sec) If the webshell has data to send, it will (also) send it as a reply to this request Otherwise it sends an empty response

In general: Data from the local proxy get send with HTTP Post There are Get requests every 0.5 sec to query the webshell for data If there is data on the webshell side get send over as a response to one of these requests

WEBSHELL

The webshell connects to a socket on the local or a remote host. Any data written on the socket get sent back to the proxy as a reply to a request (POST/GET) Any data received with a post get written to the socket.

NOTES

All requests need to have the URL parameter "proxy" set to be handled by the webshell (http://webserver/conn.ext?proxy)

AT EXIT / AT ERROR

Kills all threads and closes local socket Sends proxy&close to webshell: Kills remote threads and closes socket

SOCKS

The SOCKS support is an addon module for Tunna. Locally is a seperate thread that handles the connection requests and traffic adds a header that specifies the port and the size of the packet and forwards it to Tunna. Tunna sends it over to the remote webserver, removes the HTTP headers and forwards the packet to the remote SOCKS proxy. The remote SOCKS proxy initiates the connection and mapps the received port to the local port. If the remote SOCKS proxy receives data from the service, it looks at the mapping table and finds the port it needs to respond to, adds the port as a header so the local SOCKS proxy will know where to forward the data. Any traffic from the received port will be forwarded to the local port and vice versa.

COPYRIGHT & DISCLAIMER

Tunna, TCP Tunneling Over HTTP Nikos Vassakis Copyright (C) 2014 SECFORCE.

This tool is for legal purposes only.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

tunna's People

Contributors

evict avatar gorgiaxx avatar noraj avatar nvssks avatar radekhvizdos avatar xch12i5 avatar zt2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tunna's Issues

I have an error in connection

I need to make a SOCKS proxy in my WorkPC to tunnel connection over http to my HomePC.
When I try to connect to server I have an error.
Im trying to connect my work pc with my home pc.
In my HomePC:

sudo python webserver.py
everything ok... I have configured by default port 80, I dont have any app listening in 80.

In my Work PC:

sudo python proxy.py -u http://myhost.url -l 10400 -r 22
I want to make a tunnel connection through local port(WorkPC) 10400 to remote port(HomePC) 22.

I have this error in server:

Exception in thread SocketServer:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(_self.__args, *_self.__kwargs)
File "/home/hermes/Tunna/lib/SocksServer.py", line 29, in run
wrapper_channel, address = self.server.accept()
File "/usr/lib/python2.7/socket.py", line 202, in accept
sock, addr = self._sock.accept()
error: [Errno 11] Resource temporarily unavailable

[+] Socket Connected To SocksProxy Exception: {'socket': <socket._socketobject object at 0x7f0a088c2d00>, 'ip': '127.0.0.1', 'SocksThread': <Thread(SocketServer, stopped daemon 139681086818048)>, 'socks': True, 'running': 1, 'port': '22'} [Errno 107] Transport endpoint is not connected

In my client I have opened the port 10400.
[+] Checking for proxy: True
[+] Starting Socket Server
[S] Fri Dec 12 16:32:08 2014 Server Starts - localhost:10400.
...

Transmission of traffic through one TCP connection or multiple TCP connections

Unlike other http-tunnels, Tunna generates a tcp connection for each request and response, And this is very good, Because it simulates a real http queries.

Most of http tunnels generate only one TCP connection, And all TCP-traffics are exchanged through it.

Is there any settings to choise traffics will be transmitted through one TCP-connection or multiple connections?! (however generating a tcp connection for each request and response is better solution, but maybe one TCP-connection faster than multiple connections)

Avoiding socket_create and most of the php functions

By default most compromised servers have all functions like fsock ,socket_create and all disabled,To overcome this we can use the method of transferring data using session sharing.

I have written a tool to work in almost all compromised servers running PHP having disabled PHP functions like the mentioned above having encryption and all, but it ain't developed as Tunna is, ;-) (I am working on it adding aspx and all....) If you are able to get inspiration from it ,It would greatly help in the growth of this tool.

Tool: https://github.com/thesunRider/firedrill

options to choose the type of Encryption

Please add options to choose the type of simple Encoding/Encryption Between Tunna-client and Tunna-server; same as base64, AES, XOR, zip And NONE (Currently Zip is supported in the Tunna)

Can Tunna client written in php?

Tunna works well. But I have a question about the tunna client.

Can Tunna client written in php? (Only For Direct Tunnel, without socks or http proxy support And run in CLI Mode)

How Can I change Url Parameter

How Can I change Url Parameter ?proxy to for example ?page ?
on my country firewall ?proxy parameter is blocked!
Please add options to change Url Parameter ?proxy

Thanks.

Failed to open stream: via PHP shell in file_get_contents

msf5 exploit(multi/handler) > run

[*] Started bind TCP handler against 127.0.0.1:10000
[*] Sending stage (36 bytes) to 127.0.0.1
[*] Command shell session 4 opened (127.0.0.1:38407 -> 127.0.0.1:10000) at 2020-08-09 19:56:29 +0000

<br />
<b>Warning</b>:  file_get_contents(compress.zlib://php://input) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Success in <b>/var/www/conn.php</b> on line <b>192</b><br />
<br />
<b>Warning</b>:  file_get_contents(compress.zlib://php://input) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Success in <b>/var/www/conn.php</b> on line <b>192</b><br />
<br />
<b>Warning</b>:  file_get_contents(compress.zlib://php://input) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Success in <b>/var/www/conn.php</b> on line <b>192</b><br />
<br />
^C
Abort session 4? [y/N]  y

error: proxy -u http://192.168.1.2:8000/ -l 90 -a 192.168.1.1 -r 80 -n

proxy -u http://192.168.1.2:8000/ -l 90 -a 192.168.1.1 -r 80 -n

  _____
 |_   _|   _ _ __  _ __   __ _
   | || | | | '_ \| '_ \ / _` |
   | || |_| | | | | | | | (_| |
   |_| \__,_|_| |_|_| |_|\__,_|

Tunna v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis  secforce.com
###############################################################

[+] Spawning keep-alive thread
[-] Keep-alive thread not required
[+] Checking for proxy: False
[T] Connected To Socks:  ('192.168.1.2', 51509)
[+] Starting Ping thread
General Exception: [Errno 9] Bad file descriptor
[Server] Closing the connection
[-] Disconnected

Why does this error occur? [Errno 9] Bad file descriptor

image

Reverse TCP Socket

Hi,

Could this be changed to support sending a local port using the proxy client to the webserver rather that the other way around. e.g. send my rdp 3389 to the webserver on 4444?

I presume the code is there just would need reversing slighly, it would still need to communicate over HTTP.

Uncaught Error: Call to undefined function socket_create()

I was quickly trying a PoC were I ran the PHP wbeshell with php -S 192.168.2.149:8080.

And the proxy with:

$ tunna-proxy -u http://192.168.2.105:8080/conn.php -l 7777 -v 
  _____                        
 |_   _|   _ _ __  _ __   __ _ 
   | || | | | '_ \| '_ \ / _` |
   | || |_| | | | | | | | (_| |
   |_| \__,_|_| |_|_| |_|\__,_|

Tunna v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis <at> secforce.com
###############################################################

[+] Spawning keep-alive thread
<br />
<b>Warning</b>:  session_start(): open(/var/lib/php7/sess_jgu073cevkijfja4ukjb3pid9i, O_RDWR) failed: Permission denied (13) in <b>/home/noraj/webdir/conn.php</b> on line <b>98</b><br />
<br />
<b>Warning</b>:  session_start(): Failed to read session data: files (path: /var/lib/php7) in <b>/home/noraj/webdir/conn.php</b> on line <b>98</b><br />
[Server] Couldnt Start Session
[-] Keep-alive thread exited
[!] Received Interrupt or Something Went Wrong
[-] Disconnected

PS : on web server I see the ?proxy and the ?proxy&port=0&ip=127.0.0.1&socks

To have access to /var/lib/php7 it requires to have wwwrun or root permissions. My user is not.

So quickly trying with sudo as root (for the PoC I'd never do that in real life) I have

tunna-proxy -u http://192.168.2.105:8080/conn.php -l 7777 -v
  _____                        
 |_   _|   _ _ __  _ __   __ _ 
   | || | | | '_ \| '_ \ / _` |
   | || |_| | | | | | | | (_| |
   |_| \__,_|_| |_|_| |_|\__,_|

Tunna v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis <at> secforce.com
###############################################################

[+] Sending File
[Server] File Uploaded at /tmp/965-socks4aServer.py
[+] Spawning keep-alive thread
<br />
<b>Fatal error</b>:  Uncaught Error: Call to undefined function socket_create() in /home/noraj/webdir/conn.php:164
Stack trace:
#0 {main}
  thrown in <b>/home/noraj/webdir/conn.php</b> on line <b>164</b><br />

[-] Keep-alive thread exited
[!] Received Interrupt or Something Went Wrong
[-] Disconnected

PS : on web server I see the same error as on the client side

PHP is 7.2.5.

It says socket_create is an undefined function I checked it exist in PHP 7 : https://www.php.net/manual/en/function.socket-create.php

I also tried with XAMP for Windows 7.3.8

$ python2 proxy.py -u http://192.168.2.199/conn.php -l 7777 -v
  _____                        
 |_   _|   _ _ __  _ __   __ _ 
   | || | | | '_ \| '_ \ / _` |
   | || |_| | | | | | | | (_| |
   |_| \__,_|_| |_|_| |_|\__,_|

Tunna v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis <at> secforce.com
###############################################################

[+] Sending File
[Server]: No File Selected
[+] Spawning keep-alive thread
<br />
<b>Fatal error</b>:  Uncaught Error: Call to undefined function socket_create() in C:\xampp\htdocs\conn.php:40
Stack trace:
#0 C:\xampp\htdocs\conn.php(28): messenger-&gt;connect_to_server()
#1 C:\xampp\htdocs\conn.php(182): messenger-&gt;__construct('0', '127.0.0.1')
#2 {main}
  thrown in <b>C:\xampp\htdocs\conn.php</b> on line <b>40</b><br />

[-] Keep-alive thread exited
[!] Received Interrupt or Something Went Wrong
[-] Disconnected

Finally I found the answer here https://stackoverflow.com/questions/6137823/fatal-error-call-to-undefined-function-socket-create and I installed zypper in php7-sockets the PHP sockets module.

how can i use it ?

on my Server i just run python ./webserver.py

TunnaWebServer v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis <at> secforce.com
###############################################################

[W] Mon Oct 10 06:51:10 2016 Web Server Starts - 0.0.0.0:8000 

now in client windows i must run Proxy.exe with
proxy.exe -u MyServerIP -l 8000

seems i do it something Wrong .

FIREWALL detections

this there way, i can encode the get request as base64 before.
it is being detected and block by packet inspection firewall, but i cant detect any base64 encoded payload, i was thinking if there is any possible of encoding the request as base64? thanks

Use on Android

Hi.
This looks great ! .
Can be possible to use this on Android as client and the server on a VPS to create a tunnel and use it like VPN ?
Can someone can create a app that allow http headers request, please ?
This way we can use it bypass firewall from ISP and many people can use this excellent program .

I hope your answers.

python proxy.py -u http://xxx.jsp -l 1234 -v

Tunna v1.1a, for HTTP tunneling TCP connections by Nikos Vassakis
http://www.secforce.com / nikos.vassakis secforce.com
###############################################################

[+] Spawning keep-alive thread

[-] Keep-alive thread exited
[!] Received Interrupt or Something Went Wrong
[-] Disconnected

Error - module object has no attribute create_default_context

windows 10 with Python.exe (version 2.6.5) when I use the following command:
proxy.py -u http://X.X.X.X/conn.php -l 8080 -r 8081 --no-socks

I receive the following Error:

[-] Error: 'module' object has no attribute 'create_default_context'
[!] Received Interrupt or Something Went Wrong
[-] Disconnected

But proxy.exe -u http://X.X.X.X/conn.php -l 8080 -r 8081 --no-socks
works Fine.

I want to use proxy.py Script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.