From c6d7185603c1a759ae98b2664b1e5b445c2b2a7e Mon Sep 17 00:00:00 2001 From: Khaled Nassar Date: Mon, 3 Apr 2023 03:34:26 +0200 Subject: [PATCH 1/5] Rename loader to model --- src/lua/mod.rs | 2 +- src/lua/model.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/lua/model.rs diff --git a/src/lua/mod.rs b/src/lua/mod.rs index c0041a9..26fed15 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -1,4 +1,4 @@ -pub mod loader; +pub mod model; pub mod network; pub mod output; pub mod parsing; diff --git a/src/lua/model.rs b/src/lua/model.rs new file mode 100644 index 0000000..a29b4eb --- /dev/null +++ b/src/lua/model.rs @@ -0,0 +1,30 @@ +// This file is part of Lotus Project, a web security scanner written in Rust based on Lua scripts. +// For details, please see https://github.com/rusty-sec/lotus/ +// +// Copyright (c) 2022 - Khaled Nassar +// +// Please note that this file was originally released under the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the License, or (at your option) +// any later version. +// +// Unless required by applicable law or agreed to in writing, software distributed under the +// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +// either express or implied. See the License for the specific language governing permissions +// and limitations under the License. + +use crate::ScanTypes; +use mlua::Lua; + +/// Setup The Lua Runtime +pub struct LuaRunTime<'lua> { + pub lua: &'lua Lua, +} + +pub struct LuaOptions<'a> { + pub target_url: Option<&'a str>, + pub target_type: ScanTypes, + pub fuzz_workers: usize, + pub script_code: &'a str, + pub script_dir: &'a str, + pub env_vars: serde_json::Value, +} From 0900d930f50e478a5b5fabeba7c39bfd3bf39356 Mon Sep 17 00:00:00 2001 From: Khaled Nassar Date: Mon, 3 Apr 2023 03:34:42 +0200 Subject: [PATCH 2/5] Better Error Handling for Regex --- src/lua/loader.rs | 49 ------------------- src/lua/parsing/text.rs | 101 +++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 67 deletions(-) delete mode 100644 src/lua/loader.rs diff --git a/src/lua/loader.rs b/src/lua/loader.rs deleted file mode 100644 index 9e9ee51..0000000 --- a/src/lua/loader.rs +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Lotus Project, a web security scanner written in Rust based on Lua scripts. -// For details, please see https://github.com/rusty-sec/lotus/ -// -// Copyright (c) 2022 - Khaled Nassar -// -// Please note that this file was originally released under the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the License, or (at your option) -// any later version. -// -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -use crate::cli::errors::CliErrors; -use crate::ScanTypes; -use log::error; -use mlua::Lua; - -/// Setup The Lua Runtime -pub struct LuaRunTime<'lua> { - pub lua: &'lua Lua, -} - -pub struct LuaOptions<'a> { - pub target_url: Option<&'a str>, - pub target_type: ScanTypes, - pub fuzz_workers: usize, - pub script_code: &'a str, - pub script_dir: &'a str, - pub env_vars: serde_json::Value, -} - -/// check if the regex pattern is matching with this string or not without get the matched parts -pub fn is_match(pattern: String, resp: String) -> Result { - let re = fancy_regex::Regex::new(&pattern); - if let Ok(..) = re { - let matched = re.unwrap().is_match(&resp); - if matched.is_err() { - error!("Cannot match with resp value: {}", resp); - Err(CliErrors::RegexError) - } else { - Ok(matched.unwrap()) - } - } else { - error!("Regex Pattern ERROR {:?}", pattern); - Err(CliErrors::RegexPatternError) - } -} diff --git a/src/lua/parsing/text.rs b/src/lua/parsing/text.rs index 99a5bc1..a50497b 100644 --- a/src/lua/parsing/text.rs +++ b/src/lua/parsing/text.rs @@ -12,9 +12,10 @@ // either express or implied. See the License for the specific language governing permissions // and limitations under the License. -use mlua::UserData; +use mlua::{UserData, ExternalResult}; use regex::RegexBuilder; use tealr::TypeName; +use crate::cli::errors::CliErrors; #[derive(TypeName, Clone, Debug)] pub struct ResponseMatcher { @@ -27,11 +28,40 @@ pub struct ResponseMatcher { } impl ResponseMatcher { - pub fn match_and_body(&self, body: &str, text: Vec, is_regex: Option) -> bool { + pub fn is_match(&self, pattern: String, resp: String) -> Result { + match RegexBuilder::new(&pattern) + .multi_line(self.multi_line) + .case_insensitive(self.case_insensitive) + .unicode(self.unicode) + .octal(self.octal) + .dot_matches_new_line(self.dot_matches_new_line) + .build() + { + Ok(re) => { + if let Err(e) = re.is_match(&resp) { + log::error!("Cannot match with resp value: {}", resp); + Err(CliErrors::RegexError) + } else { + Ok(true) + } + } + Err(_) => { + log::error!("Regex Pattern ERROR {:?}", pattern); + Err(CliErrors::RegexPatternError) + } + } + } + + pub fn match_and_body( + &self, + body: &str, + text: Vec, + is_regex: Option, + ) -> Result { let mut counter = 0; - for x in text.iter() { - if is_regex.unwrap_or(false) { - if let Ok(re_pattern) = RegexBuilder::new(x) + for search_pattern in text.iter() { + match is_regex.unwrap_or(false) { + true => match RegexBuilder::new(&search_pattern) .multi_line(self.multi_line) .case_insensitive(self.case_insensitive) .unicode(self.unicode) @@ -39,15 +69,24 @@ impl ResponseMatcher { .dot_matches_new_line(self.dot_matches_new_line) .build() { - if re_pattern.is_match(body) { + Ok(re_pattern) => { + if re_pattern.is_match(body) { + counter += 1; + } + } + Err(_) => { + log::error!("Invalid regex pattern: {:?}", search_pattern); + return Err(CliErrors::RegexPatternError); + } + }, + false => { + if body.contains(search_pattern) { counter += 1; } } - } else if body.contains(x) { - counter += 1; } } - counter == text.len() + Ok(counter == text.len()) } pub fn match_once_body( @@ -55,11 +94,11 @@ impl ResponseMatcher { body: String, text: Vec, is_regex: Option, - ) -> Vec { + ) -> Result, CliErrors> { let mut matched_data = Vec::new(); for pattern in text { - if is_regex.unwrap_or(false) { - if let Ok(re) = RegexBuilder::new(&pattern) + match is_regex.unwrap_or(false) { + true => match RegexBuilder::new(&pattern) .multi_line(self.multi_line) .case_insensitive(self.case_insensitive) .unicode(self.unicode) @@ -67,31 +106,57 @@ impl ResponseMatcher { .dot_matches_new_line(self.dot_matches_new_line) .build() { - if re.is_match(&body) { + Ok(re) => { + if re.is_match(&body) { + matched_data.push(pattern); + } + } + Err(_) => { + log::error!("Invalid regex pattern: {:?}", pattern); + return Err(CliErrors::RegexPatternError); + } + }, + false => { + if body.contains(&pattern) { matched_data.push(pattern); } } - } else if body.contains(&pattern) { - matched_data.push(pattern); } } - matched_data + Ok(matched_data) } } impl UserData for ResponseMatcher { fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_method("is_match", |_, this, (regex_pattern,response): (String, String)|{ + let is_match = this.is_match(regex_pattern, response); + if Ok(..) == is_match { + Ok(is_match.unwrap()) + } else { + Err(is_match.to_lua_err()) + } + }); methods.add_method( "match_body", |_, this, (response, text_list, is_regex): (String, Vec, Option)| { - Ok(this.match_and_body(&response, text_list, is_regex)) + let body_match = this.match_and_body(&response, text_list, is_regex); + if Ok(..) == body_match { + Ok(body_match.unwrap()) + } else { + Err(body_match.to_lua_err()) + } }, ); methods.add_method( "match_body_once", |_, this, (response, text_list, is_regex): (String, Vec, Option)| { let is_match = this.match_once_body(response, text_list, is_regex); - Ok(is_match) + if Ok(..) == is_match { + Ok(is_match.unwrap()) + } else { + Err(is_match.to_lua_err()) + } }, ); methods.add_method_mut("options", |_, this, opts: mlua::Table| { From 47ca45882aaaa16d63411357bbff2b0d9365dc85 Mon Sep 17 00:00:00 2001 From: Khaled Nassar Date: Mon, 3 Apr 2023 03:56:59 +0200 Subject: [PATCH 3/5] Global Regex Matcher class --- src/cli/input/load_scripts.rs | 9 +++-- src/lib.rs | 2 +- src/lua/parsing/text.rs | 58 ++++++++++++++++++++++----------- src/lua/run.rs | 2 +- src/lua/runtime/encode_ext.rs | 2 +- src/lua/runtime/http_ext.rs | 3 +- src/lua/runtime/payloads_ext.rs | 2 +- src/lua/runtime/utils_ext.rs | 21 ++---------- 8 files changed, 53 insertions(+), 46 deletions(-) diff --git a/src/cli/input/load_scripts.rs b/src/cli/input/load_scripts.rs index 51c1607..005b721 100644 --- a/src/cli/input/load_scripts.rs +++ b/src/cli/input/load_scripts.rs @@ -1,7 +1,10 @@ -use crate::lua::runtime::{ - encode_ext::EncodeEXT, http_ext::HTTPEXT, payloads_ext::PayloadsEXT, utils_ext::UtilsEXT, +use crate::lua::{ + model::LuaRunTime, + runtime::{ + encode_ext::EncodeEXT, http_ext::HTTPEXT, payloads_ext::PayloadsEXT, utils_ext::UtilsEXT + } }; -use crate::{filename_to_string, show_msg, CliErrors, LuaRunTime, MessageLevel}; +use crate::{filename_to_string, show_msg, CliErrors, MessageLevel}; use glob::glob; use log::error; use mlua::Lua; diff --git a/src/lib.rs b/src/lib.rs index d2e790b..8c8818a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ use cli::{ input::load_scripts::{get_scripts, valid_scripts}, }; use lua::{ - loader::{LuaOptions, LuaRunTime}, + model::LuaOptions, parsing::files::filename_to_string, run::LuaLoader, threads::runner::iter_futures, diff --git a/src/lua/parsing/text.rs b/src/lua/parsing/text.rs index a50497b..f1ce62e 100644 --- a/src/lua/parsing/text.rs +++ b/src/lua/parsing/text.rs @@ -12,7 +12,8 @@ // either express or implied. See the License for the specific language governing permissions // and limitations under the License. -use mlua::{UserData, ExternalResult}; +use mlua::UserData; +use mlua::ExternalError; use regex::RegexBuilder; use tealr::TypeName; use crate::cli::errors::CliErrors; @@ -38,12 +39,7 @@ impl ResponseMatcher { .build() { Ok(re) => { - if let Err(e) = re.is_match(&resp) { - log::error!("Cannot match with resp value: {}", resp); - Err(CliErrors::RegexError) - } else { - Ok(true) - } + Ok(re.is_match(&resp)) } Err(_) => { log::error!("Regex Pattern ERROR {:?}", pattern); @@ -52,6 +48,25 @@ impl ResponseMatcher { } } + pub fn replace_txt(&self, regex_pattern: &str, replacement: &str, response: &str) -> Result { + match RegexBuilder::new(®ex_pattern) + .multi_line(self.multi_line) + .case_insensitive(self.case_insensitive) + .unicode(self.unicode) + .octal(self.octal) + .dot_matches_new_line(self.dot_matches_new_line) + .build() + { + Ok(re) => { + let replace_output = re.replacen(response, 2,replacement).to_string(); + Ok(replace_output) + } + Err(_) => { + log::error!("Regex Pattern ERROR {:?}", regex_pattern); + Err(CliErrors::RegexPatternError) + } + } + } pub fn match_and_body( &self, body: &str, @@ -131,20 +146,18 @@ impl UserData for ResponseMatcher { fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { methods.add_method("is_match", |_, this, (regex_pattern,response): (String, String)|{ let is_match = this.is_match(regex_pattern, response); - if Ok(..) == is_match { - Ok(is_match.unwrap()) - } else { - Err(is_match.to_lua_err()) + match is_match { + Ok(matched) => Ok(matched), + Err(err) => Err(err.to_lua_err()), } }); methods.add_method( "match_body", |_, this, (response, text_list, is_regex): (String, Vec, Option)| { let body_match = this.match_and_body(&response, text_list, is_regex); - if Ok(..) == body_match { - Ok(body_match.unwrap()) - } else { - Err(body_match.to_lua_err()) + match body_match { + Ok(matched) => Ok(matched), + Err(err) => Err(err.to_lua_err()), } }, ); @@ -152,13 +165,20 @@ impl UserData for ResponseMatcher { "match_body_once", |_, this, (response, text_list, is_regex): (String, Vec, Option)| { let is_match = this.match_once_body(response, text_list, is_regex); - if Ok(..) == is_match { - Ok(is_match.unwrap()) - } else { - Err(is_match.to_lua_err()) + match is_match { + Ok(matched) => Ok(matched), + Err(err) => Err(err.to_lua_err()), } }, ); + methods.add_method( + "replace", |_,this, (response, regex_pattern, replacement): (String,String, String)|{ + let replace_output = this.replace_txt(®ex_pattern, &replacement, &response); + match replace_output { + Ok(replaced) => Ok(replaced), + Err(err) => Err(err.to_lua_err()), + } + }); methods.add_method_mut("options", |_, this, opts: mlua::Table| { let response_matcher = ResponseMatcher { multi_line: opts.get::<_, bool>("multi_line").unwrap_or(this.multi_line), diff --git a/src/lua/run.rs b/src/lua/run.rs index c1ea455..fba209e 100644 --- a/src/lua/run.rs +++ b/src/lua/run.rs @@ -4,7 +4,7 @@ use crate::lua::runtime::{ use crate::{ cli::bar::BAR, lua::{ - loader::{LuaOptions, LuaRunTime}, + model::{LuaOptions, LuaRunTime}, network::http::Sender, output::report::AllReports, }, diff --git a/src/lua/runtime/encode_ext.rs b/src/lua/runtime/encode_ext.rs index 79f7e16..45cbca6 100644 --- a/src/lua/runtime/encode_ext.rs +++ b/src/lua/runtime/encode_ext.rs @@ -1,4 +1,4 @@ -use crate::LuaRunTime; +use crate::lua::model::LuaRunTime; pub trait EncodeEXT { fn add_encode_function(&self); diff --git a/src/lua/runtime/http_ext.rs b/src/lua/runtime/http_ext.rs index e197c2d..ef33355 100644 --- a/src/lua/runtime/http_ext.rs +++ b/src/lua/runtime/http_ext.rs @@ -1,9 +1,10 @@ use crate::{ lua::{ + model::LuaRunTime, output::report::AllReports, parsing::{files::filename_to_string, url::HttpMessage}, }, - CliErrors, LuaRunTime, + CliErrors, }; use log::{debug, error, info, warn}; use mlua::ExternalError; diff --git a/src/lua/runtime/payloads_ext.rs b/src/lua/runtime/payloads_ext.rs index e204cf3..f14ef03 100644 --- a/src/lua/runtime/payloads_ext.rs +++ b/src/lua/runtime/payloads_ext.rs @@ -1,6 +1,6 @@ use crate::lua::parsing::html::Location; use crate::lua::payloads; -use crate::LuaRunTime; +use crate::lua::model::LuaRunTime; pub trait PayloadsEXT { fn add_payloadsfuncs(&self); diff --git a/src/lua/runtime/utils_ext.rs b/src/lua/runtime/utils_ext.rs index aaf2d61..a51d94f 100644 --- a/src/lua/runtime/utils_ext.rs +++ b/src/lua/runtime/utils_ext.rs @@ -1,15 +1,14 @@ use crate::{ + BAR, lua::{ - loader::is_match, + model::LuaRunTime, parsing::{ html::{css_selector, html_parse, html_search}, text::ResponseMatcher, }, threads::{LuaThreader, ParamScan}, }, - LuaRunTime, BAR, }; -use mlua::ExternalError; use std::sync::{Arc, Mutex}; pub trait UtilsEXT { @@ -36,22 +35,6 @@ impl UtilsEXT for LuaRunTime<'_> { .unwrap(); } fn add_matchingfunc(&self) { - self.lua - .globals() - .set( - "is_match", - self.lua - .create_function(|_, (pattern, text): (String, String)| { - let try_match = is_match(pattern, text); - if try_match.is_err() { - Err(try_match.unwrap_err().to_lua_err()) - } else { - Ok(try_match.unwrap()) - } - }) - .unwrap(), - ) - .unwrap(); self.lua .globals() .set( From 651d0120b165ada5ee670d6a56e9c37d82bd1721 Mon Sep 17 00:00:00 2001 From: Khaled Nassar Date: Mon, 3 Apr 2023 04:12:50 +0200 Subject: [PATCH 4/5] Add Extract regex function --- src/lua/parsing/text.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lua/parsing/text.rs b/src/lua/parsing/text.rs index f1ce62e..cd802b2 100644 --- a/src/lua/parsing/text.rs +++ b/src/lua/parsing/text.rs @@ -48,6 +48,26 @@ impl ResponseMatcher { } } + pub fn extract_data(&self, regex_pattern: &str, response: &str) -> Result, CliErrors> { + match RegexBuilder::new(®ex_pattern) + .multi_line(self.multi_line) + .case_insensitive(self.case_insensitive) + .unicode(self.unicode) + .octal(self.octal) + .dot_matches_new_line(self.dot_matches_new_line) + .build() + { + Ok(re) => { + let match_iter = re.find_iter(response).map(|m| m.as_str().to_owned()).collect(); + Ok(match_iter) + } + Err(_) => { + log::error!("Regex Pattern ERROR {:?}", regex_pattern); + Err(CliErrors::RegexPatternError) + } + } + + } pub fn replace_txt(&self, regex_pattern: &str, replacement: &str, response: &str) -> Result { match RegexBuilder::new(®ex_pattern) .multi_line(self.multi_line) @@ -179,6 +199,15 @@ impl UserData for ResponseMatcher { Err(err) => Err(err.to_lua_err()), } }); + methods.add_method("extract", |_, this, (regex_pattern, response): (String, String)|{ + let extract_data = this.extract_data(®ex_pattern, &response); + match extract_data { + Ok(data) => { + Ok(data) + }, + Err(err) => Err(err.to_lua_err()) + } + }); methods.add_method_mut("options", |_, this, opts: mlua::Table| { let response_matcher = ResponseMatcher { multi_line: opts.get::<_, bool>("multi_line").unwrap_or(this.multi_line), From f02c01dcb933b9c3f4ee9783a4535333fbeb3b69 Mon Sep 17 00:00:00 2001 From: Khaled Nassar Date: Mon, 3 Apr 2023 04:13:30 +0200 Subject: [PATCH 5/5] Auto-format with cargo fmt --- src/cli/input/load_scripts.rs | 4 +- src/lib.rs | 4 +- src/lua/parsing/text.rs | 71 ++++++++++++++++++++------------- src/lua/runtime/payloads_ext.rs | 2 +- src/lua/runtime/utils_ext.rs | 2 +- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/cli/input/load_scripts.rs b/src/cli/input/load_scripts.rs index 005b721..c6ba1ed 100644 --- a/src/cli/input/load_scripts.rs +++ b/src/cli/input/load_scripts.rs @@ -1,8 +1,8 @@ use crate::lua::{ model::LuaRunTime, runtime::{ - encode_ext::EncodeEXT, http_ext::HTTPEXT, payloads_ext::PayloadsEXT, utils_ext::UtilsEXT - } + encode_ext::EncodeEXT, http_ext::HTTPEXT, payloads_ext::PayloadsEXT, utils_ext::UtilsEXT, + }, }; use crate::{filename_to_string, show_msg, CliErrors, MessageLevel}; use glob::glob; diff --git a/src/lib.rs b/src/lib.rs index 8c8818a..d088e70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,9 +21,7 @@ use cli::{ input::load_scripts::{get_scripts, valid_scripts}, }; use lua::{ - model::LuaOptions, - parsing::files::filename_to_string, - run::LuaLoader, + model::LuaOptions, parsing::files::filename_to_string, run::LuaLoader, threads::runner::iter_futures, }; use reqwest::header::HeaderMap; diff --git a/src/lua/parsing/text.rs b/src/lua/parsing/text.rs index cd802b2..c1414b4 100644 --- a/src/lua/parsing/text.rs +++ b/src/lua/parsing/text.rs @@ -12,11 +12,11 @@ // either express or implied. See the License for the specific language governing permissions // and limitations under the License. -use mlua::UserData; +use crate::cli::errors::CliErrors; use mlua::ExternalError; +use mlua::UserData; use regex::RegexBuilder; use tealr::TypeName; -use crate::cli::errors::CliErrors; #[derive(TypeName, Clone, Debug)] pub struct ResponseMatcher { @@ -38,9 +38,7 @@ impl ResponseMatcher { .dot_matches_new_line(self.dot_matches_new_line) .build() { - Ok(re) => { - Ok(re.is_match(&resp)) - } + Ok(re) => Ok(re.is_match(&resp)), Err(_) => { log::error!("Regex Pattern ERROR {:?}", pattern); Err(CliErrors::RegexPatternError) @@ -48,7 +46,11 @@ impl ResponseMatcher { } } - pub fn extract_data(&self, regex_pattern: &str, response: &str) -> Result, CliErrors> { + pub fn extract_data( + &self, + regex_pattern: &str, + response: &str, + ) -> Result, CliErrors> { match RegexBuilder::new(®ex_pattern) .multi_line(self.multi_line) .case_insensitive(self.case_insensitive) @@ -58,7 +60,10 @@ impl ResponseMatcher { .build() { Ok(re) => { - let match_iter = re.find_iter(response).map(|m| m.as_str().to_owned()).collect(); + let match_iter = re + .find_iter(response) + .map(|m| m.as_str().to_owned()) + .collect(); Ok(match_iter) } Err(_) => { @@ -66,9 +71,13 @@ impl ResponseMatcher { Err(CliErrors::RegexPatternError) } } - } - pub fn replace_txt(&self, regex_pattern: &str, replacement: &str, response: &str) -> Result { + pub fn replace_txt( + &self, + regex_pattern: &str, + replacement: &str, + response: &str, + ) -> Result { match RegexBuilder::new(®ex_pattern) .multi_line(self.multi_line) .case_insensitive(self.case_insensitive) @@ -78,7 +87,7 @@ impl ResponseMatcher { .build() { Ok(re) => { - let replace_output = re.replacen(response, 2,replacement).to_string(); + let replace_output = re.replacen(response, 2, replacement).to_string(); Ok(replace_output) } Err(_) => { @@ -164,13 +173,16 @@ impl ResponseMatcher { impl UserData for ResponseMatcher { fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { - methods.add_method("is_match", |_, this, (regex_pattern,response): (String, String)|{ - let is_match = this.is_match(regex_pattern, response); - match is_match { - Ok(matched) => Ok(matched), - Err(err) => Err(err.to_lua_err()), - } - }); + methods.add_method( + "is_match", + |_, this, (regex_pattern, response): (String, String)| { + let is_match = this.is_match(regex_pattern, response); + match is_match { + Ok(matched) => Ok(matched), + Err(err) => Err(err.to_lua_err()), + } + }, + ); methods.add_method( "match_body", |_, this, (response, text_list, is_regex): (String, Vec, Option)| { @@ -192,22 +204,25 @@ impl UserData for ResponseMatcher { }, ); methods.add_method( - "replace", |_,this, (response, regex_pattern, replacement): (String,String, String)|{ + "replace", + |_, this, (response, regex_pattern, replacement): (String, String, String)| { let replace_output = this.replace_txt(®ex_pattern, &replacement, &response); match replace_output { Ok(replaced) => Ok(replaced), Err(err) => Err(err.to_lua_err()), } - }); - methods.add_method("extract", |_, this, (regex_pattern, response): (String, String)|{ - let extract_data = this.extract_data(®ex_pattern, &response); - match extract_data { - Ok(data) => { - Ok(data) - }, - Err(err) => Err(err.to_lua_err()) - } - }); + }, + ); + methods.add_method( + "extract", + |_, this, (regex_pattern, response): (String, String)| { + let extract_data = this.extract_data(®ex_pattern, &response); + match extract_data { + Ok(data) => Ok(data), + Err(err) => Err(err.to_lua_err()), + } + }, + ); methods.add_method_mut("options", |_, this, opts: mlua::Table| { let response_matcher = ResponseMatcher { multi_line: opts.get::<_, bool>("multi_line").unwrap_or(this.multi_line), diff --git a/src/lua/runtime/payloads_ext.rs b/src/lua/runtime/payloads_ext.rs index f14ef03..eaa3e64 100644 --- a/src/lua/runtime/payloads_ext.rs +++ b/src/lua/runtime/payloads_ext.rs @@ -1,6 +1,6 @@ +use crate::lua::model::LuaRunTime; use crate::lua::parsing::html::Location; use crate::lua::payloads; -use crate::lua::model::LuaRunTime; pub trait PayloadsEXT { fn add_payloadsfuncs(&self); diff --git a/src/lua/runtime/utils_ext.rs b/src/lua/runtime/utils_ext.rs index a51d94f..b8f4c3b 100644 --- a/src/lua/runtime/utils_ext.rs +++ b/src/lua/runtime/utils_ext.rs @@ -1,5 +1,4 @@ use crate::{ - BAR, lua::{ model::LuaRunTime, parsing::{ @@ -8,6 +7,7 @@ use crate::{ }, threads::{LuaThreader, ParamScan}, }, + BAR, }; use std::sync::{Arc, Mutex};