1#![allow(non_camel_case_types)]
2#![allow(unused_assignments)]
3#[path="../../structs/mod.rs"] mod structs;
4#[path="../../connect.rs"] mod connect;
5use crate::client::Client;
6use connect::connect;
7use std::collections::HashMap;
8use serde::{Serialize,de::DeserializeOwned as DOwned};
9use rmp_serde::{Serializer,decode::Error as derror,from_read};
10use crate::error::{MsfError,Error as E};
11use structs::request as req;
12
13pub struct compactible {
14 pub name:String,
15 pub client:Client,
16}
17pub struct list {
18 pub client:Client,
19}
20impl list {
21 pub fn new(client:Client) -> Self {
22 list {
23 client:client,
24 }
25 }
26 fn serialize(&self,method:&str,body:&mut Vec<u8>) {
27 let mut se=Serializer::new(body);
28 let byte=req::modules::list(method.to_string(),self.client.token.as_ref().unwrap().to_string());
29 byte.serialize(&mut se).unwrap();
30 }
31 fn deserialize<T:DOwned>(&self,new_buf:Vec<u8>) -> Result<T,E> {
32 let ret:Result<T,derror>=from_read(new_buf.as_slice());
33 match ret {
34 Ok(val) => {
35 Ok(val)
36 },
37 Err(_) => {
38 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
39 match ret2 {
40 Ok(val) => {
41 Err(E::MsfError(val))
42 },
43 Err(e) => {
44 Err(E::DError(e))
45 },
46 }
47 },
48 }
49 }
50 pub fn exploits<T:DOwned>(&self) -> Result<T,E> {
51 let mut body=Vec::new();
52 let mut buf=vec![];
53 self.serialize("module.exploits",&mut body);
54 let con=connect(self.client.url.clone(),body,&mut buf);
55 let new_buf=buf.clone();
56 match con {
57 Ok(_) => {
58 self.deserialize(new_buf)
59 },
60 Err(e) => {
61 Err(E::ConnectionError(e))
62 },
63 }
64 }
65 pub fn auxiliary<T:DOwned>(&self) -> Result<T,E> {
66 let mut body=Vec::new();
67 let mut buf=vec![];
68 self.serialize("module.auxiliary",&mut body);
69 let con=connect(self.client.url.clone(),body,&mut buf);
70 let new_buf=buf.clone();
71 match con {
72 Ok(_) => {
73 self.deserialize(new_buf)
74 },
75 Err(e) => {
76 Err(E::ConnectionError(e))
77 },
78 }
79 }
80 pub fn post<T:DOwned>(&self) -> Result<T,E> {
81 let mut body=Vec::new();
82 let mut buf=vec![];
83 self.serialize("module.post",&mut body);
84 let con=connect(self.client.url.clone(),body,&mut buf);
85 let new_buf=buf.clone();
86 match con {
87 Ok(_) => {
88 self.deserialize(new_buf)
89 },
90 Err(e) => {
91 Err(E::ConnectionError(e))
92 },
93 }
94 }
95 pub fn payloads<T:DOwned>(&self) -> Result<T,E> {
96 let mut body=Vec::new();
97 let mut buf=vec![];
98 self.serialize("module.payloads",&mut body);
99 let con=connect(self.client.url.clone(),body,&mut buf);
100 let new_buf=buf.clone();
101 match con {
102 Ok(_) => {
103 self.deserialize(new_buf)
104 },
105 Err(e) => {
106 Err(E::ConnectionError(e))
107 },
108 }
109 }
110 pub fn encoders<T:DOwned>(&self) -> Result<T,E> {
111 let mut body=Vec::new();
112 let mut buf=vec![];
113 self.serialize("module.encoders",&mut body);
114 let con=connect(self.client.url.clone(),body,&mut buf);
115 let new_buf=buf.clone();
116 match con {
117 Ok(_) => {
118 self.deserialize(new_buf)
119 },
120 Err(e) => {
121 Err(E::ConnectionError(e))
122 },
123 }
124 }
125 pub fn nops<T:DOwned>(&self) -> Result<T,E> {
126 let mut body=Vec::new();
127 let mut buf=vec![];
128 self.serialize("module.nops",&mut body);
129 let con=connect(self.client.url.clone(),body,&mut buf);
130 let new_buf=buf.clone();
131 match con {
132 Ok(_) => {
133 self.deserialize(new_buf)
134 },
135 Err(e) => {
136 Err(E::ConnectionError(e))
137 },
138 }
139 }
140}
141pub fn info<T:DOwned>(client:Client,moduletypestr:&str,modulenamestr:&str) -> Result<T,E> {
142 let moduletype:String=moduletypestr.to_string();
143 let modulename:String=modulenamestr.to_string();
144 let mut body=Vec::new();
145 let mut buf=vec![];
146 let mut se=Serializer::new(&mut body);
147 let byte=req::modules::info("module.info".to_string(),client.token.unwrap(),moduletype,modulename);
148 byte.serialize(&mut se).unwrap();
149 let con=connect(client.url,body,&mut buf);
150 let new_buf=buf.clone();
151 match con {
152 Ok(_) => {
153 let ret:Result<T,derror>=from_read(new_buf.as_slice());
154 match ret {
155 Ok(val) => {
156 Ok(val)
157 },
158 Err(_) => {
159 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
160 match ret2 {
161 Ok(val) => {
162 Err(E::MsfError(val))
163 },
164 Err(e) => {
165 Err(E::DError(e))
166 },
167 }
168 }
169 }
170 },
171 Err(e) => {
172 Err(E::ConnectionError(e))
173 },
174 }
175}
176impl compactible {
177 pub fn new(modulename:String,client:Client) -> Self {
178 compactible {
179 name:modulename,
180 client:client,
181 }
182 }
183 pub fn payload<T:DOwned>(&self) -> Result<T,E> {
184 let mut body=Vec::new();
185 let mut buf=vec![];
186 let mut se=Serializer::new(&mut body);
187 let byte=req::modules::compactible("module.compatible_payloads".to_string(),self.client.token.as_ref().unwrap().to_string(),self.name.clone());
188 byte.serialize(&mut se).unwrap();
189 let con=connect(self.client.url.clone(),body,&mut buf);
190 let new_buf=buf.clone();
191 match con {
192 Ok(_) => {
193 let ret:Result<T,derror>=from_read(new_buf.as_slice());
194 match ret {
195 Ok(val) => {
196 Ok(val)
197 },
198 Err(_) => {
199 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
200 match ret2 {
201 Ok(val) => {
202 Err(E::MsfError(val))
203 },
204 Err(e) => {
205 Err(E::DError(e))
206 },
207 }
208 }
209 }
210 },
211 Err(e) => {
212 Err(E::ConnectionError(e))
213 },
214 }
215 }
216 pub fn target_payloads<T:DOwned>(&self,targetindx:i32) -> Result<T,E> {
217 let mut body=Vec::new();
218 let mut buf=vec![];
219 let mut se=Serializer::new(&mut body);
220 let byte=req::modules::compactible_tp("module.target_compatible_payloads".to_string(),self.client.token.as_ref().unwrap().to_string(),self.name.clone(),targetindx);
221 byte.serialize(&mut se).unwrap();
222 let con=connect(self.client.url.clone(),body,&mut buf);
223 let new_buf=buf.clone();
224 match con {
225 Ok(_) => {
226 let ret:Result<T,derror>=from_read(new_buf.as_slice());
227 match ret {
228 Ok(val) => {
229 Ok(val)
230 },
231 Err(_) => {
232 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
233 match ret2 {
234 Ok(val) => {
235 Err(E::MsfError(val))
236 },
237 Err(e) => {
238 Err(E::DError(e))
239 },
240 }
241 }
242 }
243 },
244 Err(e) => {
245 Err(E::ConnectionError(e))
246 },
247 }
248 }
249 pub fn sessions<T:DOwned>(&self) -> Result<T,E> {
250 let mut body=Vec::new();
251 let mut buf=vec![];
252 let mut se=Serializer::new(&mut body);
253 let byte=req::modules::compactible("module.compatible_sessions".to_string(),self.client.token.as_ref().unwrap().to_string(),self.name.clone());
254 byte.serialize(&mut se).unwrap();
255 let con=connect(self.client.url.clone(),body,&mut buf);
256 let new_buf=buf.clone();
257 match con {
258 Ok(_) => {
259 let ret:Result<T,derror>=from_read(new_buf.as_slice());
260 match ret {
261 Ok(val) => {
262 Ok(val)
263 },
264 Err(_) => {
265 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
266 match ret2 {
267 Ok(val) => {
268 Err(E::MsfError(val))
269 },
270 Err(e) => {
271 Err(E::DError(e))
272 },
273 }
274 }
275 }
276 },
277 Err(e) => {
278 Err(E::ConnectionError(e))
279 },
280 }
281 }
282}
283pub fn option<T:DOwned>(client:Client,moduletypestr:&str,modulenamestr:&str) -> Result<T,E> {
284 let moduletype:String=moduletypestr.to_string();
285 let modulename:String=modulenamestr.to_string();
286 let mut body=Vec::new();
287 let mut buf=vec![];
288 let mut serializer=Serializer::new(&mut body);
289 let byte=req::modules::options("module.options".to_string(),client.token.as_ref().unwrap().to_string(),moduletype.clone(),modulename.clone());
290 byte.serialize(&mut serializer).unwrap();
291 let con=connect(client.url.clone(),body,&mut buf);
292 let new_buf=buf.clone();
293 match con {
294 Ok(_) => {
295 let ret:Result<T,derror>=from_read(new_buf.as_slice());
296 match ret {
297 Ok(val) => {
298 Ok(val)
299 },
300 Err(_) => {
301 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
302 match ret2 {
303 Ok(val) => {
304 Err(E::MsfError(val))
305 },
306 Err(e) => {
307 Err(E::DError(e))
308 },
309 }
310 }
311 }
312 },
313 Err(e) => {
314 Err(E::ConnectionError(e))
315 },
316 }
317}
318pub fn encoder<T:DOwned>(client:Client,datastr:&str,encodermodulestr:&str,options:HashMap<String,String>) -> Result<T,E> {
319 let data:String=datastr.to_string();
320 let encodermodule:String=encodermodulestr.to_string();
321 let mut body=Vec::new();
322 let mut buf=vec![];
323 let mut se=Serializer::new(&mut body);
324 let byte=req::modules::encoder("module.encode".to_string(),client.token.unwrap(),data,encodermodule,options);
325 byte.serialize(&mut se).unwrap();
326 let con=connect(client.url,body,&mut buf);
327 let new_buf=buf.clone();
328 match con {
329 Ok(_) => {
330 let ret:Result<T,derror>=from_read(new_buf.as_slice());
331 match ret {
332 Ok(val) => {
333 Ok(val)
334 },
335 Err(_) => {
336 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
337 match ret2 {
338 Ok(val) => {
339 Err(E::MsfError(val))
340 },
341 Err(e) => {
342 Err(E::DError(e))
343 },
344 }
345 }
346 }
347 },
348 Err(e) => {
349 Err(E::ConnectionError(e))
350 },
351 }
352}
353pub fn execute<T:DOwned>(client:Client,moduletypestr:&str,modulenamestr:&str,options:HashMap<String,String>) -> Result<T,E> {
354 let moduletype:String=moduletypestr.to_string();
355 let modulename:String=modulenamestr.to_string();
356 let mut body=Vec::new();
357 let mut buf=vec![];
358 let mut se=Serializer::new(&mut body);
359 let byte=req::modules::execute("module.execute".to_string(),client.token.unwrap(),moduletype.clone(),modulename,options);
360 byte.serialize(&mut se).unwrap();
361 let con=connect(client.url,body,&mut buf);
362 let new_buf=buf.clone();
363 match con {
364 Ok(_) => {
365 let ret:Result<T,derror>=from_read(new_buf.as_slice());
366 match ret {
367 Ok(val) => {
368 Ok(val)
369 },
370 Err(_) => {
371 let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
372 match ret2 {
373 Ok(val) => {
374 Err(E::MsfError(val))
375 },
376 Err(e) => {
377 Err(E::DError(e))
378 },
379 }
380 }
381 }
382 },
383 Err(e) => {
384 Err(E::ConnectionError(e))
385 },
386 }
387}