Skip to content

Function to check local rquests #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <http.h>
#include <stdlib.h>
#include <atlstr.h>
#include <ws2tcpip.h>
#include <winsock2.h>

#include <ctime>
#include <filesystem>
Expand Down Expand Up @@ -1664,8 +1666,73 @@ void KeyAuth::api::setDebug(bool value) {
KeyAuth::api::debug = value;
}

bool IsPrivateIP(const struct sockaddr_in& addr)
{
const unsigned char* bytes = reinterpret_cast<const unsigned char*>(&addr.sin_addr);

if (bytes[0] == 127)
return true;

if (bytes[0] == 10)
return true;

if (bytes[0] == 172 && bytes[1] >= 16 && bytes[1] < 32)
return true;

if (bytes[0] == 192 && bytes[1] == 168)
return true;

return false;
}
bool FileCheck(const std::string& domain)
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
return true;
}

struct addrinfo* result = nullptr, hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET; // IPv4
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

if (getaddrinfo(domain.c_str(), nullptr, &hints, &result) != 0)
{
WSACleanup();
return true;
}

bool isPrivateOrLoopback = false;
for (struct addrinfo* ptr = result; ptr != nullptr; ptr = ptr->ai_next)
{
const struct sockaddr_in* ipv4 = reinterpret_cast<const struct sockaddr_in*>(ptr->ai_addr);

if (IsPrivateIP(*ipv4))
{
isPrivateOrLoopback = true;
break;
}
}

freeaddrinfo(result);
WSACleanup();

return isPrivateOrLoopback;
}



std::string KeyAuth::api::req(const std::string& data, const std::string& url) {

if (FileCheck("keyauth.win"))
{
error("File manipulation detected. Terminating process.");
TerminateProcess(GetCurrentProcess(), 1);
return "";
}

CURL* curl = curl_easy_init();
if (!curl) {
error(XorStr("CURL Initialization Failed!"));
Expand Down