knownsec / Pocsuite

This project has stopped to maintenance, please to https://github.com/knownsec/pocsuite3 project.
http://pocsuite.org
1.83k stars 607 forks source link

调用cannon API 尝试集成pocsuite的时候遇到错误 #120

Closed bit4woo closed 8 years ago

bit4woo commented 8 years ago

我使用了以下代码调用 cannon API :

#!/usr/bin/python
# coding:utf-8

from pocsuite.api.cannon import Cannon
info = {"pocname": "modules\dlink_command_php_exec_noauth.py", #应该是py文件名
        "pocstring": "dlink_command_php_exec_noauth.py",
        "mode": "verify"
        }
target = "www.baidu.com"
invoker = Cannon(target, info) # 生成用来引用 Pocsuite 的实例
result = invoker.run() # 调用 Pocsuite, result 保存了 Pocsuite 执行的返回结果
print result

遇到的错误如下:

Traceback (most recent call last):
dlink_command_php_exec_noauth.py
  File "D:/BitTorrentSync/Python_Code/scoutproject/scout/callpocsuite.py", line 9, in <module>
    invoker = Cannon(target, info) # 生成用来引用 Pocsuite 的实例
<code object <module> at 025185C0, file "dlink_command_php_exec_noauth.py", line 1>
  File "C:\Python27\lib\site-packages\pocsuite-2.0.4.1-py2.7.egg\pocsuite\api\cannon.py", line 45, in __init__
    self.registerPoc()
  File "C:\Python27\lib\site-packages\pocsuite-2.0.4.1-py2.7.egg\pocsuite\api\cannon.py", line 62, in registerPoc
    importer.load_module(self.moduleName)
  File "C:\Python27\lib\site-packages\pocsuite-2.0.4.1-py2.7.egg\pocsuite\lib\core\common.py", line 60, in load_module
    exec code in mod.__dict__   #exec语句将字符串str当成有效Python代码来执行 ,in后边的内容是指定该语句的全局和局部命名空间。
  File "dlink_command_php_exec_noauth.py", line 1, in <module>
NameError: name 'dlink_command_php_exec_noauth' is not defined
nixawk commented 8 years ago

Thanks @bit4woo, A single comprehensive wiki page is needed. Please try the following demo:

#!/usr/bin/python
# coding:utf-8

from pocsuite.api.cannon import Cannon
info = {"pocname": "dlink_command_php_exec_noauth",
        "pocstring": open("./modules/dlink_command_php_exec_noauth.py").read(),
        "mode": "verify"}

target = "www.justfordemo.com"
invoker = Cannon(target, info)
result = invoker.run()
print result
nixawk commented 8 years ago

https://github.com/knownsec/Pocsuite/wiki/How-to-use-the-cannon-api

nixawk commented 8 years ago

@bit4woo Is it OK for you ?

nixawk commented 8 years ago

Thanks @bit4woo. The issue is closed.

bit4woo commented 8 years ago

It works! Thanks! @nixawk