-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOptions.cpp
158 lines (127 loc) · 7.65 KB
/
Options.cpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "Options.h"
#include <exception>
#include <string>
#include <boost/program_options.hpp>
#include <sstream>
using namespace std;
using namespace boost::program_options;
Options::Options(int argc, const char** argv)
: help{}, tls{}, verify{}, contents{}, verbose{}, optimize{},
print_found{}, tor{}, sensitive_teardown{}, leading_zeros{},
test{}, telescoping{} {
options_description description("Usage: abrade host pattern");
description.add_options()
("host", value<string>(&host), "host name (eg example.com)")
("pattern", value<string>(&pattern)->default_value("/"), "format of URL (eg ?mynum={1:5}&myhex=0x{hhhh}). See documentation for formatting of patterns.")
("agent", value<string>(&user_agent)->default_value("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"), "User-agent string (default: Firefox 47)")
("out", value<string>(&output_path)->default_value(""), "output path. dir if contents enabled. (default: HOSTNAME)")
("err", value<string>(&error_path)->default_value(""), "error path (file). (default: HOSTNAME-err.log)")
("proxy", value<string>(&proxy)->default_value(""), "SOCKS5 proxy address:port. (default: none)")
("screen", value<string>(&screen)->default_value(""), "omits 200-level response if contents contains screen (default: none)")
("stdin,d", bool_switch(&from_stdin), "read from stdin (default: no)")
("tls,t", bool_switch(&tls), "use tls/ssl (default: no)")
("sensitive,s", bool_switch(&sensitive_teardown), "complain about rude TCP teardowns (default: no)")
("tor,o", bool_switch(&tor), "use local proxy at 127.0.0.1:9050 (default: no)")
("verify,r", bool_switch(&verify), "verify ssl (default: no)")
("leadzero,l", bool_switch(&leading_zeros), "output leading zeros in URL (default: no)")
("telescoping,e", bool_switch(&telescoping), "do not telescope the pattern (default: no)")
("found,f", bool_switch(&print_found), "print when resource found (default: no). implied by verbose")
("verbose,v", bool_switch(&verbose), "prints gratuitous output to console (default: no)")
("contents,c", bool_switch(&contents), "read full contents (default: no)")
("test", bool_switch(&test), "no network requests, just write generated URIs to console (default: no)")
("optimize,p", bool_switch(&optimize), "Optimize number of simultaneous requests (default: no)")
("init,i", value<size_t>(&initial_coroutines)->default_value(1000), "Initial number of simultaneous requests")
("min", value<size_t>(&minimum_coroutines)->default_value(1), "Minimum number of simultaneous requests")
("max", value<size_t>(&maximum_coroutines)->default_value(25000), "Maximum number of simultaneous requests")
("ssize", value<size_t>(&sample_size)->default_value(50), "Size of velocity sliding window")
("sint", value<size_t>(&sample_interval)->default_value(1000), "Size of sampling interval")
("help,h", "produce help message");
positional_options_description pos_description;
pos_description.add("host", 1);
pos_description.add("pattern", 1);
variables_map vm;
store(command_line_parser(argc, argv)
.options(description)
.positional(pos_description)
.run(), vm);
notify(vm);
help = vm.count("help") >= 1;
stringstream ss;
ss << description;
help_str = ss.str();
if (help) return;
if (host.size() == 0) throw OptionsException{ "you must supply a host.", *this };
if (!from_stdin && pattern.size() == 0) throw OptionsException{ "you must supply a pattern.", *this };
if (initial_coroutines < 1) throw OptionsException{"init must be positive", *this };
if (minimum_coroutines < 1) throw OptionsException{"min must be positive", *this };
if (maximum_coroutines < 1) throw OptionsException{"max must be positive", *this };
if (sample_size < 1) throw OptionsException{"ssize must be positive", *this };
if (sample_interval < 1) throw OptionsException{"ssize must be positive", *this };
tls |= verify;
print_found |= verbose;
if (output_path.empty()) {
output_path = host;
if (contents) { output_path += "-contents"; }
}
if (error_path.empty()) { error_path = host + "-err.log"; }
if (!is_proxy() && tor) { proxy = "127.0.0.1:9050"; }
}
string Options::get_pretty_print() const noexcept {
stringstream ss;
if (from_stdin) {
ss <<
"[ ] Reading input from stdin\n";
} else {
ss <<
"[ ] Host: " << get_host() << "\n" <<
"[ ] Pattern: " << get_pattern() << "\n";
}
ss <<
"[ ] Include leading zeros: " << (is_leading_zeros() ? "Yes" : "No") << "\n" <<
"[ ] Telescope pattern: " << (is_telescoping() ? "Yes" : "No") << "\n" <<
"[ ] TLS/SSL: " << (is_tls() ? "Yes" : "No") << "\n" <<
"[ ] TLS/SSL Peer Verify: " << (is_verify() ? "Yes" : "No") << "\n" <<
"[ ] User Agent: " << get_user_agent() << "\n" <<
"[ ] Proxy: " << (is_proxy() ? get_proxy() : "No") << "\n" <<
"[ ] Contents: " << (is_contents() ? "Yes" : "No") << "\n" <<
"[ ] Screen: " << (get_screen().empty() ? "None" : get_screen()) << "\n" <<
"[ ] Output: " << get_output_path() << "\n" <<
"[ ] Error Output: " << get_error_path() << "\n" <<
"[ ] Verbose: " << (is_verbose() ? "Yes" : "No") << "\n" <<
"[ ] Print found: " << (is_print_found() ? "Yes" : "No") << "\n" <<
"[ ] Initial connections: " << get_initial_coroutines() << "\n" <<
"[ ] Optimize connections: " << (is_optimizer() ? "Yes" : "No");
if (!is_optimizer()) {
ss << "\n" <<
"[ ] Connection range: [" << get_minimum_coroutines() << "," << get_maximum_coroutines() << "] " << "\n" <<
"[ ] Optimization sample size: " << get_sample_size() << "\n" <<
"[ ] Optimization sample interval: " << get_sample_interval();
}
return ss.str();
}
bool Options::is_stdin() const noexcept { return from_stdin; }
bool Options::is_leading_zeros() const noexcept { return leading_zeros; }
bool Options::is_test() const noexcept { return test; }
bool Options::is_help() const noexcept { return help; }
bool Options::is_verbose() const noexcept { return verbose; }
bool Options::is_contents() const noexcept { return contents; }
bool Options::is_print_found() const noexcept { return print_found; }
bool Options::is_proxy() const noexcept { return proxy.size() > 0; }
bool Options::is_telescoping() const noexcept { return telescoping; }
bool Options::is_tls() const noexcept { return tls; }
bool Options::is_verify() const noexcept { return verify; }
bool Options::is_sensitive_teardown() const noexcept { return sensitive_teardown; }
bool Options::is_optimizer() const noexcept { return optimize; }
const string& Options::get_help() const noexcept { return help_str; }
const string& Options::get_pattern() const noexcept { return pattern; }
const string& Options::get_proxy() const noexcept { return proxy; }
const string& Options::get_output_path() const noexcept { return output_path; }
const string& Options::get_error_path() const noexcept { return error_path; }
const string& Options::get_host() const noexcept { return host; }
const string& Options::get_user_agent() const noexcept { return user_agent; }
const string& Options::get_screen() const noexcept { return screen; }
size_t Options::get_initial_coroutines() const noexcept { return initial_coroutines; }
size_t Options::get_minimum_coroutines() const noexcept { return minimum_coroutines; }
size_t Options::get_maximum_coroutines() const noexcept { return maximum_coroutines; }
size_t Options::get_sample_size() const noexcept { return sample_size; }
size_t Options::get_sample_interval() const noexcept { return sample_interval; }