Skip to content

Commit

Permalink
Improve json output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh1Yo committed Oct 4, 2021
1 parent 0b2bb09 commit ee395f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "x8"
version = "3.0.2"
version = "3.1.0"
authors = ["Alexander Mironov <sh1yo@tuta.io>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
26 changes: 13 additions & 13 deletions src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn cycles(
max: usize,
green_lines: &mut HashMap<String, usize>,
remaining_params: &mut Vec<Vec<String>>,
found_params: &mut Vec<String>,
found_params: &mut HashMap<String, String>,
) {
let all = params.len() / max;
let mut count: usize = 0;
Expand All @@ -38,10 +38,10 @@ pub async fn cycles(
count += 1;
let mut futures_data = FuturesData{
remaining_params: Vec::new(),
found_params: Vec::new()
found_params: HashMap::new()
};

let found_params: &Vec<String> = &found_params;
let found_params: &HashMap<String, String> = &found_params;
let cloned_diffs = Arc::clone(&shared_diffs);
let cloned_green_lines = Arc::clone(&shared_green_lines);

Expand All @@ -65,8 +65,8 @@ pub async fn cycles(
//try to find parameters with different number of reflections
if stable.reflections && first && response.reflected_params.len() < 10 {
for param in response.reflected_params.iter() {
if !found_params.contains(param) {
futures_data.found_params.push(param.to_string());
if !found_params.contains_key(param) {
futures_data.found_params.insert(param.to_string(), String::from("Different amount of reflections"));
if config.verbose > 0 {
writeln!(
io::stdout(),
Expand Down Expand Up @@ -99,11 +99,11 @@ pub async fn cycles(
}

if !not_reflected_one.is_empty() && chunk.len() >= 2 {
futures_data.found_params.push(not_reflected_one.to_owned());
futures_data.found_params.insert(not_reflected_one.to_owned(), String::from("Causes other parameters to reflect different times"));
}

if response.reflected_params.len() == 1 {
futures_data.found_params.push(chunk[0].to_owned());
futures_data.found_params.insert(chunk[0].to_owned(), String::from("Causes other parameters to reflect different times"));
} else {
futures_data.remaining_params.append(&mut chunk.to_vec());
}
Expand Down Expand Up @@ -193,7 +193,7 @@ pub async fn cycles(
}
}

if chunk.len() == 1 && !found_params.contains(&chunk[0]) && !futures_data.found_params.contains(&chunk[0]) {
if chunk.len() == 1 && !found_params.contains_key(&chunk[0]) && !futures_data.found_params.contains_key(&chunk[0]) {
if config.verbose > 0 {
writeln!(
io::stdout(),
Expand All @@ -204,7 +204,7 @@ pub async fn cycles(
&diff
).ok();
}
futures_data.found_params.push(chunk[0].to_owned());
futures_data.found_params.insert(chunk[0].to_owned(), format!("Changes page: {} -> {}", initial_response.text.len(), response.text.len()));
break;
} else {
futures_data.remaining_params.append(&mut chunk.to_vec());
Expand All @@ -213,7 +213,7 @@ pub async fn cycles(
}
}
}
} else if chunk.len() == 1 && !found_params.contains(&chunk[0]) && !futures_data.found_params.contains(&chunk[0]) {
} else if chunk.len() == 1 && !found_params.contains_key(&chunk[0]) && !futures_data.found_params.contains_key(&chunk[0]) {
if config.verbose > 0 {
writeln!(
io::stdout(),
Expand All @@ -223,7 +223,7 @@ pub async fn cycles(
&response.code.to_string().bright_yellow()
).ok();
}
futures_data.found_params.push(chunk[0].to_owned());
futures_data.found_params.insert(chunk[0].to_owned(), format!("Changes response code: {} -> {}", initial_response.code, response.code));
} else {
if !config.save_responses.is_empty() {
let filename = random_line(10);
Expand Down Expand Up @@ -311,8 +311,8 @@ pub async fn cycles(
.await;

for instance in futures_data {
for param in instance.found_params {
found_params.push(param)
for (k, v) in instance.found_params {
found_params.insert(k, v);
}
remaining_params.push(instance.remaining_params)
}
Expand Down
18 changes: 7 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async fn run() {

let mut custom_parameters: HashMap<String, Vec<String>> = config.custom_parameters.clone();
let mut remaining_params: Vec<Vec<String>> = Vec::new();
let mut found_params: Vec<String> = Vec::new();
let mut found_params: HashMap<String, String> = HashMap::new();
let mut first: bool = true;
let initial_size: usize = params.len() / max;
let mut count: usize = 0;
Expand Down Expand Up @@ -271,7 +271,7 @@ async fn run() {
let mut found: bool = false;
for vector_params in &remaining_params {
for param in vector_params {
for found_param in &found_params {
for (found_param, _) in &found_params {
//some strange logic in order to treat admin=1 and admin=something as the same parameters
let param_key = if param.matches('=').count() == 1 {
param.split('=').next().unwrap()
Expand Down Expand Up @@ -312,13 +312,9 @@ async fn run() {
remaining_params = Vec::new()
}


found_params.sort();
found_params.dedup();

if config.verify {
let mut filtered_params = Vec::new();
for param in found_params {
let mut filtered_params = HashMap::with_capacity(found_params.len());
for (param, reason) in found_params {
let response = request(
&config, &client,
&make_hashmap(
Expand All @@ -334,7 +330,7 @@ async fn run() {
}
}
if !response.reflected_params.is_empty() || !is_the_body_the_same || !is_code_the_same {
filtered_params.push(param);
filtered_params.insert(param, reason);
}
}
found_params = filtered_params;
Expand All @@ -353,13 +349,13 @@ async fn run() {
&temp_config,
&replay_client,
&make_hashmap(
&found_params,
&found_params.keys().map(|x| x.to_owned()).collect::<Vec<String>>(),
config.value_size
),
0
).await;
} else {
for param in &found_params {
for (param, _) in &found_params {
request(
&temp_config,
&replay_client,
Expand Down
2 changes: 1 addition & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct ResponseData {
#[derive(Debug, Clone)]
pub struct FuturesData {
pub remaining_params: Vec<String>,
pub found_params: Vec<String>
pub found_params: HashMap<String, String>
}

#[derive(Debug, Clone)]
Expand Down
15 changes: 6 additions & 9 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ where
Ok(io::BufReader::new(file).lines())
}

pub fn create_output(config: &Config, found_params: Vec<String>) -> String {
pub fn create_output(config: &Config, found_params: HashMap<String, String>) -> String {
match config.output_format.as_str() {
"url" => {
let mut line = if !found_params.is_empty() {
Expand All @@ -434,7 +434,7 @@ pub fn create_output(config: &Config, found_params: Vec<String>) -> String {

if !found_params.is_empty() {

for param in &found_params {
for (param, _) in &found_params {
line.push_str(&param);
if !param.contains('=') {
line.push('=');
Expand All @@ -459,11 +459,8 @@ pub fn create_output(config: &Config, found_params: Vec<String>) -> String {

if !found_params.is_empty() {

for param in &found_params {
line.push('\"');
line.push_str(&param.replace("\"", "\\\""));
line.push('\"');
line.push_str(", ");
for (param, reason) in &found_params {
line.push_str(&format!("{{\"name\":\"{}\", \"reason\":\"{}\"}}, ", param, reason));
}

line = line[..line.len() - 2].to_string();
Expand All @@ -474,7 +471,7 @@ pub fn create_output(config: &Config, found_params: Vec<String>) -> String {
line
},
"request" => {
generate_request(config, &make_hashmap(&found_params, config.value_size))
generate_request(config, &make_hashmap(&found_params.keys().map(|x| x.to_owned()).collect::<Vec<String>>(), config.value_size))
.lines()
.skip(1)
.collect::<Vec<&str>>()
Expand All @@ -485,7 +482,7 @@ pub fn create_output(config: &Config, found_params: Vec<String>) -> String {

if !found_params.is_empty() {

for param in &found_params {
for (param, _) in &found_params {
line.push_str(&param);
line.push_str(", ")
}
Expand Down

0 comments on commit ee395f8

Please sign in to comment.