Skip to content

Commit fefbc00

Browse files
committed
adding proxy
1 parent 8bc0331 commit fefbc00

File tree

8 files changed

+120
-124
lines changed

8 files changed

+120
-124
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ glob = "0.3.0"
4747
serde_json = "1.0.85"
4848
serde = { version = "1.0.144", features = ["derive"] }
4949
isahc = "1.7.2"
50+
reqwest = "0.11.12"
5051
url = "2.2.2"
5152
thirtyfour = "0.31.0"
5253

fuzzer/active/sqli.lua

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function main(current_payload,url)
3939
VALID = false
4040
return report
4141
end
42+
http:set_proxy()
4243
local resp = http:send("GET",url,"")
4344
if resp.errors:GetErrorOrNil() then
4445
local log_msg = string.format("[SQLI] Connection Error: %s",new_url)

src/cli/args.rs

-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ pub fn cmd_args() -> ArgMatches {
2828
.validator(url::Url::parse)
2929
.long("proxy")
3030
)
31-
32-
.arg(
33-
Arg::with_name("headers")
34-
.help("Set Default Headers for all connections (eg: --headers 'API-KEY: 123')")
35-
.long("headers")
36-
.default_value("")
37-
)
38-
3931
.arg(
4032
Arg::with_name("workers")
4133
.help("Number of works of urls")

src/cli/main.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use lotus::RequestOpts;
33
mod args;
44
mod logger;
55

6-
7-
86
#[tokio::main]
97
async fn main() -> Result<(), std::io::Error> {
108
let current_subcommand = args::cmd_args()
@@ -38,30 +36,27 @@ async fn main() -> Result<(), std::io::Error> {
3836
proxy: match args::cmd_args()
3937
.subcommand_matches(&current_subcommand)
4038
.unwrap()
41-
.value_of("proxy") {
42-
Some(proxy) => {
43-
Some(proxy.to_string())
44-
},
45-
None => {
46-
None
47-
48-
}
49-
50-
},
39+
.value_of("proxy")
40+
{
41+
Some(proxy) => Some(proxy.to_string()),
42+
None => None,
43+
},
5144
timeout: args::cmd_args()
5245
.subcommand_matches(&current_subcommand)
5346
.unwrap()
5447
.value_of("timeout")
5548
.unwrap()
5649
.to_string()
57-
.parse::<u64>().unwrap(),
50+
.parse::<u64>()
51+
.unwrap(),
5852
redirects: args::cmd_args()
5953
.subcommand_matches(&current_subcommand)
6054
.unwrap()
6155
.value_of("redirects")
6256
.unwrap()
6357
.to_string()
64-
.parse::<u32>().unwrap(),
58+
.parse::<u32>()
59+
.unwrap(),
6560
};
6661
lottas
6762
.start(

src/core/mod.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::sync::Arc;
2121
pub struct RequestOpts {
2222
pub proxy: Option<String>,
2323
pub timeout: u64,
24-
pub redirects: u32
24+
pub redirects: u32,
2525
}
2626

2727
#[derive(Clone)]
@@ -32,8 +32,16 @@ pub struct LuaLoader<'a> {
3232
}
3333

3434
impl<'a> LuaLoader<'a> {
35-
pub fn new(bar: &'a indicatif::ProgressBar,request: RequestOpts,output_dir: String) -> LuaLoader {
36-
LuaLoader { output_dir,request, bar }
35+
pub fn new(
36+
bar: &'a indicatif::ProgressBar,
37+
request: RequestOpts,
38+
output_dir: String,
39+
) -> LuaLoader {
40+
LuaLoader {
41+
output_dir,
42+
request,
43+
bar,
44+
}
3745
}
3846

3947
fn write_report(&self, results: &str) {
@@ -206,24 +214,6 @@ impl<'a> LuaLoader<'a> {
206214
self.get_utilsfunc(&lua);
207215
self.get_matching_func(&lua);
208216
lua.globals().set("TARGET_URL", target_url).unwrap();
209-
lua.globals()
210-
.set(
211-
"tester",
212-
lua.create_function(|_ctx, name: mlua::Value| {
213-
match name {
214-
mlua::Value::String(ref data) => {
215-
if data == &"bruh".to_string() {
216-
println!("YES");
217-
}
218-
}
219-
_ => {}
220-
}
221-
println!(">> {:?} | ", name);
222-
Ok(())
223-
})
224-
.unwrap(),
225-
)
226-
.unwrap();
227217
match driver {
228218
None => {}
229219
_ => {
@@ -272,7 +262,7 @@ impl<'a> LuaLoader<'a> {
272262
http_sender::Sender::init(
273263
self.request.proxy.clone(),
274264
self.request.timeout,
275-
self.request.redirects
265+
self.request.redirects,
276266
),
277267
)
278268
.unwrap();

src/core/utils/http.rs

+79-67
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use isahc::{
2-
config::{RedirectPolicy, SslOption},
3-
prelude::*,
4-
HttpClientBuilder, Request,
5-
};
61
use mlua::UserData;
2+
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
3+
use reqwest::{redirect, Client, Proxy};
74
use std::{collections::HashMap, time::Duration};
85
use tealr::{mlu::FromToLua, TypeName};
96

@@ -26,19 +23,17 @@ pub enum RespType {
2623

2724
impl UserData for Sender {
2825
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
29-
methods.add_method_mut(
30-
"set_proxy", |_, this, the_proxy: mlua::Value| {
31-
match the_proxy {
32-
mlua::Value::String(new_proxy) => {
33-
this.proxy = Some(new_proxy.to_str().unwrap().to_string());
34-
},
35-
_ => {
36-
this.proxy = None;
37-
}
38-
};
39-
Ok(())
40-
}
41-
);
26+
methods.add_method_mut("set_proxy", |_, this, the_proxy: mlua::Value| {
27+
match the_proxy {
28+
mlua::Value::String(new_proxy) => {
29+
this.proxy = Some(new_proxy.to_str().unwrap().to_string());
30+
}
31+
_ => {
32+
this.proxy = None;
33+
}
34+
};
35+
Ok(())
36+
});
4237
methods.add_method_mut("set_timeout", |_, this, timeout: u64| {
4338
this.timeout = timeout;
4439
Ok(())
@@ -50,22 +45,28 @@ impl UserData for Sender {
5045
});
5146
methods.add_async_method(
5247
"send",
53-
|_, this, (method, url, req_body): (String, String, mlua::Value)| async move {
48+
|_, this, (method, url, req_body, req_headers): (String, String, mlua::Value, mlua::Value)| async move {
5449
let body: String;
55-
if req_body.type_name() == "string" {
56-
body = match req_body {
57-
mlua::Value::String(body) => {
58-
body.to_str().unwrap().to_string()
59-
},
60-
_ => {
61-
"".to_string()
62-
}
63-
};
64-
} else {
65-
body = "".to_string();
66-
}
50+
let mut all_headers = HeaderMap::new();
51+
match req_headers {
52+
mlua::Value::Table(current_headers) => {
53+
current_headers.pairs::<String,String>().for_each(|currentheader| {
54+
all_headers.insert(HeaderName::from_bytes(currentheader.clone().unwrap().0.as_bytes()).unwrap(), HeaderValue::from_bytes(currentheader.unwrap().1.as_bytes()).unwrap());
55+
});
56+
},
57+
_ => {
58+
}
59+
};
60+
body = match req_body {
61+
mlua::Value::String(body) => {
62+
body.to_str().unwrap().to_string()
63+
},
64+
_ => {
65+
"".to_string()
66+
}
67+
};
6768

68-
let resp = this.send(&method, url, body).await;
69+
let resp = this.send(&method, url, body, all_headers).await;
6970
Ok(resp)
7071
},
7172
);
@@ -81,41 +82,55 @@ impl Sender {
8182
}
8283
}
8384

84-
fn build_client(&self) -> Result<isahc::HttpClient, isahc::Error> {
85-
HttpClientBuilder::new()
86-
.timeout(Duration::from_secs(self.timeout))
87-
.redirect_policy(RedirectPolicy::Limit(self.redirects))
88-
.proxy({
89-
match &self.proxy {
90-
Some(proxy) => {
91-
Some(proxy.parse().unwrap())
92-
},
93-
None => {
94-
None
95-
}
96-
}
97-
})
98-
.ssl_options(SslOption::DANGER_ACCEPT_INVALID_CERTS)
99-
.ssl_options(SslOption::DANGER_ACCEPT_REVOKED_CERTS)
100-
.ssl_options(SslOption::DANGER_ACCEPT_INVALID_HOSTS)
101-
.build()
85+
fn build_client(&self) -> Result<reqwest::Client, reqwest::Error> {
86+
match &self.proxy {
87+
Some(the_proxy) => {
88+
Client::builder()
89+
.timeout(Duration::from_secs(self.timeout))
90+
.redirect(redirect::Policy::limited(self.redirects as usize))
91+
.proxy(Proxy::all(the_proxy).unwrap())
92+
.no_trust_dns()
93+
.user_agent(
94+
"Mozilla/5.0 (X11; Manjaro; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0",
95+
)
96+
.danger_accept_invalid_certs(true)
97+
.build()
98+
}
99+
None => {
100+
Client::builder()
101+
.timeout(Duration::from_secs(self.timeout))
102+
.redirect(redirect::Policy::limited(self.redirects as usize))
103+
.no_proxy()
104+
.no_trust_dns()
105+
.user_agent(
106+
"Mozilla/5.0 (X11; Manjaro; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0",
107+
)
108+
.danger_accept_invalid_certs(true)
109+
.build()
110+
}
111+
}
102112
}
103-
pub async fn send(&self, method: &str, url: String, body: String) -> HashMap<String, RespType> {
113+
pub async fn send(
114+
&self,
115+
method: &str,
116+
url: String,
117+
body: String,
118+
headers: HeaderMap,
119+
) -> HashMap<String, RespType> {
104120
let mut resp_data: HashMap<String, RespType> = HashMap::new();
105-
let current_request = Request::builder()
106-
.uri(url)
107-
.method(method)
108-
.header("User-agent","Mozilla/5.0 (X11; Manjaro; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0")
109-
.body(body)
110-
.unwrap();
111-
let req = self
121+
match self
112122
.build_client()
113123
.unwrap()
114-
.send_async(current_request)
115-
.await;
116-
117-
match req {
118-
Ok(mut resp) => {
124+
.request(
125+
reqwest::Method::from_bytes(method.as_bytes()).unwrap(),
126+
url.clone(),
127+
)
128+
.headers(headers)
129+
.body(body)
130+
.send()
131+
.await
132+
{
133+
Ok(resp) => {
119134
let mut resp_headers: HashMap<String, String> = HashMap::new();
120135
resp.headers()
121136
.iter()
@@ -125,10 +140,7 @@ impl Sender {
125140
header_value.to_str().unwrap().to_string(),
126141
);
127142
});
128-
resp_data.insert(
129-
"url".to_string(),
130-
RespType::Str(resp.effective_uri().unwrap().to_string()),
131-
);
143+
resp_data.insert("url".to_string(), RespType::Str(url));
132144
resp_data.insert(
133145
"status".to_string(),
134146
RespType::Str(resp.status().to_string()),

src/core/utils/report.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ fn lua_report_func(vm: &Lua) -> &Lua {
3333
)
3434
.unwrap();
3535

36-
3736
vm.globals()
38-
.set("save_file", vm.create_function(|_,(data, report_path) : (String, String)|{
39-
save_file(&report_path, &data);
40-
Ok(())
41-
}).unwrap()).unwrap();
37+
.set(
38+
"save_file",
39+
vm.create_function(|_, (data, report_path): (String, String)| {
40+
save_file(&report_path, &data);
41+
Ok(())
42+
})
43+
.unwrap(),
44+
)
45+
.unwrap();
4246
vm
4347
}
4448

src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ impl Lotus {
1818
Lotus { script }
1919
}
2020

21-
pub async fn start(&self, threads: usize,request: RequestOpts, script_threads: usize, output_path: &str) {
21+
pub async fn start(
22+
&self,
23+
threads: usize,
24+
request: RequestOpts,
25+
script_threads: usize,
26+
output_path: &str,
27+
) {
2228
if atty::is(atty::Stream::Stdin) {
2329
println!("No Urls found in Stdin");
2430
std::process::exit(0);
@@ -36,7 +42,7 @@ impl Lotus {
3642
// ProgressBar Settings
3743
let bar = create_progress(urls.len() as u64 * active.len() as u64);
3844

39-
let lualoader = Arc::new(LuaLoader::new(&bar,request, output_path.to_string()));
45+
let lualoader = Arc::new(LuaLoader::new(&bar, request, output_path.to_string()));
4046
stream::iter(urls.into_iter())
4147
.map(move |url| {
4248
let active = active.clone();
@@ -48,12 +54,7 @@ impl Lotus {
4854
let lualoader = Arc::clone(&lualoader);
4955
async move {
5056
lualoader
51-
.run_scan(
52-
None,
53-
&script_out,
54-
script_path,
55-
url,
56-
)
57+
.run_scan(None, &script_out, script_path, url)
5758
.await
5859
.unwrap()
5960
}

0 commit comments

Comments
 (0)