Skip to content

Commit

Permalink
fix: duration is undefined/req_condition default value cannot be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
xixixiba committed Jan 29, 2024
1 parent 5a83196 commit f1a6a8d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict
from dataclasses import dataclass, field
import time
from typing import Union, List, Optional

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

def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
request_count = len(request.path + request.raw)
# Determine the number of requests and modify the req_condition attribute of the HttpRequest object
if request_count > 1:
request.req_condition = True

for payload_instance in payload_generator(request.payloads, request.attack):
current_index = 0
dynamic_values.update(payload_instance)
Expand All @@ -272,9 +277,14 @@ def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
else:
raw = path.strip()
raws = list(map(lambda x: x.strip(), raw.splitlines()))
method, path, _ = raws[0].split(' ')
url = f'{Marker.ParenthesisOpen}BaseURL{Marker.ParenthesisClose}{path}'

# Extract timeout value
if raws[0].startswith('@timeout'):
timeout = Marker.extract_timeout_value(raws[0])
del raws[0]
method, path, _ = raws[0].split(' ')
kwargs.setdefault('timeout', timeout)
else:
method, path, _ = raws[0].split(' ')
if method == "POST":
index = 0
for i in raws:
Expand All @@ -290,6 +300,8 @@ def http_request_generator(request: HttpRequest, dynamic_values: OrderedDict):
else:
headers = extract_dict('\n'.join(raws[1:]), '\n', ": ")

url = f'{Marker.ParenthesisOpen}BaseURL{Marker.ParenthesisClose}{path}'

kwargs.setdefault('allow_redirects', request.redirects)
kwargs.setdefault('data', data)
kwargs.setdefault('headers', headers)
Expand Down Expand Up @@ -324,7 +336,13 @@ def execute_http_request(request: HttpRequest, dynamic_values, interactsh) -> Un
session.max_redirects = request.max_redirects
else:
session.max_redirects = 10

# Calculate response time
start_time = time.time()
response = session.request(method=method, url=url, **kwargs)
end_time = time.time()
resp_time = end_time - start_time

# for debug purpose
try:
logger.debug(dump.dump_all(response).decode('utf-8'))
Expand All @@ -335,8 +353,11 @@ def execute_http_request(request: HttpRequest, dynamic_values, interactsh) -> Un
import traceback
traceback.print_exc()
response = None

resp_data = http_response_to_dsl_map(response)
if response is not None:
resp_data['duration'] = resp_time

if response:
response.close()

Expand Down

0 comments on commit f1a6a8d

Please sign in to comment.