Skip to content

Commit

Permalink
fix: using --tcp-ports-http-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Feb 15, 2024
1 parent fefff61 commit ccf2361
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/plugins/tcp_ports/grabbers/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use regex::Regex;

use super::Banner;

// TODO: read from args
static HTTP_HEADERS_OF_INTEREST: &[&str] = &["server", "x-powered-by", "location", "content-type"];

lazy_static! {
static ref HTML_TITLE_PARSER: Regex =
Regex::new(r"(?i)<\s*title\s*>([^<]+)<\s*/\s*title\s*>").unwrap();
Expand Down Expand Up @@ -41,6 +38,7 @@ pub(crate) fn is_http_port(opts: &options::Options, port: u16) -> (bool, bool) {
}

pub(crate) async fn http_grabber(
opts: &options::Options,
address: &str,
port: u16,
stream: Box<dyn StreamLike>,
Expand Down Expand Up @@ -85,6 +83,12 @@ pub(crate) async fn http_grabber(
if let Ok(resp) = resp {
// TODO: find a way to collect certificate information if ssl

let headers_of_interest: Vec<&str> = opts
.tcp_ports_http_headers
.split(",")
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.collect();
let mut content_type = String::from("text/html");

// collect headers
Expand All @@ -95,7 +99,7 @@ pub(crate) async fn http_grabber(
if name == "content-type" {
content_type = value.to_owned();
}
if HTTP_HEADERS_OF_INTEREST.contains(&name.as_str()) {
if headers_of_interest.contains(&name.as_str()) {
banner.insert(name, value.to_owned());
}
}
Expand All @@ -110,7 +114,8 @@ pub(crate) async fn http_grabber(
caps.get(1).unwrap().as_str().to_owned(),
);
}
} else if content_type == "application/json" {
} else if content_type.starts_with("application/") || content_type.starts_with("text/")
{
banner.insert("body".to_owned(), body.to_owned());
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tcp_ports/grabbers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) async fn grab_banner(
) -> Banner {
let (is_http, with_ssl) = http::is_http_port(opts, port);
if is_http {
return http::http_grabber(address, port, stream, with_ssl, timeout).await;
return http::http_grabber(opts, address, port, stream, with_ssl, timeout).await;
}

// default to an attempt at line grabbing
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tcp_ports/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) struct Options {
#[clap(long, default_value = "443, 8443")]
/// Comma separated list of ports for HTTPS grabbing.
pub tcp_ports_https: String,
#[clap(long, default_value = "server, x-powered-by, location")]
#[clap(long, default_value = "server, x-powered-by, location, content-type")]
/// Comma separated list lowercase header names for HTTP/HTTPS grabbing.
pub tcp_ports_http_headers: String,
}

0 comments on commit ccf2361

Please sign in to comment.