3 Commits
0.0.2 ... 0.0.4

Author SHA1 Message Date
ValdikSS
30fd25bc24 Replace char* with const char* where appropriate 2017-05-20 12:25:20 +03:00
ValdikSS
9fea771d2c Less invasive Passive DPI block. Fix #2. 2017-05-20 12:24:29 +03:00
ValdikSS
bb05d357a7 Fix for getopt -4 2017-05-18 00:12:49 +03:00

View File

@@ -23,18 +23,19 @@
static HANDLE filters[MAX_FILTERS]; static HANDLE filters[MAX_FILTERS];
static int filter_num = 0; static int filter_num = 0;
static const char *http_redirect_10 = "HTTP/1.0 30"; static const char *http10_redirect_302 = "HTTP/1.0 302 ";
static const char *http_redirect_11 = "HTTP/1.1 30"; static const char *http11_redirect_302 = "HTTP/1.1 302 ";
static const char *http_host_find = "\r\nHost: "; static const char *http_host_find = "\r\nHost: ";
static const char *http_host_replace = "\r\nhoSt: "; static const char *http_host_replace = "\r\nhoSt: ";
static const char *location_http = "\r\nLocation: http://";
static char* dumb_memmem(char* haystack, int hlen, char* needle, int nlen) { static char* dumb_memmem(const char* haystack, int hlen, const char* needle, int nlen) {
// naive implementation // naive implementation
if (nlen > hlen) return 0; if (nlen > hlen) return 0;
int i; int i;
for (i=0; i<hlen-nlen+1; i++) { for (i=0; i<hlen-nlen+1; i++) {
if (memcmp(haystack+i,needle,nlen)==0) { if (memcmp(haystack+i,needle,nlen)==0) {
return haystack+i; return (char*)(haystack+i);
} }
} }
return NULL; return NULL;
@@ -66,18 +67,23 @@ static void sigint_handler(int sig) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static int find_passivedpi_redirect(char *pktdata) { static int is_passivedpi_redirect(const char *pktdata, int pktlen) {
if (memcmp(pktdata, http_redirect_11, strlen(http_redirect_11)) == 0 /* First check if this is HTTP 302 redirect */
|| memcmp(pktdata, http_redirect_10, strlen(http_redirect_10)) == 0) { if (memcmp(pktdata, http11_redirect_302, strlen(http11_redirect_302)) == 0 ||
return 1; memcmp(pktdata, http10_redirect_302, strlen(http10_redirect_302)) == 0)
{
/* Then check if this is a redirect to new http site */
if (dumb_memmem(pktdata, pktlen, location_http, strlen(location_http))) {
return 1;
}
} }
return 0; return 0;
} }
/* Finds Host header with \r\n before it */ /* Finds Host header with \r\n before it */
static PVOID find_host_header(char *pktdata, int pktlen) { static PVOID find_host_header(const char *pktdata, int pktlen) {
return dumb_memmem(pktdata, pktlen, return dumb_memmem(pktdata, pktlen,
(char*)http_host_find, strlen(http_host_find)); http_host_find, strlen(http_host_find));
} }
static void change_window_size(char *pkt, int size) { static void change_window_size(char *pkt, int size) {
@@ -114,7 +120,7 @@ int main(int argc, char *argv[]) {
= do_fragment_http = do_fragment_https = 1; = do_fragment_http = do_fragment_https = 1;
} }
while ((opt = getopt(argc, argv, "123prsf:e:")) != -1) { while ((opt = getopt(argc, argv, "1234prsf:e:")) != -1) {
switch (opt) { switch (opt) {
case '1': case '1':
do_passivedpi = do_host = do_host_removespace \ do_passivedpi = do_host = do_host_removespace \
@@ -226,7 +232,7 @@ int main(int argc, char *argv[]) {
/* If INBOUND packet with DATA (tcp.Ack) */ /* If INBOUND packet with DATA (tcp.Ack) */
/* Drop packets from filter with HTTP 30x Redirect */ /* Drop packets from filter with HTTP 30x Redirect */
if (do_passivedpi && find_passivedpi_redirect(packet_data)) { if (do_passivedpi && is_passivedpi_redirect(packet_data, packet_dataLen)) {
//printf("Dropping HTTP Redirect packet!\n"); //printf("Dropping HTTP Redirect packet!\n");
should_reinject = 0; should_reinject = 0;
} }