-
Notifications
You must be signed in to change notification settings - Fork 784
/
Copy pathtest_api_get_poc_info.py
82 lines (66 loc) · 2.48 KB
/
test_api_get_poc_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import unittest
from pocsuite3.api import init_pocsuite
from pocsuite3.api import load_file_to_module, paths, load_string_to_module
class TestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_get_info(self):
init_pocsuite({})
poc_filename = os.path.join(paths.POCSUITE_POCS_PATH, '20190404_WEB_Confluence_path_traversal.py')
mod = load_file_to_module(poc_filename)
print(mod.get_infos())
self.assertTrue(len(mod.get_infos()) > 0)
def test_get_info_from_string(self):
source = r"""
from collections import OrderedDict
from pocsuite3.api import Output, POCBase, POC_CATEGORY, register_poc, requests
from pocsuite3.api import OptString
class DemoPOC(POCBase):
vulID = '00000' # ssvid
version = '1.0'
author = ['chenghs']
vulDate = '2019-2-26'
createDate = '2019-2-26'
updateDate = '2019-2-25'
references = ['']
name = '自定义命令参数登录例子'
appPowerLink = 'http://www.knownsec.com/'
appName = 'test'
appVersion = 'test'
vulType = 'demo'
desc = '''这个例子说明了你可以使用console模式设置一些参数或者使用命令中的'--'来设置自定义的参数'''
samples = []
category = POC_CATEGORY.EXPLOITS.WEBAPP
def _options(self):
o = OrderedDict()
o["username"] = OptString('', description='这个poc需要用户登录,请输入登录账号', require=True)
o["password"] = OptString('', description='这个poc需要用户密码,请输出用户密码', require=False)
return o
def _verify(self):
result = {}
payload = "username={0}&password={1}".format(self.get_option("username"), self.get_option("password"))
r = requests.post(self.url, data=payload)
print(r.text)
if r.status_code == 200:
result['VerifyInfo'] = {}
result['VerifyInfo']['URL'] = self.url
result['VerifyInfo']['Postdata'] = payload
return self.parse_output(result)
def _attack(self):
return self._verify()
def parse_output(self, result):
output = Output(self)
if result:
output.success(result)
else:
output.fail('target is not vulnerable')
return output
register_poc(DemoPOC)
""".strip()
init_pocsuite({})
mod = load_string_to_module(source)
print(mod.get_infos())
self.assertTrue(len(mod.get_infos()) > 0)