Stuff

Interesting and not so interesting stuff

Twunnel: A HTTP/SOCKS5 Tunnel for Twisted

Twunnel is a HTTP/SOCKS5 tunnel for Twisted.

Twunnel supports:

  • HTTP
  • HTTP + Basic authentication
  • SOCKS5

The Twunnel project page: https://github.com/jvansteirteghem/twunnel

Examples

1
2
3
4
5
6
7
8
9
10
import twunnel

protocolFactory = ..

configuration = \
{
}

tunnel = twunnel.Tunnel(configuration)
tunnel.connect("www.google.com", 80, protocolFactory)
1
2
3
4
5
6
7
8
9
10
11
12
13
from twisted.internet import ssl
import twunnel

protocolFactory = ..

configuration = \
{
}

contextFactory = ssl.ClientContextFactory()

tunnel = twunnel.Tunnel(configuration)
tunnel.connect("www.google.com", 443, protocolFactory, contextFactory)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import twunnel

protocolFactory = ..

configuration = \
{
    "PROXY_SERVERS":
    [
        {
            "TYPE": "HTTP",
            "ADDRESS": "127.0.0.1",
            "PORT": 8080,
            "AUTHENTICATION":
            {
                "USERNAME": "1",
                "PASSWORD": "2"
            }
        }
    ]
}

tunnel = twunnel.Tunnel(configuration)
tunnel.connect("www.google.com", 80, protocolFactory)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import twunnel

protocolFactory = ..

configuration = \
{
    "PROXY_SERVERS":
    [
        {
            "TYPE": "SOCKS5",
            "ADDRESS": "127.0.0.1",
            "PORT": 1080
        }
    ]
}

tunnel = twunnel.Tunnel(configuration)
tunnel.connect("www.google.com", 80, protocolFactory)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import twunnel

protocolFactory = ..

configuration = \
{
    "PROXY_SERVERS":
    [
        {
            "TYPE": "HTTP",
            "ADDRESS": "127.0.0.1",
            "PORT": 8080,
            "AUTHENTICATION":
            {
                "USERNAME": "1",
                "PASSWORD": "2"
            }
        },
        {
            "TYPE": "SOCKS5",
            "ADDRESS": "127.0.0.1",
            "PORT": 1080
        }
    ]
}

tunnel = twunnel.Tunnel(configuration)
tunnel.connect("www.google.com", 80, protocolFactory)

Examples of JAP_LOCAL/REMOTE_WS.json

Example 1: LOCAL/REMOTE_PROXY_SERVER

JAP_LOCAL_WS.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"LOCAL_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 1080
},
"REMOTE_PROXY_SERVERS":
[
    {
        "TYPE": "HTTP",
        "ADDRESS": "127.0.0.1",
        "PORT": 8080,
        "AUTHENTICATION":
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    }
]

JAP_REMOTE_WS.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
"REMOTE_PROXY_SERVER":
{
    "TYPE": "HTTP",
    "ADDRESS": "127.0.0.1",
    "PORT": 8080,
    "AUTHENTICATION":
    [
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    ]
}

Example 2: LOCAL/REMOTE_PROXY_SERVER

You can generate a certificate authentication file (CA.pem) with CA.bat and CA.ini and you can generate a certificate file (C.pem) and a certificate key file (CK.pem) with C.bat and C.ini.

JAP_LOCAL_WS.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"LOCAL_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 1080
},
"REMOTE_PROXY_SERVERS":
[
    {
        "TYPE": "HTTPS",
        "ADDRESS": "127.0.0.1",
        "PORT": 8443,
        "AUTHENTICATION":
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        },
        "CERTIFICATE":
        {
            "AUTHENTICATION":
            {
                "FILE": "CA.pem"
            }
        }
    }
]

JAP_REMOTE_WS.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"REMOTE_PROXY_SERVER":
{
    "TYPE": "HTTPS",
    "ADDRESS": "127.0.0.1",
    "PORT": 8443,
    "AUTHENTICATION":
    [
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    ],
    "CERTIFICATE":
    {
        "KEY":
        {
            "FILE": "CK.pem"
        },
        "FILE": "C.pem"
    }
}

Example 3: LOCAL/REMOTE_PROXY_SERVER

JAP_LOCAL_WS.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"LOCAL_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 1080
},
"REMOTE_PROXY_SERVERS":
[
    {
        "TYPE": "HTTPS",
        "ADDRESS": "",
        "PORT": 443,
        "AUTHENTICATION":
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        },
        "CERTIFICATE":
        {
            "AUTHENTICATION":
            {
                "FILE": "CA_DEFAULT.pem"
            }
        }
    }
]

JAP_REMOTE_WS.json:

1
2
3
4
5
6
7
8
9
10
11
"REMOTE_PROXY_SERVER":
{
    "TYPE": "HTTPS",
    "AUTHENTICATION":
    [
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    ]
}

Examples of JAP_LOCAL/REMOTE_SSH.json

Example 1: LOCAL/REMOTE_PROXY_SERVER

You can generate a public/private key file (KP.pem) with KP.bat.

JAP_LOCAL_SSH.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
    "LOCAL_PROXY_SERVER":
    {
        "ADDRESS": "127.0.0.1",
        "PORT": 1080,
        "KEYS":
        [
            {
                "PUBLIC":
                {
                    "FILE": "KP.pem",
                    "PASSPHRASE": ""
                },
                "PRIVATE":
                {
                    "FILE": "KP.pem",
                    "PASSPHRASE": ""
                }
            }
        ]
    },
    "REMOTE_PROXY_SERVERS":
    [
        {
            "ADDRESS": "127.0.0.1",
            "PORT": 8022,
            "AUTHENTICATION":
            {
                "USERNAME": "1",
                "PASSWORD": "2"
            },
            "KEY":
            {
                "AUTHENTICATION":
                {
                    "FINGERPRINT": ""
                }
            }
        }
    ]
}

JAP_REMOTE_SSH.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"REMOTE_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 8022,
    "AUTHENTICATION":
    [
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    ],
    "KEY":
    {
        "PUBLIC":
        {
            "FILE": "KP.pem",
            "PASSPHRASE": ""
        },
        "PRIVATE":
        {
            "FILE": "KP.pem",
            "PASSPHRASE": ""
        }
    }
}

Example 2: LOCAL/REMOTE_PROXY_SERVER

JAP_LOCAL_SSH.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
    "LOCAL_PROXY_SERVER":
    {
        "ADDRESS": "127.0.0.1",
        "PORT": 1080,
        "KEYS":
        [
            {
                "PUBLIC":
                {
                    "FILE": "KP.pem",
                    "PASSPHRASE": ""
                },
                "PRIVATE":
                {
                    "FILE": "KP.pem",
                    "PASSPHRASE": ""
                }
            }
        ]
    },
    "REMOTE_PROXY_SERVERS":
    [
        {
            "ADDRESS": "127.0.0.1",
            "PORT": 8022,
            "AUTHENTICATION":
            {
                "USERNAME": "1",
                "PASSWORD": ""
            },
            "KEY":
            {
                "AUTHENTICATION":
                {
                    "FINGERPRINT": ""
                }
            }
        }
    ]
}

JAP_REMOTE_SSH.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"REMOTE_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 8022,
    "AUTHENTICATION":
    [
        {
            "USERNAME": "1",
            "PASSWORD": "",
            "KEYS":
            [
                {
                    "PUBLIC":
                    {
                        "FILE": "KP.pem",
                        "PASSPHRASE": ""
                    }
                }
            ]
        }
    ],
    "KEY":
    {
        "PUBLIC":
        {
            "FILE": "KP.pem",
            "PASSPHRASE": ""
        },
        "PRIVATE":
        {
            "FILE": "KP.pem",
            "PASSPHRASE": ""
        }
    }
}

Examples of JAP_LOCAL.json

Example 1: LOGGER

You can set LOGGER.LEVEL to DEBUG, INFO, WARNING, ERROR or CRITICAL.

JAP_LOCAL.json:

1
2
3
4
"LOGGER":
{
    "LEVEL": "DEBUG"
}

Example 2: DNS_RESOLVER

JAP_LOCAL.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"DNS_RESOLVER":
{
    "HOSTS":
    {
        "FILE": "H.txt"
    },
    "SERVERS": 
    [
        {
            "ADDRESS": "8.8.8.8",
            "PORT": 53
        },
        {
            "ADDRESS": "8.8.8.4",
            "PORT": 53
        }
    ]
}

H.txt:

1
127.0.0.1       localhost

Example 3: PROXY_SERVERS

You can set PROXY_SERVERS.TYPE to HTTP or SOCKS5.

JAP_LOCAL.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
"PROXY_SERVERS": 
[
    {
        "TYPE": "HTTP",
        "ADDRESS": "127.0.0.1",
        "PORT": 8080,
        "AUTHENTICATION":
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    }
]

Example 4: PROXY_SERVERS

JAP_LOCAL.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"PROXY_SERVERS": 
[
    {
        "TYPE": "HTTP",
        "ADDRESS": "127.0.0.1",
        "PORT": 8080,
        "AUTHENTICATION":
        {
            "USERNAME": "1",
            "PASSWORD": "2"
        }
    },
    {
        "TYPE": "SOCKS5",
        "ADDRESS": "127.0.0.1",
        "PORT": 2080
    },
    {
        "TYPE": "SOCKS5",
        "ADDRESS": "127.0.0.1",
        "PORT": 3080
    }
]

Example 5: LOCAL_PROXY_SERVER

JAP_LOCAL.json:

1
2
3
4
5
"LOCAL_PROXY_SERVER":
{
    "ADDRESS": "127.0.0.1",
    "PORT": 1080
}

JAP 3.0.0 Released!

JAP is a SOCKS5 proxy server written in PYTHON and JAVASCRIPT. JAP has a local proxy server (which supports TCP, TCP over SSH and TCP over WS/WSS) and a remote proxy server (which supports TCP over SSH and TCP over WS/WSS).

JAP also has a UI.

The JAP project page: https://github.com/jvansteirteghem/jap