Search This Blog

Wednesday, November 30, 2016

How to use pyobfuscate?

Here are the steps on how to hide the python scripts using pyobfuscate package:

Steps:


  • Get the source distribution from git.
                $ git clone https://github.com/astrand/pyobfuscate.

  • Enter into the pyobfuscate directory.
                $ cd pyobfuscate

  • Install pyobfuscate package
                 $ python setup.py install

         The above step will install pyobfuscate binary executable file in /usr/bin.


      Considering the actual python file is in /home/Desktop/userfile.py.
  • Run command:
                $ ./pyobfuscate '/home/Desktop/userfile.py' > /home/Documents/obfuscate.py

  • Go to the path where obfuscate.py is created.
               $ cd /home/Documents/

  • Allow execute permission for others to obfuscate.py 
               $ sudo chmod +x obfuscate.py

  • Run the obfusacte.py, the interpreter will be able to interpret the script.
               $ python obfucate.py

Tuesday, November 29, 2016

PYC-only Python Distibution

Here are the steps to build PYC-only python distribution. We shall create the build.py file, which on compilation creates pyc-only python distribution of the 'project' directory.


Steps:

  1. Lets create a build.py file in the same directory that we have project folder.
  2. Include the following code in the build.py:
 import os  
 import compileall  
 #Removes all open files from project directory.  
 command1='find . -name "*.py~" -exec rm -rf {} \;'  
 #compiles all .py files in project directory and creates corresponding file's .pyc  
 compileall.compile_dir('./project')  
 #creates a tar.gz file which excludes all .py files  
 command2='tar -zcvf project.tar project --exclude project/\*/\*.py --exclude project/\*.py --exclude ''exclude files/directory which are irrelevant''  
 #removes .pyc created in actual project directory.  
 command3='find . -name "*.pyc" -exec rm -rf {} \;'  
 #use below command if you do not want to remove any particular files in the path.  
 #command3='find . ! -name build.py -name "*.py" -exec rm -rf {} \;'  
 #Execute the commands  
 os.system(command1)  
 os.system(command2)  
 os.system(command3)  

3. Run the build.py script.
4. A project.tar.gz file will be created within the same directory.
       5. Untar the file using -xvzf command, you should be able to see only .pyc files in the                              distribution.