Skip to content

Commit 2b78990

Browse files
authored
Added goto cleanup and fixed conflict (#285)
1 parent 0ff4088 commit 2b78990

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

al-khaser/Al-khaser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int main(int argc, char* argv[])
185185
exec_check(&disk_size_getdiskfreespace, TEXT("Checking disk size using GetDiskFreeSpaceEx "));
186186
exec_check(&cpuid_is_hypervisor, TEXT("Checking if CPU hypervisor field is set using cpuid(0x1)"));
187187
exec_check(&cpuid_hypervisor_vendor, TEXT("Checking hypervisor vendor using cpuid(0x40000000)"));
188+
exec_check(&hosting_check, TEXT("Check if Machine is hosted on Cloud"));
188189
exec_check(&accelerated_sleep, TEXT("Check if time has been accelerated "));
189190
exec_check(&VMDriverServices, TEXT("VM Driver Services "));
190191
exec_check(&serial_number_bios_wmi, TEXT("Checking SerialNumber from BIOS using WMI "));

al-khaser/AntiVM/Generic.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,3 +2094,84 @@ BOOL firmware_ACPI_WAET()
20942094
}
20952095
return result;
20962096
}
2097+
2098+
/*
2099+
Check if machine is hosted on Cloud.
2100+
*/
2101+
2102+
BOOL hosting_check()
2103+
{
2104+
TCHAR msg[256] = _T("Checking if Machine is hosted on Cloud");
2105+
WSADATA wsaData;
2106+
SOCKET sock = INVALID_SOCKET;
2107+
addrinfo* result = nullptr;
2108+
addrinfo hints;
2109+
BOOL retVal = FALSE;
2110+
std::string request;
2111+
std::string response;
2112+
const int bufferSize = 512;
2113+
char buffer[bufferSize];
2114+
int bytesReceived = 0;
2115+
2116+
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
2117+
{
2118+
goto cleanup;
2119+
}
2120+
2121+
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
2122+
if (sock == INVALID_SOCKET)
2123+
{
2124+
goto cleanup;
2125+
}
2126+
2127+
2128+
memset(&hints, 0, sizeof(hints));
2129+
hints.ai_family = AF_INET;
2130+
hints.ai_socktype = SOCK_STREAM;
2131+
hints.ai_protocol = IPPROTO_TCP;
2132+
2133+
if (getaddrinfo("ip-api.com", "80", &hints, &result) != 0)
2134+
{
2135+
goto cleanup;
2136+
}
2137+
2138+
if (connect(sock, result->ai_addr, static_cast<int>(result->ai_addrlen)) == SOCKET_ERROR)
2139+
{
2140+
goto cleanup;
2141+
}
2142+
2143+
request = "GET /json/?fields=hosting HTTP/1.1\r\n";
2144+
request += "Host: ip-api.com\r\n";
2145+
request += "Connection: close\r\n\r\n";
2146+
2147+
if (send(sock, request.c_str(), static_cast<int>(request.length()), 0) == SOCKET_ERROR)
2148+
{
2149+
goto cleanup;
2150+
}
2151+
2152+
do
2153+
{
2154+
bytesReceived = recv(sock, buffer, bufferSize - 1, 0);
2155+
if (bytesReceived > 0)
2156+
{
2157+
buffer[bytesReceived] = '\0';
2158+
response += buffer;
2159+
}
2160+
} while (bytesReceived > 0);
2161+
2162+
if (bytesReceived == SOCKET_ERROR)
2163+
{
2164+
goto cleanup;
2165+
}
2166+
2167+
if (response.find("\"hosting\":true") != std::string::npos)
2168+
{
2169+
retVal = TRUE;
2170+
}
2171+
2172+
cleanup:
2173+
if (result) freeaddrinfo(result);
2174+
if (sock != INVALID_SOCKET) closesocket(sock);
2175+
WSACleanup();
2176+
return retVal;
2177+
}

al-khaser/AntiVM/Generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ BOOL registry_services_disk_enum();
5151
BOOL registry_disk_enum();
5252
BOOL number_SMBIOS_tables();
5353
BOOL firmware_ACPI_WAET();
54+
BOOL hosting_check();

al-khaser/pch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <vector>
1818
#include <filesystem>
1919

20+
#include <winsock2.h>
21+
#include <ws2tcpip.h>
2022
#include <Windows.h>
2123
#include <winternl.h>
2224
#include <stdio.h>
@@ -44,7 +46,9 @@
4446
#include <algorithm>
4547
#include <cctype>
4648
#include <slpublic.h> // SLIsGenuineLocal
49+
#include <ipmib.h>
4750

51+
#pragma comment(lib, "Ws2_32.lib")
4852
#pragma comment(lib, "wbemuuid.lib")
4953
#pragma comment(lib, "Shlwapi.lib")
5054
#pragma comment(lib, "Mpr.lib")

0 commit comments

Comments
 (0)