#proxy-server #socks5-proxy #socks5 #proxy #async-read #sock #networking

socks5-impl

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

37 releases

0.5.16 Oct 22, 2024
0.5.14 Jun 21, 2024
0.5.11 Mar 4, 2024
0.5.8 Dec 15, 2023
0.1.8 Mar 18, 2023

#183 in Network programming

Download history 459/week @ 2024-07-18 679/week @ 2024-07-25 517/week @ 2024-08-01 232/week @ 2024-08-08 330/week @ 2024-08-15 375/week @ 2024-08-22 422/week @ 2024-08-29 217/week @ 2024-09-05 674/week @ 2024-09-12 469/week @ 2024-09-19 531/week @ 2024-09-26 611/week @ 2024-10-03 348/week @ 2024-10-10 884/week @ 2024-10-17 608/week @ 2024-10-24 399/week @ 2024-10-31

2,351 downloads per month
Used in 8 crates (6 directly)

GPL-3.0-or-later

120KB
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–9MB
~85K SLoC