• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A SOCKS 4/5 reverse proxy server

RSOCKS

RSOCKS is a reverse proxy server for transferring traffic of a specific host through a SOCKS 4/5 proxy. It is useful for using SOCKS 4/5 in applications that don't have SOCKS proxy support.

Installation

$ pip install rsocks

Or

$ easy_install rsocks

To upgrade to latest version, you could execute:

$ pip install -U rsocks

Resources

Usage

First, we need to create a config file with following format:

# /path/to/rsocks.toml
[servers.foo]
proxy = "socks4://user:[email protected]:1080"
listen_host = "0.0.0.0"
listen_port = 5025
upstream_host = "smtp.example.com"
upstream_port = 25
upstream_ssl = false

There is an example for forwarding SMTP/IMAP of Gmail through a SOCKS5 proxy server:

[servers.imap]
proxy = "socks5://localhost:1080"
listen_port = 5993
upstream_host = "imap.gmail.com"
upstream_port = 993
upstream_ssl = true

[servers.smtp]
proxy = "socks5://localhost:1080"
listen_port = 5465
upstream_host = "smtp.gmail.com"
upstream_port = 465
upstream_ssl = true

Next, we start the rsocks server:

$ rsocks --config=/path/to/rsocks.toml
[14:24:44] rsocks.servers.smtp       Using proxy server socks5://localhost:1080
[14:24:44] rsocks.servers.smtp       Listening 127.0.0.1:5465
[14:24:44] rsocks.servers.imap       Using proxy server socks5://localhost:1080
[14:24:44] rsocks.servers.imap       Listening 127.0.0.1:5993
[14:24:44] rsocks.pool               Prepared "smtp"
[14:24:44] rsocks.pool               Prepared "imap"
[14:24:44] rsocks.servers.smtp       Starting server...
[14:24:44] rsocks.servers.imap       Starting server...

Don't stop it now, open your application (such as Airmail in OS X) and set the server option to local forwarding address:

SMTP: 127.0.0.1:5465 without SSL
IMAP: 127.0.0.1:5993 without SSL

Now the application's traffic will be forwarded through the proxy server (socks5://127.0.0.1:1080).

If you wish to run the rsocks server in background, please check the Platform Service Templates. For example, OS X users can create com.tonyseek.rsocks.plist file in ~/Library/LaunchAgents and load it as a service:

$ nano ~/.rsocks.toml  # create a config file
$ wget https://github.com/tonyseek/rsocks/blob/master/misc/platforms/osx-launchd/com.tonyseek.rsocks.plist \
      -O ~/Library/LaunchAgents/com.tonyseek.rsocks.plist
$ nano ~/Library/LaunchAgents/com.tonyseek.rsocks.plist  # edit the template
$ launchctl load -w ~/Library/LaunchAgents/com.tonyseek.rsocks.plist

API Overview

There is an example for using API to build a server:

import os

from rsocks.pool import ServerPool
from rsocks.server import ReverseProxyServer

proxy = os.environ.get('SOCKS_PROXY', 'socks5://localhost:1080')
pool = ServerPool()

with pool.new_server(
        name='IMAP',
        server_class=ReverseProxyServer,
        upstream=('imap.gmail.com', 993),
        use_ssl=True) as server:
    server.set_proxy(proxy)
    server.listen(('127.0.0.1', 5993))

with pool.new_server(
        name='SMTP',
        server_class=ReverseProxyServer,
        upstream=('smtp.gmail.com', 465),
        use_ssl=True) as server:
    server.set_proxy(proxy)
    server.listen(('127.0.0.1', 5465))

if __name__ == '__main__':
    pool.loop()

More Repositories

1

simple-rbac

A simple role based access control utility for Python.
Python
269
star
2

openvpn-status

Parse OpenVPN status logs in Python
Python
83
star
3

oh-my-zsh-seeker-theme

My favored oh-my-zsh theme.
47
star
4

oh-my-zsh-virtualenv-prompt

Yet another virtualenv prompt plugin of oh-my-zsh.
Shell
35
star
5

python-envcfg

For 12-factor apps - retrieve config from envvars.
Python
28
star
6

pyenv-up

Works with pyenv and virtualenv in a new shell.
Shell
23
star
7

flask-navigation

Build navigation bars in your Flask application.
Python
21
star
8

pytest-xpara

An extended parametrizing plugin of pytest.
Python
18
star
9

flask-docker

Using Docker client in your Flask application.
Python
18
star
10

python-tclip

The Python binding of tclip.
C++
13
star
11

python-orphanage

Let child processes suicide if they became orphans.
Python
12
star
12

html5lib-truncation

Truncating HTML with html5lib filter
Python
11
star
13

tinyscgi

[Homework] Yet another SCGI server.
C
10
star
14

docker-devpi

The Docker image of devpi with LDAP integration.
Python
10
star
15

emsfeed

The feed of China Express Mail Service tracking.
Python
8
star
16

macdict

CLI and library to look up dictionary in macOS.
Python
8
star
17

hare

Yet another front-end project boilerplate.
JavaScript
7
star
18

unfeed

[Inactive] The feed of unfeed sites.
Python
6
star
19

docker-tunnel

Using remote docker with SSH tunnel.
Python
5
star
20

introduce-to-coroutine

[Inactive]
Python
5
star
21

ledge

[Inactive] [Homework] A knownledge management platform.
Python
5
star
22

kickme

Kick me from Douban Group
Python
4
star
23

homebrew-premake

Install premake4 and premake5 both with Homebrew
Ruby
2
star
24

wikiquote

[Inactive] An utility to fetch daily wikiquote.
Python
2
star
25

tumblr-to-octopress

[OUTDATED]
Python
1
star
26

sphinx-kr-theme

The third-party package of Kenneth Reitz's krTheme.
Python
1
star
27

ailtdou

[INACTIVE] Email to Douban
Python
1
star
28

flask-git

[WIP]
1
star
29

homebrew-dsocks

Installing a patched DSOCKS with Homebrew
Ruby
1
star
30

homebrew-scripts

They are just scripts, but useful.
Ruby
1
star
31

homebrew-phantomjs

Installing the preview release of PhantomJS with Homebrew Cask
Ruby
1
star