Simple socks5 proxy server
Project description
PySocks5Server
Simple socks5 proxy server written in python (I was bored).
Installation
Requirements:
- Python 3.10+
pip install socksserver
Usage
Usage: python -m socks5server [-h] [--host HOST] [--port PORT] [--no-auth] [--users [USERS ...]]
options:
-h, --help show this help message and exit
--host HOST
--port PORT
--no-auth Allow connections without authentication.
--users [USERS ...] List of users. Example: "--users user1:password1 user2:password2"
TODO
- TCP/IP port binding
- UDP port association
- Socks4/socks4a support?
Code examples
Run server without authentication
from asyncio import get_event_loop
from socks5server import SocksServer
server = SocksServer("0.0.0.0", 1080, True)
if __name__ == '__main__':
get_event_loop().run_until_complete(server.serve())
Run server with callbacks
from asyncio import get_event_loop
from socks5server import SocksServer, Socks5Client, DataDirection
server = SocksServer("0.0.0.0", 1080, True)
@server.on_client_connected
async def client_connected(client: Socks5Client):
print(f"Client connected: {client}")
@server.on_client_disconnected
async def client_disconnected(client: Socks5Client):
print(f"Client disconnected: {client}")
@server.on_data
async def data_received(client: Socks5Client, direction: DataDirection, data: bytes):
print(f"{direction} | {data}")
if __name__ == '__main__':
get_event_loop().run_until_complete(server.serve())
Run server with password authentication
from asyncio import get_event_loop
from socks5server import SocksServer, PasswordAuthentication
server = SocksServer("0.0.0.0", 1080)
users = {"test_login1": "test_password1", "login": "password"}
server.register_authentication(0x02, PasswordAuthentication(users)) # 0x02 is password authentication type
if __name__ == '__main__':
get_event_loop().run_until_complete(server.serve())
Run server with custom authentication
import asyncio
from asyncio import get_event_loop
from socks5server import SocksServer, AuthenticationBase
class ChallengeHandshakeAuthentication(AuthenticationBase):
async def authenticate(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> bool:
... # Implement authentication process
return True
server = SocksServer("0.0.0.0", 1080)
# 0x03 is type of Challenge–Handshake Authentication Protocol
server.register_authentication(0x03, ChallengeHandshakeAuthentication())
if __name__ == '__main__':
get_event_loop().run_until_complete(server.serve())
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
pysocks5server-0.1.0.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file pysocks5server-0.1.0.tar.gz
.
File metadata
- Download URL: pysocks5server-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.6 Linux/6.6.4-100.fc38.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a018b80aa98fefebc9812bbf20ad8dbdcdf593c2dbe3a9bbbe70034de7c9145 |
|
MD5 | 70240ba23fabb4ae985a4ca53e6d699e |
|
BLAKE2b-256 | e9edea6ad3d193eb937ad1ab58ba0c64cdaf93949d64a9e33dafd706def04394 |
File details
Details for the file pysocks5server-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pysocks5server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.6 Linux/6.6.4-100.fc38.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbcdb7ca854fcc6b213b3e095a56dba38acfc779c6f5954cf526d1105d73dea2 |
|
MD5 | 61b68ebd0baf0d5be8bd453ee1325d85 |
|
BLAKE2b-256 | 707ff14d2725d6a8e635ba64834ce1701dc89e4a34fcc3544e9acfd5b24a3533 |