Last active
January 7, 2026 16:25
-
-
Save davidsm/6bce6d7b9036db8d15270da684df7bd5 to your computer and use it in GitHub Desktop.
Uplink PoC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::time::Duration; | |
| use h2::{client, server}; | |
| use http::{Method, Request, Response, StatusCode}; | |
| use tokio::net::{TcpListener, TcpStream}; | |
| #[tokio::main] | |
| async fn main() { | |
| tokio::spawn(async move { | |
| let stream = TcpListener::bind("127.0.0.1:3333").await.unwrap(); | |
| while let Ok((socket, _)) = stream.accept().await { | |
| println!("Got connection"); | |
| let (h2, connection) = client::handshake(socket).await.unwrap(); | |
| tokio::spawn(async move { | |
| connection.await.unwrap(); | |
| }); | |
| let mut h2 = h2.ready().await.unwrap(); | |
| // Prepare the HTTP request to send to the server. | |
| let request = Request::builder() | |
| .method(Method::GET) | |
| .uri("https://localhost/lol") | |
| .body(()) | |
| .unwrap(); | |
| let (response, _) = h2.send_request(request, true).unwrap(); | |
| let (head, _body) = response.await.unwrap().into_parts(); | |
| println!("Received response: {:?}", head); | |
| } | |
| }); | |
| tokio::time::sleep(Duration::from_secs(2)).await; | |
| let connection = TcpStream::connect("127.0.0.1:3333").await.unwrap(); | |
| println!("Connected"); | |
| let s = tokio::spawn(async { | |
| // Start the HTTP/2 connection handshake | |
| let mut h2 = server::handshake(connection).await.unwrap(); | |
| // Accept all inbound HTTP/2 streams sent over the | |
| // connection. | |
| while let Some(request) = h2.accept().await { | |
| let (request, mut respond) = request.unwrap(); | |
| println!("Received request: {:?}", request); | |
| // Build a response with no body | |
| let response = Response::builder().status(StatusCode::OK).body(()).unwrap(); | |
| // Send the response back to the client | |
| respond.send_response(response, true).unwrap(); | |
| } | |
| }); | |
| s.await.unwrap(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment