Skip to content

Commit 6fba346

Browse files
authored
Merge pull request #332 from knownsec/feat/yaml
feat: yaml poc support
2 parents a76eb72 + 43d3548 commit 6fba346

File tree

30 files changed

+2801
-59
lines changed

30 files changed

+2801
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# version 2.0.0
2+
----------------
3+
* yaml poc support, compatible with nuclei
4+
* fix httpserver module hangs on macos platform
5+
* auto correction of url protocol based on status code
6+
17
# version 1.9.11
28
----------------
39
* support customize poc protocol and default port #321

manpages/poc-console.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ is maintained at:
3131
.I https://pocsuite.org
3232
.PP
3333
.SH VERSION
34-
This manual page documents pocsuite3 version 1.9.11
34+
This manual page documents pocsuite3 version 2.0.0
3535
.SH AUTHOR
3636
.br
3737
(c) 2014-present by Knownsec 404 Team

manpages/pocsuite.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ is maintained at:
286286
.I https://pocsuite.org
287287
.PP
288288
.SH VERSION
289-
This manual page documents pocsuite3 version 1.9.11
289+
This manual page documents pocsuite3 version 2.0.0
290290
.SH AUTHOR
291291
.br
292292
(c) 2014-present by Knownsec 404 Team

pocsuite3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'pocsuite3'
2-
__version__ = '1.9.11'
2+
__version__ = '2.0.0'
33
__author__ = 'Knownsec 404 Team'
44
__author_email__ = '[email protected]'
55
__license__ = 'GPLv2'

pocsuite3/api/__init__.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
import base64
2+
import binascii
3+
import collections
4+
import json
5+
import os
6+
import re
7+
import socket
8+
import ssl
9+
import struct
10+
import textwrap
11+
import time
12+
import urllib
13+
import zlib
14+
115
from pocsuite3.lib.controller.controller import start
2-
from pocsuite3.lib.core.common import (encoder_bash_payload, check_port,
16+
from pocsuite3.lib.core.common import (OrderedDict, OrderedSet, check_port,
17+
encoder_bash_payload,
318
encoder_powershell_payload, get_host_ip,
4-
get_host_ipv6, single_time_warn_message)
19+
get_host_ipv6, mosaic,
20+
single_time_warn_message, urlparse)
521
from pocsuite3.lib.core.data import conf, kb, logger, paths
622
from pocsuite3.lib.core.datatype import AttribDict
7-
from pocsuite3.lib.core.common import OrderedSet, OrderedDict, mosaic, urlparse
823
from pocsuite3.lib.core.enums import PLUGIN_TYPE, POC_CATEGORY, VUL_TYPE
924
from pocsuite3.lib.core.interpreter_option import (OptBool, OptDict, OptFloat,
1025
OptInteger, OptIP, OptItems,
@@ -17,37 +32,24 @@
1732
from pocsuite3.lib.core.settings import DEFAULT_LISTENER_PORT
1833
from pocsuite3.lib.request import requests
1934
from pocsuite3.lib.utils import (generate_shellcode_list, get_middle_text,
20-
random_str, minimum_version_required)
35+
minimum_version_required, random_str)
36+
from pocsuite3.lib.yaml.nuclei import Nuclei
2137
from pocsuite3.modules.censys import Censys
2238
from pocsuite3.modules.ceye import CEye
2339
from pocsuite3.modules.fofa import Fofa
2440
from pocsuite3.modules.httpserver import PHTTPServer
25-
from pocsuite3.modules.listener import (REVERSE_PAYLOAD, BIND_PAYLOAD, bind_shell,
26-
bind_tcp_shell, bind_telnet_shell)
27-
from pocsuite3.modules.quake import Quake
2841
from pocsuite3.modules.hunter import Hunter
42+
from pocsuite3.modules.interactsh import Interactsh
43+
from pocsuite3.modules.listener import (BIND_PAYLOAD, REVERSE_PAYLOAD,
44+
bind_shell, bind_tcp_shell,
45+
bind_telnet_shell)
46+
from pocsuite3.modules.quake import Quake
2947
from pocsuite3.modules.seebug import Seebug
3048
from pocsuite3.modules.shodan import Shodan
3149
from pocsuite3.modules.spider import crawl
3250
from pocsuite3.modules.zoomeye import ZoomEye
33-
from pocsuite3.modules.interactsh import Interactsh
3451
from pocsuite3.shellcodes import OSShellcodes, WebShell
3552

36-
__all__ = ('requests', 'PluginBase', 'register_plugin', 'PLUGIN_TYPE',
37-
'POCBase', 'Output', 'AttribDict', 'POC_CATEGORY', 'VUL_TYPE',
38-
'register_poc', 'conf', 'kb', 'logger', 'paths', 'minimum_version_required',
39-
'DEFAULT_LISTENER_PORT', 'load_file_to_module', 'OrderedDict', 'OrderedSet',
40-
'load_string_to_module', 'single_time_warn_message', 'CEye',
41-
'Seebug', 'ZoomEye', 'Shodan', 'Fofa', 'Quake', 'Hunter', 'Censys',
42-
'PHTTPServer', 'REVERSE_PAYLOAD', 'BIND_PAYLOAD', 'get_listener_ip', 'mosaic',
43-
'urlparse', 'get_listener_port', 'get_results', 'init_pocsuite',
44-
'start_pocsuite', 'get_poc_options', 'crawl', 'OSShellcodes',
45-
'WebShell', 'OptDict', 'OptIP', 'OptPort', 'OptBool', 'OptInteger',
46-
'OptFloat', 'OptString', 'OptItems', 'get_middle_text',
47-
'generate_shellcode_list', 'random_str', 'encoder_bash_payload', 'check_port',
48-
'encoder_powershell_payload', 'get_host_ip', 'get_host_ipv6', 'bind_shell',
49-
'bind_tcp_shell', 'bind_telnet_shell', 'Interactsh')
50-
5153

5254
def get_listener_ip():
5355
return conf.connect_back_host

pocsuite3/lib/core/common.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from pocsuite3.lib.core.settings import IP_ADDRESS_REGEX
4040
from pocsuite3.lib.core.settings import OLD_VERSION_CHARACTER
4141
from pocsuite3.lib.core.settings import POCSUITE_VERSION_CHARACTER
42-
from pocsuite3.lib.core.settings import POC_NAME_REGEX
4342
from pocsuite3.lib.core.settings import POC_REQUIRES_REGEX
4443
from pocsuite3.lib.core.settings import UNICODE_ENCODING
4544
from pocsuite3.lib.core.settings import URL_ADDRESS_REGEX
@@ -576,7 +575,11 @@ def get_poc_requires(code):
576575

577576

578577
def get_poc_name(code):
579-
return extract_regex_result(POC_NAME_REGEX, code)
578+
if re.search(r'register_poc', code):
579+
return extract_regex_result(r"""(?sm)POCBase\):.*?name\s*=\s*['"](?P<result>.*?)['"]""", code)
580+
elif re.search(r'matchers:\s*-', code):
581+
return extract_regex_result(r"""(?sm)\s*name\s*:\s*(?P<result>[^\n]*).*matchers:""", code)
582+
return ''
580583

581584

582585
def is_os_64bit():
@@ -897,7 +900,7 @@ def index_modules(modules_directory):
897900

898901
modules = []
899902
for root, _, files in os.walk(modules_directory):
900-
files = filter(lambda x: not x.startswith("__") and x.endswith(".py"), files)
903+
files = filter(lambda x: not x.startswith("__") and x.endswith(".py") or x.endswith(".yaml"), files)
901904
modules.extend(map(lambda x: os.path.join(root, os.path.splitext(x)[0]), files))
902905

903906
return modules

pocsuite3/lib/core/interpreter.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
3-
# @Time : 2018/12/25 上午10:58
4-
# @Author : chenghs
5-
# @File : interpreter.py
1+
# pylint: disable=E0202
62
import os
73
import re
84
import chardet
@@ -325,19 +321,27 @@ def command_use(self, module_path, *args, **kwargs):
325321
logger.warning("Index out of range")
326322
return
327323
module_path = self.last_search[index]
328-
if not module_path.endswith(".py"):
329-
module_path = module_path + ".py"
330-
if not os.path.exists(module_path):
331-
module_path = os.path.join(self.module_parent_directory, module_path)
332-
if not os.path.exists(module_path):
333-
errMsg = "No such file: '{0}'".format(module_path)
334-
logger.error(errMsg)
335-
return
324+
325+
module_ext = ''
326+
module_path_found = False
327+
for module_ext in ['.py', '.yaml']:
328+
if os.path.exists(module_path + module_ext):
329+
module_path_found = True
330+
break
331+
elif os.path.exists(os.path.join(self.module_parent_directory, module_path + module_ext)):
332+
module_path_found = True
333+
module_path = os.path.join(self.module_parent_directory, module_path + module_ext)
334+
break
335+
336+
if not module_path_found:
337+
errMsg = "No such file: '{0}'".format(module_path)
338+
logger.error(errMsg)
339+
return
340+
336341
try:
337342
load_file_to_module(module_path)
338343
self.current_module = kb.current_poc
339-
self.current_module.pocsuite3_module_path = ltrim(
340-
rtrim(module_path, ".py"), self.module_parent_directory)
344+
self.current_module.pocsuite3_module_path = ltrim(rtrim(module_path, module_ext), self.module_parent_directory)
341345
except Exception as err:
342346
logger.error(str(err))
343347

@@ -457,6 +461,8 @@ def command_list(self, *args, **kwargs):
457461
index = 0
458462
for tmp_module in self.main_modules_dirs:
459463
found = os.path.join(self.module_parent_directory, tmp_module + ".py")
464+
if not os.path.exists(found):
465+
found = os.path.join(self.module_parent_directory, tmp_module + ".yaml")
460466
code = get_file_text(found)
461467
name = get_poc_name(code)
462468
tb.add_row([str(index), tmp_module, name])

pocsuite3/lib/core/option.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,21 @@ def _set_pocs_modules():
338338

339339
elif any([poc in exists_poc_with_ext, poc in exists_pocs]):
340340
poc_name, poc_ext = os.path.splitext(poc)
341-
if poc_ext in ['.py', '.pyc']:
341+
if poc_ext in ['.py', '.pyc', '.yaml']:
342342
file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc)
343343
else:
344344
file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc + exists_pocs.get(poc))
345345
_pocs.append(file_path)
346346

347347
elif check_path(poc):
348348
for root, _, files in os.walk(poc):
349-
files = filter(lambda x: not x.startswith("__") and x.endswith(".py"), files)
349+
files = filter(lambda x: not x.startswith("__") and x.endswith(".py") or
350+
x.endswith('.yaml'), files)
350351
_pocs.extend(map(lambda x: os.path.join(root, x), files))
351352

352353
for p in _pocs:
353354
file_content = get_file_text(p)
354-
if not re.search(r'register_poc', file_content):
355+
if not re.search(r'register_poc|matchers:\s+-', file_content):
355356
continue
356357
if conf.poc_keyword:
357358
if not re.search(conf.poc_keyword, file_content, re.I | re.M):

pocsuite3/lib/core/register.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def check_requires(data):
6868
def exec_module(self, module):
6969
filename = self.get_filename(self.fullname)
7070
poc_code = self.get_data(filename)
71+
72+
# convert yaml template to pocsuite3 poc script
73+
if filename.endswith('.yaml') and re.search(r'matchers:\s+-', poc_code):
74+
from pocsuite3.lib.yaml.nuclei import Nuclei
75+
poc_code = str(Nuclei(poc_code))
76+
7177
self.check_requires(poc_code)
7278
obj = compile(poc_code, filename, 'exec', dont_inherit=True, optimize=-1)
7379
try:

pocsuite3/lib/core/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393

9494
POC_REQUIRES_REGEX = r"install_requires\s*=\s*\[(?P<result>.*?)\]"
9595

96-
POC_NAME_REGEX = r"""(?sm)POCBase\):.*?name\s*=\s*['"](?P<result>.*?)['"]"""
97-
9896
MAX_NUMBER_OF_THREADS = 200
9997

10098
DEFAULT_LISTENER_PORT = 6666

0 commit comments

Comments
 (0)