Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Tutorial 

License System for Python apps.

[Image: oKTRsJt.gif]


Lately I have had a few people ask about how to sell/rent a Python app without having it leaked or cracked.
Many people suggest using Beeware to compile it into an executable, but we all know that can easily be reversed.

What I have done to secure a few programs I have made in Python is develop an interactive console menu as the front-end if you will.
You install your app onto a simple bare-bones Debian VPS and modify the user logins to execute the app instead of bash/shell.

1. Make sure to add the shebang at the top of the python app that you want run on login.
Code
#!/usr/bin/env python3

2. Also add this code to the main function of your app before any other code so you are in the correct working path.
Code
os.chdir("/path/to/python/app")

3. Create a new file called new_license.sh and include the code below.
Code
#!/bin/bash

new_license() {
    printf "Enter username: "
    read -r licenseUser

    printf "Enter password: "
    read -r licensePass

    printf "Date Format >> 2024-04-20\n"
    printf "Enter cutoff date: "
    read -r cutoffDate

    adduser --quiet --disabled-password --gecos "User" $licenseUser
    echo "$licenseUser:$licensePass" | chpasswd

    usermod -e $cutoffDate $licenseUser

    chmod +x /root/PythonApp.py
    usermod -s /root/PythonApp.py $licenseUser
}

new_license

4. Make the new_license.sh executable.
Code
chmod +x new_license.sh

5. Create a new user by running the bash script and entering the needed information. This step can be repeated when needed to create a new user.
Code
./new_license.sh

Now login by ssh using ssh or putty and the user/pass you set in step 5. You should be presented with your console application. Enjoy and if you run into any problems send me a DM and I can help you out.
Nice share mate! Keep it up!
so this is restricted to ssh access only? and what if the program is nontrivial and requires any sort of i/o?
(Jun 17, 2024 03:35 PM)mtaujanskas Wrote:  so this is restricted to ssh access only? and what if the program is nontrivial and requires any sort of i/o?

Idk about this but for windows, simply use https://github.com/Nuitka/Nuitka and use a pre-existing license SDK, like KeyAuth.
(Jun 17, 2024 03:35 PM)mtaujanskas Wrote:  so this is restricted to ssh access only? and what if the program is nontrivial and requires any sort of i/o?

In that case I use a Flask server as an example and I run it as a service. All incoming data is stored in a sqlite3 DB and the ConsoleMenu can access it when logged in through SSH.

If you need to do something like a download then you can write a file temporary to /var/www/html.


(Jun 17, 2024 06:45 PM)Tentco Wrote:  Idk about this but for windows, simply use https://github.com/Nuitka/Nuitka and use a pre-existing license SDK, like KeyAuth.

You can do same on Windows, just host the app on Linux so its always running. Then in Windows use cmd.exe/powershell.exe to run ssh.

Nuitka I feel is same as Beeware in terms of cracking though and the file size for any Python app is huge once compiled.
(Jun 18, 2024 05:55 AM)Qismon Wrote:  In that case I use a Flask server as an example and I run it as a service. All incoming data is stored in a sqlite3 DB and the ConsoleMenu can access it when logged in through SSH.

If you need to do something like a download then you can write a file temporary to /var/www/html.



You can do same on Windows, just host the app on Linux so its always running. Then in Windows use cmd.exe/powershell.exe to run ssh.

Nuitka I feel is same as Beeware in terms of cracking though and the file size for any Python app is huge once compiled.

Nuitka is not same, it translates source to C and is obviously less in size most of the time.
(Jun 18, 2024 06:10 AM)Tentco Wrote:  Nuitka is not same, it translates source to C and is obviously less in size most of the time.

Honestly I have not tried it before, but it uses CPython correct?

I have never been able to get a exe for Python less than 7MB and even with just print() it gets detected as malware.
(Jun 18, 2024 06:19 AM)Qismon Wrote:  Honestly I have not tried it before, but it uses CPython correct?

I have never been able to get a exe for Python less than 7MB and even with just print() it gets detected as malware.

https://github.com/Nuitka/Nuitka

7mb for hello world sounds like pyinstaller.
(Jun 18, 2024 06:23 AM)Tentco Wrote:  https://github.com/Nuitka/Nuitka

7mb for hello world sounds like pyinstaller.

PyInstaller or Beeware had the same problem with compiled size. Thanks I'll check it out sometime today.
(Jun 18, 2024 05:55 AM)Qismon Wrote:  In that case I use a Flask server as an example and I run it as a service. All incoming data is stored in a sqlite3 DB and the ConsoleMenu can access it when logged in through SSH.

If you need to do something like a download then you can write a file temporary to /var/www/html.

so it's not a drop-in module for an application (and not even necessarily Python-specific)? and you also have to rework your application based around the axiom that you have no access to the user's system in any way whatsoever.
(Jun 18, 2024 08:07 AM)mtaujanskas Wrote:  so it's not a drop-in module for an application (and not even necessarily Python-specific)? and you also have to rework your application based around the axiom that you have no access to the user's system in any way whatsoever.

Never said it was a drop in module or Python specific. No need to rework your application at all either, it's literally 1 chdir statement to make sure you are in the same path as the running app.

I have been renting a builder that runs on same tech and without any problems of having access to the users system.
Interesting approach. Thanks for sharing.
[Image: O444cFs.jpg]
So when the user connects to the ssh user it will instantly open the python script? and what if they do CTRL + C? i did do an app like that a while ago. seems cool.
[Image: rezize.png]
(Jun 24, 2024 04:15 PM)Novo Wrote:  So when the user connects to the ssh user it will instantly open the python script? and what if they do CTRL + C? i did do an app like that a while ago. seems cool.

Yes instead of opening bash shell as normal it will run the python app. Ctrl+C will kill the SSH session but if you are in a while loop or running threads then it will just break from the loop.
(Jun 25, 2024 06:30 AM)Qismon Wrote:  Yes instead of opening bash shell as normal it will run the python app. Ctrl+C will kill the SSH session but if you are in a while loop or running threads then it will just break from the loop.

Seems very cool. Thank you for sharing this!
[Image: rezize.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[.NET] by evikingOct 4, 2022 11:57 PM 0 201 Oct 4, 2022 11:57 PM
Last Post: eviking
[Python] by BIZZY.Apr 29, 2021 12:05 PM 0 134 Apr 29, 2021 12:05 PM
Last Post: BIZZY.