Add proper parsing for the gzip content encoding

master
Dirk Engling 7 months ago
parent 35f55290f3
commit bd4992435c

@ -24,7 +24,7 @@ STRIP?=strip
#FEATURES+=-DWANT_DYNAMIC_ACCESSLIST #FEATURES+=-DWANT_DYNAMIC_ACCESSLIST
#FEATURES+=-DWANT_SYNC_LIVE #FEATURES+=-DWANT_SYNC_LIVE
#FEATURES+=-DWANT_IP_FROM_QUERY_STRING FEATURES+=-DWANT_IP_FROM_QUERY_STRING
#FEATURES+=-DWANT_COMPRESSION_GZIP #FEATURES+=-DWANT_COMPRESSION_GZIP
#FEATURES+=-DWANT_COMPRESSION_GZIP_ALWAYS #FEATURES+=-DWANT_COMPRESSION_GZIP_ALWAYS
#FEATURES+=-DWANT_LOG_NETWORKS #FEATURES+=-DWANT_LOG_NETWORKS
@ -48,7 +48,7 @@ FEATURES+=-DWANT_FULLSCRAPE
OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
OPTS_production=-O3 OPTS_production=-O3
CFLAGS+=-I$(LIBOWFAT_HEADERS) -Wall -pipe -pthread -Wextra #-ansi -pedantic CFLAGS+=-I$(LIBOWFAT_HEADERS) -Wall -pipe -pthread -Wextra -Wincompatible-pointer-types #-ansi -pedantic
LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread -lz LDFLAGS+=-L$(LIBOWFAT_LIBRARY) -lowfat -pthread -lz
#LDFLAGS+=-lbsd #LDFLAGS+=-lbsd

@ -262,17 +262,19 @@ fprintf(stderr, "GZIP path\n");
if( deflate( &strm, Z_FINISH ) < Z_OK ) if( deflate( &strm, Z_FINISH ) < Z_OK )
fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" ); fprintf( stderr, "deflate() failed while in fullscrape_make()'s endgame.\n" );
if( !strm.avail_out ) {
unsigned int pending;
int bits;
deflatePending( &strm, &pending, &bits);
pending += ( bits ? 1 : 0 );
iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base; iovector.iov_len = (char *)strm.next_out - (char *)iovector.iov_base;
if (mutex_workqueue_pushchunked(taskid, &iovector) ) { if (mutex_workqueue_pushchunked(taskid, &iovector) ) {
free(iovector.iov_base); free(iovector.iov_base);
return mutex_bucket_unlock( bucket, 0 ); return mutex_bucket_unlock( bucket, 0 );
} }
{
unsigned int pending;
int bits;
deflatePending( &strm, &pending, &bits);
pending += ( bits ? 1 : 0 );
if (pending) {
/* Allocate a fresh output buffer */ /* Allocate a fresh output buffer */
iovector.iov_base = malloc( pending ); iovector.iov_base = malloc( pending );
iovector.iov_len = pending; iovector.iov_len = pending;
@ -290,6 +292,7 @@ fprintf(stderr, "GZIP path\n");
if( mutex_workqueue_pushchunked(taskid, &iovector) ) if( mutex_workqueue_pushchunked(taskid, &iovector) )
free(iovector.iov_base); free(iovector.iov_base);
} }
}
deflateEnd(&strm); deflateEnd(&strm);
} }

@ -162,7 +162,7 @@ fprintf(stderr, "http_sendiovecdata sending %d iovec entries found cookie->batch
header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n%sContent-Length: %zd\r\n\r\n", encoding, size ); header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n%sContent-Length: %zd\r\n\r\n", encoding, size );
else { else {
if ( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )) { if ( !(cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER )) {
header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n%sTransfer-Encoding: chunked\r\n\r\n%zx\r\n", encoding, size ); header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: application/octet-stream\r\n%sTransfer-Encoding: chunked\r\n\r\n%zx\r\n", encoding, size );
cookie->flag |= STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; cookie->flag |= STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER;
} else } else
header_size = sprintf( header, "%zx\r\n", size ); header_size = sprintf( header, "%zx\r\n", size );
@ -269,12 +269,12 @@ static const ot_keywords keywords_format[] =
tai6464 t; tai6464 t;
#ifdef WANT_COMPRESSION_GZIP #ifdef WANT_COMPRESSION_GZIP
ws->request[ws->request_size] = 0; ws->request[ws->request_size] = 0;
#ifdef WANT_COMPRESSION_GZIP_ALWAYS #ifndef WANT_COMPRESSION_GZIP_ALWAYS
if( strstr( read_ptr - 1, "gzip" ) ) { if( strstr( read_ptr - 1, "gzip" ) ) {
#endif #endif
cookie->flag |= STRUCT_HTTP_FLAG_GZIP; cookie->flag |= STRUCT_HTTP_FLAG_GZIP;
format |= TASK_FLAG_GZIP; format |= TASK_FLAG_GZIP;
#ifdef WANT_COMPRESSION_GZIP_ALWAYS #ifndef WANT_COMPRESSION_GZIP_ALWAYS
} }
#endif #endif
#endif #endif
@ -337,11 +337,15 @@ static ssize_t http_handle_fullscrape( const int64 sock, struct ot_workstruct *w
#ifdef WANT_COMPRESSION_GZIP #ifdef WANT_COMPRESSION_GZIP
ws->request[ws->request_size-1] = 0; ws->request[ws->request_size-1] = 0;
#ifndef WANT_COMPRESSION_GZIP_ALWAYS
if( strstr( ws->request, "gzip" ) ) { if( strstr( ws->request, "gzip" ) ) {
#endif
cookie->flag |= STRUCT_HTTP_FLAG_GZIP; cookie->flag |= STRUCT_HTTP_FLAG_GZIP;
format = TASK_FLAG_GZIP; format = TASK_FLAG_GZIP;
stats_issue_event( EVENT_FULLSCRAPE_REQUEST_GZIP, 0, (uintptr_t)cookie->ip ); stats_issue_event( EVENT_FULLSCRAPE_REQUEST_GZIP, 0, (uintptr_t)cookie->ip );
#ifndef WANT_COMPRESSION_GZIP_ALWAYS
} else } else
#endif
#endif #endif
stats_issue_event( EVENT_FULLSCRAPE_REQUEST, 0, (uintptr_t)cookie->ip ); stats_issue_event( EVENT_FULLSCRAPE_REQUEST, 0, (uintptr_t)cookie->ip );

@ -2,13 +2,21 @@
while true; do while true; do
request_string="GET /announce?info_hash=012345678901234567\ request_string="GET /announce?info_hash=012345678901234567\
%$(printf %02X $(( $RANDOM & 0xff )) )\ $(printf %02X $(( $RANDOM & 0xff )) )\
%$(printf %02X $(( $RANDOM & 0xff )) )\ &ip=$(( $RANDOM & 0xff )).17.13.15&port=$(( $RANDOM & 0xff )) HTTP/1.0"
&ip=$(( $RANDOM & 0xff )).17.13.15&port=$(( $RANDOM & 0xff )) HTTP/1.0\n"
# echo $request_string
echo $request_string # echo
echo printf "%s\n\n" "$request_string" | nc 84.200.61.9 6969 | hexdump -C
echo $request_string | nc 23.23.23.237 6969 >/dev/null
echo request_string="GET /announce?info_hash=012345678901234567\
$(printf %02X $(( $RANDOM & 0xff )) )\
&ip=2001:1608:6:27::$(( $RANDOM & 0xff ))&port=$(( $RANDOM & 0xff )) HTTP/1.0"
printf "%s\n\n" "$request_string" | nc 2001:1608:6:27::9 6969 | hexdump -C
printf "%s\n\n" "$request_string"
request_string="GET /scrape?info_hash=012345678901234567\
$(printf %02X $(( $RANDOM & 0xff )) ) HTTP/1.0"
printf "%s\n\n" "$request_string" | nc 2001:1608:6:27::9 6969 | hexdump -C
done done

Loading…
Cancel
Save