#[cfg(not(miri))] #[tokio::test] asyncfn test_socks_v5_without_auth_works() { let proxy_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let proxy_addr = proxy_tcp.local_addr().expect("local_addr"); let proxy_dst = format!("http://{proxy_addr}").parse().expect("uri");
let target_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let target_addr = target_tcp.local_addr().expect("local_addr"); let target_dst = format!("http://{target_addr}").parse().expect("uri");
// Client // // Will use `SocksV5` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let conn = connector.call(target_dst).await.expect("tunnel"); letmut tcp = conn.into_inner();
letmut buf = [0u8; 64]; let n = tcp.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Goodbye!");
});
// Proxy // // Will receive CONNECT command from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); letmut buf = [0u8; 513];
// negotiation req/res let n = to_client.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], [0x05, 0x01, 0x00]);
// Target server // // Will accept connection from proxy server // Will receive "Hello World!" from the client and return "Goodbye!" let t3 = tokio::spawn(asyncmove { let (mut io, _) = target_tcp.accept().await.expect("accept"); letmut buf = [0u8; 64];
let n = io.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Hello World!");
#[cfg(not(miri))] #[tokio::test] asyncfn test_socks_v5_with_auth_works() { let proxy_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let proxy_addr = proxy_tcp.local_addr().expect("local_addr"); let proxy_dst = format!("http://{proxy_addr}").parse().expect("uri");
let target_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let target_addr = target_tcp.local_addr().expect("local_addr"); let target_dst = format!("http://{target_addr}").parse().expect("uri");
// Client // // Will use `SocksV5` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let conn = connector.call(target_dst).await.expect("tunnel"); letmut tcp = conn.into_inner();
letmut buf = [0u8; 64]; let n = tcp.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Goodbye!");
});
// Proxy // // Will receive CONNECT command from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); letmut buf = [0u8; 513];
// negotiation req/res let n = to_client.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], [0x05, 0x01, 0x02]);
// Target server // // Will accept connection from proxy server // Will receive "Hello World!" from the client and return "Goodbye!" let t3 = tokio::spawn(asyncmove { let (mut io, _) = target_tcp.accept().await.expect("accept"); letmut buf = [0u8; 64];
let n = io.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Hello World!");
// Client // // Will use `SocksV5` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let _conn = connector
.call("https://hyper.rs:443".try_into().unwrap())
.await
.expect("tunnel");
});
// Proxy // // Will receive CONNECT command from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); letmut buf = [0u8; 513];
// negotiation req/res let n = to_client.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], [0x05, 0x01, 0x02]);
// Client // // Will use `SocksV5` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let _conn = connector
.call("https://hyper.rs:443".try_into().unwrap())
.await
.expect("tunnel");
});
// Proxy // // Will receive CONNECT command from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); letmut buf = [0u8; 513];
// negotiation req/res let n = to_client.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], [0x05, 0x01, 0x02]);
#[cfg(not(miri))] #[tokio::test] asyncfn test_socks_v4_works() { let proxy_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let proxy_addr = proxy_tcp.local_addr().expect("local_addr"); let proxy_dst = format!("http://{proxy_addr}").parse().expect("uri");
let target_tcp = TcpListener::bind("127.0.0.1:0").await.expect("bind"); let target_addr = target_tcp.local_addr().expect("local_addr"); let target_dst = format!("http://{target_addr}").parse().expect("uri");
// Client // // Will use `SocksV4` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let conn = connector.call(target_dst).await.expect("tunnel"); letmut tcp = conn.into_inner();
letmut buf = [0u8; 64]; let n = tcp.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Goodbye!");
});
// Proxy // // Will receive CONNECT command from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); letmut buf = [0u8; 512];
let [p1, p2] = target_addr.port().to_be_bytes(); let [ip1, ip2, ip3, ip4] = [127, 0, 0, 1]; let message = [4, 0x01, p1, p2, ip1, ip2, ip3, ip4, 0, 0]; let n = to_client.read(&mut buf).await.expect("read");
assert_eq!(&buf[..n], message);
// Target server // // Will accept connection from proxy server // Will receive "Hello World!" from the client and return "Goodbye!" let t3 = tokio::spawn(asyncmove { let (mut io, _) = target_tcp.accept().await.expect("accept"); letmut buf = [0u8; 64];
let n = io.read(&mut buf).await.expect("read 1");
assert_eq!(&buf[..n], b"Hello World!");
// Client // // Will use `SocksV5` to establish proxy tunnel. // Will send "Hello World!" to the target and receive "Goodbye!" back. let t1 = tokio::spawn(asyncmove { let _ = connector.call(target_dst).await.expect("tunnel");
});
// Proxy // // Will receive SOCKS handshake from client. // Will connect to target and success code back to client. // Will blindly tunnel between client and target. let t2 = tokio::spawn(asyncmove { let (mut to_client, _) = proxy_tcp.accept().await.expect("accept"); let [p1, p2] = target_addr.port().to_be_bytes();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.