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:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pysocksproto-0.0.9.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | be68c1855bdd7fac6bc980799ebef1fb4791fe9e631c588a62bb3bda4e7a1131 |
|
MD5 | 6908112217d38fa2e1be90b13665f313 |
|
BLAKE2b-256 | 498bb931b016e05334dc6e10fcccde7c85522e7bd323e48309496dff93505150 |
Hashes for pysocksproto-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a4641c0166c4a649ab489e88341e5b695bdf82631567a03a9fdd0a256b8b102 |
|
MD5 | fee9c572dfc848fd5c6f2ab05d98f9cc |
|
BLAKE2b-256 | 5e6182dd1b00ae6504a23051b5d24c6bfea4b8d57567ff33217e6d28620fd972 |