diff --git a/src/network.cpp b/src/network.cpp index cc8ab8f..b41bf77 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -5,43 +5,9 @@ #include #include -void TestSockets(int sender_s, int receiver_s) { - char in_buf[BUF_SIZE]; // Input buffer for GET resquest - char out_buf[BUF_SIZE]; // Output buffer for HTML response - ssize_t buf_len; // Buffer length for file reads - // - // Pass GET along from browser to server - std::cout << "Attempting to send data to receiver" << std::endl; - do { - buf_len = recv(sender_s, in_buf, BUF_SIZE, 0); - std::cout << "LOG (info) - pipe packet recv size: " << buf_len << std::endl; - if (buf_len == -1) { - std::cout << "ERROR (info) - recv" << std::endl; - return; - } - if (buf_len == 0) { break; } - buf_len = send(receiver_s, in_buf, buf_len, 0); - std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl; - } while (buf_len == BUF_SIZE); - std::cout << "Sent data to receiver" << std::endl; - - // Pass response along from server to browser - std::cout << "Attempting to send to browser" << std::endl; - do { - buf_len = recv(sender_s, out_buf, BUF_SIZE, 0); - std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl; - if (buf_len == -1) { - std::cout << "ERROR (info) - recv" << std::endl; - return; - } - if (buf_len == 0) { break; } - buf_len = send(receiver_s, out_buf, buf_len, 0); - std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl; - } while (buf_len == BUF_SIZE); - std::cout << "Sent to browser" << std::endl; - close(sender_s); - close(receiver_s); -} +// Hazardous globals +char hazardous_contents_CS_01[256] = "password.txt"; +char hazardous_contents_CS_02[256] = "admin.config"; void PipeSockets(int sender_s, int receiver_s) { char in_buf[BUF_SIZE]; // Input buffer for GET resquest @@ -61,6 +27,16 @@ void PipeSockets(int sender_s, int receiver_s) { } if (buf_len == 0) { continue; } + // Hazardous check + if ((strstr(in_buf, hazardous_contents_CS_01) != NULL) + || (strstr(in_buf, hazardous_contents_CS_02) != NULL)) { + std::cerr << "LOG (warn) - Hazardous contents detected" << std::endl; + strcpy(in_buf, FORBIDDEN_403); + send(receiver_s, in_buf, strlen(in_buf), 0); + strcpy(in_buf, MESS_403); + send(receiver_s, in_buf, strlen(in_buf), 0); + } + // Send buf_len = send(receiver_s, in_buf, buf_len, 0); std::cout << "LOG (info) - pipe packet send size: " << buf_len << '\n'; @@ -84,6 +60,16 @@ void ProxySockets(int sender_s, int receiver_s) { return; } + // Hazardous check + if ((strstr(out_buf, hazardous_contents_CS_01) != NULL) + || (strstr(out_buf, hazardous_contents_CS_02) != NULL)) { + std::cerr << "LOG (warn) - Hazardous contents detected" << std::endl; + strcpy(out_buf, FORBIDDEN_403); + send(receiver_s, out_buf, strlen(out_buf), 0); + strcpy(out_buf, MESS_403); + send(receiver_s, out_buf, strlen(out_buf), 0); + } + // Send buf_len = send(receiver_s, out_buf, buf_len, 0); if (buf_len == 96) { break; } diff --git a/src/network.hpp b/src/network.hpp index bcab3d9..f3c6ac3 100644 --- a/src/network.hpp +++ b/src/network.hpp @@ -9,8 +9,13 @@ #define kProxyPort 9080 #define kWebserverIP "127.0.0.1" #define kWebserverPort 7080 +#define FORBIDDEN_403 "HTTP/1.0 403 Forbidden\nContent-Type:text/html\n\n" +#define MESS_403 "

FORBIDDEN ACCESS

" + +// Hazardous globals +extern char hazardous_contents_CS_01[256]; +extern char hazardous_contents_CS_02[256]; -void TestSockets(int sender_s, int receiver_s); void PipeSockets(int sender_s, int receiver_s); void ProxySockets(int sender_s, int receiver_s); diff --git a/src/proxy.cpp b/src/proxy.cpp index 980c8f8..4b66ef9 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -1,18 +1,15 @@ //----- Include files --------------------------------------------------------- #include +#include #include #include #include #include "network.hpp" -//----- HTTP response messages ---------------------------------------------- -#define OK_IMAGE "HTTP/1.0 200 OK\nContent-Type:image/gif\n\n" -#define OK_TEXT "HTTP/1.0 200 OK\nContent-Type:text/html\n\n" -#define NOTOK_404 "HTTP/1.0 404 Not Found\nContent-Type:text/html\n\n" -#define MESS_404 "

FILE NOT FOUND

" - int main(void) { + strcpy(hazardous_contents_CS_01, "password.txt"); + strcpy(hazardous_contents_CS_02, "admin.config"); std::vector> pending_futures; Server proxy(kProxyPort); Client browser; diff --git a/src/web_server.cpp b/src/web_server.cpp index 595a8d5..6eaa5da 100644 --- a/src/web_server.cpp +++ b/src/web_server.cpp @@ -34,7 +34,6 @@ #include // Needed for strcpy() and strlen() #include // Needed for file i/o constants #include // Needed for file i/o constants -#include #include #include #include