5 releases

0.1.4 Sep 20, 2020
0.1.3 Sep 17, 2020
0.1.2 Sep 13, 2020
0.1.1 Sep 1, 2020
0.1.0 Aug 31, 2020

#10 in #socket-address

MIT license

22KB
502 lines

Asynchronous SOCKS5 Proxy server/client written in Rust

Example

The following example sends a simple HTTP request to google.com through SOCKS5 proxy server.

use socks5_async::{SocksStream, TargetAddr};
use std::{
    boxed::Box,
    error::Error,
    net::{SocketAddr},
};
use tokio::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {

    // Enter a valid SOCKS5 server
    let proxy_addr: SocketAddr = "127.0.0.1:1080".parse().unwrap();

    // Send request to google.com
    let target_addr = TargetAddr::Domain((String::from("google.com"), 80));
    
    // Pass Some((String, String)) to authenticate with username & password
    let userpass = None;

    // Connect to server
    let mut stream = SocksStream::connect(proxy_addr, target_addr, userpass).await?;

    // Send a simple HTTP request
    stream.write(b"GET / HTTP/1.1").await?;
    stream.write(&[0x0d, 0x0a, 0x0d, 0x0a]).await?;
    
    // Read response
    let mut buf = [0; 256]; // 256 bytes => only read few first headers
    stream.read(&mut buf).await.expect("Unable to read the response");
    println!("{}", std::str::from_utf8(&buf).unwrap());

    Ok(())
}

TODO

  • Server
  • Client
  • SOCKS5 Commands
    • CONNECT
    • BIND
    • UDP ASSOCIATE
  • SOCKS5 Authentication Methods
    • NO AUTHENTICATION
    • USERNAME/PASSWORD

Dependencies

~4.5MB
~66K SLoC