Skip to content

Commit fefff61

Browse files
committed
new: improved tcp.ports http banner grabbing by content type
1 parent 3381b1a commit fefff61

File tree

1 file changed

+18
-4
lines changed
  • src/plugins/tcp_ports/grabbers

1 file changed

+18
-4
lines changed

src/plugins/tcp_ports/grabbers/http.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use regex::Regex;
77
use super::Banner;
88

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

1212
lazy_static! {
1313
static ref HTML_TITLE_PARSER: Regex =
@@ -85,19 +85,33 @@ pub(crate) async fn http_grabber(
8585
if let Ok(resp) = resp {
8686
// TODO: find a way to collect certificate information if ssl
8787

88+
let mut content_type = String::from("text/html");
89+
8890
// collect headers
8991
for (name, value) in resp.headers() {
9092
let name = name.to_string();
93+
let value = value.to_str().unwrap();
94+
95+
if name == "content-type" {
96+
content_type = value.to_owned();
97+
}
9198
if HTTP_HEADERS_OF_INTEREST.contains(&name.as_str()) {
92-
banner.insert(name, value.to_str().unwrap().to_owned());
99+
banner.insert(name, value.to_owned());
93100
}
94101
}
95102

96103
// collect info from html
97104
let body = resp.text().await;
98105
if let Ok(body) = body {
99-
if let Some(caps) = HTML_TITLE_PARSER.captures(&body) {
100-
banner.insert("title".to_owned(), caps.get(1).unwrap().as_str().to_owned());
106+
if content_type == "text/html" {
107+
if let Some(caps) = HTML_TITLE_PARSER.captures(&body) {
108+
banner.insert(
109+
"html.title".to_owned(),
110+
caps.get(1).unwrap().as_str().to_owned(),
111+
);
112+
}
113+
} else if content_type == "application/json" {
114+
banner.insert("body".to_owned(), body.to_owned());
101115
}
102116
} else {
103117
log::error!(

0 commit comments

Comments
 (0)