Skip to content

Commit

Permalink
Merge pull request #62 from maikthulhu/master
Browse files Browse the repository at this point in the history
Added Cookie support
  • Loading branch information
shekyan authored Aug 24, 2020
2 parents b0bcfbc + 89603b2 commit 6e29ba4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/slowhttptest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const char* SlowHTTPTest::get_random_extra() {

bool SlowHTTPTest::init(const char* url, const char* verb,
const char* path, const char* proxy,
const char* content_type, const char* accept) {
const char* content_type, const char* accept, const char* cookie) {
if(!change_fd_limits()) {
slowlog(LOG_INFO, "error setting open file limits\n");

Expand Down Expand Up @@ -333,6 +333,13 @@ bool SlowHTTPTest::init(const char* url, const char* verb,
request_.append(user_agent_);
request_.append("\r\n");
request_.append(referer);
// Cookie
if (cookie != 0 && strlen(cookie)) {
cookie_.append(cookie);
request_.append("Cookie: ");
request_.append(cookie_);
request_.append(crlf);
}
// method for probe is always GET
probe_request_.append("GET");
if(eProbeProxy == proxy_type_) {
Expand Down Expand Up @@ -392,6 +399,7 @@ bool SlowHTTPTest::init(const char* url, const char* verb,
"<tr><td><b>Number of connections</b></td><td>%d</td></tr>"
"<tr><td><b>Verb</b></td><td>%s</td></tr>"
"<tr><td><b>Content-Length header value</b></td><td>%d</td></tr>"
"<tr><td><b>Cookie</b></td><td>%s</td></tr>"
"<tr><td><b>Extra data max length</b></td><td>%d</td></tr>"
"<tr><td><b>Interval between follow up data</b></td><td>%d seconds</td></tr>"
"<tr><td><b>Connections per seconds</b></td><td>%d</td></tr>"
Expand All @@ -403,6 +411,7 @@ bool SlowHTTPTest::init(const char* url, const char* verb,
num_connections_,
verb_.c_str(),
content_length_,
cookie,
extra_data_max_len_total_,
followup_timing_,
delay_,
Expand All @@ -416,6 +425,7 @@ bool SlowHTTPTest::init(const char* url, const char* verb,
"<tr><th>Test parameters</th></tr>"
"<tr><td><b>Test type</b></td><td>%s</td></tr>"
"<tr><td><b>Number of connections</b></td><td>%d</td></tr>"
"<tr><td><b>Cookie</b></td><td>%s</td></tr>"
"<tr><td><b>Receive window range</b></td><td>%d - %d</td></tr>"
"<tr><td><b>Pipeline factor</b></td><td>%d</td></tr>"
"<tr><td><b>Read rate from receive buffer</b></td><td>%d bytes / %d sec</td></tr>"
Expand All @@ -426,6 +436,7 @@ bool SlowHTTPTest::init(const char* url, const char* verb,
"</table>",
test_type_name[test_type_],
num_connections_,
cookie,
window_lower_limit_,
window_upper_limit_,
pipeline_factor_,
Expand Down Expand Up @@ -485,6 +496,7 @@ void SlowHTTPTest::report_parameters() {
cBLU "number of connections:" cLBL " %d\n"
cBLU "URL:" cLBL " %s\n"
cBLU "verb:" cLBL " %s\n"
cBLU "cookie:" cLBL " %s\n"
cBLU "Content-Length header value:" cLBL " %d\n"
cBLU "follow up data max size:" cLBL " %d\n"
cBLU "interval between follow up data:" cLBL " %d seconds\n"
Expand All @@ -496,6 +508,7 @@ void SlowHTTPTest::report_parameters() {
num_connections_,
base_uri_.getData(),
verb_.c_str(),
cookie_.c_str(),
content_length_,
extra_data_max_len_total_,
followup_timing_,
Expand All @@ -512,6 +525,7 @@ void SlowHTTPTest::report_parameters() {
cBLU "number of connections:" cLBL " %d\n"
cBLU "URL:" cLBL " %s\n"
cBLU "verb:" cLBL " %s\n"
cBLU "cookie:" cLBL" %s\n"
cBLU "receive window range:" cLBL " %d - %d\n"
cBLU "pipeline factor:" cLBL " %d\n"
cBLU "read rate from receive buffer:" cLBL " %d bytes / %d sec\n"
Expand All @@ -523,6 +537,7 @@ void SlowHTTPTest::report_parameters() {
num_connections_,
base_uri_.getData(),
verb_.c_str(),
cookie_.c_str(),
window_lower_limit_,
window_upper_limit_,
pipeline_factor_,
Expand Down
3 changes: 2 additions & 1 deletion src/slowhttptest.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SlowHTTPTest {

bool init(const char* url, const char* verb,
const char* path, const char* proxy,
const char* content_type, const char* accept);
const char* content_type, const char* accept, const char* cookie);
void report_parameters();
void report_status(bool to_csv);
void report_csv();
Expand All @@ -99,6 +99,7 @@ class SlowHTTPTest {
std::string probe_request_;
std::string random_extra_;
std::string verb_;
std::string cookie_;
std::string user_agent_;
std::string content_type_;
std::string accept_;
Expand Down
9 changes: 7 additions & 2 deletions src/slowhttptestmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static void usage() {
" -e host:port probe traffic directed through HTTP proxy at host:port (off)\n"
" -p seconds timeout to wait for HTTP response on probe connection,\n"
" after which server is considered inaccessible (5)\n"
" -j cookies value of Cookie header (ex.: -j \"user_id=1001; timeout=9000\")\n"
"\nRange attack specific options:\n\n"
" -a start left boundary of range in range header (5)\n"
" -b bytes limit for range header right boundary values (2000)\n"
Expand Down Expand Up @@ -148,6 +149,7 @@ int main(int argc, char **argv) {
char verb[16] = { 0 };
char content_type[1024] = { 0 };
char accept[1024] = { 0 };
char cookie[1024] = { 0 };
// default values
int conn_cnt = 50;
int content_length = 4096;
Expand All @@ -169,7 +171,7 @@ int main(int argc, char **argv) {
ProxyType proxy_type = slowhttptest::eNoProxy;
long tmp;
int o;
while((o = getopt(argc, argv, ":HBRXgha:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:v:w:x:y:z:")) != -1) {
while((o = getopt(argc, argv, ":HBRXgha:b:c:d:e:f:i:j:k:l:m:n:o:p:r:s:t:u:v:w:x:y:z:")) != -1) {
switch (o) {
case 'a':
if(!parse_int(range_start, 65539))
Expand Down Expand Up @@ -221,6 +223,9 @@ int main(int argc, char **argv) {
if(!parse_int(interval))
return -1;
break;
case 'j':
strncpy(cookie, optarg, 1023);
break;
case 'k':
if(!parse_int(pipeline_factor, 10))
return -1;
Expand Down Expand Up @@ -315,7 +320,7 @@ int main(int argc, char **argv) {
type, need_stats, pipeline_factor, probe_interval,
range_start, range_limit, read_interval, read_len,
window_lower_limit, window_upper_limit, proxy_type, debug_level));
if(!slow_test->init(url, verb, path, proxy, content_type, accept)) {
if(!slow_test->init(url, verb, path, proxy, content_type, accept, cookie)) {
slowlog(LOG_FATAL, "%s: error setting up slow HTTP test\n", __FUNCTION__);
return -1;
} else if(!slow_test->run_test()) {
Expand Down

0 comments on commit 6e29ba4

Please sign in to comment.