http_to_command/
http_to_command.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use bytes::Bytes;
use slinger::record::CommandRecord;

/// ## ncat command
/// ```bash
/// #
/// printf 'GET /test1 HTTP/1.1\r\n'\
/// 'Host: 192.168.83.196:8081\r\n'\
/// 'Content-Length: 42\r\n'\
/// 'Transfer-Encoding: chunked\r\n'\
/// '\r\n'\
/// '0\r\n'\
/// '\r\n'\
/// 'GET /test1 HTTP/1.1\r\n'\
/// 'Host: 192.168.83.196:8081\r\n'\
/// 'X: GET http://192.168.83.1:8080/admin.jsp HTTP/1.0\r\n'\
/// '\r\n'\
/// '\r\n'\
/// |ncat 127.0.0.1 9015
/// #
/// ```
///
/// ## curl command
/// ```bash
/// #
/// curl -X GET --compressed\
///  -H 'x: X'\
///  -d '\x7fELF\x01\x00\x02\x03'\
///  'http://httpbin.org/get'
/// #
/// ```
const RAW: &str = "GET /test1 HTTP/1.1
Host: 192.168.83.196:8081
Content-Length: 42
Transfer-Encoding: chunked

0

GET /test1 HTTP/1.1
Host: 192.168.83.196:8081
X: GET http://192.168.83.1:8080/admin.jsp HTTP/1.0

";

fn main() {
  let req: slinger::Request = slinger::Request::builder()
    .uri("http://httpbin.org/get")
    .header("X", "X")
    .body(Bytes::from(b"\x7f\x45\x4c\x46\x01\x00\x02\x03".to_vec()))
    .unwrap()
    .into();
  println!("{}", req.get_command());
  let raw = RAW.replace('\n', "\r\n");
  let raw = [raw.as_bytes(), b"\x7f\x45\x4c\x46\x01\x00\x02\x03"].concat();
  let raw_req = slinger::RequestBuilder::default()
    .raw(raw, true)
    .build()
    .unwrap();
  println!("{}", raw_req.get_command());
  // or from request
  println!("{}", CommandRecord::from(&req))
}