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
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.1.0.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc1551a64d51fe9c287a7352406b37a454b033a5920b65fba35a6648331f13bb |
|
MD5 | 49b6c71c15a09b7224a259c223854c86 |
|
BLAKE2b-256 | 0f0e4063d422fb1507dd0bdc976a4ca471f5f713eb4a90a62779dc19fd5465e0 |
Hashes for pysocksproto-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a10e85d2bc3e741b5918b5ed76a141f0e0f03e7770440efff08178fab36b34 |
|
MD5 | f14ee20f7bb62ddd0970d3e841d27ecf |
|
BLAKE2b-256 | 3521177e4b9cc71cb0d14171bb6a7214485a75a58eb4926956b1dda3a9a77e1e |