#socks5 #socks #proxy #async #network

socks5-impl

Fundamental abstractions and async read / write functions for SOCKS5 protocol and Relatively low-level asynchronized SOCKS5 server implementation based on tokio

27 releases (4 breaking)

0.5.6 Nov 19, 2023
0.5.4 Sep 19, 2023
0.5.2 Jul 31, 2023
0.1.8 Mar 18, 2023

#5 in #socks-proxy

Download history 289/week @ 2023-08-10 288/week @ 2023-08-17 123/week @ 2023-08-24 279/week @ 2023-08-31 35/week @ 2023-09-07 95/week @ 2023-09-14 262/week @ 2023-09-21 288/week @ 2023-09-28 208/week @ 2023-10-05 30/week @ 2023-10-12 131/week @ 2023-10-19 336/week @ 2023-10-26 172/week @ 2023-11-02 448/week @ 2023-11-09 244/week @ 2023-11-16 110/week @ 2023-11-23

1,021 downloads per month

GPL-3.0-or-later

115KB
2.5K SLoC

socks5-impl

Fundamental abstractions and async read / write functions for SOCKS5 protocol and Relatively low-level asynchronized SOCKS5 server implementation based on tokio.

This repo hosts at socks5-impl

Version Documentation License

Features

  • Fully asynchronized
  • Supports all SOCKS5 commands
    • CONNECT
    • BIND
    • ASSOCIATE
  • Customizable authentication
    • No authentication
    • Username / password
    • GSSAPI

Usage

The entry point of this crate is socks5_impl::server::Server.

Check examples for usage examples.

Example

use socks5_impl::protocol::{handshake, Address, AuthMethod, Reply, Request, Response, StreamOperation};

fn main() -> socks5_impl::Result<()> {
    let listener = std::net::TcpListener::bind("127.0.0.1:5000")?;
    let (mut stream, _) = listener.accept()?;

    let request = handshake::Request::retrieve_from_stream(&mut stream)?;

    if request.evaluate_method(AuthMethod::NoAuth) {
        let response = handshake::Response::new(AuthMethod::NoAuth);
        response.write_to_stream(&mut stream)?;
    } else {
        let response = handshake::Response::new(AuthMethod::NoAcceptableMethods);
        response.write_to_stream(&mut stream)?;
        let _ = stream.shutdown(std::net::Shutdown::Both);
        let err = "No available handshake method provided by client";
        return Err(std::io::Error::new(std::io::ErrorKind::Unsupported, err).into());
    }

    let req = match Request::retrieve_from_stream(&mut stream) {
        Ok(req) => req,
        Err(err) => {
            let resp = Response::new(Reply::GeneralFailure, Address::unspecified());
            resp.write_to_stream(&mut stream)?;
            let _ = stream.shutdown(std::net::Shutdown::Both);
            return Err(err.into());
        }
    };

    match req.command {
        _ => {} // process request
    }

    Ok(())
}

License

GNU General Public License v3.0

Dependencies

~3–9.5MB
~79K SLoC