Skip to main content

Customizable python module for create your own programs on SOCKS protocol

Project description

Pysocksproto

A library for creating your own programs on SOCKS proto

Examples

Open a simply socks server

import pysocksproto
hs = pysocksproto.socksServer("0.0.0.0", 4545, pysocksproto.socksThread)
hs.serve()

To support BIND command, you have to specify ipv4 or ipv6 bind adresses

hs.set_bind_addresses("0.0.0.0", None)

To support username/password auth

hs = pysocksproto.socksServer("0.0.0.0", 
                            4545,  
                            pysocksproto.socksThread,    
                            require_auth=True, 
                            valid_creds={"username":"passw0rd", "u2":"p2"})

Or override verify_creds method in socksThread, for your own verification method

class custom(pysocksproto.socksThread):
    def verify_creds(self, username:str, password:str):
        if random.randint(0, 2) == 1:
            return True
        return False

hs = pysocksproto.socksServer("0.0.0.0", 4545, custom, require_auth=True)
hs.serve()      

You can use methods stored in Tools class, methods that start with "server" - provide server functionality, with "client" - client functionality.

For example, use your own CONNECT method - allow connect only to specific adresses

class custom(pysocksproto.socksThread):
    def connect_request_handler(self, version:int, cmd:int, atype:int, target_address:str, target_port:int):
        allowed = ['12.34.56.78', '11.22.33.44']
        resolved = target_adress
        if atype == pysocksproto.ATYP_DOMAINNAME:
            resolved = socket.gethostbyname(resolved)
        if not resolved in allowed:
            pysocksproto.Tools.serverSendCmdResp(self.conn, 
                                    version, 
                                    pysocksproto.REPCODE_FORBIDDEN, 
                                    atype, 
                                    target_adress, 
                                    target_port)
            return
        super().connect_request_handler(version, cmd, atype, target_address, target_port)

hs = pysocksproto.socksServer("0.0.0.0", 4545, custom)
hs.serve()      

Bind a port on socks proxy

class socksBind - for creating BIND requests to socks servers. Example:

import ysocksproto

cl = pysocksproto.socksBind("132.232.14.30", 	33221)
_, address, port = cl.BindProxyPort()
print(f"Proxy bound a port {port} on {address}")
_, address2, port2 = cl.WaitProxyBindConnect()
print(f"Someone connected to proxy from {address2}:{port2}")
cl.conn.send(b"hello, baby\n")
print(cl.conn.recv(10))

If you want to redirect connection to bound port on your system, use

cl.CreateProxyRedirection("127.0.0.1", 4444)

Program will connect to 127.0.0.1:4444, and then resend all data from proxy connection to 127.0.0.1 and back

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysocksproto-0.1.0.linux-x86_64.tar.gz (15.5 kB view hashes)

Uploaded Source

Built Distribution

pysocksproto-0.1.0-py3-none-any.whl (11.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page