diff options
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | slowloris.c | 18 | 
2 files changed, 18 insertions, 9 deletions
| @@ -17,8 +17,15 @@ LD_PRELOAD=./slowloris.so curl 10.23.25.3  ```  A delay between individual send() calls (in microseconds) can be set by -providing `SLOWLORIS_DELAY` like so: +providing `SLOWLORIS_DELAY`. The default delay is `0`.  ```shell  SLOWLORIS_DELAY=1000 LD_PRELOAD=./slowloris.so curl 10.23.25.3  ``` + +The number of bytes sent per iteration can be set by supplying `SLOWLORIS_CHUNK`. +The default chunking is `1`. + +```shell +SLOWLORIS_CHUNK=10 LD_PRELOAD=./slowloris.so curl 10.23.25.3 +``` diff --git a/slowloris.c b/slowloris.c index 846afde..2dca208 100644 --- a/slowloris.c +++ b/slowloris.c @@ -8,17 +8,19 @@  static int silent_mode = 0;  static unsigned send_delay = 0; +static unsigned send_chunk = 1; -char* xgetenv(const char* name){ +char* xgetenv(const char* name, char* def){  	char* rv = getenv(name); -	return rv ? rv : ""; +	return rv ? rv : def;  } -__attribute__ ((constructor)) void slowloris_init(){ -	silent_mode = strtoul(xgetenv("SLOWLORIS_SILENT"), NULL, 10); -	send_delay = strtoul(xgetenv("SLOWLORIS_DELAY"), NULL, 10); +__attribute__((constructor)) void slowloris_init(){ +	silent_mode = strtoul(xgetenv("SLOWLORIS_SILENT", "0"), NULL, 10); +	send_delay = strtoul(xgetenv("SLOWLORIS_DELAY", "0"), NULL, 10); +	send_chunk = strtoul(xgetenv("SLOWLORIS_CHUNK", "1"), NULL, 10);  	if(!silent_mode){ -		printf("preload-slowloris active\nDelay: %d\n", send_delay); +		printf("preload-slowloris active\nDelay: %d\nChunking: %d\n", send_delay, send_chunk);  	}  } @@ -49,8 +51,8 @@ ssize_t send(int sockfd, const void* buf, size_t len, int flags){  	ssize_t rv = 0; -	for(size_t u = 0; u < len; u++){ -		ssize_t sent = real_send(sockfd, buf + u, 1, flags); +	for(size_t u = 0; u < len; u += send_chunk){ +		ssize_t sent = real_send(sockfd, buf + u, (send_chunk < len - u) ? send_chunk : (len - u), flags);  		if(sent < 0){  			return -1;  		} | 
