From adc4eb0ba9ab646af7981d4c38dbec5545f357fc Mon Sep 17 00:00:00 2001 From: Ahsan-Ullah <69212320+TechQaiser@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:15:09 +0500 Subject: [PATCH 1/3] Add files via upload Python key Auth example package. Fixed Errors & Divided Code in separate files for easy use. removed main.py >> example.py, basically its not main its example file. added multpile options in example.py so users can select and understand the code they want to use easily. updated README.md file also with this new package functions & objects. easy to use . --- LICENSE | 186 ++-- README.md | 629 +++++------ example.py | 126 +++ keyauth/__init__.py | 28 + keyauth/api.py | 567 ++++++++++ keyauth/hwid.py | 65 ++ keyauth/req.py | 47 + other-examples/README.md | 52 +- other-examples/merged_example.py | 1732 ++++++++++++++--------------- other-examples/method1.py | 1750 ++++++++++++++--------------- other-examples/method2.py | 1752 +++++++++++++++--------------- other-examples/method3.py | 616 +++++++++++ requirements.txt | 3 +- 13 files changed, 4506 insertions(+), 3047 deletions(-) create mode 100644 example.py create mode 100644 keyauth/__init__.py create mode 100644 keyauth/api.py create mode 100644 keyauth/hwid.py create mode 100644 keyauth/req.py create mode 100644 other-examples/method3.py diff --git a/LICENSE b/LICENSE index 809108b..fef6f0d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,93 +1,93 @@ -Elastic License 2.0 - -URL: https://www.elastic.co/licensing/elastic-license - -## Acceptance - -By using the software, you agree to all of the terms and conditions below. - -## Copyright License - -The licensor grants you a non-exclusive, royalty-free, worldwide, -non-sublicensable, non-transferable license to use, copy, distribute, make -available, and prepare derivative works of the software, in each case subject to -the limitations and conditions below. - -## Limitations - -You may not provide the software to third parties as a hosted or managed -service, where the service provides users with access to any substantial set of -the features or functionality of the software. - -You may not move, change, disable, or circumvent the license key functionality -in the software, and you may not remove or obscure any functionality in the -software that is protected by the license key. - -You may not alter, remove, or obscure any licensing, copyright, or other notices -of the licensor in the software. Any use of the licensor’s trademarks is subject -to applicable law. - -## Patents - -The licensor grants you a license, under any patent claims the licensor can -license, or becomes able to license, to make, have made, use, sell, offer for -sale, import and have imported the software, in each case subject to the -limitations and conditions in this license. This license does not cover any -patent claims that you cause to be infringed by modifications or additions to -the software. If you or your company make any written claim that the software -infringes or contributes to infringement of any patent, your patent license for -the software granted under these terms ends immediately. If your company makes -such a claim, your patent license ends immediately for work on behalf of your -company. - -## Notices - -You must ensure that anyone who gets a copy of any part of the software from you -also gets a copy of these terms. - -If you modify the software, you must include in any modified copies of the -software prominent notices stating that you have modified the software. - -## No Other Rights - -These terms do not imply any licenses other than those expressly granted in -these terms. - -## Termination - -If you use the software in violation of these terms, such use is not licensed, -and your licenses will automatically terminate. If the licensor provides you -with a notice of your violation, and you cease all violation of this license no -later than 30 days after you receive that notice, your licenses will be -reinstated retroactively. However, if you violate these terms after such -reinstatement, any additional violation of these terms will cause your licenses -to terminate automatically and permanently. - -## No Liability - -*As far as the law allows, the software comes as is, without any warranty or -condition, and the licensor will not be liable to you for any damages arising -out of these terms or the use or nature of the software, under any kind of -legal claim.* - -## Definitions - -The **licensor** is the entity offering these terms, and the **software** is the -software the licensor makes available under these terms, including any portion -of it. - -**you** refers to the individual or entity agreeing to these terms. - -**your company** is any legal entity, sole proprietorship, or other kind of -organization that you work for, plus all organizations that have control over, -are under the control of, or are under common control with that -organization. **control** means ownership of substantially all the assets of an -entity, or the power to direct its management and policies by vote, contract, or -otherwise. Control can be direct or indirect. - -**your licenses** are all the licenses granted to you for the software under -these terms. - -**use** means anything you do with the software requiring one of your licenses. - -**trademark** means trademarks, service marks, and similar rights. +Elastic License 2.0 + +URL: https://www.elastic.co/licensing/elastic-license + +## Acceptance + +By using the software, you agree to all of the terms and conditions below. + +## Copyright License + +The licensor grants you a non-exclusive, royalty-free, worldwide, +non-sublicensable, non-transferable license to use, copy, distribute, make +available, and prepare derivative works of the software, in each case subject to +the limitations and conditions below. + +## Limitations + +You may not provide the software to third parties as a hosted or managed +service, where the service provides users with access to any substantial set of +the features or functionality of the software. + +You may not move, change, disable, or circumvent the license key functionality +in the software, and you may not remove or obscure any functionality in the +software that is protected by the license key. + +You may not alter, remove, or obscure any licensing, copyright, or other notices +of the licensor in the software. Any use of the licensor’s trademarks is subject +to applicable law. + +## Patents + +The licensor grants you a license, under any patent claims the licensor can +license, or becomes able to license, to make, have made, use, sell, offer for +sale, import and have imported the software, in each case subject to the +limitations and conditions in this license. This license does not cover any +patent claims that you cause to be infringed by modifications or additions to +the software. If you or your company make any written claim that the software +infringes or contributes to infringement of any patent, your patent license for +the software granted under these terms ends immediately. If your company makes +such a claim, your patent license ends immediately for work on behalf of your +company. + +## Notices + +You must ensure that anyone who gets a copy of any part of the software from you +also gets a copy of these terms. + +If you modify the software, you must include in any modified copies of the +software prominent notices stating that you have modified the software. + +## No Other Rights + +These terms do not imply any licenses other than those expressly granted in +these terms. + +## Termination + +If you use the software in violation of these terms, such use is not licensed, +and your licenses will automatically terminate. If the licensor provides you +with a notice of your violation, and you cease all violation of this license no +later than 30 days after you receive that notice, your licenses will be +reinstated retroactively. However, if you violate these terms after such +reinstatement, any additional violation of these terms will cause your licenses +to terminate automatically and permanently. + +## No Liability + +*As far as the law allows, the software comes as is, without any warranty or +condition, and the licensor will not be liable to you for any damages arising +out of these terms or the use or nature of the software, under any kind of +legal claim.* + +## Definitions + +The **licensor** is the entity offering these terms, and the **software** is the +software the licensor makes available under these terms, including any portion +of it. + +**you** refers to the individual or entity agreeing to these terms. + +**your company** is any legal entity, sole proprietorship, or other kind of +organization that you work for, plus all organizations that have control over, +are under the control of, or are under common control with that +organization. **control** means ownership of substantially all the assets of an +entity, or the power to direct its management and policies by vote, contract, or +otherwise. Control can be direct or indirect. + +**your licenses** are all the licenses granted to you for the software under +these terms. + +**use** means anything you do with the software requiring one of your licenses. + +**trademark** means trademarks, service marks, and similar rights. diff --git a/README.md b/README.md index 8a3cc9f..daa22db 100644 --- a/README.md +++ b/README.md @@ -1,309 +1,320 @@ -# KeyAuth-Python-Example : Please star 🌟 - -KeyAuth Python example SDK for https://keyauth.cc license key API auth. - -## **Bugs** - -If you are using our example with no significant changes, and you are having problems, please Report Bug here https://keyauth.cc/app/?page=forms - -However, we do **NOT** provide support for adding KeyAuth to your project. If you can't figure this out you should use Google or YouTube to learn more about the programming language you want to sell a program in. - -## Copyright License - -KeyAuth is licensed under **Elastic License 2.0** - -* You may not provide the software to third parties as a hosted or managed -service, where the service provides users with access to any substantial set of -the features or functionality of the software. - -* You may not move, change, disable, or circumvent the license key functionality -in the software, and you may not remove or obscure any functionality in the -software that is protected by the license key. - -* You may not alter, remove, or obscure any licensing, copyright, or other notices -of the licensor in the software. Any use of the licensor’s trademarks is subject -to applicable law. - -Thank you for your compliance, we work hard on the development of KeyAuth and do not appreciate our copyright being infringed. - -## **What is KeyAuth?** - -KeyAuth is an Open source authentication system with cloud hosting plans as well. 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. - -> [!TIP] -> https://vaultcord.com FREE Discord bot to Backup server, members, channels, messages & more. Custom verify page, block alt accounts, VPNs & more. - -## **Customer connection issues?** - -This is common amongst all authentication systems. Program obfuscation causes false positives in virus scanners, and with the scale of KeyAuth this is perceived as a malicious domain. So, `keyauth.com` and `keyauth.win` have been blocked by many internet providers. for dashbord, reseller panel, customer panel, use `keyauth.cc` - -For API, `keyauth.cc` will not work because I purposefully blocked it on there so `keyauth.cc` doesn't get blocked also. So, you should create your own domain and follow this tutorial video https://www.youtube.com/watch?v=a2SROFJ0eYc. The tutorial video shows you how to create a domain name for 100% free if you don't want to purchase one. - -## **How to compile?** - -You can either use Pyinstaller or Nuitka. - -Links: -- Nutika: https://nuitka.net/ -- Pyinstaller: https://pyinstaller.org/ - -Pyinstaller: -- Basic command: `pyinstaller --onefile main.py` - -Nutika: -- Basic command: `python -m nuitka --follow-imports --onefile main.py` - -## **`KeyAuthApp` instance definition** - -Visit https://keyauth.cc/app/ and select your application, then click on the **Python** tab - -It'll provide you with the code which you should replace with in the `main.py` file. - -```PY -keyauthapp = api( - name = "", #App name (Manage Applications --> Application name) - ownerid = "", #Owner ID (Account-Settings --> OwnerID) - secret = "", #App secret(Manage Applications --> App credentials code) - version = "", - hash_to_check = getchecksum() -) -``` - -## **Initialize application** - -You don't need to add any code to initalize. KeyAuth will initalize when the instance definition is made. - -## **Display application information** - -```py -keyauthapp.fetchStats() -print(f""" -App data: -Number of users: {keyauthapp.app_data.numUsers} -Number of online users: {keyauthapp.app_data.onlineUsers} -Number of keys: {keyauthapp.app_data.numKeys} -Application Version: {keyauthapp.app_data.app_ver} -Customer panel link: {keyauthapp.app_data.customer_panel} -""") -``` - -## **Check session validation** - -Use this to see if the user is logged in or not. - -```py -print(f"Current Session Validation Status: {keyauthapp.check()}") -``` - -## **Check blacklist status** - -Check if HWID or IP Address is blacklisted. You can add this if you want, just to make sure nobody can open your program for less than a second if they're blacklisted. Though, if you don't mind a blacklisted user having the program for a few seconds until they try to login and register, and you care about having the quickest program for your users, you shouldn't use this function then. If a blacklisted user tries to login/register, the KeyAuth server will check if they're blacklisted and deny entry if so. So the check blacklist function is just auxiliary function that's optional. - -```py -if keyauthapp.checkblacklist(): - print("You've been blacklisted from our application.") - os._exit(1) -``` - -## **Login with username/password** - -```py -user = input('Provide username: ') -password = input('Provide password: ') -keyauthapp.login(user, password) -``` - -## **Register with username/password/key** - -```py -user = input('Provide username: ') -password = input('Provide password: ') -license = input('Provide License: ') -keyauthapp.register(user, password, license) -``` - -## **Upgrade user username/key** - -Used so the user can add extra time to their account by claiming new key. - -> [!Warning] -> No password is needed to upgrade account. So, unlike login, register, and license functions - you should **not** log user in after successful upgrade. - -```py -user = input('Provide username: ') -license = input('Provide License: ') -keyauthapp.upgrade(user, license) -``` - -## **Login with just license key** - -Users can use this function if their license key has never been used before, and if it has been used before. So if you plan to just allow users to use keys, you can remove the login and register functions from your code. - -```py -key = input('Enter your license: ') -keyauthapp.license(key) -``` - -## **User Data** - -Show information for current logged-in user. - -```py -print("\nUser data: ") -print("Username: " + keyauthapp.user_data.username) -print("IP address: " + keyauthapp.user_data.ip) -print("Hardware-Id: " + keyauthapp.user_data.hwid) - -subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft -for i in range(len(subs)): - sub = subs[i]["subscription"] # Subscription from every Sub - expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( - '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub - timeleft = subs[i]["timeleft"] # Timeleft from every Sub - - print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") -print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) -print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) -print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) -print(f"Current Session Validation Status: {keyauthapp.check()}") -``` - -## **Show list of online users** - -```py -onlineUsers = keyauthapp.fetchOnline() -OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. -if onlineUsers is None: - OU = "No online users" -else: - for i in range(len(onlineUsers)): - OU += onlineUsers[i]["credential"] + " " - -print("\n" + OU + "\n") -``` - -## **Application variables** - -A string that is kept on the server-side of KeyAuth. On the dashboard you can choose for each variable to be authenticated (only logged in users can access), or not authenticated (any user can access before login). These are global and static for all users, unlike User Variables which will be dicussed below this section. - -```py -* Get normal variable and print it -data = keyauthapp.var("varName") -print(data) -``` - -## **User Variables** - -User variables are strings kept on the server-side of KeyAuth. They are specific to users. They can be set on Dashboard in the Users tab, via SellerAPI, or via your loader using the code below. `discord` is the user variable name you fetch the user variable by. `test#0001` is the variable data you get when fetching the user variable. - -```py -* Set up user variable -keyauthapp.setvar("varName", "varValue") -``` - -And here's how you fetch the user variable: - -```py -* Get user variable and print it -data = keyauthapp.getvar("varName") -print(data) -``` - -## **Application Logs** - -Can be used to log data. Good for anti-debug alerts and maybe error debugging. If you set Discord webhook in the app settings of the Dashboard, it will send log messages to your Discord webhook rather than store them on site. It's recommended that you set Discord webhook, as logs on site are deleted 1 month after being sent. - -You can use the log function before login & after login. - -```py -* Log message to the server and then to your webhook what is set on app settings -keyauthapp.log("Message") -``` - -## **Ban the user** - -Ban the user and blacklist their HWID and IP Address. Good function to call upon if you use anti-debug and have detected an intrusion attempt. - -Function only works after login. - -```py -keyauthapp.ban() -``` - -## **Logout session** - -Logout the users session and close the application. - -This only works if the user is authenticated (logged in) -```py -keyauthapp.logout() -``` - -## **Server-sided webhooks** - -Tutorial video https://www.youtube.com/watch?v=ENRaNPPYJbc - -> [!NOTE] -> Read documentation for KeyAuth webhooks here https://keyauth.readme.io/reference/webhooks-1 - -Send HTTP requests to URLs securely without leaking the URL in your application. You should definitely use if you want to send requests to SellerAPI from your application, otherwise if you don't use you'll be leaking your seller key to everyone. And then someone can mess up your application. - -1st example is how to send request with no POST data. just a GET request to the URL. `7kR0UedlVI` is the webhook ID, `https://keyauth.win/api/seller/?sellerkey=sellerkeyhere&type=black` is what you should put as the webhook endpoint on the dashboard. This is the part you don't want users to see. And then you have `&ip=1.1.1.1&hwid=abc` in your program code which will be added to the webhook endpoint on the keyauth server and then the request will be sent. - -2nd example includes post data. it is form data. it is an example request to the KeyAuth API. `7kR0UedlVI` is the webhook ID, `https://keyauth.win/api/1.2/` is the webhook endpoint. - -3rd examples included post data though it's JSON. It's an example reques to Discord webhook `7kR0UedlVI` is the webhook ID, `https://discord.com/api/webhooks/...` is the webhook endpoint. - -```py -* example to send normal request with no POST data -data = keyauthapp.webhook("7kR0UedlVI", "&ip=1.1.1.1&hwid=abc") - -* example to send form data -data = keyauthapp.webhook("7kR0UedlVI", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") - -* example to send JSON -data = keyauthapp.webhook("7kR0UedlVI", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") -``` - -## **Download file** - -> [!NOTE] -> Read documentation for KeyAuth files here https://docs.keyauth.cc/website/dashboard/files - -Keep files secure by providing KeyAuth your file download link on the KeyAuth dashboard. Make sure this is a direct download link (as soon as you go to the link, it starts downloading without you clicking anything). The KeyAuth download function provides the bytes, and then you get to decide what to do with those. This example shows how to write it to a file named `text.txt` in the same folder as the program, though you could execute with RunPE or whatever you want. - -`385624` is the file ID you get from the dashboard after adding file. - -```py -* Download Files form the server to your computer using the download function in the api class -bytes = keyauthapp.file("385624") -f = open("example.exe", "wb") -f.write(bytes) -f.close() -``` - -## **Chat channels** - -Allow users to communicate amongst themselves in your program. - -Example from the form example on how to fetch the chat messages. - -```py -* Get chat messages -messages = keyauthapp.chatGet("CHANNEL") - -Messages = "" -for i in range(len(messages)): -Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" - -print("\n\n" + Messages) -``` - -Example on how to send chat message. - -```py -* Send chat message -keyauthapp.chatSend("MESSAGE", "CHANNEL") -``` - -Looking for a Discord bot made by the KeyAuth & RestoreCord founder that you can use to backup your Discord members, server settings, and messages? Go to https://vaultcord.com +# KeyAuth-Python-Example : Please star 🌟 + +KeyAuth Python example SDK for https://keyauth.cc license key API auth. + +## **Bugs** + +If you are using our example with no significant changes, and you are having problems, please Report Bug here https://keyauth.cc/app/?page=forms + +However, we do **NOT** provide support for adding KeyAuth to your project. If you can't figure this out you should use Google or YouTube to learn more about the programming language you want to sell a program in. + +## Copyright License + +KeyAuth is licensed under **Elastic License 2.0** + +* You may not provide the software to third parties as a hosted or managed +service, where the service provides users with access to any substantial set of +the features or functionality of the software. + +* You may not move, change, disable, or circumvent the license key functionality +in the software, and you may not remove or obscure any functionality in the +software that is protected by the license key. + +* You may not alter, remove, or obscure any licensing, copyright, or other notices +of the licensor in the software. Any use of the licensor’s trademarks is subject +to applicable law. + +Thank you for your compliance, we work hard on the development of KeyAuth and do not appreciate our copyright being infringed. + +## **What is KeyAuth?** + +KeyAuth is an Open source authentication system with cloud hosting plans as well. 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. + +> [!TIP] +> https://vaultcord.com FREE Discord bot to Backup server, members, channels, messages & more. Custom verify page, block alt accounts, VPNs & more. + +## **Customer connection issues?** + +This is common amongst all authentication systems. Program obfuscation causes false positives in virus scanners, and with the scale of KeyAuth this is perceived as a malicious domain. So, `keyauth.com` and `keyauth.win` have been blocked by many internet providers. for dashbord, reseller panel, customer panel, use `keyauth.cc` + +For API, `keyauth.cc` will not work because I purposefully blocked it on there so `keyauth.cc` doesn't get blocked also. So, you should create your own domain and follow this tutorial video https://www.youtube.com/watch?v=a2SROFJ0eYc. The tutorial video shows you how to create a domain name for 100% free if you don't want to purchase one. + +## **How to compile?** + +You can either use Pyinstaller or Nuitka. + +Links: +- Nutika: https://nuitka.net/ +- Pyinstaller: https://pyinstaller.org/ + +Pyinstaller: +- Basic command: `pyinstaller --onefile main.py` + +Nutika: +- Basic command: `python -m nuitka --follow-imports --onefile main.py` + +## **`KeyAuthApp` instance definition** + +Visit https://keyauth.cc/app/ and select your application, then click on the **Python** tab + +It'll provide you with the code which you should replace with in the `main.py` file. + +```PY +keyauthapp = api( + name = "", #App name (Manage Applications --> Application name) + ownerid = "", #Owner ID (Account-Settings --> OwnerID) + secret = "", #App secret(Manage Applications --> App credentials code) + version = "", + hash_to_check = getchecksum() +) +``` + +## **Initialize application** + +You don't need to add any code to initalize. KeyAuth will initalize when the instance definition is made. + +## **Display application information** + +```py +keyauth = keyauthapp.fetchStats() +print(f""" +App data: +Number of users: {keyauth['appinfo']['numUsers']} +Number of online users: {keyauth['appinfo']['numOnlineUsers']} +Number of keys: {keyauth['appinfo']['numKeys']} +Application Version: {keyauth['appinfo']['version']} +Customer panel link: {keyauth['appinfo']['customerPanelLink']} +""") +``` + +## **Check session validation** + +Use this to see if the user is logged in or not. + +```py +print(f"Current Session Validation Status: {keyauthapp.check()}") +``` + +## **Check blacklist status** + +Check if HWID or IP Address is blacklisted. You can add this if you want, just to make sure nobody can open your program for less than a second if they're blacklisted. Though, if you don't mind a blacklisted user having the program for a few seconds until they try to login and register, and you care about having the quickest program for your users, you shouldn't use this function then. If a blacklisted user tries to login/register, the KeyAuth server will check if they're blacklisted and deny entry if so. So the check blacklist function is just auxiliary function that's optional. + +```py +if keyauthapp.check_blacklist(): + print("You've been blacklisted from our application.") +``` + +## **Login with username/password** + +```py +user = input('Provide username: ') +password = input('Provide password: ') +keyauthapp.login(user, password) +``` + +## **Register with username/password/key** + +```py +user = input('Provide username: ') +password = input('Provide password: ') +license = input('Provide License: ') +keyauthapp.register(user, password, license) +``` + +## **Upgrade user username/key** + +Used so the user can add extra time to their account by claiming new key. + +> [!Warning] +> No password is needed to upgrade account. So, unlike login, register, and license functions - you should **not** log user in after successful upgrade. + +```py +user = input('Provide username: ') +license = input('Provide License: ') +keyauthapp.upgrade(user, license) +``` + +## **Login with just license key** + +Users can use this function if their license key has never been used before, and if it has been used before. So if you plan to just allow users to use keys, you can remove the login and register functions from your code. + +```py +key = input('Enter your license: ') +keyauthapp.license(key) +``` + +## **User Data** + +Show information for current logged-in user. + +```py + +# you can use login also i just using it for guide +key = input('Enter your license: ') +keyauth = keyauthapp.license(key) + +print("\nUser data: ") +print("Username: " + keyauth['username']) +print("IP address: " + keyauth['ip']) +print("Hardware-Id: " + keyauth['hwid']) + +# Loop through subscriptions list to get subscription details +for data in keyauth['subscriptions']: + subs = data['subscription'] + key = data['key'] + expiry = datetime.datetime.fromtimestamp(int(data["expiry"]), datetime.UTC).strftime('%Y-%m-%d %H:%M:%S') # Expiry date for each subscription + timeleft = data["timeleft"] # Time left for each subscription + + print(f"Subscription: {subs}") + print(f"Key: {key}") + print(f"Expiry: {expiry}") + print(f"Time left: {timeleft}\n") + +# Print creation, last login, and expiration dates +print("Created at: " + datetime.datetime.fromtimestamp(int(keyauth['create_date']), datetime.UTC).strftime('%Y-%m-%d %H:%M:%S')) +print("Last login at: " + datetime.datetime.fromtimestamp(int(keyauth['last_login']), datetime.UTC).strftime('%Y-%m-%d %H:%M:%S')) +print("Expires at: " + datetime.datetime.fromtimestamp(int(keyauth['expire']), datetime.UTC).strftime('%Y-%m-%d %H:%M:%S')) + +# Print session validation status +print(f"Current Session Validation Status: {keyauthapp.check()}") +``` + +## **Show list of online users** + +```py +onlineUsers = keyauthapp.fetchOnline() +OU = "" +if not onlineUsers: + OU = "No online users" +else: + for i in range(len(onlineUsers)): + OU += onlineUsers[i]["credential"] + " " + +print("\n" + OU + "\n") +``` + +## **Application variables** + +A string that is kept on the server-side of KeyAuth. On the dashboard you can choose for each variable to be authenticated (only logged in users can access), or not authenticated (any user can access before login). These are global and static for all users, unlike User Variables which will be dicussed below this section. + +```py +* Get normal variable and print it +data = keyauthapp.var("varName") +print(data) +``` + +## **User Variables** + +User variables are strings kept on the server-side of KeyAuth. They are specific to users. They can be set on Dashboard in the Users tab, via SellerAPI, or via your loader using the code below. `discord` is the user variable name you fetch the user variable by. `test#0001` is the variable data you get when fetching the user variable. + +```py +* Set up user variable +keyauthapp.setvar("varName", "varValue") +``` + +And here's how you fetch the user variable: + +```py +* Get user variable and print it +data = keyauthapp.getvar("varName") +print(data) +``` + +## **Application Logs** + +Can be used to log data. Good for anti-debug alerts and maybe error debugging. If you set Discord webhook in the app settings of the Dashboard, it will send log messages to your Discord webhook rather than store them on site. It's recommended that you set Discord webhook, as logs on site are deleted 1 month after being sent. + +You can use the log function before login & after login. + +```py +* Log message to the server and then to your webhook what is set on app settings +keyauthapp.log("Message") +``` + +## **Ban the user** + +Ban the user and blacklist their HWID and IP Address. Good function to call upon if you use anti-debug and have detected an intrusion attempt. + +Function only works after login. + +```py +keyauthapp.ban() +``` + +## **Logout session** + +Logout the users session and close the application. + +This only works if the user is authenticated (logged in) +```py +keyauthapp.logout() +``` + +## **Server-sided webhooks** + +Tutorial video https://www.youtube.com/watch?v=ENRaNPPYJbc + +> [!NOTE] +> Read documentation for KeyAuth webhooks here https://keyauth.readme.io/reference/webhooks-1 + +Send HTTP requests to URLs securely without leaking the URL in your application. You should definitely use if you want to send requests to SellerAPI from your application, otherwise if you don't use you'll be leaking your seller key to everyone. And then someone can mess up your application. + +1st example is how to send request with no POST data. just a GET request to the URL. `7kR0UedlVI` is the webhook ID, `https://keyauth.win/api/seller/?sellerkey=sellerkeyhere&type=black` is what you should put as the webhook endpoint on the dashboard. This is the part you don't want users to see. And then you have `&ip=1.1.1.1&hwid=abc` in your program code which will be added to the webhook endpoint on the keyauth server and then the request will be sent. + +2nd example includes post data. it is form data. it is an example request to the KeyAuth API. `7kR0UedlVI` is the webhook ID, `https://keyauth.win/api/1.2/` is the webhook endpoint. + +3rd examples included post data though it's JSON. It's an example reques to Discord webhook `7kR0UedlVI` is the webhook ID, `https://discord.com/api/webhooks/...` is the webhook endpoint. + +```py +* example to send normal request with no POST data +data = keyauthapp.webhook("7kR0UedlVI", "&ip=1.1.1.1&hwid=abc") + +* example to send form data +data = keyauthapp.webhook("7kR0UedlVI", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") + +* example to send JSON +data = keyauthapp.webhook("7kR0UedlVI", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") +``` + +## **Download file** + +> [!NOTE] +> Read documentation for KeyAuth files here https://docs.keyauth.cc/website/dashboard/files + +Keep files secure by providing KeyAuth your file download link on the KeyAuth dashboard. Make sure this is a direct download link (as soon as you go to the link, it starts downloading without you clicking anything). The KeyAuth download function provides the bytes, and then you get to decide what to do with those. This example shows how to write it to a file named `text.txt` in the same folder as the program, though you could execute with RunPE or whatever you want. + +`385624` is the file ID you get from the dashboard after adding file. + +```py +* Download Files form the server to your computer using the download function in the api class +bytes = keyauthapp.file("385624") +f = open("example.exe", "wb") +f.write(bytes) +f.close() +``` + +## **Chat channels** + +Allow users to communicate amongst themselves in your program. + +Example from the form example on how to fetch the chat messages. + +```py +* Get chat messages +messages = keyauthapp.chatGet("CHANNEL") + +Messages = "" +for i in range(len(messages)): +Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" + +print("\n\n" + Messages) +``` + +Example on how to send chat message. + +```py +* Send chat message +keyauthapp.chatSend("MESSAGE", "CHANNEL") +``` + +Looking for a Discord bot made by the KeyAuth & RestoreCord founder that you can use to backup your Discord members, server settings, and messages? Go to https://vaultcord.com diff --git a/example.py b/example.py new file mode 100644 index 0000000..4950549 --- /dev/null +++ b/example.py @@ -0,0 +1,126 @@ +#utf-8 + +''' +KeyAuth.cc Python Example + +Go to https://keyauth.cc/app/ and click the Python tab. Copy that code and replace the existing keyauthapp instance in this file. + +If you get an error saying it can't find module KeyAuth, try following this https://github.com/KeyAuth/KeyAuth-Python-Example#how-to-compile + +If that doesn't work for you, you can paste the contents of KeyAuth.py ABOVE this comment and then remove the "from keyauth import api" and that should work too. + +READ HERE TO LEARN ABOUT KEYAUTH FUNCTIONS https://github.com/KeyAuth/KeyAuth-Python-Example#keyauthapp-instance-definition +''' + +from hashlib import md5 +from keyauth import api +import datetime, os + +def get_checksum(): + """ + getting working main file file name ``stack()[1].filename`` + Calculate and return the MD5 checksum of the file specified in argv. + """ + try: + ''' + you can simply put your filename like that : + with open('main.py, "rb") as file + ''' + with open(__file__.split('\\')[-1], "rb") as file: # You can Use argv[1:] to avoid including the script name + md5_hash = md5() + md5_hash.update(file.read()) + return md5_hash.hexdigest() + except (IndexError, FileNotFoundError, IOError) as e: + print(f"Error: {e}") + return None + +keyauthapp = api( + name = "testing_program", + ownerid = "jNleIQFMNP", + version = "1.0", + hash_to_check = get_checksum() # use to verify file hash usefull to check if somone modify the file it return false +) + +keyauthfetch = keyauthapp.fetchStats() + +print(f""" +{70*'='} +Keyauth python example package. +Replace api arguments with yours. +select option to test using yours. +{70*'='} + + + ---------- App data ---------- +Number of users: {keyauthfetch['appinfo']['numUsers']} +Number of online users: {keyauthfetch['appinfo']['numOnlineUsers']} +Number of keys: {keyauthfetch['appinfo']['numKeys']} +Application Version: {keyauthfetch['appinfo']['version']} +Customer panel link: {keyauthfetch['appinfo']['customerPanelLink']} +\n +[1] Login username & password. +[2] Register username & password. +[3] Login using license. +[4] Upgrade user License. +[5] Send log/messages. +[6] Keyauth webhook. +[7] Check blacklist. +[8] Check online users.\n +""") + +select = input('Input >>> ');os.system('cls') + +if select == '1': + user = input('Provide username: ') + password = input('Provide password: ') + res = keyauthapp.login(user, password) + print(res) + +elif select == '2': + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + print(keyauthapp.register(user, password, license)) + +elif select == '3': + key = input('Enter your license: ') + keyauth = keyauthapp.license(key) + print(keyauth) + +elif select == '4': + user = input('Provide username: ') + license = input('Provide License: ') + print(keyauthapp.upgrade(user, license)) + +elif select == '5': + data = keyauthapp.log("Hello World !") + print(data) + +elif select == '6': + ''' + replace ipify with the name var of your webhook added + replace ?format=json with your params + ''' + data = keyauthapp.webhook('ipify', '?format=json') + print(data) + +elif select == '7': + if keyauthapp.check_blacklist(): + print("You've been blacklisted from our application.") + else: + print('You are not blacklist') + +elif select == '8': + onlineUsers = keyauthapp.fetchOnline() + try: + OU = "" + if not onlineUsers: + OU = "No online users" + else: + for i in range(len(onlineUsers)): + OU += onlineUsers[i]["credential"] + " " + except KeyError: + print(onlineUsers['message']) + +else: + print('Selected Invalid Option !') \ No newline at end of file diff --git a/keyauth/__init__.py b/keyauth/__init__.py new file mode 100644 index 0000000..81de02e --- /dev/null +++ b/keyauth/__init__.py @@ -0,0 +1,28 @@ +from .api import mainapi +from .hwid import WINDOWS_HWID +from os import _exit, system +from json import loads + +def sys_hwid() -> str: + ''' + this def will return a hardware id, + hardware id is a unique key use for key auth + this will return a unique hwid key depend on os + supported os -> window, darwin, linux + ''' + return WINDOWS_HWID().main() + +def api(name=None, ownerid=None, version=None, hash_to_check=None): + ''' + :param name: Name of the app. + :param ownerid: Account ID. + :param version: Application version. + :param hash_to_check: value of MD5 checksum (hash) of a file. + ''' + instance = mainapi( + name=name, + ownerid=ownerid, + version=version, + hash_to_check=hash_to_check + ) + return instance diff --git a/keyauth/api.py b/keyauth/api.py new file mode 100644 index 0000000..48ffa03 --- /dev/null +++ b/keyauth/api.py @@ -0,0 +1,567 @@ +from os import _exit, system, getenv +from json import loads +from binascii import unhexlify +from .hwid import WINDOWS_HWID +from .req import post as _req_post + +class mainapi: + def __init__(self, name=None, ownerid=None, version=None, hash_to_check=None): + """ + Initializes the API instance with given parameters. + + :param name: Name of the app. + :param ownerid: Account ID. + :param version: Application version. + :param hash_to_check: Value of MD5 checksum (hash) of a file. + """ + self.name = name + self.ownerid = ownerid + self.version = version + self.hash_to_check = hash_to_check + self.initialized = False + self.init() + + def CheckInit_HWID(self): + if not self.initialized: + print("Initialize first, in order to use the functions") + _exit(1) + return WINDOWS_HWID().main() + + def init(self): + if len(self.ownerid) != 10: + print( + "Invalid owner ID length. Visit https://keyauth.cc/app/, copy the Python code, " + "and replace the code in main.py with that." + ) + _exit(1) + + post_data = { + "type": "init", + "ver": self.version, + "hash": self.hash_to_check, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) # response & statusCode in txt from req.py `sever` + + if response == "KeyAuth_Invalid": + print(f"The application doesn't exist ") + _exit(1) + + response_json = loads(response) + if response_json["message"] == "invalidver": + if response_json["download"] != "": + print("New Version Available") + download_link = response_json["download"] + system(f"start {download_link}") + _exit(1) + else: + print("Invalid Version, Contact owner to add download link to latest app version") + _exit(1) + + if not response_json["success"]: + print('Something went wrong here !') + print(f'Response From Server : \n\n{response_json}') + + self.initialized = True + self.sessionid = response_json["sessionid"] + + def fetchStats(self): + """ + fetch stats return dict of data that include stats + example total keys, seller panel link, etc + """ + params = { + "type": "fetchStats", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid} + response = _req_post(params) + return loads(response) + + def fetchOnline(self): + """ + fetch number of users online + """ + + self.CheckInit_HWID() + post_data = { + "type": "fetchOnline", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json.get("success"): + return json.get("users") if json.get("users") else None + else: + return json + + + def log(self, message): + ''' + Log message to the server and then to your webhook what is set on app settings + keyauthapp.log("Message") + ''' + + self.CheckInit_HWID() + post_data = { + "type": "log", + "pcuser": getenv('username'), + "message": message, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + resp = loads(_req_post(post_data)) + resp['message'] = message + return resp + + def register(self, user, password, license, hwid=None): + """ + Registering new username & password + + :param user: username to set. + :param password: password to set. + :param license: LicenseKey. + :param hwid: user HWID || You can also use this paramter with SSID. + """ + sys_hwid = self.CheckInit_HWID() + + post_data = { + "type": "register", + "username": user, + "pass": password, + "key": license, + "hwid": sys_hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + print(json["message"]) + return load_user_data(json["info"]) + else: + print(json["message"]) + return json + + def license(self, key, hwid=None): + """ + Checking License Key Validity + + :param key: license key using as login. + :param hwid: user hwid to verify device login. + """ + sys_hwid = self.CheckInit_HWID() + post_data = { + "type": "license", + "key": key, + "hwid": sys_hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + print(json["message"]) + return load_user_data(json["info"]) + else: + print(json["message"]) + return json + + def upgrade(self, user, license): + """ + Upgrading duration of user + + :param user: username. + :param license: license key. + """ + self.CheckInit_HWID() + + post_data = { + "type": "upgrade", + "username": user, + "key": license, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + + json = loads(response) + + if json["success"]: + print(json["message"]) + print("Please restart program and login") + return json["message"] + else: + print(json["message"]) + return json + + def login(self, user, password, hwid=None): + """ + login user with username & password + + :param user: username for login. + :param password: password for login. + :param hwid: user hwid to verify device login. + """ + sys_hwid = self.CheckInit_HWID() + + post_data = { + "type": "login", + "username": user, + "pass": password, + "hwid": sys_hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + + json = loads(response) + + if json["success"]: + print(json["message"]) + return load_user_data(json['info']) + else: + print(json["message"]) + return json + + def var(self, name): + ''' + Get normal variable and print it + data = keyauthapp.var("varName") + ''' + self.CheckInit_HWID() + post_data = { + "type": "var", + "varid": name, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + + json = loads(response) + if json["success"]: + print(json['message']) + return json["message"] + else: + print(json["message"]) + return json + + def getvar(self, var_name): + ''' + Get user variable and print it + keyauthapp.getvar("varName") + ''' + self.CheckInit_HWID() + post_data = { + "type": "getvar", + "var": var_name, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + + json = loads(response) + + if json["success"]: + print(json['response']) + return json["response"] + else: + print(f"NOTE: This is commonly misunderstood. This is for user variables, not the normal variables.\nUse keyauthapp.var(\"{var_name}\") for normal variables"); + print(json["message"]) + return json + + def setvar(self, var_name, var_data): + ''' + :param var_name: Name Of Variable. + :param var_data: data to set on variable data. + Set up user variable + keyauthapp.setvar("varName", "varValue") + ''' + self.CheckInit_HWID() + post_data = { + "type": "setvar", + "var": var_name, + "data": var_data, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + json = loads(response) + if json["success"]: + return True + else: + print(json["message"]) + return False + + def ban(self): + ''' + Ban the user and blacklist their HWID and IP Address. + Good function to call upon if you use anti-debug and have detected an intrusion attempt. + :Note: Function only works after login. + keyauthapp.ban() + ''' + self.CheckInit_HWID() + post_data = { + "type": "ban", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + + json = loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + return False + + def file(self, fileid): + ''' + Download Files form the server to your computer using the download function in the api class + bytes = keyauthapp.file("385624") + f = open("example.exe", "wb") + f.write(bytes) + f.close() + ''' + + self.CheckInit_HWID() + post_data = { + "type": "file", + "fileid": fileid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + print(json) + + if json["success"]: + print(json) + else: + print(json["message"]) + + return unhexlify(json["contents"]) + + def webhook(self, webid, param, body = "", conttype = ""): + ''' + Log message to the server and then to your webhook what is set on app settings + keyauthapp.log("Message") + ''' + + self.CheckInit_HWID() + post_data = { + "type": "webhook", + "webid": webid, + "params": param, + "body": body, + "conttype": conttype, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + return json + + def check(self): + ''' + Use this to see if the user is logged in or not. + print(f"Current Session Validation Status: {keyauthapp.check()}") + ''' + self.CheckInit_HWID() + + post_data = { + "type": "check", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + return True + else: + return False + + def check_blacklist(self): + """ + Verifies whether the HWID or IP address is blacklisted. + + This optional check can enhance security by preventing blacklisted users from accessing the program, even for a brief moment. + However, for faster performance, you may opt to skip this check and rely on the KeyAuth server to automatically + block blacklisted users at login or registration attempts. This function serves as an auxiliary, preemptive security measure. + """ + + hwid = self.CheckInit_HWID() + post_data = { + "type": "checkblacklist", + "hwid": hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = _req_post(post_data) + json = loads(response) + return json['success'] + + def chatGet(self, channel): + ''' + Example from the form example on how to fetch the chat messages. + + Get chat messages + messages = keyauthapp.chatGet("CHANNEL") + ''' + + self.CheckInit_HWID() + post_data = { + "type": "chatget", + "channel": channel, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + return json["messages"] + else: + return None + + def chatSend(self, message, channel): + ''' + * Send chat message + keyauthapp.chatSend("MESSAGE", "CHANNEL") + ''' + + self.CheckInit_HWID() + post_data = { + "type": "chatsend", + "message": message, + "channel": channel, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + return True + else: + return False + + def changeUsername(self, username): + ''' + use this to change username from old -> new, username + ''' + + self.CheckInit_HWID() + post_data = { + "type": "changeUsername", + "newUsername": username, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + print("Successfully changed username") + else: + print(json["message"]) + return json + + def logout(self): + ''' + Logout the users session and close the application. + + This only works if the user is authenticated (logged in) + :call func: keyauthapp.logout() + ''' + + self.CheckInit_HWID() + post_data = { + "type": "logout", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = _req_post(post_data) + json = loads(response) + + if json["success"]: + print("Successfully logged out") + return json + else: + print(json["message"]) + return json + +def load_app_data(data) -> dict: + ''' + :param data: contain app data. + this will return a dictonary containing `app data` + ''' + results: dict = {} + results.update({ + 'users_len': data["numUsers"], + 'keys_len': data["numKeys"], + 'app_version': data["version"], + 'customer_panel': data["customerPanelLink"], + 'active_users': data["numOnlineUsers"], + }) + return results + +def load_user_data(data: dict) -> dict: + ''' + :param data: contain user data. + this will also return dictonary which include `user data` + ''' + results: dict = {} + results.update({ + 'username': data["username"], + 'ip': data["ip"], + 'hwid': data["hwid"] or "N/A", + 'expire': data["subscriptions"][0]["expiry"], + 'create_date': data["createdate"], + 'last_login': data["lastlogin"], + 'subscription': data["subscriptions"][0]["subscription"], + 'subscriptions': data["subscriptions"], + }) + return results diff --git a/keyauth/hwid.py b/keyauth/hwid.py new file mode 100644 index 0000000..aa0bd5d --- /dev/null +++ b/keyauth/hwid.py @@ -0,0 +1,65 @@ +from platform import system +from os import getlogin +from subprocess import Popen, PIPE +import ctypes +from ctypes.wintypes import DWORD + +class WINDOWS_HWID: + def main(self): + if system() == "Linux": + with open("/etc/machine-id") as f: + hwid = f.read() + return hwid # return hwid for linux + + elif system() == 'Windows': + return self.get_hwid() # return hwid for window + + elif system() == 'Darwin': + output = Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=PIPE, shell=True).communicate()[0] + serial = output.decode().split('=', 1)[1].replace(' ', '') + hwid = serial[1:-2] + return hwid # return hwid for darwin os + + def get_hwid(self): + winuser = getlogin() + # sid = self.hwid_sid_ctype(winuser, 'sid') + hwid = self.hwid_sid_ctype(winuser, 'hwid') + + return hwid + + def hwid_sid_ctype(self, win_usr, key=''): + if key == 'hwid': + return self.sid_2_Str_sid(self.acc_lkup(None, win_usr)) + else: + sid = "PySID:"+self.sid_2_Str_sid(self.acc_lkup(None, win_usr)) + return sid + + def acc_lkup(self,system, account_name): + MAX_DOMAIN = 256 + domain_name_buf = ctypes.create_unicode_buffer(MAX_DOMAIN) + sid = ctypes.create_string_buffer(256) + sid_size = ctypes.c_ulong(256) + domain_size = ctypes.c_ulong(MAX_DOMAIN) + use = DWORD() + result = ctypes.windll.advapi32.LookupAccountNameW( + system, + account_name, + sid, + ctypes.byref(sid_size), + domain_name_buf, + ctypes.byref(domain_size), + ctypes.byref(use) + ) + if not result: + raise WindowsError(ctypes.GetLastError()) + return sid.raw + + def sid_2_Str_sid(self, sid): + string_sid = ctypes.c_wchar_p() + result = ctypes.windll.advapi32.ConvertSidToStringSidW(sid, ctypes.byref(string_sid)) + if not result: + raise WindowsError(ctypes.GetLastError()) + return string_sid.value + +# data = WINDOWS_HWID().main() +# print(data) \ No newline at end of file diff --git a/keyauth/req.py b/keyauth/req.py new file mode 100644 index 0000000..693cf3d --- /dev/null +++ b/keyauth/req.py @@ -0,0 +1,47 @@ +from requests import post as req_post, exceptions, get as req_get +from time import sleep, strftime +from os import makedirs, path, _exit +from discord_interactions import verify_key +import datetime + +def post(data, timeout=15): + try: + response = req_post("https://keyauth.win/api/1.3/", data=data, timeout=timeout) + + # For log or file post types, return raw text from response server + if data["type"] in {"log", "file"}: + return response.text + + # Validate signature timestamp for security + signature = response.headers["x-signature-ed25519"] + timestamp = int(response.headers["x-signature-timestamp"]) + current_time = int(datetime.datetime.utcnow().timestamp()) + + if current_time - timestamp > 20: + print("Warning: Timestamp is older than 20 seconds.") + sleep(3) + _exit(1) + + # Ensure KeyAuth log directory structure exists + keyauth_dir = "C:\\ProgramData\\KeyAuth\\Debug" + exe_name = path.basename(__file__) + exe_log_dir = path.join(keyauth_dir, exe_name) + + if not path.exists(exe_log_dir): + makedirs(exe_log_dir) + + # Append log entry if response is under 200 characters + if len(response.text) <= 200: + log_entry = f"{strftime('%I:%M %p | %m/%d/%Y')} | {data['type']}\nResponse: {response.text}\n" + with open(path.join(exe_log_dir, "log.txt"), "a") as log_file: + log_file.write(log_entry) + + if not verify_key(response.text.encode('utf-8'), signature, str(timestamp), '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b'): + print("Signature checksum failed. Request was tampered with or session ended most likely.") + print("Response: " + response.text) + return response.text + + return response.text + + except exceptions.Timeout: + print("Request timed out. The server may be temporarily unavailable.") diff --git a/other-examples/README.md b/other-examples/README.md index 8447c31..ac48d66 100644 --- a/other-examples/README.md +++ b/other-examples/README.md @@ -1,26 +1,26 @@ -# Other-Examples -KeyAuth Python Examples - -**merged_example.py** - -Yes title says everything. This file contains the `keyauth.py` and `main.py` from https://github.com/KeyAuth/KeyAuth-Python-Example - -A few people did not know how to merge the files, so I made an example. - -**method1.py** - -This file shows you how to add your program to keyauth example. - -All you have to do is copy and paste your code below the example, you can check it in the `method1.py` file. - -**method2.py** - -This file shows you how to use your code if it's above the example code. - -- This method will only work if you call your functions after login. -- **Example:** -Create 1 function that will call all the other needed functions. You can also create 1 function and put everything in it. This is all your choice, method 1 would be a better idea. -- This can be exploited with Python code injection, for example injecting a code that will call the function before login. - - ->Created by: `Marci#1337` +# Other-Examples +KeyAuth Python Examples + +**merged_example.py** + +Yes title says everything. This file contains the `keyauth.py` and `main.py` from https://github.com/KeyAuth/KeyAuth-Python-Example + +A few people did not know how to merge the files, so I made an example. + +**method1.py** + +This file shows you how to add your program to keyauth example. + +All you have to do is copy and paste your code below the example, you can check it in the `method1.py` file. + +**method2.py** + +This file shows you how to use your code if it's above the example code. + +- This method will only work if you call your functions after login. +- **Example:** +Create 1 function that will call all the other needed functions. You can also create 1 function and put everything in it. This is all your choice, method 1 would be a better idea. +- This can be exploited with Python code injection, for example injecting a code that will call the function before login. + + +>Created by: `Marci#1337` diff --git a/other-examples/merged_example.py b/other-examples/merged_example.py index 2e653ac..cfa6876 100644 --- a/other-examples/merged_example.py +++ b/other-examples/merged_example.py @@ -1,866 +1,866 @@ -# 1 file version - -import binascii # hex encoding -import hashlib -import json as jsond # json -import os -import platform # check platform -import subprocess # needed for mac device -import sys -import time # sleep before exit -from datetime import datetime -from time import sleep -from uuid import uuid4 # gen random guid - -try: - if os.name == 'nt': - import win32security # get sid (WIN only) - import requests # https requests - from Crypto.Cipher import AES - from Crypto.Hash import SHA256 - from Crypto.Util.Padding import pad, unpad -except ModuleNotFoundError: - print("Exception when importing modules") - print("Installing necessary modules....") - if os.path.isfile("requirements.txt"): - os.system("pip install -r requirements.txt") - else: - os.system("pip install pywin32") - os.system("pip install pycryptodome") - os.system("pip install requests") - print("Modules installed!") - time.sleep(1.5) - os._exit(1) - -try: # Connection check - s = requests.Session() # Session - s.get('https://google.com') -except requests.exceptions.RequestException as e: - print(e) - time.sleep(3) - os._exit(1) - - -class api: - - name = ownerid = secret = version = hash_to_check = "" - - def __init__(self, name, ownerid, secret, version, hash_to_check): - self.name = name - - self.ownerid = ownerid - - self.secret = secret - - self.version = version - self.hash_to_check = hash_to_check - self.init() - - sessionid = enckey = "" - initialized = False - - def init(self): - - if self.sessionid != "": - print("You've already initialized!") - time.sleep(2) - os._exit(1) - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("init").encode()), - "ver": encryption.encrypt(self.version, self.secret, init_iv), - "hash": self.hash_to_check, - "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - if response == "KeyAuth_Invalid": - print("The application doesn't exist") - os._exit(1) - - response = encryption.decrypt(response, self.secret, init_iv) - json = jsond.loads(response) - - if json["message"] == "invalidver": - if json["download"] != "": - print("New Version Available") - download_link = json["download"] - os.system(f"start {download_link}") - os._exit(1) - else: - print("Invalid Version, Contact owner to add download link to latest app version") - os._exit(1) - - if not json["success"]: - print(json["message"]) - os._exit(1) - - self.sessionid = json["sessionid"] - self.initialized = True - self.__load_app_data(json["appinfo"]) - - def register(self, user, password, license, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("register").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - print("successfully registered") - self.__load_user_data(json["info"]) - else: - print(json["message"]) - os._exit(1) - - def upgrade(self, user, license): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("upgrade").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - print("successfully upgraded user") - print("please restart program and login") - time.sleep(2) - os._exit(1) - else: - print(json["message"]) - os._exit(1) - - def login(self, user, password, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("login").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged in") - else: - print(json["message"]) - os._exit(1) - - def license(self, key, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("license").encode()), - "key": encryption.encrypt(key, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged into license") - else: - print(json["message"]) - os._exit(1) - - def var(self, name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("var").encode()), - "varid": encryption.encrypt(name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def getvar(self, var_name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("getvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["response"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def setvar(self, var_name, var_data): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("setvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "data": encryption.encrypt(var_data, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def ban(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("ban").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def file(self, fileid): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("file").encode()), - "fileid": encryption.encrypt(fileid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if not json["success"]: - print(json["message"]) - time.sleep(5) - os._exit(1) - return binascii.unhexlify(json["contents"]) - - def webhook(self, webid, param, body = "", conttype = ""): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("webhook").encode()), - "webid": encryption.encrypt(webid, self.enckey, init_iv), - "params": encryption.encrypt(param, self.enckey, init_iv), - "body": encryption.encrypt(body, self.enckey, init_iv), - "conttype": encryption.encrypt(conttype, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def check(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("check").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def checkblacklist(self): - self.checkinit() - hwid = others.get_hwid() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("checkblacklist").encode()), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def log(self, message): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("log").encode()), - "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), - "message": encryption.encrypt(message, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - self.__do_request(post_data) - - def fetchOnline(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("fetchOnline").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - if len(json["users"]) == 0: - return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. - else: - return json["users"] - else: - return None - - def chatGet(self, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatget").encode()), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["messages"] - else: - return None - - def chatSend(self, message, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatsend").encode()), - "message": encryption.encrypt(message, self.enckey, init_iv), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - return False - - def checkinit(self): - if not self.initialized: - print("Initialize first, in order to use the functions") - time.sleep(2) - os._exit(1) - - def __do_request(self, post_data): - try: - rq_out = s.post( - "https://keyauth.win/api/1.0/", data=post_data, timeout=30 - ) - return rq_out.text - except requests.exceptions.Timeout: - print("Request timed out") - - class application_data_class: - numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" - # region user_data - - class user_data_class: - username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" - - user_data = user_data_class() - app_data = application_data_class() - - def __load_app_data(self, data): - self.app_data.numUsers = data["numUsers"] - self.app_data.numKeys = data["numKeys"] - self.app_data.app_ver = data["version"] - self.app_data.customer_panel = data["customerPanelLink"] - self.app_data.onlineUsers = data["numOnlineUsers"] - - def __load_user_data(self, data): - self.user_data.username = data["username"] - self.user_data.ip = data["ip"] - self.user_data.hwid = data["hwid"] - self.user_data.expires = data["subscriptions"][0]["expiry"] - self.user_data.createdate = data["createdate"] - self.user_data.lastlogin = data["lastlogin"] - self.user_data.subscription = data["subscriptions"][0]["subscription"] - self.user_data.subscriptions = data["subscriptions"] - - -class others: - @staticmethod - def get_hwid(): - if platform.system() == "Linux": - with open("/etc/machine-id") as f: - hwid = f.read() - return hwid - elif platform.system() == 'Windows': - winuser = os.getlogin() - sid = win32security.LookupAccountName(None, winuser)[0] - hwid = win32security.ConvertSidToStringSid(sid) - return hwid - elif platform.system() == 'Darwin': - output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] - serial = output.decode().split('=', 1)[1].replace(' ', '') - hwid = serial[1:-2] - return hwid - - - -class encryption: - @staticmethod - def encrypt_string(plain_text, key, iv): - plain_text = pad(plain_text, 16) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - raw_out = aes_instance.encrypt(plain_text) - - return binascii.hexlify(raw_out) - - @staticmethod - def decrypt_string(cipher_text, key, iv): - cipher_text = binascii.unhexlify(cipher_text) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - cipher_text = aes_instance.decrypt(cipher_text) - - return unpad(cipher_text, 16) - - @staticmethod - def encrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - @staticmethod - def decrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - -# import json as jsond -# ^^ only for auto login/json writing/reading - -# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA - -if sys.version_info.minor < 10: # Python version check (Bypass Patch) - print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") - print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) - -if platform.system() == 'Windows': - os.system('cls & title Python Example') # clear console, change title -elif platform.system() == 'Linux': - os.system('clear') # clear console - sys.stdout.write("\x1b]0;Python Example\x07") # change title -elif platform.system() == 'Darwin': - os.system("clear && printf '\e[3J'") # clear console - os.system('''echo - n - e "\033]0;Python Example\007"''') # change title - -print("Initializing") - - -def getchecksum(): - md5_hash = hashlib.md5() - file = open(''.join(sys.argv), "rb") - md5_hash.update(file.read()) - digest = md5_hash.hexdigest() - return digest - - -keyauthapp = api( - name = "", #App name (Manage Applications --> Application name) - ownerid = "", #Owner ID (Account-Settings --> OwnerID) - secret = "", #App secret(Manage Applications --> App credentials code) - version = "1.0", - hash_to_check = getchecksum() -) - -print(f""" -App data: -Number of users: {keyauthapp.app_data.numUsers} -Number of online users: {keyauthapp.app_data.onlineUsers} -Number of keys: {keyauthapp.app_data.numKeys} -Application Version: {keyauthapp.app_data.app_ver} -Customer panel link: {keyauthapp.app_data.customer_panel} -""") -print(f"Current Session Validation Status: {keyauthapp.check()}") -print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted - - -def answer(): - try: - print(""" -1.Login -2.Register -3.Upgrade -4.License Key Only - """) - ans = input("Select Option: ") - if ans == "1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user, password) - elif ans == "2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user, password, license) - elif ans == "3": - user = input('Provide username: ') - license = input('Provide License: ') - keyauthapp.upgrade(user, license) - elif ans == "4": - key = input('Enter your license: ') - keyauthapp.license(key) - else: - print("\nNot Valid Option") - time.sleep(1) - os.system('cls') - answer() - except KeyboardInterrupt: - os._exit(1) - - -answer() - -# region Extra Functions - -# * Download Files form the server to your computer using the download function in the api class -# bytes = keyauthapp.file("FILEID") -# f = open("example.exe", "wb") -# f.write(bytes) -# f.close() - - -# * Set up user variable -# keyauthapp.setvar("varName", "varValue") - -# * Get user variable and print it -# data = keyauthapp.getvar("varName") -# print(data) - -# * Get normal variable and print it -# data = keyauthapp.var("varName") -# print(data) - -# * Log message to the server and then to your webhook what is set on app settings -# keyauthapp.log("Message") - -# * Get if the user pc have been blacklisted -# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") - -# * See if the current session is validated -# print(f"Session Validated?: {keyauthapp.check()}") - - -# * example to send normal request with no POST data -# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") - -# * example to send form data -# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") - -# * example to send JSON -# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") - -# * Get chat messages -# messages = keyauthapp.chatGet("CHANNEL") - -# Messages = "" -# for i in range(len(messages)): -# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" - -# print("\n\n" + Messages) - -# * Send chat message -# keyauthapp.chatSend("MESSAGE", "CHANNEL") - -# * Add Application Information to Title -# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") - -# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) -# 1. Checking and Reading JSON - -#### Note: Remove the ''' on line 151 and 226 - -'''try: - if os.path.isfile('auth.json'): #Checking if the auth file exist - if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not - print(""" -1. Login -2. Register - """) - ans=input("Select Option: ") #Skipping auto-login bc auth file is empty - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - else: - try: #2. Auto login - with open('auth.json', 'r') as f: - authfile = jsond.load(f) - authuser = authfile.get('authusername') - authpass = authfile.get('authpassword') - keyauthapp.login(authuser,authpass) - except Exception as e: #Error stuff - print(e) - else: #Creating auth file bc its missing - try: - f = open("auth.json", "a") #Writing content - f.write("""{ - "authusername": "", - "authpassword": "" -}""") - f.close() - print (""" -1. Login -2. Register - """)#Again skipping auto-login bc the file is empty/missing - ans=input("Select Option: ") - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - except Exception as e: #Error stuff - print(e) - os._exit(1) -except Exception as e: #Error stuff - print(e) - os._exit(1)''' - -# endregion - - -print("\nUser data: ") -print("Username: " + keyauthapp.user_data.username) -print("IP address: " + keyauthapp.user_data.ip) -print("Hardware-Id: " + keyauthapp.user_data.hwid) -# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name - -subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft -for i in range(len(subs)): - sub = subs[i]["subscription"] # Subscription from every Sub - expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( - '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub - timeleft = subs[i]["timeleft"] # Timeleft from every Sub - - print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") - -onlineUsers = keyauthapp.fetchOnline() -OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. -if onlineUsers is None: - OU = "No online users" -else: - for i in range(len(onlineUsers)): - OU += onlineUsers[i]["credential"] + " " - -print("\n" + OU + "\n") - -print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) -print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) -print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) -print(f"Current Session Validation Status: {keyauthapp.check()}") -print("Exiting in 10 secs....") -sleep(10) -os._exit(1) +# 1 file version + +import binascii # hex encoding +import hashlib +import json as jsond # json +import os +import platform # check platform +import subprocess # needed for mac device +import sys +import time # sleep before exit +from datetime import datetime +from time import sleep +from uuid import uuid4 # gen random guid + +try: + if os.name == 'nt': + import win32security # get sid (WIN only) + import requests # https requests + from Crypto.Cipher import AES + from Crypto.Hash import SHA256 + from Crypto.Util.Padding import pad, unpad +except ModuleNotFoundError: + print("Exception when importing modules") + print("Installing necessary modules....") + if os.path.isfile("requirements.txt"): + os.system("pip install -r requirements.txt") + else: + os.system("pip install pywin32") + os.system("pip install pycryptodome") + os.system("pip install requests") + print("Modules installed!") + time.sleep(1.5) + os._exit(1) + +try: # Connection check + s = requests.Session() # Session + s.get('https://google.com') +except requests.exceptions.RequestException as e: + print(e) + time.sleep(3) + os._exit(1) + + +class api: + + name = ownerid = secret = version = hash_to_check = "" + + def __init__(self, name, ownerid, secret, version, hash_to_check): + self.name = name + + self.ownerid = ownerid + + self.secret = secret + + self.version = version + self.hash_to_check = hash_to_check + self.init() + + sessionid = enckey = "" + initialized = False + + def init(self): + + if self.sessionid != "": + print("You've already initialized!") + time.sleep(2) + os._exit(1) + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("init").encode()), + "ver": encryption.encrypt(self.version, self.secret, init_iv), + "hash": self.hash_to_check, + "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + if response == "KeyAuth_Invalid": + print("The application doesn't exist") + os._exit(1) + + response = encryption.decrypt(response, self.secret, init_iv) + json = jsond.loads(response) + + if json["message"] == "invalidver": + if json["download"] != "": + print("New Version Available") + download_link = json["download"] + os.system(f"start {download_link}") + os._exit(1) + else: + print("Invalid Version, Contact owner to add download link to latest app version") + os._exit(1) + + if not json["success"]: + print(json["message"]) + os._exit(1) + + self.sessionid = json["sessionid"] + self.initialized = True + self.__load_app_data(json["appinfo"]) + + def register(self, user, password, license, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("register").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + print("successfully registered") + self.__load_user_data(json["info"]) + else: + print(json["message"]) + os._exit(1) + + def upgrade(self, user, license): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("upgrade").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + print("successfully upgraded user") + print("please restart program and login") + time.sleep(2) + os._exit(1) + else: + print(json["message"]) + os._exit(1) + + def login(self, user, password, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("login").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged in") + else: + print(json["message"]) + os._exit(1) + + def license(self, key, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("license").encode()), + "key": encryption.encrypt(key, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged into license") + else: + print(json["message"]) + os._exit(1) + + def var(self, name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("var").encode()), + "varid": encryption.encrypt(name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def getvar(self, var_name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("getvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["response"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def setvar(self, var_name, var_data): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("setvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "data": encryption.encrypt(var_data, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def ban(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("ban").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def file(self, fileid): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("file").encode()), + "fileid": encryption.encrypt(fileid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if not json["success"]: + print(json["message"]) + time.sleep(5) + os._exit(1) + return binascii.unhexlify(json["contents"]) + + def webhook(self, webid, param, body = "", conttype = ""): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("webhook").encode()), + "webid": encryption.encrypt(webid, self.enckey, init_iv), + "params": encryption.encrypt(param, self.enckey, init_iv), + "body": encryption.encrypt(body, self.enckey, init_iv), + "conttype": encryption.encrypt(conttype, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def check(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("check").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def checkblacklist(self): + self.checkinit() + hwid = others.get_hwid() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("checkblacklist").encode()), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def log(self, message): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("log").encode()), + "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), + "message": encryption.encrypt(message, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + self.__do_request(post_data) + + def fetchOnline(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("fetchOnline").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + if len(json["users"]) == 0: + return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. + else: + return json["users"] + else: + return None + + def chatGet(self, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatget").encode()), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["messages"] + else: + return None + + def chatSend(self, message, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatsend").encode()), + "message": encryption.encrypt(message, self.enckey, init_iv), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + return False + + def checkinit(self): + if not self.initialized: + print("Initialize first, in order to use the functions") + time.sleep(2) + os._exit(1) + + def __do_request(self, post_data): + try: + rq_out = s.post( + "https://keyauth.win/api/1.0/", data=post_data, timeout=30 + ) + return rq_out.text + except requests.exceptions.Timeout: + print("Request timed out") + + class application_data_class: + numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" + # region user_data + + class user_data_class: + username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" + + user_data = user_data_class() + app_data = application_data_class() + + def __load_app_data(self, data): + self.app_data.numUsers = data["numUsers"] + self.app_data.numKeys = data["numKeys"] + self.app_data.app_ver = data["version"] + self.app_data.customer_panel = data["customerPanelLink"] + self.app_data.onlineUsers = data["numOnlineUsers"] + + def __load_user_data(self, data): + self.user_data.username = data["username"] + self.user_data.ip = data["ip"] + self.user_data.hwid = data["hwid"] + self.user_data.expires = data["subscriptions"][0]["expiry"] + self.user_data.createdate = data["createdate"] + self.user_data.lastlogin = data["lastlogin"] + self.user_data.subscription = data["subscriptions"][0]["subscription"] + self.user_data.subscriptions = data["subscriptions"] + + +class others: + @staticmethod + def get_hwid(): + if platform.system() == "Linux": + with open("/etc/machine-id") as f: + hwid = f.read() + return hwid + elif platform.system() == 'Windows': + winuser = os.getlogin() + sid = win32security.LookupAccountName(None, winuser)[0] + hwid = win32security.ConvertSidToStringSid(sid) + return hwid + elif platform.system() == 'Darwin': + output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] + serial = output.decode().split('=', 1)[1].replace(' ', '') + hwid = serial[1:-2] + return hwid + + + +class encryption: + @staticmethod + def encrypt_string(plain_text, key, iv): + plain_text = pad(plain_text, 16) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + raw_out = aes_instance.encrypt(plain_text) + + return binascii.hexlify(raw_out) + + @staticmethod + def decrypt_string(cipher_text, key, iv): + cipher_text = binascii.unhexlify(cipher_text) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + cipher_text = aes_instance.decrypt(cipher_text) + + return unpad(cipher_text, 16) + + @staticmethod + def encrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + @staticmethod + def decrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + +# import json as jsond +# ^^ only for auto login/json writing/reading + +# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA + +if sys.version_info.minor < 10: # Python version check (Bypass Patch) + print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") + print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) + +if platform.system() == 'Windows': + os.system('cls & title Python Example') # clear console, change title +elif platform.system() == 'Linux': + os.system('clear') # clear console + sys.stdout.write("\x1b]0;Python Example\x07") # change title +elif platform.system() == 'Darwin': + os.system("clear && printf '\e[3J'") # clear console + os.system('''echo - n - e "\033]0;Python Example\007"''') # change title + +print("Initializing") + + +def getchecksum(): + md5_hash = hashlib.md5() + file = open(''.join(sys.argv), "rb") + md5_hash.update(file.read()) + digest = md5_hash.hexdigest() + return digest + + +keyauthapp = api( + name = "", #App name (Manage Applications --> Application name) + ownerid = "", #Owner ID (Account-Settings --> OwnerID) + secret = "", #App secret(Manage Applications --> App credentials code) + version = "1.0", + hash_to_check = getchecksum() +) + +print(f""" +App data: +Number of users: {keyauthapp.app_data.numUsers} +Number of online users: {keyauthapp.app_data.onlineUsers} +Number of keys: {keyauthapp.app_data.numKeys} +Application Version: {keyauthapp.app_data.app_ver} +Customer panel link: {keyauthapp.app_data.customer_panel} +""") +print(f"Current Session Validation Status: {keyauthapp.check()}") +print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted + + +def answer(): + try: + print(""" +1.Login +2.Register +3.Upgrade +4.License Key Only + """) + ans = input("Select Option: ") + if ans == "1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user, password) + elif ans == "2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user, password, license) + elif ans == "3": + user = input('Provide username: ') + license = input('Provide License: ') + keyauthapp.upgrade(user, license) + elif ans == "4": + key = input('Enter your license: ') + keyauthapp.license(key) + else: + print("\nNot Valid Option") + time.sleep(1) + os.system('cls') + answer() + except KeyboardInterrupt: + os._exit(1) + + +answer() + +# region Extra Functions + +# * Download Files form the server to your computer using the download function in the api class +# bytes = keyauthapp.file("FILEID") +# f = open("example.exe", "wb") +# f.write(bytes) +# f.close() + + +# * Set up user variable +# keyauthapp.setvar("varName", "varValue") + +# * Get user variable and print it +# data = keyauthapp.getvar("varName") +# print(data) + +# * Get normal variable and print it +# data = keyauthapp.var("varName") +# print(data) + +# * Log message to the server and then to your webhook what is set on app settings +# keyauthapp.log("Message") + +# * Get if the user pc have been blacklisted +# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") + +# * See if the current session is validated +# print(f"Session Validated?: {keyauthapp.check()}") + + +# * example to send normal request with no POST data +# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") + +# * example to send form data +# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") + +# * example to send JSON +# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") + +# * Get chat messages +# messages = keyauthapp.chatGet("CHANNEL") + +# Messages = "" +# for i in range(len(messages)): +# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" + +# print("\n\n" + Messages) + +# * Send chat message +# keyauthapp.chatSend("MESSAGE", "CHANNEL") + +# * Add Application Information to Title +# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") + +# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) +# 1. Checking and Reading JSON + +#### Note: Remove the ''' on line 151 and 226 + +'''try: + if os.path.isfile('auth.json'): #Checking if the auth file exist + if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not + print(""" +1. Login +2. Register + """) + ans=input("Select Option: ") #Skipping auto-login bc auth file is empty + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + else: + try: #2. Auto login + with open('auth.json', 'r') as f: + authfile = jsond.load(f) + authuser = authfile.get('authusername') + authpass = authfile.get('authpassword') + keyauthapp.login(authuser,authpass) + except Exception as e: #Error stuff + print(e) + else: #Creating auth file bc its missing + try: + f = open("auth.json", "a") #Writing content + f.write("""{ + "authusername": "", + "authpassword": "" +}""") + f.close() + print (""" +1. Login +2. Register + """)#Again skipping auto-login bc the file is empty/missing + ans=input("Select Option: ") + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + except Exception as e: #Error stuff + print(e) + os._exit(1) +except Exception as e: #Error stuff + print(e) + os._exit(1)''' + +# endregion + + +print("\nUser data: ") +print("Username: " + keyauthapp.user_data.username) +print("IP address: " + keyauthapp.user_data.ip) +print("Hardware-Id: " + keyauthapp.user_data.hwid) +# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name + +subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft +for i in range(len(subs)): + sub = subs[i]["subscription"] # Subscription from every Sub + expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( + '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub + timeleft = subs[i]["timeleft"] # Timeleft from every Sub + + print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") + +onlineUsers = keyauthapp.fetchOnline() +OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. +if onlineUsers is None: + OU = "No online users" +else: + for i in range(len(onlineUsers)): + OU += onlineUsers[i]["credential"] + " " + +print("\n" + OU + "\n") + +print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) +print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) +print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) +print(f"Current Session Validation Status: {keyauthapp.check()}") +print("Exiting in 10 secs....") +sleep(10) +os._exit(1) diff --git a/other-examples/method1.py b/other-examples/method1.py index 0c03ee8..225585e 100644 --- a/other-examples/method1.py +++ b/other-examples/method1.py @@ -1,875 +1,875 @@ -import binascii # hex encoding -import hashlib -import json as jsond # json -import os -import platform # check platform -import subprocess # needed for mac device -import sys -import time # sleep before exit -from datetime import datetime -from time import sleep -from uuid import uuid4 # gen random guid - -try: - if os.name == 'nt': - import win32security # get sid (WIN only) - import requests # https requests - from Crypto.Cipher import AES - from Crypto.Hash import SHA256 - from Crypto.Util.Padding import pad, unpad -except ModuleNotFoundError: - print("Exception when importing modules") - print("Installing necessary modules....") - if os.path.isfile("requirements.txt"): - os.system("pip install -r requirements.txt") - else: - os.system("pip install pywin32") - os.system("pip install pycryptodome") - os.system("pip install requests") - print("Modules installed!") - time.sleep(1.5) - os._exit(1) - -try: # Connection check - s = requests.Session() # Session - s.get('https://google.com') -except requests.exceptions.RequestException as e: - print(e) - time.sleep(3) - os._exit(1) - - -class api: - - name = ownerid = secret = version = hash_to_check = "" - - def __init__(self, name, ownerid, secret, version, hash_to_check): - self.name = name - - self.ownerid = ownerid - - self.secret = secret - - self.version = version - self.hash_to_check = hash_to_check - self.init() - - sessionid = enckey = "" - initialized = False - - def init(self): - - if self.sessionid != "": - print("You've already initialized!") - time.sleep(2) - os._exit(1) - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("init").encode()), - "ver": encryption.encrypt(self.version, self.secret, init_iv), - "hash": self.hash_to_check, - "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - if response == "KeyAuth_Invalid": - print("The application doesn't exist") - os._exit(1) - - response = encryption.decrypt(response, self.secret, init_iv) - json = jsond.loads(response) - - if json["message"] == "invalidver": - if json["download"] != "": - print("New Version Available") - download_link = json["download"] - os.system(f"start {download_link}") - os._exit(1) - else: - print("Invalid Version, Contact owner to add download link to latest app version") - os._exit(1) - - if not json["success"]: - print(json["message"]) - os._exit(1) - - self.sessionid = json["sessionid"] - self.initialized = True - self.__load_app_data(json["appinfo"]) - - def register(self, user, password, license, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("register").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - print("successfully registered") - self.__load_user_data(json["info"]) - else: - print(json["message"]) - os._exit(1) - - def upgrade(self, user, license): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("upgrade").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - print("successfully upgraded user") - print("please restart program and login") - time.sleep(2) - os._exit(1) - else: - print(json["message"]) - os._exit(1) - - def login(self, user, password, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("login").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged in") - else: - print(json["message"]) - os._exit(1) - - def license(self, key, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("license").encode()), - "key": encryption.encrypt(key, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged into license") - else: - print(json["message"]) - os._exit(1) - - def var(self, name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("var").encode()), - "varid": encryption.encrypt(name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def getvar(self, var_name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("getvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["response"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def setvar(self, var_name, var_data): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("setvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "data": encryption.encrypt(var_data, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def ban(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("ban").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def file(self, fileid): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("file").encode()), - "fileid": encryption.encrypt(fileid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if not json["success"]: - print(json["message"]) - time.sleep(5) - os._exit(1) - return binascii.unhexlify(json["contents"]) - - def webhook(self, webid, param, body = "", conttype = ""): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("webhook").encode()), - "webid": encryption.encrypt(webid, self.enckey, init_iv), - "params": encryption.encrypt(param, self.enckey, init_iv), - "body": encryption.encrypt(body, self.enckey, init_iv), - "conttype": encryption.encrypt(conttype, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def check(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("check").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def checkblacklist(self): - self.checkinit() - hwid = others.get_hwid() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("checkblacklist").encode()), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def log(self, message): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("log").encode()), - "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), - "message": encryption.encrypt(message, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - self.__do_request(post_data) - - def fetchOnline(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("fetchOnline").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - if len(json["users"]) == 0: - return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. - else: - return json["users"] - else: - return None - - def chatGet(self, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatget").encode()), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["messages"] - else: - return None - - def chatSend(self, message, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatsend").encode()), - "message": encryption.encrypt(message, self.enckey, init_iv), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - return False - - def checkinit(self): - if not self.initialized: - print("Initialize first, in order to use the functions") - time.sleep(2) - os._exit(1) - - def __do_request(self, post_data): - try: - rq_out = s.post( - "https://keyauth.win/api/1.0/", data=post_data, timeout=30 - ) - return rq_out.text - except requests.exceptions.Timeout: - print("Request timed out") - - class application_data_class: - numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" - # region user_data - - class user_data_class: - username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" - - user_data = user_data_class() - app_data = application_data_class() - - def __load_app_data(self, data): - self.app_data.numUsers = data["numUsers"] - self.app_data.numKeys = data["numKeys"] - self.app_data.app_ver = data["version"] - self.app_data.customer_panel = data["customerPanelLink"] - self.app_data.onlineUsers = data["numOnlineUsers"] - - def __load_user_data(self, data): - self.user_data.username = data["username"] - self.user_data.ip = data["ip"] - self.user_data.hwid = data["hwid"] - self.user_data.expires = data["subscriptions"][0]["expiry"] - self.user_data.createdate = data["createdate"] - self.user_data.lastlogin = data["lastlogin"] - self.user_data.subscription = data["subscriptions"][0]["subscription"] - self.user_data.subscriptions = data["subscriptions"] - - -class others: - @staticmethod - def get_hwid(): - if platform.system() == "Linux": - with open("/etc/machine-id") as f: - hwid = f.read() - return hwid - elif platform.system() == 'Windows': - winuser = os.getlogin() - sid = win32security.LookupAccountName(None, winuser)[0] - hwid = win32security.ConvertSidToStringSid(sid) - return hwid - elif platform.system() == 'Darwin': - output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] - serial = output.decode().split('=', 1)[1].replace(' ', '') - hwid = serial[1:-2] - return hwid - - - -class encryption: - @staticmethod - def encrypt_string(plain_text, key, iv): - plain_text = pad(plain_text, 16) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - raw_out = aes_instance.encrypt(plain_text) - - return binascii.hexlify(raw_out) - - @staticmethod - def decrypt_string(cipher_text, key, iv): - cipher_text = binascii.unhexlify(cipher_text) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - cipher_text = aes_instance.decrypt(cipher_text) - - return unpad(cipher_text, 16) - - @staticmethod - def encrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - @staticmethod - def decrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - -# import json as jsond -# ^^ only for auto login/json writing/reading - -# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA - -if sys.version_info.minor < 10: # Python version check (Bypass Patch) - print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") - print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) - -if platform.system() == 'Windows': - os.system('cls & title Python Example') # clear console, change title -elif platform.system() == 'Linux': - os.system('clear') # clear console - sys.stdout.write("\x1b]0;Python Example\x07") # change title -elif platform.system() == 'Darwin': - os.system("clear && printf '\e[3J'") # clear console - os.system('''echo - n - e "\033]0;Python Example\007"''') # change title - -print("Initializing") - - -def getchecksum(): - md5_hash = hashlib.md5() - file = open(''.join(sys.argv), "rb") - md5_hash.update(file.read()) - digest = md5_hash.hexdigest() - return digest - - -keyauthapp = api( - name = "", #App name (Manage Applications --> Application name) - ownerid = "", #Owner ID (Account-Settings --> OwnerID) - secret = "", #App secret(Manage Applications --> App credentials code) - version = "1.0", - hash_to_check = getchecksum() -) - -print(f""" -App data: -Number of users: {keyauthapp.app_data.numUsers} -Number of online users: {keyauthapp.app_data.onlineUsers} -Number of keys: {keyauthapp.app_data.numKeys} -Application Version: {keyauthapp.app_data.app_ver} -Customer panel link: {keyauthapp.app_data.customer_panel} -""") -print(f"Current Session Validation Status: {keyauthapp.check()}") -print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted - - -def answer(): - try: - print(""" -1.Login -2.Register -3.Upgrade -4.License Key Only - """) - ans = input("Select Option: ") - if ans == "1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user, password) - elif ans == "2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user, password, license) - elif ans == "3": - user = input('Provide username: ') - license = input('Provide License: ') - keyauthapp.upgrade(user, license) - elif ans == "4": - key = input('Enter your license: ') - keyauthapp.license(key) - else: - print("\nNot Valid Option") - time.sleep(1) - os.system('cls') - answer() - except KeyboardInterrupt: - os._exit(1) - - -answer() - -# region Extra Functions - -# * Download Files form the server to your computer using the download function in the api class -# bytes = keyauthapp.file("FILEID") -# f = open("example.exe", "wb") -# f.write(bytes) -# f.close() - - -# * Set up user variable -# keyauthapp.setvar("varName", "varValue") - -# * Get user variable and print it -# data = keyauthapp.getvar("varName") -# print(data) - -# * Get normal variable and print it -# data = keyauthapp.var("varName") -# print(data) - -# * Log message to the server and then to your webhook what is set on app settings -# keyauthapp.log("Message") - -# * Get if the user pc have been blacklisted -# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") - -# * See if the current session is validated -# print(f"Session Validated?: {keyauthapp.check()}") - - -# * example to send normal request with no POST data -# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") - -# * example to send form data -# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") - -# * example to send JSON -# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") - -# * Get chat messages -# messages = keyauthapp.chatGet("CHANNEL") - -# Messages = "" -# for i in range(len(messages)): -# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" - -# print("\n\n" + Messages) - -# * Send chat message -# keyauthapp.chatSend("MESSAGE", "CHANNEL") - -# * Add Application Information to Title -# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") - -# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) -# 1. Checking and Reading JSON - -#### Note: Remove the ''' on line 151 and 226 - -'''try: - if os.path.isfile('auth.json'): #Checking if the auth file exist - if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not - print(""" -1. Login -2. Register - """) - ans=input("Select Option: ") #Skipping auto-login bc auth file is empty - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - else: - try: #2. Auto login - with open('auth.json', 'r') as f: - authfile = jsond.load(f) - authuser = authfile.get('authusername') - authpass = authfile.get('authpassword') - keyauthapp.login(authuser,authpass) - except Exception as e: #Error stuff - print(e) - else: #Creating auth file bc its missing - try: - f = open("auth.json", "a") #Writing content - f.write("""{ - "authusername": "", - "authpassword": "" -}""") - f.close() - print (""" -1. Login -2. Register - """)#Again skipping auto-login bc the file is empty/missing - ans=input("Select Option: ") - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - except Exception as e: #Error stuff - print(e) - os._exit(1) -except Exception as e: #Error stuff - print(e) - os._exit(1)''' - -# endregion - - -print("\nUser data: ") -print("Username: " + keyauthapp.user_data.username) -print("IP address: " + keyauthapp.user_data.ip) -print("Hardware-Id: " + keyauthapp.user_data.hwid) -# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name - -subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft -for i in range(len(subs)): - sub = subs[i]["subscription"] # Subscription from every Sub - expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( - '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub - timeleft = subs[i]["timeleft"] # Timeleft from every Sub - - print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") - -onlineUsers = keyauthapp.fetchOnline() -OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. -if onlineUsers is None: - OU = "No online users" -else: - for i in range(len(onlineUsers)): - OU += onlineUsers[i]["credential"] + " " - -print("\n" + OU + "\n") - -print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) -print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) -print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) -print(f"Current Session Validation Status: {keyauthapp.check()}") - - -# Method 1 -# Example -# Put all your code here, remove the example_program function and the "if __name__ == '__main__':" - -def example_program(): - print("\nHello world.") - time.sleep(3) - os._exit(1) - - -if __name__ == '__main__': - example_program() +import binascii # hex encoding +import hashlib +import json as jsond # json +import os +import platform # check platform +import subprocess # needed for mac device +import sys +import time # sleep before exit +from datetime import datetime +from time import sleep +from uuid import uuid4 # gen random guid + +try: + if os.name == 'nt': + import win32security # get sid (WIN only) + import requests # https requests + from Crypto.Cipher import AES + from Crypto.Hash import SHA256 + from Crypto.Util.Padding import pad, unpad +except ModuleNotFoundError: + print("Exception when importing modules") + print("Installing necessary modules....") + if os.path.isfile("requirements.txt"): + os.system("pip install -r requirements.txt") + else: + os.system("pip install pywin32") + os.system("pip install pycryptodome") + os.system("pip install requests") + print("Modules installed!") + time.sleep(1.5) + os._exit(1) + +try: # Connection check + s = requests.Session() # Session + s.get('https://google.com') +except requests.exceptions.RequestException as e: + print(e) + time.sleep(3) + os._exit(1) + + +class api: + + name = ownerid = secret = version = hash_to_check = "" + + def __init__(self, name, ownerid, secret, version, hash_to_check): + self.name = name + + self.ownerid = ownerid + + self.secret = secret + + self.version = version + self.hash_to_check = hash_to_check + self.init() + + sessionid = enckey = "" + initialized = False + + def init(self): + + if self.sessionid != "": + print("You've already initialized!") + time.sleep(2) + os._exit(1) + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("init").encode()), + "ver": encryption.encrypt(self.version, self.secret, init_iv), + "hash": self.hash_to_check, + "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + if response == "KeyAuth_Invalid": + print("The application doesn't exist") + os._exit(1) + + response = encryption.decrypt(response, self.secret, init_iv) + json = jsond.loads(response) + + if json["message"] == "invalidver": + if json["download"] != "": + print("New Version Available") + download_link = json["download"] + os.system(f"start {download_link}") + os._exit(1) + else: + print("Invalid Version, Contact owner to add download link to latest app version") + os._exit(1) + + if not json["success"]: + print(json["message"]) + os._exit(1) + + self.sessionid = json["sessionid"] + self.initialized = True + self.__load_app_data(json["appinfo"]) + + def register(self, user, password, license, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("register").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + print("successfully registered") + self.__load_user_data(json["info"]) + else: + print(json["message"]) + os._exit(1) + + def upgrade(self, user, license): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("upgrade").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + print("successfully upgraded user") + print("please restart program and login") + time.sleep(2) + os._exit(1) + else: + print(json["message"]) + os._exit(1) + + def login(self, user, password, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("login").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged in") + else: + print(json["message"]) + os._exit(1) + + def license(self, key, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("license").encode()), + "key": encryption.encrypt(key, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged into license") + else: + print(json["message"]) + os._exit(1) + + def var(self, name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("var").encode()), + "varid": encryption.encrypt(name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def getvar(self, var_name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("getvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["response"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def setvar(self, var_name, var_data): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("setvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "data": encryption.encrypt(var_data, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def ban(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("ban").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def file(self, fileid): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("file").encode()), + "fileid": encryption.encrypt(fileid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if not json["success"]: + print(json["message"]) + time.sleep(5) + os._exit(1) + return binascii.unhexlify(json["contents"]) + + def webhook(self, webid, param, body = "", conttype = ""): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("webhook").encode()), + "webid": encryption.encrypt(webid, self.enckey, init_iv), + "params": encryption.encrypt(param, self.enckey, init_iv), + "body": encryption.encrypt(body, self.enckey, init_iv), + "conttype": encryption.encrypt(conttype, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def check(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("check").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def checkblacklist(self): + self.checkinit() + hwid = others.get_hwid() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("checkblacklist").encode()), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def log(self, message): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("log").encode()), + "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), + "message": encryption.encrypt(message, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + self.__do_request(post_data) + + def fetchOnline(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("fetchOnline").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + if len(json["users"]) == 0: + return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. + else: + return json["users"] + else: + return None + + def chatGet(self, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatget").encode()), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["messages"] + else: + return None + + def chatSend(self, message, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatsend").encode()), + "message": encryption.encrypt(message, self.enckey, init_iv), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + return False + + def checkinit(self): + if not self.initialized: + print("Initialize first, in order to use the functions") + time.sleep(2) + os._exit(1) + + def __do_request(self, post_data): + try: + rq_out = s.post( + "https://keyauth.win/api/1.0/", data=post_data, timeout=30 + ) + return rq_out.text + except requests.exceptions.Timeout: + print("Request timed out") + + class application_data_class: + numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" + # region user_data + + class user_data_class: + username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" + + user_data = user_data_class() + app_data = application_data_class() + + def __load_app_data(self, data): + self.app_data.numUsers = data["numUsers"] + self.app_data.numKeys = data["numKeys"] + self.app_data.app_ver = data["version"] + self.app_data.customer_panel = data["customerPanelLink"] + self.app_data.onlineUsers = data["numOnlineUsers"] + + def __load_user_data(self, data): + self.user_data.username = data["username"] + self.user_data.ip = data["ip"] + self.user_data.hwid = data["hwid"] + self.user_data.expires = data["subscriptions"][0]["expiry"] + self.user_data.createdate = data["createdate"] + self.user_data.lastlogin = data["lastlogin"] + self.user_data.subscription = data["subscriptions"][0]["subscription"] + self.user_data.subscriptions = data["subscriptions"] + + +class others: + @staticmethod + def get_hwid(): + if platform.system() == "Linux": + with open("/etc/machine-id") as f: + hwid = f.read() + return hwid + elif platform.system() == 'Windows': + winuser = os.getlogin() + sid = win32security.LookupAccountName(None, winuser)[0] + hwid = win32security.ConvertSidToStringSid(sid) + return hwid + elif platform.system() == 'Darwin': + output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] + serial = output.decode().split('=', 1)[1].replace(' ', '') + hwid = serial[1:-2] + return hwid + + + +class encryption: + @staticmethod + def encrypt_string(plain_text, key, iv): + plain_text = pad(plain_text, 16) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + raw_out = aes_instance.encrypt(plain_text) + + return binascii.hexlify(raw_out) + + @staticmethod + def decrypt_string(cipher_text, key, iv): + cipher_text = binascii.unhexlify(cipher_text) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + cipher_text = aes_instance.decrypt(cipher_text) + + return unpad(cipher_text, 16) + + @staticmethod + def encrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + @staticmethod + def decrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + +# import json as jsond +# ^^ only for auto login/json writing/reading + +# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA + +if sys.version_info.minor < 10: # Python version check (Bypass Patch) + print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") + print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) + +if platform.system() == 'Windows': + os.system('cls & title Python Example') # clear console, change title +elif platform.system() == 'Linux': + os.system('clear') # clear console + sys.stdout.write("\x1b]0;Python Example\x07") # change title +elif platform.system() == 'Darwin': + os.system("clear && printf '\e[3J'") # clear console + os.system('''echo - n - e "\033]0;Python Example\007"''') # change title + +print("Initializing") + + +def getchecksum(): + md5_hash = hashlib.md5() + file = open(''.join(sys.argv), "rb") + md5_hash.update(file.read()) + digest = md5_hash.hexdigest() + return digest + + +keyauthapp = api( + name = "", #App name (Manage Applications --> Application name) + ownerid = "", #Owner ID (Account-Settings --> OwnerID) + secret = "", #App secret(Manage Applications --> App credentials code) + version = "1.0", + hash_to_check = getchecksum() +) + +print(f""" +App data: +Number of users: {keyauthapp.app_data.numUsers} +Number of online users: {keyauthapp.app_data.onlineUsers} +Number of keys: {keyauthapp.app_data.numKeys} +Application Version: {keyauthapp.app_data.app_ver} +Customer panel link: {keyauthapp.app_data.customer_panel} +""") +print(f"Current Session Validation Status: {keyauthapp.check()}") +print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted + + +def answer(): + try: + print(""" +1.Login +2.Register +3.Upgrade +4.License Key Only + """) + ans = input("Select Option: ") + if ans == "1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user, password) + elif ans == "2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user, password, license) + elif ans == "3": + user = input('Provide username: ') + license = input('Provide License: ') + keyauthapp.upgrade(user, license) + elif ans == "4": + key = input('Enter your license: ') + keyauthapp.license(key) + else: + print("\nNot Valid Option") + time.sleep(1) + os.system('cls') + answer() + except KeyboardInterrupt: + os._exit(1) + + +answer() + +# region Extra Functions + +# * Download Files form the server to your computer using the download function in the api class +# bytes = keyauthapp.file("FILEID") +# f = open("example.exe", "wb") +# f.write(bytes) +# f.close() + + +# * Set up user variable +# keyauthapp.setvar("varName", "varValue") + +# * Get user variable and print it +# data = keyauthapp.getvar("varName") +# print(data) + +# * Get normal variable and print it +# data = keyauthapp.var("varName") +# print(data) + +# * Log message to the server and then to your webhook what is set on app settings +# keyauthapp.log("Message") + +# * Get if the user pc have been blacklisted +# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") + +# * See if the current session is validated +# print(f"Session Validated?: {keyauthapp.check()}") + + +# * example to send normal request with no POST data +# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") + +# * example to send form data +# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") + +# * example to send JSON +# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") + +# * Get chat messages +# messages = keyauthapp.chatGet("CHANNEL") + +# Messages = "" +# for i in range(len(messages)): +# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" + +# print("\n\n" + Messages) + +# * Send chat message +# keyauthapp.chatSend("MESSAGE", "CHANNEL") + +# * Add Application Information to Title +# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") + +# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) +# 1. Checking and Reading JSON + +#### Note: Remove the ''' on line 151 and 226 + +'''try: + if os.path.isfile('auth.json'): #Checking if the auth file exist + if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not + print(""" +1. Login +2. Register + """) + ans=input("Select Option: ") #Skipping auto-login bc auth file is empty + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + else: + try: #2. Auto login + with open('auth.json', 'r') as f: + authfile = jsond.load(f) + authuser = authfile.get('authusername') + authpass = authfile.get('authpassword') + keyauthapp.login(authuser,authpass) + except Exception as e: #Error stuff + print(e) + else: #Creating auth file bc its missing + try: + f = open("auth.json", "a") #Writing content + f.write("""{ + "authusername": "", + "authpassword": "" +}""") + f.close() + print (""" +1. Login +2. Register + """)#Again skipping auto-login bc the file is empty/missing + ans=input("Select Option: ") + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + except Exception as e: #Error stuff + print(e) + os._exit(1) +except Exception as e: #Error stuff + print(e) + os._exit(1)''' + +# endregion + + +print("\nUser data: ") +print("Username: " + keyauthapp.user_data.username) +print("IP address: " + keyauthapp.user_data.ip) +print("Hardware-Id: " + keyauthapp.user_data.hwid) +# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name + +subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft +for i in range(len(subs)): + sub = subs[i]["subscription"] # Subscription from every Sub + expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( + '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub + timeleft = subs[i]["timeleft"] # Timeleft from every Sub + + print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") + +onlineUsers = keyauthapp.fetchOnline() +OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. +if onlineUsers is None: + OU = "No online users" +else: + for i in range(len(onlineUsers)): + OU += onlineUsers[i]["credential"] + " " + +print("\n" + OU + "\n") + +print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) +print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) +print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) +print(f"Current Session Validation Status: {keyauthapp.check()}") + + +# Method 1 +# Example +# Put all your code here, remove the example_program function and the "if __name__ == '__main__':" + +def example_program(): + print("\nHello world.") + time.sleep(3) + os._exit(1) + + +if __name__ == '__main__': + example_program() diff --git a/other-examples/method2.py b/other-examples/method2.py index 1a4d17b..f2cf639 100644 --- a/other-examples/method2.py +++ b/other-examples/method2.py @@ -1,876 +1,876 @@ -import binascii # hex encoding -import hashlib -import json as jsond # json -import os -import platform # check platform -import subprocess # needed for mac device -import sys -import time # sleep before exit -from datetime import datetime -from uuid import uuid4 # gen random guid - - -# Method 2 -# Example -# Put all your code here, remove the example_program function. This method will only work if you call your functions after login. Line 207 -# Create 1 function that will call all the other needed functions. You can also create 1 function and put everything in it. This is all your choice, method 1 would be a better idea. -# This can be exploited with Python code injection, for example injecting a code that will call the function before login. - - -def example_program(): - print("\nHello world.") - time.sleep(3) - os._exit(1) - - - -try: - if os.name == 'nt': - import win32security # get sid (WIN only) - import requests # https requests - from Crypto.Cipher import AES - from Crypto.Hash import SHA256 - from Crypto.Util.Padding import pad, unpad -except ModuleNotFoundError: - print("Exception when importing modules") - print("Installing necessary modules....") - if os.path.isfile("requirements.txt"): - os.system("pip install -r requirements.txt") - else: - os.system("pip install pywin32") - os.system("pip install pycryptodome") - os.system("pip install requests") - print("Modules installed!") - time.sleep(1.5) - os._exit(1) - -try: # Connection check - s = requests.Session() # Session - s.get('https://google.com') -except requests.exceptions.RequestException as e: - print(e) - time.sleep(3) - os._exit(1) - - -class api: - - name = ownerid = secret = version = hash_to_check = "" - - def __init__(self, name, ownerid, secret, version, hash_to_check): - self.name = name - - self.ownerid = ownerid - - self.secret = secret - - self.version = version - self.hash_to_check = hash_to_check - self.init() - - sessionid = enckey = "" - initialized = False - - def init(self): - - if self.sessionid != "": - print("You've already initialized!") - time.sleep(2) - os._exit(1) - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("init").encode()), - "ver": encryption.encrypt(self.version, self.secret, init_iv), - "hash": self.hash_to_check, - "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - if response == "KeyAuth_Invalid": - print("The application doesn't exist") - os._exit(1) - - response = encryption.decrypt(response, self.secret, init_iv) - json = jsond.loads(response) - - if json["message"] == "invalidver": - if json["download"] != "": - print("New Version Available") - download_link = json["download"] - os.system(f"start {download_link}") - os._exit(1) - else: - print("Invalid Version, Contact owner to add download link to latest app version") - os._exit(1) - - if not json["success"]: - print(json["message"]) - os._exit(1) - - self.sessionid = json["sessionid"] - self.initialized = True - self.__load_app_data(json["appinfo"]) - - def register(self, user, password, license, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("register").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - print("successfully registered") - self.__load_user_data(json["info"]) - else: - print(json["message"]) - os._exit(1) - - def upgrade(self, user, license): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("upgrade").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "key": encryption.encrypt(license, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - print("successfully upgraded user") - print("please restart program and login") - time.sleep(2) - os._exit(1) - else: - print(json["message"]) - os._exit(1) - - def login(self, user, password, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("login").encode()), - "username": encryption.encrypt(user, self.enckey, init_iv), - "pass": encryption.encrypt(password, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged in") - example_program() - else: - print(json["message"]) - os._exit(1) - - def license(self, key, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("license").encode()), - "key": encryption.encrypt(key, self.enckey, init_iv), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print("successfully logged into license") - else: - print(json["message"]) - os._exit(1) - - def var(self, name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("var").encode()), - "varid": encryption.encrypt(name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def getvar(self, var_name): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("getvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["response"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def setvar(self, var_name, var_data): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("setvar").encode()), - "var": encryption.encrypt(var_name, self.enckey, init_iv), - "data": encryption.encrypt(var_data, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def ban(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("ban").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def file(self, fileid): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("file").encode()), - "fileid": encryption.encrypt(fileid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if not json["success"]: - print(json["message"]) - time.sleep(5) - os._exit(1) - return binascii.unhexlify(json["contents"]) - - def webhook(self, webid, param, body = "", conttype = ""): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("webhook").encode()), - "webid": encryption.encrypt(webid, self.enckey, init_iv), - "params": encryption.encrypt(param, self.enckey, init_iv), - "body": encryption.encrypt(body, self.enckey, init_iv), - "conttype": encryption.encrypt(conttype, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(5) - os._exit(1) - - def check(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("check").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def checkblacklist(self): - self.checkinit() - hwid = others.get_hwid() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - post_data = { - "type": binascii.hexlify(("checkblacklist").encode()), - "hwid": encryption.encrypt(hwid, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - response = self.__do_request(post_data) - - response = encryption.decrypt(response, self.enckey, init_iv) - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def log(self, message): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("log").encode()), - "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), - "message": encryption.encrypt(message, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - self.__do_request(post_data) - - def fetchOnline(self): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("fetchOnline").encode()), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - if len(json["users"]) == 0: - return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. - else: - return json["users"] - else: - return None - - def chatGet(self, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatget").encode()), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return json["messages"] - else: - return None - - def chatSend(self, message, channel): - self.checkinit() - init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() - - post_data = { - "type": binascii.hexlify(("chatsend").encode()), - "message": encryption.encrypt(message, self.enckey, init_iv), - "channel": encryption.encrypt(channel, self.enckey, init_iv), - "sessionid": binascii.hexlify(self.sessionid.encode()), - "name": binascii.hexlify(self.name.encode()), - "ownerid": binascii.hexlify(self.ownerid.encode()), - "init_iv": init_iv - } - - response = self.__do_request(post_data) - response = encryption.decrypt(response, self.enckey, init_iv) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - return False - - def checkinit(self): - if not self.initialized: - print("Initialize first, in order to use the functions") - time.sleep(2) - os._exit(1) - - def __do_request(self, post_data): - try: - rq_out = s.post( - "https://keyauth.win/api/1.0/", data=post_data, timeout=30 - ) - return rq_out.text - except requests.exceptions.Timeout: - print("Request timed out") - - class application_data_class: - numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" - # region user_data - - class user_data_class: - username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" - - user_data = user_data_class() - app_data = application_data_class() - - def __load_app_data(self, data): - self.app_data.numUsers = data["numUsers"] - self.app_data.numKeys = data["numKeys"] - self.app_data.app_ver = data["version"] - self.app_data.customer_panel = data["customerPanelLink"] - self.app_data.onlineUsers = data["numOnlineUsers"] - - def __load_user_data(self, data): - self.user_data.username = data["username"] - self.user_data.ip = data["ip"] - self.user_data.hwid = data["hwid"] - self.user_data.expires = data["subscriptions"][0]["expiry"] - self.user_data.createdate = data["createdate"] - self.user_data.lastlogin = data["lastlogin"] - self.user_data.subscription = data["subscriptions"][0]["subscription"] - self.user_data.subscriptions = data["subscriptions"] - - -class others: - @staticmethod - def get_hwid(): - if platform.system() == "Linux": - with open("/etc/machine-id") as f: - hwid = f.read() - return hwid - elif platform.system() == 'Windows': - winuser = os.getlogin() - sid = win32security.LookupAccountName(None, winuser)[0] - hwid = win32security.ConvertSidToStringSid(sid) - return hwid - elif platform.system() == 'Darwin': - output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] - serial = output.decode().split('=', 1)[1].replace(' ', '') - hwid = serial[1:-2] - return hwid - - - -class encryption: - @staticmethod - def encrypt_string(plain_text, key, iv): - plain_text = pad(plain_text, 16) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - raw_out = aes_instance.encrypt(plain_text) - - return binascii.hexlify(raw_out) - - @staticmethod - def decrypt_string(cipher_text, key, iv): - cipher_text = binascii.unhexlify(cipher_text) - - aes_instance = AES.new(key, AES.MODE_CBC, iv) - - cipher_text = aes_instance.decrypt(cipher_text) - - return unpad(cipher_text, 16) - - @staticmethod - def encrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - @staticmethod - def decrypt(message, enc_key, iv): - try: - _key = SHA256.new(enc_key.encode()).hexdigest()[:32] - - _iv = SHA256.new(iv.encode()).hexdigest()[:16] - - return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() - except: - print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") - os._exit(1) - - -# import json as jsond -# ^^ only for auto login/json writing/reading - -# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA - -if sys.version_info.minor < 10: # Python version check (Bypass Patch) - print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") - print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) - -if platform.system() == 'Windows': - os.system('cls & title Python Example') # clear console, change title -elif platform.system() == 'Linux': - os.system('clear') # clear console - sys.stdout.write("\x1b]0;Python Example\x07") # change title -elif platform.system() == 'Darwin': - os.system("clear && printf '\e[3J'") # clear console - os.system('''echo - n - e "\033]0;Python Example\007"''') # change title - -print("Initializing") - - -def getchecksum(): - md5_hash = hashlib.md5() - file = open(''.join(sys.argv), "rb") - md5_hash.update(file.read()) - digest = md5_hash.hexdigest() - return digest - - -keyauthapp = api( - name = "", #App name (Manage Applications --> Application name) - ownerid = "", #Owner ID (Account-Settings --> OwnerID) - secret = "", #App secret(Manage Applications --> App credentials code) - version = "1.0", - hash_to_check = getchecksum() -) - -print(f""" -App data: -Number of users: {keyauthapp.app_data.numUsers} -Number of online users: {keyauthapp.app_data.onlineUsers} -Number of keys: {keyauthapp.app_data.numKeys} -Application Version: {keyauthapp.app_data.app_ver} -Customer panel link: {keyauthapp.app_data.customer_panel} -""") -print(f"Current Session Validation Status: {keyauthapp.check()}") -print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted - - -def answer(): - try: - print(""" -1.Login -2.Register -3.Upgrade -4.License Key Only - """) - ans = input("Select Option: ") - if ans == "1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user, password) - elif ans == "2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user, password, license) - elif ans == "3": - user = input('Provide username: ') - license = input('Provide License: ') - keyauthapp.upgrade(user, license) - elif ans == "4": - key = input('Enter your license: ') - keyauthapp.license(key) - else: - print("\nNot Valid Option") - time.sleep(1) - os.system('cls') - answer() - except KeyboardInterrupt: - os._exit(1) - - -answer() - -# region Extra Functions - -# * Download Files form the server to your computer using the download function in the api class -# bytes = keyauthapp.file("FILEID") -# f = open("example.exe", "wb") -# f.write(bytes) -# f.close() - - -# * Set up user variable -# keyauthapp.setvar("varName", "varValue") - -# * Get user variable and print it -# data = keyauthapp.getvar("varName") -# print(data) - -# * Get normal variable and print it -# data = keyauthapp.var("varName") -# print(data) - -# * Log message to the server and then to your webhook what is set on app settings -# keyauthapp.log("Message") - -# * Get if the user pc have been blacklisted -# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") - -# * See if the current session is validated -# print(f"Session Validated?: {keyauthapp.check()}") - - -# * example to send normal request with no POST data -# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") - -# * example to send form data -# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") - -# * example to send JSON -# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") - -# * Get chat messages -# messages = keyauthapp.chatGet("CHANNEL") - -# Messages = "" -# for i in range(len(messages)): -# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" - -# print("\n\n" + Messages) - -# * Send chat message -# keyauthapp.chatSend("MESSAGE", "CHANNEL") - -# * Add Application Information to Title -# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") - -# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) -# 1. Checking and Reading JSON - -#### Note: Remove the ''' on line 151 and 226 - -'''try: - if os.path.isfile('auth.json'): #Checking if the auth file exist - if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not - print(""" -1. Login -2. Register - """) - ans=input("Select Option: ") #Skipping auto-login bc auth file is empty - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - else: - try: #2. Auto login - with open('auth.json', 'r') as f: - authfile = jsond.load(f) - authuser = authfile.get('authusername') - authpass = authfile.get('authpassword') - keyauthapp.login(authuser,authpass) - except Exception as e: #Error stuff - print(e) - else: #Creating auth file bc its missing - try: - f = open("auth.json", "a") #Writing content - f.write("""{ - "authusername": "", - "authpassword": "" -}""") - f.close() - print (""" -1. Login -2. Register - """)#Again skipping auto-login bc the file is empty/missing - ans=input("Select Option: ") - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - except Exception as e: #Error stuff - print(e) - os._exit(1) -except Exception as e: #Error stuff - print(e) - os._exit(1)''' - -# endregion - - -print("\nUser data: ") -print("Username: " + keyauthapp.user_data.username) -print("IP address: " + keyauthapp.user_data.ip) -print("Hardware-Id: " + keyauthapp.user_data.hwid) -# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name - -subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft -for i in range(len(subs)): - sub = subs[i]["subscription"] # Subscription from every Sub - expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( - '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub - timeleft = subs[i]["timeleft"] # Timeleft from every Sub - - print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") - -onlineUsers = keyauthapp.fetchOnline() -OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. -if onlineUsers is None: - OU = "No online users" -else: - for i in range(len(onlineUsers)): - OU += onlineUsers[i]["credential"] + " " - -print("\n" + OU + "\n") - -print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) -print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) -print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) -print(f"Current Session Validation Status: {keyauthapp.check()}") +import binascii # hex encoding +import hashlib +import json as jsond # json +import os +import platform # check platform +import subprocess # needed for mac device +import sys +import time # sleep before exit +from datetime import datetime +from uuid import uuid4 # gen random guid + + +# Method 2 +# Example +# Put all your code here, remove the example_program function. This method will only work if you call your functions after login. Line 207 +# Create 1 function that will call all the other needed functions. You can also create 1 function and put everything in it. This is all your choice, method 1 would be a better idea. +# This can be exploited with Python code injection, for example injecting a code that will call the function before login. + + +def example_program(): + print("\nHello world.") + time.sleep(3) + os._exit(1) + + + +try: + if os.name == 'nt': + import win32security # get sid (WIN only) + import requests # https requests + from Crypto.Cipher import AES + from Crypto.Hash import SHA256 + from Crypto.Util.Padding import pad, unpad +except ModuleNotFoundError: + print("Exception when importing modules") + print("Installing necessary modules....") + if os.path.isfile("requirements.txt"): + os.system("pip install -r requirements.txt") + else: + os.system("pip install pywin32") + os.system("pip install pycryptodome") + os.system("pip install requests") + print("Modules installed!") + time.sleep(1.5) + os._exit(1) + +try: # Connection check + s = requests.Session() # Session + s.get('https://google.com') +except requests.exceptions.RequestException as e: + print(e) + time.sleep(3) + os._exit(1) + + +class api: + + name = ownerid = secret = version = hash_to_check = "" + + def __init__(self, name, ownerid, secret, version, hash_to_check): + self.name = name + + self.ownerid = ownerid + + self.secret = secret + + self.version = version + self.hash_to_check = hash_to_check + self.init() + + sessionid = enckey = "" + initialized = False + + def init(self): + + if self.sessionid != "": + print("You've already initialized!") + time.sleep(2) + os._exit(1) + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("init").encode()), + "ver": encryption.encrypt(self.version, self.secret, init_iv), + "hash": self.hash_to_check, + "enckey": encryption.encrypt(self.enckey, self.secret, init_iv), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + if response == "KeyAuth_Invalid": + print("The application doesn't exist") + os._exit(1) + + response = encryption.decrypt(response, self.secret, init_iv) + json = jsond.loads(response) + + if json["message"] == "invalidver": + if json["download"] != "": + print("New Version Available") + download_link = json["download"] + os.system(f"start {download_link}") + os._exit(1) + else: + print("Invalid Version, Contact owner to add download link to latest app version") + os._exit(1) + + if not json["success"]: + print(json["message"]) + os._exit(1) + + self.sessionid = json["sessionid"] + self.initialized = True + self.__load_app_data(json["appinfo"]) + + def register(self, user, password, license, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("register").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + print("successfully registered") + self.__load_user_data(json["info"]) + else: + print(json["message"]) + os._exit(1) + + def upgrade(self, user, license): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("upgrade").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "key": encryption.encrypt(license, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + print("successfully upgraded user") + print("please restart program and login") + time.sleep(2) + os._exit(1) + else: + print(json["message"]) + os._exit(1) + + def login(self, user, password, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("login").encode()), + "username": encryption.encrypt(user, self.enckey, init_iv), + "pass": encryption.encrypt(password, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged in") + example_program() + else: + print(json["message"]) + os._exit(1) + + def license(self, key, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("license").encode()), + "key": encryption.encrypt(key, self.enckey, init_iv), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print("successfully logged into license") + else: + print(json["message"]) + os._exit(1) + + def var(self, name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("var").encode()), + "varid": encryption.encrypt(name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def getvar(self, var_name): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("getvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["response"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def setvar(self, var_name, var_data): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("setvar").encode()), + "var": encryption.encrypt(var_name, self.enckey, init_iv), + "data": encryption.encrypt(var_data, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def ban(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("ban").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def file(self, fileid): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("file").encode()), + "fileid": encryption.encrypt(fileid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if not json["success"]: + print(json["message"]) + time.sleep(5) + os._exit(1) + return binascii.unhexlify(json["contents"]) + + def webhook(self, webid, param, body = "", conttype = ""): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("webhook").encode()), + "webid": encryption.encrypt(webid, self.enckey, init_iv), + "params": encryption.encrypt(param, self.enckey, init_iv), + "body": encryption.encrypt(body, self.enckey, init_iv), + "conttype": encryption.encrypt(conttype, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(5) + os._exit(1) + + def check(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("check").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def checkblacklist(self): + self.checkinit() + hwid = others.get_hwid() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + post_data = { + "type": binascii.hexlify(("checkblacklist").encode()), + "hwid": encryption.encrypt(hwid, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + response = self.__do_request(post_data) + + response = encryption.decrypt(response, self.enckey, init_iv) + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def log(self, message): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("log").encode()), + "pcuser": encryption.encrypt(os.getenv('username'), self.enckey, init_iv), + "message": encryption.encrypt(message, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + self.__do_request(post_data) + + def fetchOnline(self): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("fetchOnline").encode()), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + if len(json["users"]) == 0: + return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array. + else: + return json["users"] + else: + return None + + def chatGet(self, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatget").encode()), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return json["messages"] + else: + return None + + def chatSend(self, message, channel): + self.checkinit() + init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest() + + post_data = { + "type": binascii.hexlify(("chatsend").encode()), + "message": encryption.encrypt(message, self.enckey, init_iv), + "channel": encryption.encrypt(channel, self.enckey, init_iv), + "sessionid": binascii.hexlify(self.sessionid.encode()), + "name": binascii.hexlify(self.name.encode()), + "ownerid": binascii.hexlify(self.ownerid.encode()), + "init_iv": init_iv + } + + response = self.__do_request(post_data) + response = encryption.decrypt(response, self.enckey, init_iv) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + return False + + def checkinit(self): + if not self.initialized: + print("Initialize first, in order to use the functions") + time.sleep(2) + os._exit(1) + + def __do_request(self, post_data): + try: + rq_out = s.post( + "https://keyauth.win/api/1.0/", data=post_data, timeout=30 + ) + return rq_out.text + except requests.exceptions.Timeout: + print("Request timed out") + + class application_data_class: + numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" + # region user_data + + class user_data_class: + username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" + + user_data = user_data_class() + app_data = application_data_class() + + def __load_app_data(self, data): + self.app_data.numUsers = data["numUsers"] + self.app_data.numKeys = data["numKeys"] + self.app_data.app_ver = data["version"] + self.app_data.customer_panel = data["customerPanelLink"] + self.app_data.onlineUsers = data["numOnlineUsers"] + + def __load_user_data(self, data): + self.user_data.username = data["username"] + self.user_data.ip = data["ip"] + self.user_data.hwid = data["hwid"] + self.user_data.expires = data["subscriptions"][0]["expiry"] + self.user_data.createdate = data["createdate"] + self.user_data.lastlogin = data["lastlogin"] + self.user_data.subscription = data["subscriptions"][0]["subscription"] + self.user_data.subscriptions = data["subscriptions"] + + +class others: + @staticmethod + def get_hwid(): + if platform.system() == "Linux": + with open("/etc/machine-id") as f: + hwid = f.read() + return hwid + elif platform.system() == 'Windows': + winuser = os.getlogin() + sid = win32security.LookupAccountName(None, winuser)[0] + hwid = win32security.ConvertSidToStringSid(sid) + return hwid + elif platform.system() == 'Darwin': + output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] + serial = output.decode().split('=', 1)[1].replace(' ', '') + hwid = serial[1:-2] + return hwid + + + +class encryption: + @staticmethod + def encrypt_string(plain_text, key, iv): + plain_text = pad(plain_text, 16) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + raw_out = aes_instance.encrypt(plain_text) + + return binascii.hexlify(raw_out) + + @staticmethod + def decrypt_string(cipher_text, key, iv): + cipher_text = binascii.unhexlify(cipher_text) + + aes_instance = AES.new(key, AES.MODE_CBC, iv) + + cipher_text = aes_instance.decrypt(cipher_text) + + return unpad(cipher_text, 16) + + @staticmethod + def encrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.encrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + @staticmethod + def decrypt(message, enc_key, iv): + try: + _key = SHA256.new(enc_key.encode()).hexdigest()[:32] + + _iv = SHA256.new(iv.encode()).hexdigest()[:16] + + return encryption.decrypt_string(message.encode(), _key.encode(), _iv.encode()).decode() + except: + print("Invalid Application Information. Long text is secret short text is ownerid. Name is supposed to be app name not username") + os._exit(1) + + +# import json as jsond +# ^^ only for auto login/json writing/reading + +# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA + +if sys.version_info.minor < 10: # Python version check (Bypass Patch) + print("[Security] - Python 3.10 or higher is recommended. The bypass will not work on 3.10+") + print("You are using Python {}.{}".format(sys.version_info.major, sys.version_info.minor)) + +if platform.system() == 'Windows': + os.system('cls & title Python Example') # clear console, change title +elif platform.system() == 'Linux': + os.system('clear') # clear console + sys.stdout.write("\x1b]0;Python Example\x07") # change title +elif platform.system() == 'Darwin': + os.system("clear && printf '\e[3J'") # clear console + os.system('''echo - n - e "\033]0;Python Example\007"''') # change title + +print("Initializing") + + +def getchecksum(): + md5_hash = hashlib.md5() + file = open(''.join(sys.argv), "rb") + md5_hash.update(file.read()) + digest = md5_hash.hexdigest() + return digest + + +keyauthapp = api( + name = "", #App name (Manage Applications --> Application name) + ownerid = "", #Owner ID (Account-Settings --> OwnerID) + secret = "", #App secret(Manage Applications --> App credentials code) + version = "1.0", + hash_to_check = getchecksum() +) + +print(f""" +App data: +Number of users: {keyauthapp.app_data.numUsers} +Number of online users: {keyauthapp.app_data.onlineUsers} +Number of keys: {keyauthapp.app_data.numKeys} +Application Version: {keyauthapp.app_data.app_ver} +Customer panel link: {keyauthapp.app_data.customer_panel} +""") +print(f"Current Session Validation Status: {keyauthapp.check()}") +print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted + + +def answer(): + try: + print(""" +1.Login +2.Register +3.Upgrade +4.License Key Only + """) + ans = input("Select Option: ") + if ans == "1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user, password) + elif ans == "2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user, password, license) + elif ans == "3": + user = input('Provide username: ') + license = input('Provide License: ') + keyauthapp.upgrade(user, license) + elif ans == "4": + key = input('Enter your license: ') + keyauthapp.license(key) + else: + print("\nNot Valid Option") + time.sleep(1) + os.system('cls') + answer() + except KeyboardInterrupt: + os._exit(1) + + +answer() + +# region Extra Functions + +# * Download Files form the server to your computer using the download function in the api class +# bytes = keyauthapp.file("FILEID") +# f = open("example.exe", "wb") +# f.write(bytes) +# f.close() + + +# * Set up user variable +# keyauthapp.setvar("varName", "varValue") + +# * Get user variable and print it +# data = keyauthapp.getvar("varName") +# print(data) + +# * Get normal variable and print it +# data = keyauthapp.var("varName") +# print(data) + +# * Log message to the server and then to your webhook what is set on app settings +# keyauthapp.log("Message") + +# * Get if the user pc have been blacklisted +# print(f"Blacklisted? : {keyauthapp.checkblacklist()}") + +# * See if the current session is validated +# print(f"Session Validated?: {keyauthapp.check()}") + + +# * example to send normal request with no POST data +# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username") + +# * example to send form data +# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded") + +# * example to send JSON +# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json") + +# * Get chat messages +# messages = keyauthapp.chatGet("CHANNEL") + +# Messages = "" +# for i in range(len(messages)): +# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n" + +# print("\n\n" + Messages) + +# * Send chat message +# keyauthapp.chatSend("MESSAGE", "CHANNEL") + +# * Add Application Information to Title +# os.system(f"cls & title KeyAuth Python Example - Total Users: {keyauthapp.app_data.numUsers} - Online Users: {keyauthapp.app_data.onlineUsers} - Total Keys: {keyauthapp.app_data.numKeys}") + +# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY) +# 1. Checking and Reading JSON + +#### Note: Remove the ''' on line 151 and 226 + +'''try: + if os.path.isfile('auth.json'): #Checking if the auth file exist + if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not + print(""" +1. Login +2. Register + """) + ans=input("Select Option: ") #Skipping auto-login bc auth file is empty + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + else: + try: #2. Auto login + with open('auth.json', 'r') as f: + authfile = jsond.load(f) + authuser = authfile.get('authusername') + authpass = authfile.get('authpassword') + keyauthapp.login(authuser,authpass) + except Exception as e: #Error stuff + print(e) + else: #Creating auth file bc its missing + try: + f = open("auth.json", "a") #Writing content + f.write("""{ + "authusername": "", + "authpassword": "" +}""") + f.close() + print (""" +1. Login +2. Register + """)#Again skipping auto-login bc the file is empty/missing + ans=input("Select Option: ") + if ans=="1": + user = input('Provide username: ') + password = input('Provide password: ') + keyauthapp.login(user,password) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + elif ans=="2": + user = input('Provide username: ') + password = input('Provide password: ') + license = input('Provide License: ') + keyauthapp.register(user,password,license) + authfile = jsond.load(open("auth.json")) + authfile["authusername"] = user + authfile["authpassword"] = password + jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) + else: + print("\nNot Valid Option") + os._exit(1) + except Exception as e: #Error stuff + print(e) + os._exit(1) +except Exception as e: #Error stuff + print(e) + os._exit(1)''' + +# endregion + + +print("\nUser data: ") +print("Username: " + keyauthapp.user_data.username) +print("IP address: " + keyauthapp.user_data.ip) +print("Hardware-Id: " + keyauthapp.user_data.hwid) +# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name + +subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft +for i in range(len(subs)): + sub = subs[i]["subscription"] # Subscription from every Sub + expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( + '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub + timeleft = subs[i]["timeleft"] # Timeleft from every Sub + + print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") + +onlineUsers = keyauthapp.fetchOnline() +OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING. +if onlineUsers is None: + OU = "No online users" +else: + for i in range(len(onlineUsers)): + OU += onlineUsers[i]["credential"] + " " + +print("\n" + OU + "\n") + +print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) +print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) +print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) +print(f"Current Session Validation Status: {keyauthapp.check()}") diff --git a/other-examples/method3.py b/other-examples/method3.py new file mode 100644 index 0000000..5d14f53 --- /dev/null +++ b/other-examples/method3.py @@ -0,0 +1,616 @@ + +import os +import json as jsond # json +import time # sleep before exit +import binascii # hex encoding +import platform # check platform +import subprocess # needed for mac device +from datetime import datetime +# from discord_interactions import verify_key # used for signature verification + +try: + if os.name == 'nt': + import win32security # get sid (WIN only) + import requests # https requests +except ModuleNotFoundError: + print("Exception when importing modules") + print("Installing necessary modules....") + if os.path.isfile("requirements.txt"): + os.system("pip install -r requirements.txt") + else: + if os.name == 'nt': + os.system("pip install pywin32") + os.system("pip install requests") + print("Modules installed!") + time.sleep(1.5) + os._exit(1) + + +class api: + + name = ownerid = version = hash_to_check = "" + + def __init__(self, name, ownerid, version, hash_to_check): + if len(ownerid) != 10: + print("Visit https://keyauth.cc/app/, copy Pthon code, and replace code in main.py with that") + time.sleep(3) + os._exit(1) + + self.name = name + + self.ownerid = ownerid + + self.version = version + self.hash_to_check = hash_to_check + self.init() + + sessionid = enckey = "" + initialized = False + + def init(self): + if self.sessionid != "": + print("You've already initialized!") + time.sleep(3) + os._exit(1) + + post_data = { + "type": "init", + "ver": self.version, + "hash": self.hash_to_check, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + if response == "KeyAuth_Invalid": + print("The application doesn't exist") + time.sleep(3) + os._exit(1) + + json = jsond.loads(response) + + if json["message"] == "invalidver": + if json["download"] != "": + print("New Version Available") + download_link = json["download"] + os.system(f"start {download_link}") + time.sleep(3) + os._exit(1) + else: + print("Invalid Version, Contact owner to add download link to latest app version") + time.sleep(3) + os._exit(1) + + if not json["success"]: + print(json["message"]) + time.sleep(3) + os._exit(1) + + self.sessionid = json["sessionid"] + self.initialized = True + + def register(self, user, password, license, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + post_data = { + "type": "register", + "username": user, + "pass": password, + "key": license, + "hwid": hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + print(json["message"]) + self.__load_user_data(json["info"]) + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def upgrade(self, user, license): + self.checkinit() + + post_data = { + "type": "upgrade", + "username": user, + "key": license, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + print(json["message"]) + print("Please restart program and login") + time.sleep(3) + os._exit(1) + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def login(self, user, password, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + post_data = { + "type": "login", + "username": user, + "pass": password, + "hwid": hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print(json["message"]) + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def license(self, key, hwid=None): + self.checkinit() + if hwid is None: + hwid = others.get_hwid() + + post_data = { + "type": "license", + "key": key, + "hwid": hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + self.__load_user_data(json["info"]) + print(json["message"]) + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def var(self, name): + self.checkinit() + + post_data = { + "type": "var", + "varid": name, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def getvar(self, var_name): + self.checkinit() + + post_data = { + "type": "getvar", + "var": var_name, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return json["response"] + else: + print(f"NOTE: This is commonly misunderstood. This is for user variables, not the normal variables.\nUse keyauthapp.var(\"{var_name}\") for normal variables"); + print(json["message"]) + time.sleep(3) + os._exit(1) + + def setvar(self, var_name, var_data): + self.checkinit() + + post_data = { + "type": "setvar", + "var": var_name, + "data": var_data, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def ban(self): + self.checkinit() + + post_data = { + "type": "ban", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def file(self, fileid): + self.checkinit() + + post_data = { + "type": "file", + "fileid": fileid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if not json["success"]: + print(json["message"]) + time.sleep(3) + os._exit(1) + return binascii.unhexlify(json["contents"]) + + def webhook(self, webid, param, body = "", conttype = ""): + self.checkinit() + + post_data = { + "type": "webhook", + "webid": webid, + "params": param, + "body": body, + "conttype": conttype, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return json["message"] + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def check(self): + self.checkinit() + + post_data = { + "type": "check", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = self.__do_request(post_data) + + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def checkblacklist(self): + self.checkinit() + hwid = others.get_hwid() + + post_data = { + "type": "checkblacklist", + "hwid": hwid, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + response = self.__do_request(post_data) + + json = jsond.loads(response) + if json["success"]: + return True + else: + return False + + def log(self, message): + self.checkinit() + + post_data = { + "type": "log", + "pcuser": os.getenv('username'), + "message": message, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + self.__do_request(post_data) + + def fetchOnline(self): + self.checkinit() + + post_data = { + "type": "fetchOnline", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + if len(json["users"]) == 0: + return None + else: + return json["users"] + else: + return None + + def fetchStats(self): + self.checkinit() + + post_data = { + "type": "fetchStats", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + self.__load_app_data(json["appinfo"]) + + def chatGet(self, channel): + self.checkinit() + + post_data = { + "type": "chatget", + "channel": channel, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return json["messages"] + else: + return None + + def chatSend(self, message, channel): + self.checkinit() + + post_data = { + "type": "chatsend", + "message": message, + "channel": channel, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + return True + else: + return False + + def checkinit(self): + if not self.initialized: + print("Initialize first, in order to use the functions") + time.sleep(3) + os._exit(1) + + def changeUsername(self, username): + self.checkinit() + + post_data = { + "type": "changeUsername", + "newUsername": username, + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + print("Successfully changed username") + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def logout(self): + self.checkinit() + + post_data = { + "type": "logout", + "sessionid": self.sessionid, + "name": self.name, + "ownerid": self.ownerid + } + + response = self.__do_request(post_data) + + json = jsond.loads(response) + + if json["success"]: + print("Successfully logged out") + time.sleep(3) + os._exit(1) + else: + print(json["message"]) + time.sleep(3) + os._exit(1) + + def __do_request(self, post_data): + try: + response = requests.post( + "https://keyauth.win/api/1.3/", data=post_data, timeout=10 + ) + + if post_data["type"] == "log" or post_data["type"] == "file": return response.text + + signature = response.headers["x-signature-ed25519"] + timestamp = response.headers["x-signature-timestamp"] + + unix_timestamp = int(timestamp) + # Get the current time + current_time = int(datetime.utcnow().timestamp()) + + # Check if the timestamp is older than 20 seconds + if current_time - unix_timestamp > 20: + print("Timestamp OLD") + time.sleep(3) + os._exit(1) + + if not os.path.exists("C:\\ProgramData\\KeyAuth"): + os.makedirs("C:\\ProgramData\\KeyAuth") + os.makedirs("C:\\ProgramData\\KeyAuth\\Debug") + + exe_name = os.path.basename(__file__) + if not os.path.exists(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}"): + os.makedirs(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}") + + with open(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}\\log.txt", "a") as log_file: + if len(response.text) <= 200: + execution_time = time.strftime("%I:%M %p | %m/%d/%Y") + log_file.write(f"\n{execution_time} | {post_data['type']} \nResponse: {response.text}") + + if not verify_key(response.text.encode('utf-8'), signature, timestamp, '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b'): + print("Signature checksum failed. Request was tampered with or session ended most likely.") + print("Response: " + response.text) + time.sleep(3) + os._exit(1) + + return response.text + except requests.exceptions.Timeout: + print("Request timed out. Server is probably down/slow at the moment") + + class application_data_class: + numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" + + class user_data_class: + username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" + + user_data = user_data_class() + app_data = application_data_class() + + def __load_app_data(self, data): + self.app_data.numUsers = data["numUsers"] + self.app_data.numKeys = data["numKeys"] + self.app_data.app_ver = data["version"] + self.app_data.customer_panel = data["customerPanelLink"] + self.app_data.onlineUsers = data["numOnlineUsers"] + + def __load_user_data(self, data): + self.user_data.username = data["username"] + self.user_data.ip = data["ip"] + self.user_data.hwid = data["hwid"] or "N/A" + self.user_data.expires = data["subscriptions"][0]["expiry"] + self.user_data.createdate = data["createdate"] + self.user_data.lastlogin = data["lastlogin"] + self.user_data.subscription = data["subscriptions"][0]["subscription"] + self.user_data.subscriptions = data["subscriptions"] + + +class others: + @staticmethod + def get_hwid(): + if platform.system() == "Linux": + with open("/etc/machine-id") as f: + hwid = f.read() + return hwid + elif platform.system() == 'Windows': + winuser = os.getlogin() + sid = win32security.LookupAccountName(None, winuser)[0] # You can also use WMIC (better than SID, some users had problems with WMIC) + hwid = win32security.ConvertSidToStringSid(sid) + return hwid + ''' + cmd = subprocess.Popen( + "wmic useraccount where name='%username%' get sid", + stdout=subprocess.PIPE, + shell=True, + ) + + (suppost_sid, error) = cmd.communicate() + + suppost_sid = suppost_sid.split(b"\n")[1].strip() + + return suppost_sid.decode() + + ^^ HOW TO DO IT USING WMIC + ''' + elif platform.system() == 'Darwin': + output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] + serial = output.decode().split('=', 1)[1].replace(' ', '') + hwid = serial[1:-2] + return hwid + diff --git a/requirements.txt b/requirements.txt index 1778876..c613201 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ requests -pywin32 -discord-interactions +discord-interactions \ No newline at end of file From d17f3d0b7ae5bbac07958480d12b8bd95c42c400 Mon Sep 17 00:00:00 2001 From: Ahsan-Ullah <69212320+TechQaiser@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:32:38 +0500 Subject: [PATCH 2/3] Delete keyauth.py no need any more --- keyauth.py | 615 ----------------------------------------------------- 1 file changed, 615 deletions(-) delete mode 100644 keyauth.py diff --git a/keyauth.py b/keyauth.py deleted file mode 100644 index b11b4cd..0000000 --- a/keyauth.py +++ /dev/null @@ -1,615 +0,0 @@ -import os -import json as jsond # json -import time # sleep before exit -import binascii # hex encoding -import platform # check platform -import subprocess # needed for mac device -from datetime import datetime -from discord_interactions import verify_key # used for signature verification - -try: - if os.name == 'nt': - import win32security # get sid (WIN only) - import requests # https requests -except ModuleNotFoundError: - print("Exception when importing modules") - print("Installing necessary modules....") - if os.path.isfile("requirements.txt"): - os.system("pip install -r requirements.txt") - else: - if os.name == 'nt': - os.system("pip install pywin32") - os.system("pip install requests") - print("Modules installed!") - time.sleep(1.5) - os._exit(1) - - -class api: - - name = ownerid = version = hash_to_check = "" - - def __init__(self, name, ownerid, version, hash_to_check): - if len(ownerid) != 10: - print("Visit https://keyauth.cc/app/, copy Pthon code, and replace code in main.py with that") - time.sleep(3) - os._exit(1) - - self.name = name - - self.ownerid = ownerid - - self.version = version - self.hash_to_check = hash_to_check - self.init() - - sessionid = enckey = "" - initialized = False - - def init(self): - if self.sessionid != "": - print("You've already initialized!") - time.sleep(3) - os._exit(1) - - post_data = { - "type": "init", - "ver": self.version, - "hash": self.hash_to_check, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - if response == "KeyAuth_Invalid": - print("The application doesn't exist") - time.sleep(3) - os._exit(1) - - json = jsond.loads(response) - - if json["message"] == "invalidver": - if json["download"] != "": - print("New Version Available") - download_link = json["download"] - os.system(f"start {download_link}") - time.sleep(3) - os._exit(1) - else: - print("Invalid Version, Contact owner to add download link to latest app version") - time.sleep(3) - os._exit(1) - - if not json["success"]: - print(json["message"]) - time.sleep(3) - os._exit(1) - - self.sessionid = json["sessionid"] - self.initialized = True - - def register(self, user, password, license, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - post_data = { - "type": "register", - "username": user, - "pass": password, - "key": license, - "hwid": hwid, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - print(json["message"]) - self.__load_user_data(json["info"]) - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def upgrade(self, user, license): - self.checkinit() - - post_data = { - "type": "upgrade", - "username": user, - "key": license, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - print(json["message"]) - print("Please restart program and login") - time.sleep(3) - os._exit(1) - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def login(self, user, password, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - post_data = { - "type": "login", - "username": user, - "pass": password, - "hwid": hwid, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print(json["message"]) - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def license(self, key, hwid=None): - self.checkinit() - if hwid is None: - hwid = others.get_hwid() - - post_data = { - "type": "license", - "key": key, - "hwid": hwid, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - self.__load_user_data(json["info"]) - print(json["message"]) - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def var(self, name): - self.checkinit() - - post_data = { - "type": "var", - "varid": name, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def getvar(self, var_name): - self.checkinit() - - post_data = { - "type": "getvar", - "var": var_name, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return json["response"] - else: - print(f"NOTE: This is commonly misunderstood. This is for user variables, not the normal variables.\nUse keyauthapp.var(\"{var_name}\") for normal variables"); - print(json["message"]) - time.sleep(3) - os._exit(1) - - def setvar(self, var_name, var_data): - self.checkinit() - - post_data = { - "type": "setvar", - "var": var_name, - "data": var_data, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def ban(self): - self.checkinit() - - post_data = { - "type": "ban", - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def file(self, fileid): - self.checkinit() - - post_data = { - "type": "file", - "fileid": fileid, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if not json["success"]: - print(json["message"]) - time.sleep(3) - os._exit(1) - return binascii.unhexlify(json["contents"]) - - def webhook(self, webid, param, body = "", conttype = ""): - self.checkinit() - - post_data = { - "type": "webhook", - "webid": webid, - "params": param, - "body": body, - "conttype": conttype, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return json["message"] - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def check(self): - self.checkinit() - - post_data = { - "type": "check", - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - response = self.__do_request(post_data) - - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def checkblacklist(self): - self.checkinit() - hwid = others.get_hwid() - - post_data = { - "type": "checkblacklist", - "hwid": hwid, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - response = self.__do_request(post_data) - - json = jsond.loads(response) - if json["success"]: - return True - else: - return False - - def log(self, message): - self.checkinit() - - post_data = { - "type": "log", - "pcuser": os.getenv('username'), - "message": message, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - self.__do_request(post_data) - - def fetchOnline(self): - self.checkinit() - - post_data = { - "type": "fetchOnline", - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - if len(json["users"]) == 0: - return None - else: - return json["users"] - else: - return None - - def fetchStats(self): - self.checkinit() - - post_data = { - "type": "fetchStats", - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - self.__load_app_data(json["appinfo"]) - - def chatGet(self, channel): - self.checkinit() - - post_data = { - "type": "chatget", - "channel": channel, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return json["messages"] - else: - return None - - def chatSend(self, message, channel): - self.checkinit() - - post_data = { - "type": "chatsend", - "message": message, - "channel": channel, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - return True - else: - return False - - def checkinit(self): - if not self.initialized: - print("Initialize first, in order to use the functions") - time.sleep(3) - os._exit(1) - - def changeUsername(self, username): - self.checkinit() - - post_data = { - "type": "changeUsername", - "newUsername": username, - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - print("Successfully changed username") - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def logout(self): - self.checkinit() - - post_data = { - "type": "logout", - "sessionid": self.sessionid, - "name": self.name, - "ownerid": self.ownerid - } - - response = self.__do_request(post_data) - - json = jsond.loads(response) - - if json["success"]: - print("Successfully logged out") - time.sleep(3) - os._exit(1) - else: - print(json["message"]) - time.sleep(3) - os._exit(1) - - def __do_request(self, post_data): - try: - response = requests.post( - "https://keyauth.win/api/1.3/", data=post_data, timeout=10 - ) - - if post_data["type"] == "log" or post_data["type"] == "file": return response.text - - signature = response.headers["x-signature-ed25519"] - timestamp = response.headers["x-signature-timestamp"] - - unix_timestamp = int(timestamp) - # Get the current time - current_time = int(datetime.utcnow().timestamp()) - - # Check if the timestamp is older than 20 seconds - if current_time - unix_timestamp > 20: - print("Timestamp OLD") - time.sleep(3) - os._exit(1) - - if not os.path.exists("C:\\ProgramData\\KeyAuth"): - os.makedirs("C:\\ProgramData\\KeyAuth") - os.makedirs("C:\\ProgramData\\KeyAuth\\Debug") - - exe_name = os.path.basename(__file__) - if not os.path.exists(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}"): - os.makedirs(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}") - - with open(f"C:\\ProgramData\\KeyAuth\\Debug\\{exe_name}\\log.txt", "a") as log_file: - if len(response.text) <= 200: - execution_time = time.strftime("%I:%M %p | %m/%d/%Y") - log_file.write(f"\n{execution_time} | {post_data['type']} \nResponse: {response.text}") - - if not verify_key(response.text.encode('utf-8'), signature, timestamp, '5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b'): - print("Signature checksum failed. Request was tampered with or session ended most likely.") - print("Response: " + response.text) - time.sleep(3) - os._exit(1) - - return response.text - except requests.exceptions.Timeout: - print("Request timed out. Server is probably down/slow at the moment") - - class application_data_class: - numUsers = numKeys = app_ver = customer_panel = onlineUsers = "" - - class user_data_class: - username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = "" - - user_data = user_data_class() - app_data = application_data_class() - - def __load_app_data(self, data): - self.app_data.numUsers = data["numUsers"] - self.app_data.numKeys = data["numKeys"] - self.app_data.app_ver = data["version"] - self.app_data.customer_panel = data["customerPanelLink"] - self.app_data.onlineUsers = data["numOnlineUsers"] - - def __load_user_data(self, data): - self.user_data.username = data["username"] - self.user_data.ip = data["ip"] - self.user_data.hwid = data["hwid"] or "N/A" - self.user_data.expires = data["subscriptions"][0]["expiry"] - self.user_data.createdate = data["createdate"] - self.user_data.lastlogin = data["lastlogin"] - self.user_data.subscription = data["subscriptions"][0]["subscription"] - self.user_data.subscriptions = data["subscriptions"] - - -class others: - @staticmethod - def get_hwid(): - if platform.system() == "Linux": - with open("/etc/machine-id") as f: - hwid = f.read() - return hwid - elif platform.system() == 'Windows': - winuser = os.getlogin() - sid = win32security.LookupAccountName(None, winuser)[0] # You can also use WMIC (better than SID, some users had problems with WMIC) - hwid = win32security.ConvertSidToStringSid(sid) - return hwid - ''' - cmd = subprocess.Popen( - "wmic useraccount where name='%username%' get sid", - stdout=subprocess.PIPE, - shell=True, - ) - - (suppost_sid, error) = cmd.communicate() - - suppost_sid = suppost_sid.split(b"\n")[1].strip() - - return suppost_sid.decode() - - ^^ HOW TO DO IT USING WMIC - ''' - elif platform.system() == 'Darwin': - output = subprocess.Popen("ioreg -l | grep IOPlatformSerialNumber", stdout=subprocess.PIPE, shell=True).communicate()[0] - serial = output.decode().split('=', 1)[1].replace(' ', '') - hwid = serial[1:-2] - return hwid - From 38e697c41235165609fdf8e1e88d4ddece49814b Mon Sep 17 00:00:00 2001 From: Ahsan-Ullah <69212320+TechQaiser@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:33:02 +0500 Subject: [PATCH 3/3] Delete main.py not usefull as converted it in example.py --- main.py | 187 -------------------------------------------------------- 1 file changed, 187 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index 8aaded8..0000000 --- a/main.py +++ /dev/null @@ -1,187 +0,0 @@ -''' -KeyAuth.cc Python Example - -Go to https://keyauth.cc/app/ and click the Python tab. Copy that code and replace the existing keyauthapp instance in this file. - -If you get an error saying it can't find module KeyAuth, try following this https://github.com/KeyAuth/KeyAuth-Python-Example#how-to-compile - -If that doesn't work for you, you can paste the contents of KeyAuth.py ABOVE this comment and then remove the "from keyauth import api" and that should work too. - -READ HERE TO LEARN ABOUT KEYAUTH FUNCTIONS https://github.com/KeyAuth/KeyAuth-Python-Example#keyauthapp-instance-definition -''' -from keyauth import api - -import sys -import time -import platform -import os -import hashlib -from time import sleep -from datetime import datetime - -# import json as jsond -# ^^ only for auto login/json writing/reading - -# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA - -def clear(): - if platform.system() == 'Windows': - os.system('cls & title Python Example') # clear console, change title - elif platform.system() == 'Linux': - os.system('clear') # clear console - sys.stdout.write("\x1b]0;Python Example\x07") # change title - elif platform.system() == 'Darwin': - os.system("clear && printf '\e[3J'") # clear console - os.system('''echo - n - e "\033]0;Python Example\007"''') # change title - -print("Initializing") - - -def getchecksum(): - md5_hash = hashlib.md5() - file = open(''.join(sys.argv), "rb") - md5_hash.update(file.read()) - digest = md5_hash.hexdigest() - return digest - - -keyauthapp = api( - name = "", # Application Name - ownerid = "", # Owner ID - version = "1.0", # Application Version - hash_to_check = getchecksum() -) - -def answer(): - try: - print("""1.Login -2.Register -3.Upgrade -4.License Key Only - """) - ans = input("Select Option: ") - if ans == "1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user, password) - elif ans == "2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user, password, license) - elif ans == "3": - user = input('Provide username: ') - license = input('Provide License: ') - keyauthapp.upgrade(user, license) - elif ans == "4": - key = input('Enter your license: ') - keyauthapp.license(key) - else: - print("\nInvalid option") - sleep(1) - clear() - answer() - except KeyboardInterrupt: - os._exit(1) - - -answer() - -'''try: - if os.path.isfile('auth.json'): #Checking if the auth file exist - if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not - print(""" -1. Login -2. Register - """) - ans=input("Select Option: ") #Skipping auto-login bc auth file is empty - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - else: - try: #2. Auto login - with open('auth.json', 'r') as f: - authfile = jsond.load(f) - authuser = authfile.get('authusername') - authpass = authfile.get('authpassword') - keyauthapp.login(authuser,authpass) - except Exception as e: #Error stuff - print(e) - else: #Creating auth file bc its missing - try: - f = open("auth.json", "a") #Writing content - f.write("""{ - "authusername": "", - "authpassword": "" -}""") - f.close() - print (""" -1. Login -2. Register - """)#Again skipping auto-login bc the file is empty/missing - ans=input("Select Option: ") - if ans=="1": - user = input('Provide username: ') - password = input('Provide password: ') - keyauthapp.login(user,password) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - elif ans=="2": - user = input('Provide username: ') - password = input('Provide password: ') - license = input('Provide License: ') - keyauthapp.register(user,password,license) - authfile = jsond.load(open("auth.json")) - authfile["authusername"] = user - authfile["authpassword"] = password - jsond.dump(authfile, open('auth.json', 'w'), sort_keys=False, indent=4) - else: - print("\nNot Valid Option") - os._exit(1) - except Exception as e: #Error stuff - print(e) - os._exit(1) -except Exception as e: #Error stuff - print(e) - os._exit(1)''' - - -print("\nUser data: ") -print("Username: " + keyauthapp.user_data.username) -print("IP address: " + keyauthapp.user_data.ip) -print("Hardware-Id: " + keyauthapp.user_data.hwid) - -subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft -for i in range(len(subs)): - sub = subs[i]["subscription"] # Subscription from every Sub - expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime( - '%Y-%m-%d %H:%M:%S') # Expiry date from every Sub - timeleft = subs[i]["timeleft"] # Timeleft from every Sub - - print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}") - -print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S')) -print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S')) -print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S')) -print("\nExiting in five seconds..") -sleep(5) -os._exit(1)