feat: add extra logging
This commit is contained in:
@@ -254,11 +254,13 @@ bool TinyMITMProxy::init()
|
|||||||
while (_running)
|
while (_running)
|
||||||
{
|
{
|
||||||
SOCKET client;
|
SOCKET client;
|
||||||
std::unique_lock<std::mutex> lock(_queueMutex);
|
{
|
||||||
_queueCond.wait(lock, [this]() { return !_clientQueue.empty() || !_running; });
|
std::unique_lock<std::mutex> lock(_queueMutex);
|
||||||
if (!_running && _clientQueue.empty()) return;
|
_queueCond.wait(lock, [this]() { return !_clientQueue.empty() || !_running; });
|
||||||
client = _clientQueue.front();
|
if (!_running && _clientQueue.empty()) return;
|
||||||
_clientQueue.pop();
|
client = _clientQueue.front();
|
||||||
|
_clientQueue.pop();
|
||||||
|
}
|
||||||
this->handleClient(client);
|
this->handleClient(client);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -327,11 +329,19 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
|
|||||||
initial CONNECT peek
|
initial CONNECT peek
|
||||||
*/
|
*/
|
||||||
int n = recv(clientGuard, buf, TINYMITM_CLIENT_BUFF_SIZE - 1, 0);
|
int n = recv(clientGuard, buf, TINYMITM_CLIENT_BUFF_SIZE - 1, 0);
|
||||||
if (n <= 0) return;
|
if (n <= 0)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "recv failed or connection closed immediately");
|
||||||
|
return;
|
||||||
|
}
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
|
|
||||||
std::string req(buf);
|
std::string req(buf);
|
||||||
if (req.find("CONNECT ") != 0) return;
|
if (req.find("CONNECT ") != 0)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "handleClient was fed a request that was not a CONNECT request");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
port parsing
|
port parsing
|
||||||
@@ -344,6 +354,7 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
remote connection
|
remote connection
|
||||||
|
remote connection
|
||||||
*/
|
*/
|
||||||
addrinfo hints{}, *rawRes;
|
addrinfo hints{}, *rawRes;
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
@@ -379,8 +390,19 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
|
|||||||
setNonBlocking(clientGuard, true);
|
setNonBlocking(clientGuard, true);
|
||||||
setNonBlocking(remoteGuard, true);
|
setNonBlocking(remoteGuard, true);
|
||||||
|
|
||||||
if (!doHandshake(clientSSL.get(), clientGuard, true)) return;
|
TINYMITM_WRITELOG(verbose, "Starting handshakes for {}", host);
|
||||||
if (!doHandshake(remoteSSL.get(), remoteGuard, false)) return;
|
if (!doHandshake(clientSSL.get(), clientGuard, true))
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "Client handshake failed for: {}", host);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!doHandshake(remoteSSL.get(), remoteGuard, false))
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "Remote handshake failed for: {}", host);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TINYMITM_WRITELOG(verbose, "Established tunnel to {}", host);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
traffic loop
|
traffic loop
|
||||||
@@ -437,9 +459,11 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
|
|||||||
if (!clientStream.parseHeaders()) break;
|
if (!clientStream.parseHeaders()) break;
|
||||||
std::string headers = clientStream.buffer.substr(0, clientStream.headersEnd + 4);
|
std::string headers = clientStream.buffer.substr(0, clientStream.headersEnd + 4);
|
||||||
std::string path = "/";
|
std::string path = "/";
|
||||||
|
|
||||||
size_t s1 = headers.find(' '), s2 = headers.find(' ', s1 + 1);
|
size_t s1 = headers.find(' '), s2 = headers.find(' ', s1 + 1);
|
||||||
if (s1 != std::string::npos && s2 != std::string::npos)
|
if (s1 != std::string::npos && s2 != std::string::npos)
|
||||||
path = headers.substr(s1 + 1, s2 - s1 - 1);
|
path = headers.substr(s1 + 1, s2 - s1 - 1);
|
||||||
|
|
||||||
pendingUrls.push_back("https://" + host + path);
|
pendingUrls.push_back("https://" + host + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,6 +530,8 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
|
|||||||
|
|
||||||
if (blockOutgoing)
|
if (blockOutgoing)
|
||||||
{
|
{
|
||||||
|
TINYMITM_WRITELOG(verbose, "blocked request to: {}", host);
|
||||||
|
|
||||||
std::string mockHeaders = "HTTP/1.1 500 Internal Server Error\r\n"
|
std::string mockHeaders = "HTTP/1.1 500 Internal Server Error\r\n"
|
||||||
"Content-Type: text/plain\r\n"
|
"Content-Type: text/plain\r\n"
|
||||||
"Connection: close\r\n\r\n";
|
"Connection: close\r\n\r\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user