using System; using System.IO; using System.Net; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.Win32; namespace BlackAuth { public class ResponseData { public bool success { get; set; } = false; public string message { get; set; } = ""; public string code { get; set; } = ""; public string sig { get; set; } = ""; } public class SubscriptionData { public string subscription { get; set; } = "default"; public string expiry { get; set; } = "Lifetime"; } public class UserData { public string username { get; set; } = ""; public string ip { get; set; } = ""; public string hwid { get; set; } = ""; public string createdate { get; set; } = ""; public string lastlogin { get; set; } = ""; public List subscriptions { get; set; } = new List(); } public class api { public string name { get; set; } public string ownerid { get; set; } public string secret { get; set; } public string version { get; set; } public string url { get; set; } public string sessionid { get; private set; } public string enckey { get; private set; } public ResponseData response { get; set; } = new ResponseData(); public UserData user_data { get; set; } = new UserData(); [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)] private static extern bool IsDebuggerPresent(); [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)] private static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent); public api(string name, string ownerid, string secret, string version, string url = "https://blackauth.online/api/v1") { this.name = name; this.ownerid = ownerid; this.secret = secret; this.version = version; this.url = url.TrimEnd('/'); } // ====================================================== // Anti-Cracking & Threat Defense Subsystem // ====================================================== public bool check_security(bool autoTerminate = true) { string threat = ""; // 1. Managed & Win32 Debugger Detection if (Debugger.IsAttached || Debugger.IsLogging() || IsDebuggerPresent()) { threat = "Active debugger detected"; } // 2. Remote Debugger Attachment if (string.IsNullOrEmpty(threat)) { try { bool isRemote = false; CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isRemote); if (isRemote) threat = "Remote debugger attached"; } catch { } } // 3. Reverse Engineering & Cracking Tool Watchdog if (string.IsNullOrEmpty(threat)) { string[] blacklist = new string[] { "dnspy", "de4dot", "fiddler", "httpdebugger", "httpdebuggerui", "cheatengine", "cheatengine-x86_64", "x64dbg", "x32dbg", "ida", "ida64", "processhacker", "ksdumper", "scylla", "ilspy" }; try { foreach (Process proc in Process.GetProcesses()) { string pName = proc.ProcessName.ToLower(); foreach (string bad in blacklist) { if (pName.Contains(bad)) { threat = $"Cracking tool process detected: {proc.ProcessName}"; break; } } if (!string.IsNullOrEmpty(threat)) break; } } catch { } } if (!string.IsNullOrEmpty(threat)) { if (autoTerminate) { panic(threat); } return false; } return true; } public void panic(string threat) { // Report to enclave to auto-blacklist the intruder's IP & HWID try { if (!string.IsNullOrEmpty(sessionid)) { string hwid = get_hwid(); string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"message\":\"[SECURITY ALERT] Tamper attempt: {escape(threat)}\",\"hwid\":\"{escape(hwid)}\"}}"; post("/log", json); } } catch { } // Unrecoverable application termination Environment.FailFast($"Security Exception: {threat}"); Process.GetCurrentProcess().Kill(); } // ====================================================== // Authentication & Core Operations // ====================================================== public void init() { check_security(true); string hwid = get_hwid(); string json = $"{{\"name\":\"{escape(name)}\",\"ownerid\":\"{escape(ownerid)}\",\"secret\":\"{escape(secret)}\",\"version\":\"{escape(version)}\",\"hwid\":\"{escape(hwid)}\"}}"; string res = post("/init", json); parse_response(res); if (response.success) { sessionid = extract_json_value(res, "sessionid"); enckey = extract_json_value(res, "enckey"); } } public void license(string key) { check_security(true); if (string.IsNullOrEmpty(sessionid)) { response.success = false; response.message = "Session not initialized. Call init() first."; return; } string hwid = get_hwid(); string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"key\":\"{escape(key)}\",\"hwid\":\"{escape(hwid)}\"}}"; string res = post("/license", json); parse_response(res); if (response.success) { parse_user(res); } } public void login(string username, string password) { check_security(true); if (string.IsNullOrEmpty(sessionid)) { response.success = false; response.message = "Session not initialized. Call init() first."; return; } string hwid = get_hwid(); string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"username\":\"{escape(username)}\",\"password\":\"{escape(password)}\",\"hwid\":\"{escape(hwid)}\"}}"; string res = post("/login", json); parse_response(res); if (response.success) { parse_user(res); } } public void register(string username, string password, string key) { check_security(true); if (string.IsNullOrEmpty(sessionid)) { response.success = false; response.message = "Session not initialized. Call init() first."; return; } string hwid = get_hwid(); string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"username\":\"{escape(username)}\",\"password\":\"{escape(password)}\",\"key\":\"{escape(key)}\",\"hwid\":\"{escape(hwid)}\"}}"; string res = post("/register", json); parse_response(res); if (response.success) { parse_user(res); } } public bool check() { check_security(true); if (string.IsNullOrEmpty(sessionid)) return false; string json = $"{{\"sessionid\":\"{escape(sessionid)}\"}}"; string res = post("/check", json); parse_response(res); return response.success; } public string var(string varid) { check_security(true); if (string.IsNullOrEmpty(sessionid)) return ""; string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"varid\":\"{escape(varid)}\"}}"; string res = post("/var", json); parse_response(res); if (response.success) { return extract_json_value(res, "response"); } return ""; } public byte[] file(string fileid) { check_security(true); if (string.IsNullOrEmpty(sessionid)) return new byte[0]; string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"fileid\":\"{escape(fileid)}\"}}"; string res = post("/file", json); parse_response(res); if (response.success) { string raw = extract_json_value(res, "contents"); try { return Convert.FromBase64String(raw); } catch { return Encoding.UTF8.GetBytes(raw); } } return new byte[0]; } public void log(string message) { if (string.IsNullOrEmpty(sessionid)) return; string hwid = get_hwid(); string json = $"{{\"sessionid\":\"{escape(sessionid)}\",\"message\":\"{escape(message)}\",\"hwid\":\"{escape(hwid)}\"}}"; post("/log", json); } public static string get_hwid() { try { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Cryptography")) { if (key != null) { object guid = key.GetValue("MachineGuid"); if (guid != null) return guid.ToString(); } } } catch { } return Environment.MachineName + "_" + Environment.UserName; } private string post(string endpoint, string json) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url + endpoint); req.Method = "POST"; req.ContentType = "application/json"; req.UserAgent = "BlackAuthDotNetClient/2.4"; req.Timeout = 10000; byte[] bytes = Encoding.UTF8.GetBytes(json); req.ContentLength = bytes.Length; using (Stream stream = req.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) using (StreamReader reader = new StreamReader(resp.GetResponseStream())) { return reader.ReadToEnd(); } } catch (WebException wex) { if (wex.Response != null) { using (StreamReader reader = new StreamReader(wex.Response.GetResponseStream())) { return reader.ReadToEnd(); } } return $"{{\"success\":false,\"message\":\"{wex.Message}\"}}"; } catch (Exception ex) { return $"{{\"success\":false,\"message\":\"{ex.Message}\"}}"; } } private void parse_response(string json) { string s = extract_json_value(json, "success"); response.success = (s == "true" || s == "1"); response.message = extract_json_value(json, "message"); response.code = extract_json_value(json, "code"); response.sig = extract_json_value(json, "sig"); if (string.IsNullOrEmpty(response.message)) { response.message = extract_json_value(json, "info"); } } private void parse_user(string json) { user_data.username = extract_json_value(json, "username"); user_data.ip = extract_json_value(json, "ip"); user_data.hwid = extract_json_value(json, "hwid"); user_data.createdate = extract_json_value(json, "createdate"); user_data.lastlogin = extract_json_value(json, "lastlogin"); string subName = extract_json_value(json, "subscription"); if (string.IsNullOrEmpty(subName)) subName = "Pro"; string expiry = extract_json_value(json, "expiry"); if (string.IsNullOrEmpty(expiry)) expiry = extract_json_value(json, "expires"); if (string.IsNullOrEmpty(expiry)) expiry = "Lifetime"; user_data.subscriptions.Clear(); user_data.subscriptions.Add(new SubscriptionData { subscription = subName, expiry = expiry }); } private string extract_json_value(string json, string key) { string pattern = $"\"{key}\":\""; int idx = json.IndexOf(pattern); if (idx != -1) { idx += pattern.Length; int end = json.IndexOf("\"", idx); if (end != -1) return json.Substring(idx, end - idx); } pattern = $"\"{key}\":"; idx = json.IndexOf(pattern); if (idx != -1) { idx += pattern.Length; int end = json.IndexOfAny(new char[] { ',', '}', '\n' }, idx); if (end != -1) { return json.Substring(idx, end - idx).Trim(new char[] { ' ', '"' }); } } return ""; } private string escape(string s) { if (string.IsNullOrEmpty(s)) return ""; return s.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\n").Replace("\r", "\\r"); } } }