|
|
@ -136,8 +136,8 @@ static int running_from_service = 0; |
|
|
|
static int exiting = 0; |
|
|
|
static HANDLE filters[MAX_FILTERS]; |
|
|
|
static int filter_num = 0; |
|
|
|
static const char http10_redirect_302[] = "HTTP/1.0 302 "; |
|
|
|
static const char http11_redirect_302[] = "HTTP/1.1 302 "; |
|
|
|
static const char *http10_redirect_302 = "HTTP/1.0 302 "; |
|
|
|
static const char *http11_redirect_302 = "HTTP/1.1 302 "; |
|
|
|
static const char http_host_find[] = "\r\nHost: "; |
|
|
|
static const char http_host_replace[] = "\r\nhoSt: "; |
|
|
|
static const char http_useragent_find[] = "\r\nUser-Agent: "; |
|
|
@ -316,32 +316,41 @@ static void mix_case(char *pktdata, unsigned int pktlen) { |
|
|
|
|
|
|
|
|
|
|
|
static int is_passivedpi_redirect(const char *pktdata, unsigned int pktlen) { |
|
|
|
/* First check if this is HTTP 302 redirect */ |
|
|
|
if (memcmp(pktdata, http11_redirect_302, sizeof(http11_redirect_302)-1) == 0 || |
|
|
|
memcmp(pktdata, http10_redirect_302, sizeof(http10_redirect_302)-1) == 0) |
|
|
|
{ |
|
|
|
/* Then check if this is a redirect to new http site with Connection: close */ |
|
|
|
if (dumb_memmem(pktdata, pktlen, location_http, sizeof(location_http)-1) && |
|
|
|
dumb_memmem(pktdata, pktlen, connection_close, sizeof(connection_close)-1)) { |
|
|
|
|
|
|
|
/* Check HTTP status code using hash table lookup */ |
|
|
|
if (http_status_code_hash(pktdata) == 302) { |
|
|
|
|
|
|
|
/* Search for location header using Boyer-Moore */ |
|
|
|
if (boyer_moore_search(pktdata, pktlen, location_http, sizeof(location_http)-1)) { |
|
|
|
|
|
|
|
/* Search for connection header using Boyer-Moore */ |
|
|
|
if (boyer_moore_search(pktdata, pktlen, connection_close, sizeof(connection_close)-1)) { |
|
|
|
return TRUE; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int find_header_and_get_info(const char *pktdata, unsigned int pktlen, |
|
|
|
const char *hdrname, |
|
|
|
char **hdrnameaddr, |
|
|
|
char **hdrvalueaddr, unsigned int *hdrvaluelen) { |
|
|
|
char *data_addr_rn; |
|
|
|
|
|
|
|
char *hdr_begin; |
|
|
|
char *data_addr_rn; |
|
|
|
|
|
|
|
*hdrvaluelen = 0u; |
|
|
|
*hdrnameaddr = NULL; |
|
|
|
*hdrvalueaddr = NULL; |
|
|
|
|
|
|
|
/* Search for the header */ |
|
|
|
hdr_begin = dumb_memmem(pktdata, pktlen, |
|
|
|
/* Search for the header using Boyer-Moore */ |
|
|
|
hdr_begin = boyer_moore_search(pktdata, pktlen, |
|
|
|
hdrname, strlen(hdrname)); |
|
|
|
if (!hdr_begin) return FALSE; |
|
|
|
if (pktdata > hdr_begin) return FALSE; |
|
|
@ -350,8 +359,8 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen, |
|
|
|
*hdrnameaddr = hdr_begin; |
|
|
|
*hdrvalueaddr = hdr_begin + strlen(hdrname); |
|
|
|
|
|
|
|
/* Search for header end (\r\n) */ |
|
|
|
data_addr_rn = dumb_memmem(*hdrvalueaddr, |
|
|
|
/* Search for header end using Boyer-Moore */ |
|
|
|
data_addr_rn = boyer_moore_search(*hdrvalueaddr, |
|
|
|
pktlen - (uintptr_t)(*hdrvalueaddr - pktdata), |
|
|
|
"\r\n", 2); |
|
|
|
if (data_addr_rn) { |
|
|
@ -359,9 +368,11 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen, |
|
|
|
if (*hdrvaluelen >= 3 && *hdrvaluelen <= HOST_MAXLEN) |
|
|
|
return TRUE; |
|
|
|
} |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Very crude Server Name Indication (TLS ClientHello hostname) extractor. |
|
|
|
*/ |
|
|
|