1 | 1 | | use clap::Parser; |
2 | | - | |
3 | 2 | | use netstat2::*; |
| 3 | + | use std::io::{self, BufRead}; |
4 | 4 | | use sysinfo::{PidExt, ProcessExt, SystemExt}; |
5 | 5 | | use sysinfo::{ProcessRefreshKind, RefreshKind, System}; |
6 | 6 | | use websocket::{ClientBuilder, Message}; |
| skipped 109 lines |
116 | 116 | | /// Fetch available objects and exit. |
117 | 117 | | #[clap(long, takes_value = false)] |
118 | 118 | | domains: bool, |
| 119 | + | /// Execute a custom request payload, use '-' to read from stdin. |
| 120 | + | #[clap(long)] |
| 121 | + | custom_payload: Option<String>, |
119 | 122 | | } |
120 | 123 | | |
121 | 124 | | fn main() { |
| skipped 33 lines |
155 | 158 | | } |
156 | 159 | | }; |
157 | 160 | | |
158 | | - | // only show available domains |
159 | 161 | | if args.domains { |
| 162 | + | // only show available domains |
160 | 163 | | let domains = match protocol::get_domains(inspect_port) { |
161 | 164 | | Ok(url) => url, |
162 | 165 | | Err(e) => { |
| skipped 20 lines |
183 | 186 | | } |
184 | 187 | | }; |
185 | 188 | | |
186 | | - | // 4. send Runtime.evaluate request -> profit |
| 189 | + | // 4. send payload request -> profit |
187 | 190 | | println!("connecting to {:?}", &debug_url); |
188 | 191 | | |
189 | 192 | | let mut builder = ClientBuilder::new(&debug_url).unwrap(); |
190 | 193 | | |
191 | 194 | | let mut client = builder.connect_insecure().unwrap(); |
192 | 195 | | |
193 | | - | println!("connected, sending payload ..."); |
| 196 | + | let payload = if let Some(custom) = args.custom_payload { |
| 197 | + | // execute custom payload |
| 198 | + | if custom == "-" { |
| 199 | + | // read payload from stdin |
| 200 | + | let stdin = io::stdin(); |
| 201 | + | stdin |
| 202 | + | .lock() |
| 203 | + | .lines() |
| 204 | + | .into_iter() |
| 205 | + | .map(|r| r.unwrap()) |
| 206 | + | .collect::<Vec<String>>() |
| 207 | + | .join("\n") |
| 208 | + | } else { |
| 209 | + | custom |
| 210 | + | } |
| 211 | + | } else { |
| 212 | + | // execute default Runtime.evaluate payload |
| 213 | + | let script = match args.code { |
| 214 | + | Some(code) => code, |
| 215 | + | None => std::fs::read_to_string(&args.script).unwrap(), |
| 216 | + | }; |
194 | 217 | | |
195 | | - | let script = match args.code { |
196 | | - | Some(code) => code, |
197 | | - | None => std::fs::read_to_string(&args.script).unwrap(), |
198 | | - | }; |
| 218 | + | let request = protocol::EvalRequest::new(&script); |
199 | 219 | | |
200 | | - | let request = protocol::EvalRequest::new(&script); |
| 220 | + | serde_json::to_string(&request).unwrap() |
| 221 | + | }; |
201 | 222 | | |
202 | | - | let raw = serde_json::to_string(&request).unwrap(); |
| 223 | + | println!("connected, sending payload ..."); |
203 | 224 | | |
204 | | - | client.send_message(&Message::text(raw)).unwrap(); |
| 225 | + | client.send_message(&Message::text(payload)).unwrap(); |
205 | 226 | | |
206 | 227 | | println!("payload sent!"); |
207 | 228 | | |
| skipped 6 lines |