Skip to content

Commit e7f2843

Browse files
authored
Merge pull request #407 from wh0am1i/master
Solve nuclei dsl parsing
2 parents 5a83196 + cdcbc89 commit e7f2843

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

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__ = '2.0.7'
2+
__version__ = '2.0.8'
33
__author__ = 'Knownsec 404 Team'
44
__author_email__ = '[email protected]'
55
__license__ = 'GPLv2'

pocsuite3/lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def get_poc_name(code):
582582
if re.search(r'register_poc', code):
583583
return extract_regex_result(r"""(?sm)POCBase\):.*?name\s*=\s*['"](?P<result>.*?)['"]""", code)
584584
elif re.search(r'matchers:\s*-', code):
585-
return extract_regex_result(r"""(?sm)\s*name\s*:\s*(?P<result>[^\n]*).*matchers:""", code)
585+
return extract_regex_result(r"""(?sm)\s*name\s*:\s*(?P<result>[^\r\n]*).*matchers:""", code)
586586
return ''
587587

588588

pocsuite3/lib/yaml/nuclei/protocols/common/expressions/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class Marker:
3131
# ParenthesisClose marker - end of a placeholder
3232
ParenthesisClose = "}}"
3333

34+
def extract_timeout_value(raw_timeout: str) -> int:
35+
match = re.search(r'@timeout:?(\d+)s', raw_timeout, re.IGNORECASE)
36+
if match:
37+
return int(match.group(1))
38+
return None
39+
3440

3541
def auto_convert_types(func):
3642
@wraps(func)

pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import OrderedDict
22
from dataclasses import dataclass, field
3+
import time
34
from typing import Union, List, Optional
45

56
from requests_toolbelt.utils import dump
@@ -254,6 +255,10 @@ def extract_dict(text, line_sep='\n', kv_sep='='):
254255

255256
def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
256257
request_count = len(request.path + request.raw)
258+
# Determine the number of requests and modify the req_condition attribute of the HttpRequest object
259+
if request_count > 1:
260+
request.req_condition = True
261+
257262
for payload_instance in payload_generator(request.payloads, request.attack):
258263
current_index = 0
259264
dynamic_values.update(payload_instance)
@@ -272,9 +277,14 @@ def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
272277
else:
273278
raw = path.strip()
274279
raws = list(map(lambda x: x.strip(), raw.splitlines()))
275-
method, path, _ = raws[0].split(' ')
276-
url = f'{Marker.ParenthesisOpen}BaseURL{Marker.ParenthesisClose}{path}'
277-
280+
# Extract timeout value
281+
if raws[0].startswith('@timeout'):
282+
timeout = Marker.extract_timeout_value(raws[0])
283+
del raws[0]
284+
method, path, _ = raws[0].split(' ')
285+
kwargs.setdefault('timeout', timeout)
286+
else:
287+
method, path, _ = raws[0].split(' ')
278288
if method == "POST":
279289
index = 0
280290
for i in raws:
@@ -290,6 +300,8 @@ def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
290300
else:
291301
headers = extract_dict('\n'.join(raws[1:]), '\n', ": ")
292302

303+
url = f'{Marker.ParenthesisOpen}BaseURL{Marker.ParenthesisClose}{path}'
304+
293305
kwargs.setdefault('allow_redirects', request.redirects)
294306
kwargs.setdefault('data', data)
295307
kwargs.setdefault('headers', headers)
@@ -324,7 +336,13 @@ def execute_http_request(request: HttpRequest, dynamic_values, interactsh) -> Un
324336
session.max_redirects = request.max_redirects
325337
else:
326338
session.max_redirects = 10
339+
340+
# Calculate response time
341+
start_time = time.time()
327342
response = session.request(method=method, url=url, **kwargs)
343+
end_time = time.time()
344+
resp_time = end_time - start_time
345+
328346
# for debug purpose
329347
try:
330348
logger.debug(dump.dump_all(response).decode('utf-8'))
@@ -337,6 +355,9 @@ def execute_http_request(request: HttpRequest, dynamic_values, interactsh) -> Un
337355
response = None
338356

339357
resp_data = http_response_to_dsl_map(response)
358+
if response is not None:
359+
resp_data['duration'] = resp_time
360+
340361
if response:
341362
response.close()
342363

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def find_packages(where='.'):
2121

2222
setup(
2323
name='pocsuite3',
24-
version='2.0.7',
24+
version='2.0.8',
2525
url='https://pocsuite.org',
2626
description='Open-sourced remote vulnerability testing framework.',
2727
long_description=long_description,

0 commit comments

Comments
 (0)