How to Secure Termux Script (compile/encode/encrypt)

The termux script that we make is often rewritten by other people, this is because there is no encryption. Well, this time I will give a tutorial on how to secure the termux script to make it difficult for recorders.

Remember!! the language used for each termux script is different. Likewise with the encoding used, must be adjusted. The languages ​​that are often used are python, bash, and php.

If the script has been given security can not be recoded again?

No, even scripts that have been given extra security can still be recoded. It just takes a long time, that’s why I wrote it ‘complicates the recorders’.

Okay, now let’s just start the tutorial from the first language, namely:

Compile python with marshal (comarsh)

To secure the python script we can use marshal. Later the code in the script will be changed to exec(marshal.loads(‘cxxxx’)).

Marshaled python script
Marshaled python script

Remember this is only for python, python2, python3.

Here is how to compile python using marshal

Download tool marshal

How to download it can use wget followed by the address where to save the file. But first write down the following command:

termux-setup-storage
apt update && apt upgrade -y
pkg install python 
pkg install python2 
pkg install wget
cd /sdcard
wget 

After writing the wget command, the marshal tool will automatically be stored in the android storage.

comarsh.py . file
comarsh.py . file

Press ls to display it, if there is a file named comarsh.py, then the download process is successful.

comarsh.py file in internal storage
comarsh.py file in internal storage

Prepare the python script to be compiled

The script must be located in internal storage outside the folder. The goal is to make it easier to search for scripts.

If the script file is still in the download folder, please minimize the termux application first and then move the file outside the folder.

Remember the name of the file because it will be included in the tool.

Execute file comarsh.py

Go back to the termux application and run the comarsh.py file using the command:

python2 comarsh.py

The marshal tool will run and display the menu along with the author.

comarsh Tool tool
comarsh Tool tool

Select the compile marshal option

At the start of the tool, just select the first option, namely compile marshal. The trick just press the number 1 then press enter.

Next write the name of the python script file that will be encoded and press enter.

When the process is successful there will be a menu that comes out, namely compile again? y/n
Just hit t and enter.

Options for comarsh tool users
Options for comarsh tool users

Open the out folder

If the compilation process is successful, the resulting file will be namedhasil.py and stored in the out folder. This folder is created automatically by the marshal tool.

To open it can use the command:

cd out
Open the encrypted marshal file
Open the encrypted marshal file

Write the command immediately after the compilation process is complete.

To see if the code in the script has changed or not, you can use the command:

nano hasil.py

if you haven’t installed nano, it will error. the solution first enter the command pkg install nano -y and press enter.

Marshal is a single layer security on python scripts. To add layered security can use marshal combined with base64 and zlib.

Encrypt python scripts with marhsal, base and zlib

This encryption is three layers, so it will be very annoying for the person who will decode it. I myself also often use this security instead of comarsh.

The way to use it is the same as comarsh, which is to select the encrypt menu and then enter the script file name. And the packages that must be installed are also the same, namely python2, wget and bash.

For information this tool is made by deray. This name is quite popular if you often change termux scripts.

Extra python encryption tool
Extra python encryption tool

Due to many sought after reasons so…

This layered security tool can be downloaded in the newbie cyber group.

Encrypt python with pyc

Pyc can also be combined with other python security tools. The result of encrypting pyc is that the script code will turn into a symbol. And if uploaded to github the script can’t be seen.

Termux script that digithub can't see
Termux script that digithub can’t see

You can also install the pyc tool by downloading it using the wget command.

In detail, here is how to download and use the pyc tool.

Just in the termux application enter the command:

pkg isntall python2
pkg install wget
wget 

Next to run the pyc tool just use the command

python2 pyc

The script will run and just enter the name of the python script file that will be changed to pyc.

The name of the script after it is successful in pyc will have a C suffix behind it.

Example: if the initial script is named hackfb.py it will change to hackfb.pyc

Tip: Change my .pyc extension to .py to make it easier later when someone else executes it from github.

OK, now let’s move on to the next language, which is bash.

Compile bash scripts with the bash compiler tool

This tool is written by febry, so every result of the compiled bash script will have a -febry.sh suffix and to replace it just use the command mv -f the old filename and the new filename.

Likewise, the modified script code will become:

#!/bin/bash
#Obfuscated By xNot_Found
#Github : https://github.com/hatakecnk/BashProte

Just remove the #Obfuscated By and #Github lines to make it look more professional.

Edit the result of encrypting bash script
Edit the result of encrypting bash script

Here’s how to compile a bash script using the Bash compiler.

Step 1: Download the Bash compiler tool

The download method is still the same using the wget command. But first, open the internal storage from termux.

How to enter the command

cd /sdcard

Then enter the command again

pkg install python2
pkg install bash
wget

Step 2: Move the bash script outside the folder

remember, friends, put the bash script file that will be encrypted on internal storage outside any folder.

Step 3: Run the run.sh file

The downloaded bash compiler tool is called run.sh and to run it you can use the command:

bash run.sh

The tool will run as shown below.

Bash compiler tools
Bash compiler tools

Step 4: Enter the bash script to be encoded

Enter the name of the bash script file to be encrypted and press enter.

Next input the output (the name of the script result) without the .sh extension

For example, if you want the result of the script name to be my script then just write my script and press enter. And wait for the process to finish.

Automatically the script will be named scriptku-febry.sh

Options for using bash compiler tools
Options for using bash compiler tools

Step 5: Edit the encrypted result

Edit here because the code in the encrypted script has added the author and link of this tool.

The way you first install nano with the command:

pkg install nano

Next enter the command:

nano diikuti nama hasil enkripsi script
contoh: nano hackfb-febry.sh

When you have entered the nano editor, delete the second and third lines so that they become

#!Bash
Vvsjsjndnd (contoh kode Bash)

When finished, press ctrl+x then y and enter to save.

Another alternative can be to use the obfuscate tool

How to encrypt bash using obfuscate

Obfuscate is an easier tool for encrypting bash scripts. We just need to install the package first, then immediately execute the file to add security.

The result of encrypting with obfuscate the code will change to:

z="
";xxx ;xxx"

For the tutorial, please follow the steps below:

  1. Write orders pkg install nodejs in termux
  2. Rewrite the command npm install -g bash-obfuscate
  3. Move the bash script to be encrypted to termux ($HOME).
  4. Type the command bash-obfuscate filenamescript.sh -o resultname.sh

After the encryption process is complete, please check it with the nano command.

Compile php scripts with online compiler

This is the easiest way, you just need to copy all the php code to be encrypted and paste it on the php compiler site. Then just copy again the results from the compiler and paste it in a new file.

online php compiler
online php compiler

You can check the site for the online php compiler here.

To create a new file using termux, you can use the nano command followed by the name of the new file to be created.

Contoh: nano fileku.php

Next, paste the encrypted php code from the site earlier.

New file myfile.php
New file myfile.php

Conclusion

After the termux script has been added security, then upload the termux script to github. Try to create a new repository so that the traces of the previous script (unencrypted) don’t exist.

Encryption is an attempt to make it difficult for the recorder to see the original code of the script. Actually there is also a tool that can be used to open the encryption.

Especially for python, you can combine security with pyc. The trick is to compile the python script first with marshal, then compile the results again with pyc.

Okay, so this tutorial, hopefully it can be useful. If there are problems or things you want to ask, please write them in the comments column. Thank you

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *