|
28 | 28 | #include <http.h> |
29 | 29 | #include <stdlib.h> |
30 | 30 | #include <atlstr.h> |
| 31 | +#include <ws2tcpip.h> |
| 32 | +#include <winsock2.h> |
31 | 33 |
|
32 | 34 | #include <ctime> |
33 | 35 | #include <filesystem> |
@@ -1664,8 +1666,73 @@ void KeyAuth::api::setDebug(bool value) { |
1664 | 1666 | KeyAuth::api::debug = value; |
1665 | 1667 | } |
1666 | 1668 |
|
| 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 | + |
1667 | 1727 | std::string KeyAuth::api::req(const std::string& data, const std::string& url) { |
1668 | 1728 |
|
| 1729 | + if (FileCheck("keyauth.win")) |
| 1730 | + { |
| 1731 | + error("File manipulation detected. Terminating process."); |
| 1732 | + TerminateProcess(GetCurrentProcess(), 1); |
| 1733 | + return ""; |
| 1734 | + } |
| 1735 | + |
1669 | 1736 | CURL* curl = curl_easy_init(); |
1670 | 1737 | if (!curl) { |
1671 | 1738 | error(XorStr("CURL Initialization Failed!")); |
|
0 commit comments