From 7f94c6c03d00b9151b1003a489506500d6ef4237 Mon Sep 17 00:00:00 2001 From: Xre0uS Date: Thu, 3 Jul 2025 00:03:46 +0800 Subject: [PATCH] Properly close connection handles on WinINet errors --- .../src_beacon/beacon/ConnectorHTTP.cpp | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Extenders/agent_beacon/src_beacon/beacon/ConnectorHTTP.cpp b/Extenders/agent_beacon/src_beacon/beacon/ConnectorHTTP.cpp index 3a53d707..4c99378b 100644 --- a/Extenders/agent_beacon/src_beacon/beacon/ConnectorHTTP.cpp +++ b/Extenders/agent_beacon/src_beacon/beacon/ConnectorHTTP.cpp @@ -229,19 +229,17 @@ void ConnectorHTTP::SendData(BYTE* data, ULONG data_size) attempt++; if (!connected) { - if ( dwError == ERROR_INTERNET_CANNOT_CONNECT || dwError == ERROR_INTERNET_TIMEOUT ) { - if (this->hConnect) { - this->functions->InternetCloseHandle(this->hConnect); - this->hConnect = NULL; - } - if (this->hInternet) { - this->functions->InternetCloseHandle(this->hInternet); - this->hInternet = NULL; - } - - this->functions->InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); - this->functions->InternetSetOptionA(NULL, INTERNET_OPTION_REFRESH, NULL, 0); + if (this->hConnect) { + this->functions->InternetCloseHandle(this->hConnect); + this->hConnect = NULL; } + if (this->hInternet) { + this->functions->InternetCloseHandle(this->hInternet); + this->hInternet = NULL; + } + + this->functions->InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); + this->functions->InternetSetOptionA(NULL, INTERNET_OPTION_REFRESH, NULL, 0); this->server_index = (this->server_index + 1) % this->server_count; } @@ -283,4 +281,4 @@ void ConnectorHTTP::CloseConnector() this->functions->InternetCloseHandle(this->hInternet); this->functions->InternetCloseHandle(this->hConnect); -} \ No newline at end of file +}