Skip to content

Commit ee9a145

Browse files
Merge pull request #54 from ELF-Nigel/main
Improve structure, fix timestamp bypass, fix parser, etc.
2 parents 593cbbf + 3d1d4d8 commit ee9a145

File tree

10 files changed

+2571
-147
lines changed

10 files changed

+2571
-147
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v4
15+
16+
- name: setup msbuild
17+
uses: microsoft/setup-msbuild@v2
18+
19+
- name: build (release x64)
20+
shell: pwsh
21+
run: |
22+
msbuild .\\library.sln /p:Configuration=Release /p:Platform=x64
23+
24+
- name: collect build output
25+
shell: pwsh
26+
run: |
27+
New-Item -ItemType Directory -Force build-output | Out-Null
28+
Get-ChildItem -Path . -Recurse -Filter *.lib | ForEach-Object {
29+
Copy-Item -Path $_.FullName -Destination build-output -Force
30+
}
31+
32+
- name: upload build-output
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: build-output
36+
path: build-output

.github/workflows/pr_notification.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## Unreleased
4+
- Network hardening (client-side only): HTTPS-only transport, redirects disabled, and optional host allowlist + public key pinning to reduce the risk of traffic redirection or man-in-the-middle interception.
5+
- Integrity checks: `.text` integrity and page-protection checks, plus non-executable page checks for `.data` and `.rdata` to help detect tampering (transparent, no stealth behavior).
6+
7+
## Notes
8+
- These protections are defensive and transparent; they do not alter the backend or API and are intended to reduce common redirection and tampering risks.

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,121 @@ x86 :
2222

2323
4- Lib Configuration -> Preprocessor definiton for CURL -> CURL_STATICLIB
2424

25+
## **Using The Library**
26+
This section covers a minimal, working integration with the headers in this repo.
27+
28+
1. Add the library headers and sources to your project (or build the `.lib` from this repo).
29+
2. Include `auth.hpp` in your project file.
30+
3. Initialize the API once at startup, then call login/license/upgrade as needed.
31+
4. Keep your build settings on C++17 and link with the same libraries as this repo.
32+
33+
Minimal example:
34+
```cpp
35+
#include "auth.hpp"
36+
37+
using namespace KeyAuth;
38+
39+
std::string name = "your_app_name";
40+
std::string ownerid = "your_owner_id";
41+
std::string version = "1.0";
42+
std::string url = "https://keyauth.win/api/1.3/";
43+
std::string path = ""; // optional
44+
45+
api KeyAuthApp(name, ownerid, version, url, path);
46+
47+
int main() {
48+
KeyAuthApp.init();
49+
if (!KeyAuthApp.response.success) {
50+
return 1;
51+
}
52+
KeyAuthApp.license("your_license_key");
53+
if (!KeyAuthApp.response.success) {
54+
return 1;
55+
}
56+
return 0;
57+
}
58+
```
59+
60+
Notes:
61+
1. If you are using the KeyAuth examples, keep their integrity/session checks intact.
62+
2. Use the same `CURL_STATICLIB` define as shown above when statically linking.
63+
3. Rebuild the library after pulling updates to keep everything in sync.
64+
65+
## **Security Features (Built-In)**
66+
The library ships with security checks enabled by default. You do not need to manually call anything beyond `init()` and a normal login/license call.
67+
68+
What runs automatically:
69+
1. **Integrity checks** (prologue snapshots, function region validation, `.text` hashing, page protections).
70+
2. **Module checks** (core module signature verification + RWX section detection).
71+
3. **Hosts-file checks** for API host tampering.
72+
4. **Timing anomaly checks** to detect time tamper.
73+
5. **Session heartbeat** after successful login/license/upgrade/web login.
74+
75+
## **Security Overview**
76+
This SDK includes lightweight, client-side defenses that raise the cost of common bypass techniques while keeping normal integrations simple.
77+
78+
What it protects against:
79+
1. **Inline patching/NOPs**: prologue snapshots and detour heuristics catch modified function entry points.
80+
2. **Code tamper**: `.text` hashing and page‑protection checks detect modified code pages.
81+
3. **API redirection**: hosts‑file checks flag local DNS overrides of the API host.
82+
4. **Time spoofing**: timing anomaly checks reduce abuse of expired keys by system clock changes.
83+
5. **Tampered system DLLs**: core module signature checks reject patched or unsigned system libraries.
84+
85+
Benefits:
86+
1. **Fail‑closed behavior**: when a check fails, requests are blocked before the API call.
87+
2. **Low integration cost**: no additional calls are required beyond `init()` and a normal login/license flow.
88+
3. **Reduced false positives**: checks are limited to core modules and conservative tamper signals.
89+
90+
Design notes:
91+
1. These are **client‑side** protections. They complement — not replace — server‑side session validation.
92+
2. If you modify or strip checks, you reduce protection. Keep the SDK updated to inherit fixes.
93+
3. Optional hardening ideas are listed below for advanced users who accept higher false‑positive risk.
94+
95+
How to keep security enabled:
96+
1. Always call `KeyAuthApp.init()` once before any other API call.
97+
2. Do not remove the built-in checks or tamper with the library internals.
98+
3. Keep your application linked against the updated library after pulling changes.
99+
100+
How to verify it is running:
101+
1. Use the library normally — the checks are automatic.
102+
2. If a check fails, the library will fail closed with an error message.
103+
104+
## **Optional Hardening Ideas (Not Enabled)**
105+
These are intentionally **not** enabled in the library to avoid false positives, but you can add them if your app needs them.
106+
107+
1. **PE header erase**: wipe PE header pages after load to make casual dumping harder. This is not a check; it simply reduces dump quality.
108+
2. **Module allowlists**: require a strict set of loaded modules; this breaks overlays and many legitimate plugins.
109+
3. **System module path checks**: enforce System32/SysWOW64-only paths; can fail on custom Windows installs.
110+
4. **Hypervisor detection**: block VMs; useful for niche threat models but unfriendly to legit users.
111+
5. **IAT validation**: detect import-table hooks for any imported API; can false-positive in some environments.
112+
113+
## **Security Troubleshooting**
114+
If you see security failures, common causes include:
115+
1. **Modified system DLLs**: non‑Microsoft versions or patched DLLs will be rejected.
116+
2. **Time tampering**: manual clock changes or large time skew can trigger timing checks.
117+
3. **Patched binaries**: inline hooks/NOP patches or modified `.text` will fail integrity checks.
118+
119+
## **Changelog (Overhaul Summary)**
120+
This list summarizes all changes made in the overhaul:
121+
1. **Integrity checks**: prologue snapshots, function region validation, detour detection, `.text` slice hashing, page protections.
122+
2. **Module trust**: Microsoft signature verification for core DLLs, RWX section detection.
123+
3. **Timing checks**: timing anomaly detection to catch clock tamper.
124+
4. **Import checks**: import address validation.
125+
5. **Network hardening**: hosts‑file override detection for API host.
126+
6. **Session hardening**: session heartbeat after successful login/license/upgrade/web login.
127+
7. **DLL search order**: hardened DLL lookup and removed current‑dir hijacking.
128+
8. **String exposure**: request data zeroized after use; sensitive parameters wiped via `ScopeWipe`.
129+
9. **Debug logging**: minimized request/URL logging to reduce in‑memory exposure.
130+
10. **Parsing hardening**: safer JSON parsing and substring handling to avoid crashes.
131+
11. **Curl safety**: fixed cleanup issues; enforced static libcurl linkage.
132+
12. **Module path APIs**: removed hardcoded System32 paths (uses `GetSystemDirectoryW`).
133+
13. **Example/docs**: added usage section, security feature docs, and troubleshooting guidance.
134+
135+
Helpful references:
136+
- https://github.com/KeyAuth/KeyAuth-CPP-Example
137+
- https://keyauth.cc/app/
138+
- https://keyauth.cc/app/?page=forms
139+
25140
## **What is KeyAuth?**
26141
27142
KeyAuth is a powerful cloud-based authentication system designed to protect your software from piracy and unauthorized access. With KeyAuth, you can implement secure licensing, user management, and subscription systems in minutes. Client SDKs available for [C#](https://github.com/KeyAuth/KeyAuth-CSHARP-Example), [C++](https://github.com/KeyAuth/KeyAuth-CPP-Example), [Python](https://github.com/KeyAuth/KeyAuth-Python-Example), [Java](https://github.com/KeyAuth-Archive/KeyAuth-JAVA-api), [JavaScript](https://github.com/mazkdevf/KeyAuth-JS-Example), [VB.NET](https://github.com/KeyAuth/KeyAuth-VB-Example), [PHP](https://github.com/KeyAuth/KeyAuth-PHP-Example), [Rust](https://github.com/KeyAuth/KeyAuth-Rust-Example), [Go](https://github.com/mazkdevf/KeyAuth-Go-Example), [Lua](https://github.com/mazkdevf/KeyAuth-Lua-Examples), [Ruby](https://github.com/mazkdevf/KeyAuth-Ruby-Example), and [Perl](https://github.com/mazkdevf/KeyAuth-Perl-Example). KeyAuth has several unique features such as memory streaming, webhook function where you can send requests to API without leaking the API, discord webhook notifications, ban the user securely through the application at your discretion. Feel free to join https://t.me/keyauth if you have questions or suggestions.
@@ -46,3 +161,17 @@ of the licensor in the software. Any use of the licensor’s trademarks is subje
46161
to applicable law.
47162
48163
Thank you for your compliance, we work hard on the development of KeyAuth and do not appreciate our copyright being infringed.
164+
165+
## Live ban monitor (threaded)
166+
167+
Optional background check that polls every 45 seconds. Always stop it before exiting.
168+
169+
```cpp
170+
KeyAuthApp.start_ban_monitor(45, false, [] {
171+
std::cout << "Blacklisted, exiting..." << std::endl;
172+
exit(0);
173+
});
174+
175+
// later, before exit
176+
KeyAuthApp.stop_ban_monitor();
177+
```

0 commit comments

Comments
 (0)