Skip to content

Commit

Permalink
cargo clippy things
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh1Yo committed Dec 7, 2022
1 parent 6ee4532 commit d953d5d
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 85 deletions.
20 changes: 10 additions & 10 deletions src/config/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use super::structs::Config;

/// shorcut to convert Option<&str> to Option<String> to be able to return it from the function
pub(super) fn convert_to_string_if_some(el: Option<&str>) -> Option<String> {
if el.is_some() {
Some(el.unwrap().to_string())
if let Some(val) = el {
Some(val.to_string())
} else {
None
}
Expand All @@ -38,12 +38,12 @@ pub(super) fn parse_request<'a>(
Box<dyn Error>,
> {
// request by lines
let lines = if split_by.is_none() {
request.lines().collect::<Vec<&str>>()
} else {
let lines = if let Some(val) = split_by {
request
.split(&split_by.unwrap().replace("\\r", "\r").replace("\\n", "\n"))
.split(&val.replace("\\r", "\r").replace("\\n", "\n"))
.collect::<Vec<&str>>()
} else {
request.lines().collect::<Vec<&str>>()
};
let mut lines = lines.iter();

Expand All @@ -64,7 +64,7 @@ pub(super) fn parse_request<'a>(
.contains("HTTP/2");

// parse headers
while let Some(line) = lines.next() {
for line in lines.by_ref() {
if line.is_empty() {
break;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ pub(super) fn parse_request<'a>(
}

let mut body = lines.next().unwrap_or(&"").to_string();
while let Some(part) = lines.next() {
for part in lines {
if !part.is_empty() {
body.push_str("\r\n");
body.push_str(part);
Expand All @@ -121,9 +121,9 @@ pub(super) fn parse_request<'a>(
} else {
// neither --port nor port within the host header were specified
if scheme == "http" {
(host.to_string(), 80u16)
(host, 80u16)
} else {
(host.to_string(), 443u16)
(host, 443u16)
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod network;
pub mod runner;
pub mod utils;

const RANDOM_CHARSET: &'static [u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
const RANDOM_CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";

/// To ignore pages with size > 25MB. Usually it's some binary things. Can be ignored with --force
const MAX_PAGE_SIZE: usize = 25 * 1024 * 1024;
Expand Down
46 changes: 23 additions & 23 deletions src/network/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use std::{
use url::Url;

/// in order to be able to use make_query() for headers as well
const HEADERS_TEMPLATE: &'static str = "%k\x00@%=%@\x00%v";
const HEADERS_MIDDLE: &'static str = "\x00@%=%@\x00";
const HEADERS_JOINER: &'static str = "\x01@%&%@\x01";
const HEADERS_TEMPLATE: &str = "%k\x00@%=%@\x00%v";
const HEADERS_MIDDLE: &str = "\x00@%=%@\x00";
const HEADERS_JOINER: &str = "\x01@%&%@\x01";

use super::{
response::Response,
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'a> Request<'a> {
defaults: l,
headers: Vec::new(),
body: l.body.clone(),
parameters: parameters,
parameters,
prepared_parameters: Vec::new(), //l.parameters.clone(),
non_random_parameters: Vec::new(),
prepared: false,
Expand Down Expand Up @@ -189,8 +189,8 @@ impl<'a> Request<'a> {
self.non_random_parameters = Vec::from_iter(
self.parameters
.iter()
.filter(|x| x.contains("="))
.map(|x| x.split("="))
.filter(|x| x.contains('='))
.map(|x| x.split('='))
.map(|mut x| {
(
x.next().unwrap().to_owned(),
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'a> Request<'a> {
InjectionPlace::HeaderValue => {
// in case someone searches headers while sending a valid body - it's usually important to set Content-Type header as well.
if self.defaults.method != "GET" && self.defaults.method != "HEAD" && !self.body.is_empty() {
if self.body.starts_with("{") {
if self.body.starts_with('{') {
self.set_header("Content-Type", "application/json");
} else {
self.set_header("Content-Type", "application/x-www-form-urlencoded");
Expand All @@ -261,7 +261,7 @@ impl<'a> Request<'a> {
InjectionPlace::Headers => {
// in case someone searches headers while sending a valid body - it's usually important to set Content-Type header as well.
if self.defaults.method != "GET" && self.defaults.method != "HEAD" && !self.body.is_empty() {
if self.body.starts_with("{") {
if self.body.starts_with('{') {
self.set_header("Content-Type", "application/json");
} else {
self.set_header("Content-Type", "application/x-www-form-urlencoded");
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<'a> Request<'a> {

pub fn print_sent(&self) -> String {
let host = if self.headers.contains_key("Host") {
self.headers.get_value("Host").unwrap().to_string()
self.headers.get_value("Host").unwrap()
} else {
self.defaults.host.to_owned()
};
Expand Down Expand Up @@ -476,26 +476,26 @@ impl<'a> RequestDefaults {

let (template, joiner) = (
template
.unwrap_or(guessed_template.to_string().into())
.unwrap_or_else(|| guessed_template.to_string().into())
.into(),
joiner.unwrap_or(guessed_joiner.to_string().into()).into().replace("\\r", "\r").replace("\\n", "\n"),
joiner.unwrap_or_else(|| guessed_joiner.to_string().into()).into().replace("\\r", "\r").replace("\\n", "\n"),
);

let url = Url::parse(url)?;

let (path, body) = if data_type.is_some() {
let (path, body) = if let Some(data_type) = data_type {
RequestDefaults::fix_path_and_body(
// &url[url::Position::BeforePath..].to_string() instead of url.path() because we need to preserve query as well
&url[url::Position::BeforePath..].to_string(),
&url[url::Position::BeforePath..],
body,
&joiner,
&injection_place,
data_type.unwrap(),
data_type,
)
} else {
// injection within headers
(
url[url::Position::BeforePath..].to_string().to_string(),
url[url::Position::BeforePath..].to_string(),
body.to_owned(),
)
};
Expand All @@ -509,8 +509,8 @@ impl<'a> RequestDefaults {
port: url.port_or_known_default().ok_or("Wrong scheme")?,
delay,
client,
template: template.to_string(),
joiner: joiner.to_string(),
template,
joiner,
encode,
is_json,
body,
Expand All @@ -529,8 +529,8 @@ impl<'a> RequestDefaults {
injection_place: &InjectionPlace,
data_type: Option<DataType>,
) -> (&'a str, &'a str, bool, Option<DataType>) {
if data_type.is_some() {
match data_type.unwrap() {
if let Some(data_type) = data_type {
match data_type {
// %v isn't within quotes because not every json value needs to be in quotes
DataType::Json => ("\"%k\": %v", ", ", true, Some(DataType::Json)),
DataType::Urlencoded => ("%k=%v", "&", false, Some(DataType::Urlencoded)),
Expand All @@ -539,7 +539,7 @@ impl<'a> RequestDefaults {
} else {
match injection_place {
InjectionPlace::Body => {
if body.starts_with("{") {
if body.starts_with('{') {
("\"%k\": %v", ", ", true, Some(DataType::Json))
} else {
("%k=%v", "&", false, Some(DataType::Urlencoded))
Expand All @@ -566,8 +566,8 @@ impl<'a> RequestDefaults {
(path.to_string(), body.to_string())
} else if body.is_empty() {
match data_type {
DataType::Urlencoded => (path.to_string(), format!("%s")),
DataType::Json => (path.to_string(), format!("{{%s}}")),
DataType::Urlencoded => (path.to_string(), "%s".to_string()),
DataType::Json => (path.to_string(), "{{%s}}".to_string()),
_ => unreachable!(),
}
} else {
Expand All @@ -585,7 +585,7 @@ impl<'a> RequestDefaults {
InjectionPlace::Path => {
if path.contains("%s") {
(path.to_string(), body.to_string())
} else if path.contains("?") {
} else if path.contains('?') {
(format!("{}{}%s", path, joiner), body.to_string())
} else if joiner == "&" {
(format!("{}?%s", path), body.to_string())
Expand Down
4 changes: 2 additions & 2 deletions src/network/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> Response<'a> {
pub fn compare(
&self,
initial_response: &'a Response<'a>,
old_diffs: &Vec<String>,
old_diffs: &[String],
) -> Result<(bool, Vec<String>), Box<dyn Error>> {
let mut is_code_diff: bool = false;
let mut diffs: Vec<String> = Vec::new();
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'a> Response<'a> {
.get_value_case_insensitive("content-type")
.unwrap()
.contains("json"))
|| (self.text.starts_with("{") && self.text.ends_with("}"))
|| (self.text.starts_with('{') && self.text.ends_with('}'))
{
let body = self.text.replace("\\\"", "'").replace("\",", "\",\n");
let body = RE_JSON_BRACKETS.replace_all(&body, "${bracket}\n");
Expand Down
4 changes: 2 additions & 2 deletions src/network/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lazy_static! {
}

/// enum mainly created for the correct json parsing
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DataType {
/// we need a different data type for json because some json values can be used without quotes (numbers, booleans, ..)
/// and therefore this type should be treated differently
Expand All @@ -41,7 +41,7 @@ pub enum DataType {
}

/// where to insert parameters
#[derive(Debug, Clone, PartialEq, Serialize, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Copy)]
pub enum InjectionPlace {
Path,
Body,
Expand Down
21 changes: 9 additions & 12 deletions src/runner/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ impl<'a> Runner<'a> {

let (reflected_parameter, repeat) = response.proceed_reflected_parameters();

if reflected_parameter.is_some() {
let reflected_parameter = reflected_parameter.unwrap();
if let Some(reflected_parameter) = reflected_parameter {

let mut found_params = shared_found_params.lock();
if !found_params.iter().any(|x| x.name == reflected_parameter) {
Expand Down Expand Up @@ -98,10 +97,10 @@ impl<'a> Runner<'a> {

response.write_and_save(
self.id,
&self.config,
self.config,
&self.initial_response,
kind,
&reflected_parameter,
reflected_parameter,
None,
self.progress_bar,
)?;
Expand Down Expand Up @@ -164,7 +163,7 @@ impl<'a> Runner<'a> {
if params.len() == 1 {
response.write_and_save(
self.id,
&self.config,
self.config,
&self.initial_response,
ReasonKind::Code,
&params[0],
Expand Down Expand Up @@ -231,26 +230,24 @@ impl<'a> Runner<'a> {

// check whether the page still(after making a random request and storing it's diffs) has an unique diffs
for diff in new_diffs.iter() {
if !diffs.contains(&diff) {
if !diffs.contains(diff) {
let mut found_params = shared_found_params.lock();

// there's only one parameter left that changing the page
if params.len() == 1 && !found_params.iter().any(|x| x.name == params[0]) {
// repeating --strict checks. We need to do it twice because we're usually running in parallel
// and some parameters may be found after the first check
if self.config.strict {
if found_params.iter().any(|x| x.diffs == new_diffs.join("|")) {
return Ok(());
}
if self.config.strict && found_params.iter().any(|x| x.diffs == new_diffs.join("|")) {
return Ok(());
}

response.write_and_save(
self.id,
&self.config,
self.config,
&self.initial_response,
ReasonKind::Text,
&params[0],
Some(&diff),
Some(diff),
self.progress_bar,
)?;

Expand Down
2 changes: 1 addition & 1 deletion src/runner/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl RunnerOutput {
let line = if !self.found_params.is_empty()
&& self.injection_place == InjectionPlace::Path
{
if !self.url.contains("?") {
if !self.url.contains('?') {
self.url.clone() + "?%s"
} else {
self.url.clone() + "&%s"
Expand Down
22 changes: 11 additions & 11 deletions src/runner/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> Runner<'a> {

// find how many times was the random parameter reflected
request_defaults.amount_of_reflections =
initial_response.count(&temp_request_defaults.parameters.iter().next().unwrap().1);
initial_response.count(&temp_request_defaults.parameters.first().unwrap().1);

// some "magic" to be able to return initial_response
// otherwise throws lifetime errors
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'a> Runner<'a> {
// add only unique possible params to the vec of all params (the tool works properly only with unique parameters)
// less efficient than making it within the sorted vec but I want to preserve the order
for param in self.possible_params.iter() {
if !params.contains(&param) {
if !params.contains(param) {
params.push(param.to_owned());
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<'a> Runner<'a> {
filtered_params
} else {
utils::info(
&self.config,
self.config,
self.id,
self.progress_bar,
"~",
Expand All @@ -165,15 +165,15 @@ impl<'a> Runner<'a> {

// replay request with found parameters via another proxy
if !self.config.replay_proxy.is_empty() {
if let Err(_) = replay(
&self.config,
if replay(
self.config,
&self.request_defaults,
&create_client(self.config)?,
&found_params,
)
.await {
).await
.is_err() {
utils::info(
&self.config,
self.config,
self.id,
self.progress_bar,
"~",
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<'a> Runner<'a> {
//do not request parameters that already have been found
if found_params
.iter()
.map(|x| x.name.split("=").next().unwrap())
.map(|x| x.name.split('=').next().unwrap())
.any(|x| x == k)
{
continue;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl<'a> Runner<'a> {
},
};

self.max = default_max.abs() as usize;
self.max = default_max.unsigned_abs();

//make a few requests and collect all persistent diffs, check for stability
self.empty_reqs().await?;
Expand Down Expand Up @@ -311,7 +311,7 @@ impl<'a> Runner<'a> {
.is_empty()
{
utils::info(
&self.config,
self.config,
self.id,
self.progress_bar,
"~",
Expand Down
Loading

0 comments on commit d953d5d

Please sign in to comment.