Skip to content

Instantly share code, notes, and snippets.

@harr1424
Last active December 17, 2024 02:26
Show Gist options
  • Save harr1424/00e2d131bde38875f02aa110e0ff5317 to your computer and use it in GitHub Desktop.
Save harr1424/00e2d131bde38875f02aa110e0ff5317 to your computer and use it in GitHub Desktop.
Web Request Scripting in Rust
/*
This code was written to solve a challenege on hackthebox:
https://app.hackthebox.com/challenges/67
*/
use md5;
use reqwest;
use scraper::{Html, Selector};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = reqwest::Client::builder().cookie_store(true).build()?;
let url = "http://94.237.54.42:59509";
let resp = client.get(url).send().await?;
let content = resp.text().await?;
let doc = Html::parse_document(&content);
let selector = Selector::parse("h3").expect("Failed to parse h3 selector");
if let Some(element) = doc.select(&selector).next() {
let input = element.inner_html();
let digest = md5::compute(input.as_bytes());
let hashed = format!("{:x}", digest);
let response = client.post(url).form(&[("hash", &hashed)]).send().await?;
println!("\n=== Response Details ===");
println!("Status: {}", response.status());
println!("Status Code: {}", response.status().as_u16());
println!("\n=== Headers ===");
for (name, value) in response.headers() {
println!(
"{}: {}",
name,
value.to_str().unwrap_or("Unable to display value")
);
}
println!("\n=== Response Body ===");
let body = response.text().await?;
println!("{}", body);
} else {
eprintln!("Failed to find h3 element")
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment