1use crate::*;
2use serde_json::Value;
3
4#[derive(Debug)]
7pub struct MsfParamWrapper(Option<Value>);
8
9pub trait GetArg {
10 fn get_arg(&self, val: &str) -> Option<String>;
11}
12
13impl MsfParamWrapper{
14 pub fn new(val:Value)->Self{
15 MsfParamWrapper(Some(val))
16 }
17}
18
19impl GetArg for MsfParamWrapper {
20 fn get_arg(&self, val: &str) -> Option<String>{
21 let param = match self{
22 MsfParamWrapper(Some(v)) => {
23 match v.get(val){
24 Some(y) => y,
25 None => {
26 log_error(
27 &format!("parameter not received by module :{}",
28 val));
29 return None;
30 }
31 }
32 }
33 MsfParamWrapper(None) => {
34 log_error(&format!("value not received by module :{}",val));
35 return None;
36 }
37 };
38 let param_str = match param.as_str(){
39 Some(v) => Some(v.to_string()),
40 None =>{
41 log_error(
42 &format!("unable to parse param into a string:{}\n\
43 received param: {:#?}", val,param));
44 return None;
45 }
46 };
47 param_str
48 }
49}
50
51#[derive(serde_derive::Deserialize,serde_derive::Serialize, Debug)]
52#[serde(rename_all = "camelCase")] pub struct ReportParam {
54 pub Type: String,
55 pub data: HashMap<String,String>,
56}
57
58#[derive(serde_derive::Deserialize,serde_derive::Serialize, Debug)]
59pub struct ReportRequest {
60 pub jsonrpc: String,
61 pub method: String,
62 pub params: ReportParam,
63}
64
65#[derive(serde_derive::Deserialize,serde_derive::Serialize, Debug)]
66pub struct Request {
67 pub jsonrpc: String,
68 pub method: String,
69 pub id: String,
70 pub params: Value,
71}
72
73fn report(
74 kind: &str,
75 data: HashMap<String,String>
76) {
77 let report_request: ReportRequest = ReportRequest {
78 jsonrpc: "2.0".to_string(),
79 method: "report".to_string(),
80 params: ReportParam {
81 Type: kind.to_string(),
82 data: data,
83 }
84 };
85
86 let report_request_string = serde_json::to_string(&report_request)
87 .expect("couldn't serialize report_request;");
88 rpc_send(report_request_string.as_str());
89}
90
91pub fn report_service(
92 host: &str,
93 port: &str,
94 proto: &str,
95 provided_map: Option<HashMap<String,String>>
96) {
97 let mut option_map: HashMap<String,String> = HashMap::new();
98 option_map.insert("host".to_string(),host.to_string());
99 option_map.insert("port".to_string(),port.to_string());
100 option_map.insert("proto".to_string(),proto.to_string());
101 match provided_map {
102 Some(v) => option_map.extend(v),
103 None => (),
104 }
105
106 report("service",option_map);
107}
108
109pub fn report_vuln(
110 host: &str,
111 name: &str,
112 provided_map: Option<HashMap<String,String>>
113) {
114 let mut option_map: HashMap<String,String> = HashMap::new();
115 option_map.insert("host".to_string(),host.to_string());
116 option_map.insert("name".to_string(),name.to_string());
117 match provided_map {
118 Some(v) => option_map.extend(v),
119 None => (),
120 }
121
122 report("vuln",option_map);
123}
124
125pub fn report_wrong_password(
126 username: &str,
127 password: &str,
128 provided_map: Option<HashMap<String,String>>,
129) {
130 let mut option_map: HashMap<String,String> = HashMap::new();
131 option_map.insert("username".to_string(),username.to_string());
132 option_map.insert("password".to_string(),password.to_string());
133 match provided_map {
134 Some(v) => option_map.extend(v),
135 None => (),
136 }
137
138 report("wrong_password",option_map);
139}
140
141pub fn report_correct_password(
142 username: &str,
143 password: &str,
144 provided_map: Option<HashMap<String,String>>
145) {
146 let mut option_map: HashMap<String,String> = HashMap::new();
147 option_map.insert("username".to_string(),username.to_string());
148 option_map.insert("password".to_string(),password.to_string());
149 match provided_map {
150 Some(v) => option_map.extend(v),
151 None => (),
152 }
153
154 report("correct_password",option_map);
155}
156
157pub fn report_credential_login(
158 address: &str,
159 port: &str,
160 protocol: &str,
161 service_name: &str,
162 provided_map: Option<HashMap<String,String>>
163) {
164 let mut option_map: HashMap<String,String> = HashMap::new();
165 option_map.insert("address".to_string(),address.to_string());
166 option_map.insert("port".to_string(),port.to_string());
167 option_map.insert("protocol".to_string(),protocol.to_string());
168 option_map.insert("service_name".to_string(),service_name.to_string());
169 match provided_map {
170 Some(v) => option_map.extend(v),
171 None => (),
172 }
173
174 report("credential_login",option_map);
175}
176
177pub fn report_host(
178 host: &str,
179 provided_map: Option<HashMap<String,String>>
180) {
181 let mut option_map: HashMap<String,String> = HashMap::new();
182 option_map.insert("host".to_string(),host.to_string());
183 match provided_map {
184 Some(v) => option_map.extend(v),
185 None => (),
186 }
187
188 report("host",option_map);
189}