pyinstaller
打包一个文件试试看
#!/usr/bin/env python
# coding: utf-8
# file: myip.py
from __future__ import print_function
import time
import requests
from api import API
def main():
url = API.url
r = requests.get(url)
print(r.content)
if __name__ == "__main__":
# time.sleep(120)
main()
#!/usr/bin/env python
# coding: utf-8
# file: api.py
class API(object):
def __init__(self):
super(API).__init__()
url = "http://myip.ipip.net"
# lightless @ VM-UBUNTU in ~/program/pyinstaller [22:18:27]
$ pyinstaller -F myip.py
15 INFO: PyInstaller: 3.2.1
15 INFO: Python: 2.7.12
16 INFO: Platform: Linux-4.4.0-77-generic-x86_64-with-Ubuntu-16.04-xenial
16 INFO: wrote /home/lightless/program/pyinstaller/myip.spec
19 INFO: UPX is not available.
20 INFO: Extending PYTHONPATH with paths
['/home/lightless/program/pyinstaller', '/home/lightless/program/pyinstaller']
20 INFO: checking Analysis
24 INFO: Building because /home/lightless/program/pyinstaller/myip.py changed
24 INFO: Initializing module dependency graph...
25 INFO: Initializing module graph hooks...
57 INFO: running Analysis out00-Analysis.toc
74 INFO: Caching module hooks...
76 INFO: Analyzing /home/lightless/program/pyinstaller/myip.py
2739 INFO: Loading module hooks...
2740 INFO: Loading module hook "hook-httplib.py"...
2740 INFO: Loading module hook "hook-requests.py"...
2742 INFO: Loading module hook "hook-encodings.py"...
3012 INFO: Looking for ctypes DLLs
3058 INFO: Analyzing run-time hooks ...
3067 INFO: Looking for dynamic libraries
3272 INFO: Looking for eggs
3273 INFO: Python library not in binary depedencies. Doing additional searching...
3296 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
3299 INFO: Warnings written to /home/lightless/program/pyinstaller/build/myip/warnmyip.txt
3357 INFO: checking PYZ
3359 INFO: Building because toc changed
3360 INFO: Building PYZ (ZlibArchive) /home/lightless/program/pyinstaller/build/myip/out00-PYZ.pyz
3777 INFO: Building PYZ (ZlibArchive) /home/lightless/program/pyinstaller/build/myip/out00-PYZ.pyz completed successfully.
3835 INFO: checking PKG
3836 INFO: Building because /home/lightless/program/pyinstaller/build/myip/out00-PYZ.pyz changed
3836 INFO: Building PKG (CArchive) out00-PKG.pkg
5693 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
5699 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run
5699 INFO: checking EXE
5699 INFO: Rebuilding out00-EXE.toc because pkg is more recent
5699 INFO: Building EXE from out00-EXE.toc
5700 INFO: Appending archive to ELF section in EXE /home/lightless/program/pyinstaller/dist/myip
5728 INFO: Building EXE from out00-EXE.toc completed successfully.
# lightless @ VM-UBUNTU in ~/program/pyinstaller [22:36:53]
$ ./dist/myip
当前 IP:1.1.1.1 来自于:中国 浙江 杭州 联通
提取python源码
# lightless @ VM-UBUNTU in ~/program/pyinstaller/dist [22:43:37] C:2
$ python archive_viewer.py myip
Traceback (most recent call last):
File "archive_viewer.py", line 266, in <module>
run()
File "archive_viewer.py", line 258, in run
PyInstaller.log.__process_options(parser, args)
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/log.py", line 49, in __process_options
logger.setLevel(level)
NameError: global name 'logger' is not defined
U: go Up one level
O <name>: open embedded archive name
X <name>: extract name
Q: quit
? x myip
to filename? myip.pyc
?
还原Python源码
参考文献
pyinstaller document
How to decompile files from PyInstaller PYZ file
技术分享 | CVE-Python webbrowser.py 命令执行漏洞分析
更多技术分享
请关注MLSRC微信公众号