Meterpreter的“ python扩展 ”已于2015年11月添加到Metasploit框架中。这是一个完美的例子,社区可以如何扩展,并为Metasploit这个已经多功能的框架做出贡献。
在编写本文时,扩展仍处于积极的发展阶段,但是这个附加组件显示出很大的希望,因为它使用户能够在目标机器上本地运行Python代码,而无需安装解释器。各种Python模块(如cType)的内存中实现可以极大地扩展Meterpreter对受攻击的Windows目标的控制。
在我们的目标机器上运行一个活动的meterpreter shell程序,输入“load python”将会加载扩展名,使我们可以访问新的命令。
meterpreter > load python
Loading extension python...success.
一旦加载,我们可以发出“help”命令以查看Python命令。
meterpreter > help
...
Python Commands
===============
Command Description
------- -----------
python_execute Execute a python command string
python_import Import/run a python file or module
python_reset Resets/restarts the Python interpreter
“python_execute”在目标上运行给定的python字符串。如果需要结果,它应该存储在一个python变量中,并且该变量应该使用-r参数传递。
meterpreter > python_execute -h
Usage: python_execute [-r result var name]
Runs the given python string on the target. If a result is required, it should be stored in a python variable,
and that variable should passed using the -r parameter.
OPTIONS:
-h Help banner
-r <opt> Name of the variable containing the result (optional)
将Python代码文件或模块从磁盘加载到目标上的内存中。模块加载程序需要指向包含该模块的文件夹的路径,并且文件夹名称将用作模块名称。只有.py文件可用于模块。
meterpreter > python_import -h
Usage: python_import [-n mod name] [-r result var name]
Loads a python code file or module from disk into memory on the target.
The module loader requires a path to a folder that contains the module,
and the folder name will be used as the module name. Only .py files will
work with modules.
OPTIONS:
-f <opt> Path to the file (.py, .pyc), or module directory to import
-h Help banner
-n <opt> Name of the module (optional, for single files only)
-r <opt> Name of the variable containing the result (optional, single files only)
这是一个简单的用法解释:
meterpreter > python_reset -h
[+] Python interpreter successfully reset