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
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use crate::{structs::Config};
use clap::{crate_version, App, AppSettings, Arg};
use std::{collections::HashMap, io::{self, Write}};
use url::Url;

pub fn get_config() -> Config {
    let app = App::new("request_smuggler")
        .setting(AppSettings::ArgRequiredElseHelp)
        .version(crate_version!())
        .author("sh1yo <sh1yo@tuta.io>")
        .about("Http request smuggling vulnerability scanner")
        .arg(Arg::with_name("url")
            .short("u")
            .long("url")
            .takes_value(true)
            .required(true)
        )
        /*.arg(
            Arg::with_name("proxy")
                .short("x")
                .long("proxy")
                .value_name("proxy")
        )*/
        .arg(
            Arg::with_name("method")
                .short("X")
                .long("method")
                .value_name("method")
                .help("(default is \"POST\")")
                .takes_value(true)
        )
        .arg(
            Arg::with_name("headers")
                .short("H")
                .long("header")
                .help("Example: -H 'one:one' 'two:two'")
                .takes_value(true)
                .min_values(1)
        )
        .arg(
            Arg::with_name("verbose")
                .short("v")
                .long("verbose")
                .help("0 - print detected cases and errors only, 1 - print first line of server responses (default is 0)")
                .takes_value(true)
        )
        .arg(
            Arg::with_name("full")
                .long("full")
                .help("Tries to detect the vulnerability using differential responses as well.\nCan disrupt other users!!!")
        )
        .arg(
            Arg::with_name("amount-of-payloads")
                .long("amount-of-payloads")
                .help("low/medium/all (default is \"low\")")
                .takes_value(true)
        );

    let args = app.clone().get_matches();

    let verbose: usize = match args.value_of("verbose") {
        Some(val) => val.parse().expect("incorrect verbose"),
        None => 0,
    };

    let mut headers: HashMap<String, String> = HashMap::new();
    if let Some(val) = args.values_of("headers") {
        for header in val {
            let mut k_v = header.split(':');
            let key = match k_v.next() {
                Some(val) => val,
                None => {
                    writeln!(io::stderr(), "Unable to parse headers").ok();
                    std::process::exit(1);
                }
            };
            let value: String = [
                match k_v.next() {
                    Some(val) => val.trim().to_owned(),
                    None => {
                        writeln!(io::stderr(), "Unable to parse headers").ok();
                        std::process::exit(1);
                    }
                },
                k_v.map(|x| ":".to_owned() + x).collect(),
            ].concat();

            headers.insert(key.to_string(), value);
        }
    };

    let url = match Url::parse(args.value_of("url").unwrap_or("https://example.com")) {
        Ok(val) => val,
        Err(err) => {
            writeln!(io::stderr(), "Unable to parse target url: {}", err).ok();
            std::process::exit(1);
        },
    };

    let host = url.host_str().unwrap();
    let path = url[url::Position::BeforePath..].to_string();
    let mut port = match url.port() {
        Some(val) => val as usize,
        None => 0
    };

    if !headers.keys().any(|i| i.contains("User-Agent")) {
        headers.insert(String::from("User-Agent"), String::from("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"));
    }
    if !headers.keys().any(|i| i.contains("Host")) {
        headers.insert(String::from("Host"), host.to_string());
    }
    if !headers.keys().any(|i| i.contains("Accept")) {
        headers.insert(String::from("Accept"), String::from("*/*"));
    }
    headers.insert(String::from("Accept-Encoding"), String::from("gzip"));

    let url = args
        .value_of("url")
        .unwrap_or("https://something.something")
        .to_string();

    let https = url.contains("https://");
    if port == 0 {
        port = match https {
            true => 443,
            false => 80
        }
    };

    Config{
        url,
        host: host.to_string(),
        path,
        method: args.value_of("method").unwrap_or("POST").to_string(),
        https,
        port,
        proxy: args.value_of("proxy").unwrap_or("").to_string(),
        headers,
        full: args.is_present("full"),
        amount_of_payloads: args.value_of("amount-of-payloads").unwrap_or("low").to_string(),
        verbose
    }
}