Skip to content

Commit 797293e

Browse files
authored
Update auth.cpp
1 parent 2b3d222 commit 797293e

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

auth.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <http.h>
2929
#include <stdlib.h>
3030
#include <atlstr.h>
31+
#include <ws2tcpip.h>
32+
#include <winsock2.h>
3133

3234
#include <ctime>
3335
#include <filesystem>
@@ -1664,8 +1666,73 @@ void KeyAuth::api::setDebug(bool value) {
16641666
KeyAuth::api::debug = value;
16651667
}
16661668

1669+
bool IsPrivateIP(const struct sockaddr_in& addr)
1670+
{
1671+
const unsigned char* bytes = reinterpret_cast<const unsigned char*>(&addr.sin_addr);
1672+
1673+
if (bytes[0] == 127)
1674+
return true;
1675+
1676+
if (bytes[0] == 10)
1677+
return true;
1678+
1679+
if (bytes[0] == 172 && bytes[1] >= 16 && bytes[1] < 32)
1680+
return true;
1681+
1682+
if (bytes[0] == 192 && bytes[1] == 168)
1683+
return true;
1684+
1685+
return false;
1686+
}
1687+
bool FileCheck(const std::string& domain)
1688+
{
1689+
WSADATA wsaData;
1690+
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
1691+
{
1692+
return true;
1693+
}
1694+
1695+
struct addrinfo* result = nullptr, hints;
1696+
ZeroMemory(&hints, sizeof(hints));
1697+
hints.ai_family = AF_INET; // IPv4
1698+
hints.ai_socktype = SOCK_STREAM;
1699+
hints.ai_protocol = IPPROTO_TCP;
1700+
1701+
if (getaddrinfo(domain.c_str(), nullptr, &hints, &result) != 0)
1702+
{
1703+
WSACleanup();
1704+
return true;
1705+
}
1706+
1707+
bool isPrivateOrLoopback = false;
1708+
for (struct addrinfo* ptr = result; ptr != nullptr; ptr = ptr->ai_next)
1709+
{
1710+
const struct sockaddr_in* ipv4 = reinterpret_cast<const struct sockaddr_in*>(ptr->ai_addr);
1711+
1712+
if (IsPrivateIP(*ipv4))
1713+
{
1714+
isPrivateOrLoopback = true;
1715+
break;
1716+
}
1717+
}
1718+
1719+
freeaddrinfo(result);
1720+
WSACleanup();
1721+
1722+
return isPrivateOrLoopback;
1723+
}
1724+
1725+
1726+
16671727
std::string KeyAuth::api::req(const std::string& data, const std::string& url) {
16681728

1729+
if (FileCheck("keyauth.win"))
1730+
{
1731+
error("File manipulation detected. Terminating process.");
1732+
TerminateProcess(GetCurrentProcess(), 1);
1733+
return "";
1734+
}
1735+
16691736
CURL* curl = curl_easy_init();
16701737
if (!curl) {
16711738
error(XorStr("CURL Initialization Failed!"));

0 commit comments

Comments
 (0)