From 6da44c18dc634c8ce18af6e1c2f7fddb842e018e Mon Sep 17 00:00:00 2001 From: xiaobo Date: Tue, 12 Mar 2024 11:40:36 +0800 Subject: [PATCH 1/8] Update dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 规范dockerfile的写法: 1.ENV采用大写 2.MAINTAINER已经被弃用,改用LABEL Signed-off-by: xiaobo --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5a0c8a74..f77130a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM ubuntu:22.04 -MAINTAINER Knownsec 404 Team +LABEL maintainer="Knownsec 404 Team" ARG version -env DEBIAN_FRONTEND=noninteractive +ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y \ From 7099dcdff9ed0e19fb7fc4614625c1cae2e15346 Mon Sep 17 00:00:00 2001 From: wh0am1i Date: Thu, 22 Feb 2024 14:32:12 +0800 Subject: [PATCH 2/8] reset upload pypi --- .github/workflows/release.yml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3702b168..916a99fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,23 +9,22 @@ jobs: pypi: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - pip install -r requirements.txt - - name: Build and publish - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} homebrew: runs-on: ubuntu-latest From 87e1a2c498f17fd960699928b22aad26ba59ac90 Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Tue, 12 Mar 2024 15:31:19 +0800 Subject: [PATCH 3/8] fix: 'xpath' is not a valid MatcherType --- .../lib/yaml/nuclei/operators/__init__.py | 4 +- .../nuclei/operators/extrators/__init__.py | 2 +- .../nuclei/operators/matchers/__init__.py | 41 +++++++++++++++++++ .../yaml/nuclei/protocols/http/__init__.py | 5 ++- .../yaml/nuclei/protocols/network/__init__.py | 5 ++- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/pocsuite3/lib/yaml/nuclei/operators/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/__init__.py index 351b8503..af38c0e7 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/__init__.py @@ -11,7 +11,8 @@ match_regex, match_size, match_status_code, - match_words) + match_words, + match_xpath) __all__ = [ "ExtractorType", @@ -29,4 +30,5 @@ "match_regex", "match_binary", "match_dsl", + "match_xpath", ] diff --git a/pocsuite3/lib/yaml/nuclei/operators/extrators/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/extrators/__init__.py index 357684cf..6fd27f68 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/extrators/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/extrators/__init__.py @@ -137,7 +137,7 @@ def extract_xpath(e: Extractor, corpus: str) -> dict: else: doc = etree.HTML(corpus) - if not doc: + if doc is None: return results for x in e.xpath: diff --git a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py index 7badbbba..7685c76c 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py @@ -1,6 +1,7 @@ import binascii import re from dataclasses import dataclass, field +from lxml import html from typing import List from pocsuite3.lib.yaml.nuclei.model import CaseInsensitiveEnum @@ -14,6 +15,7 @@ class MatcherType(CaseInsensitiveEnum): RegexMatcher = "regex" BinaryMatcher = "binary" DSLMatcher = "dsl" + XpathMatcher = "xpath" @dataclass @@ -49,6 +51,9 @@ class Matcher: # Regex contains Regular Expression patterns required to be present in the response part. regex: List[str] = field(default_factory=list) + # Xpath contains xpath patterns required to be present in the response part. + xpath: List[str] = field(default_factory=list) + # Binary are the binary patterns required to be present in the response part. binary: List[str] = field(default_factory=list) @@ -181,3 +186,39 @@ def match_dsl(matcher: Matcher, data: dict) -> bool: if len(matcher.dsl) - 1 == i: return True return False + +def match_xpath(matcher: Matcher, body: str) -> (bool, list): + """Matches xpath check against a body. + """ + # Convert the body string to etree.HTML object for xpath manipulations + body_tree = html.fromstring(body) + matched_xpaths = [] + + for i, xpath_pattern in enumerate(matcher.xpath): + try: + # Applying xpath on the HTML and capturing the result + result = body_tree.xpath(xpath_pattern) + if not result: + # If result is empty, the xpath expression did not match anything in the HTML body + if matcher.condition == 'and': + return False, [] + elif matcher.condition == 'or': + continue + + if matcher.condition == 'or' and not matcher.match_all: + return True, [result] + + matched_xpaths.append(result) + + if len(matcher.xpath) - 1 == i and not matcher.match_all: + return True, matched_xpaths + + except Exception as e: + print(f"Error while matching with XPath {xpath_pattern}. Error: {str(e)}") + + if len(matched_xpaths) > 0 and matcher.match_all: + return True, matched_xpaths + + return False, [] + + diff --git a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py index d3f72e6a..a74e57b4 100644 --- a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py @@ -16,7 +16,7 @@ extract_xpath, match_binary, match_dsl, match_regex, match_size, match_status_code, - match_words) + match_words, match_xpath) from pocsuite3.lib.yaml.nuclei.protocols.common.generators import AttackType, payload_generator from pocsuite3.lib.yaml.nuclei.protocols.common.interactsh import InteractshClient from pocsuite3.lib.yaml.nuclei.protocols.common.replacer import ( @@ -198,6 +198,9 @@ def http_match(request: HttpRequest, resp_data: dict, interactsh=None): elif matcher.type == MatcherType.DSLMatcher: matcher_res = match_dsl(matcher, resp_data) + elif matcher.type == MatcherType.XpathMatcher: + matcher_res == match_xpath(matcher, item) + if matcher.negative: matcher_res = not matcher_res diff --git a/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py b/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py index 953bf95d..a5537e10 100644 --- a/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py @@ -15,7 +15,7 @@ extract_dsl, extract_kval, extract_regex, match_binary, match_dsl, match_regex, - match_size, match_words) + match_size, match_words, match_xpath) from pocsuite3.lib.yaml.nuclei.protocols.common.generators import AttackType, payload_generator from pocsuite3.lib.yaml.nuclei.protocols.common.interactsh import InteractshClient from pocsuite3.lib.yaml.nuclei.protocols.common.replacer import ( @@ -162,6 +162,9 @@ def network_match(request: NetworkRequest, resp_data: dict, interactsh=None): elif matcher.type == MatcherType.BinaryMatcher: matcher_res, _ = match_binary(matcher, item) + elif matcher.type == MatcherType.XpathMatcher: + matcher_res, = match_xpath(matcher, item) + elif matcher.type == MatcherType.DSLMatcher: matcher_res = match_dsl(matcher, resp_data) From e1ce9d60b688c14287d92b3b3ac0ff5bc50fd154 Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Tue, 12 Mar 2024 15:35:07 +0800 Subject: [PATCH 4/8] fix: 'xpath' is not a valid MatcherType --- pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py index a74e57b4..16a1a40c 100644 --- a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py @@ -199,7 +199,7 @@ def http_match(request: HttpRequest, resp_data: dict, interactsh=None): matcher_res = match_dsl(matcher, resp_data) elif matcher.type == MatcherType.XpathMatcher: - matcher_res == match_xpath(matcher, item) + matcher_res, = match_xpath(matcher, item) if matcher.negative: matcher_res = not matcher_res From 4022af902ab6ec1c9ebe0fe69d1a86d0cb82af60 Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Tue, 12 Mar 2024 16:13:10 +0800 Subject: [PATCH 5/8] fix: 'xpath' is not a valid MatcherType --- pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py | 2 ++ pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py | 2 +- pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py index 7685c76c..24d55467 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py @@ -191,6 +191,8 @@ def match_xpath(matcher: Matcher, body: str) -> (bool, list): """Matches xpath check against a body. """ # Convert the body string to etree.HTML object for xpath manipulations + if body is None: + return False body_tree = html.fromstring(body) matched_xpaths = [] diff --git a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py index 16a1a40c..1e670c1b 100644 --- a/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/protocols/http/__init__.py @@ -199,7 +199,7 @@ def http_match(request: HttpRequest, resp_data: dict, interactsh=None): matcher_res = match_dsl(matcher, resp_data) elif matcher.type == MatcherType.XpathMatcher: - matcher_res, = match_xpath(matcher, item) + matcher_res, _ = match_xpath(matcher, item) if matcher.negative: matcher_res = not matcher_res diff --git a/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py b/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py index a5537e10..3584dcc0 100644 --- a/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/protocols/network/__init__.py @@ -163,7 +163,7 @@ def network_match(request: NetworkRequest, resp_data: dict, interactsh=None): matcher_res, _ = match_binary(matcher, item) elif matcher.type == MatcherType.XpathMatcher: - matcher_res, = match_xpath(matcher, item) + matcher_res, _ = match_xpath(matcher, item) elif matcher.type == MatcherType.DSLMatcher: matcher_res = match_dsl(matcher, resp_data) From 69f7e9a525392030f267be657b6f6e5c7f2ffffb Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Thu, 14 Mar 2024 17:18:32 +0800 Subject: [PATCH 6/8] Fix 'xpath' is not a valid MatcherType --- pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py index 24d55467..1fa334fb 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py @@ -187,6 +187,7 @@ def match_dsl(matcher: Matcher, data: dict) -> bool: return True return False + def match_xpath(matcher: Matcher, body: str) -> (bool, list): """Matches xpath check against a body. """ @@ -221,6 +222,4 @@ def match_xpath(matcher: Matcher, body: str) -> (bool, list): if len(matched_xpaths) > 0 and matcher.match_all: return True, matched_xpaths - return False, [] - - + return False, [] \ No newline at end of file From da937c0f387e767c8dddf8d71d6e513a7f5b3500 Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Thu, 14 Mar 2024 17:48:44 +0800 Subject: [PATCH 7/8] W292 no newline at end of file --- pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py index 1fa334fb..a84f0363 100644 --- a/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py +++ b/pocsuite3/lib/yaml/nuclei/operators/matchers/__init__.py @@ -222,4 +222,4 @@ def match_xpath(matcher: Matcher, body: str) -> (bool, list): if len(matched_xpaths) > 0 and matcher.match_all: return True, matched_xpaths - return False, [] \ No newline at end of file + return False, [] From 7a06e09a176d8d1e13e65fe466fb5e7c65ac8be6 Mon Sep 17 00:00:00 2001 From: xixixiba <1343995156@qq.com> Date: Fri, 15 Mar 2024 10:51:53 +0800 Subject: [PATCH 8/8] Modify the binding port of HTTP server --- pocsuite3/modules/httpserver/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pocsuite3/modules/httpserver/__init__.py b/pocsuite3/modules/httpserver/__init__.py index 3115b3cc..80aced2b 100644 --- a/pocsuite3/modules/httpserver/__init__.py +++ b/pocsuite3/modules/httpserver/__init__.py @@ -89,7 +89,7 @@ class HTTPServerV4(HTTPServer): class PHTTPServer(threading.Thread, metaclass=PHTTPSingleton): - def __init__(self, bind_ip='0.0.0.0', bind_port=666, is_ipv6=False, use_https=False, + def __init__(self, bind_ip='0.0.0.0', bind_port=6666, is_ipv6=False, use_https=False, certfile=os.path.join(paths.POCSUITE_TMP_PATH, 'cacert.pem'), requestHandler=BaseRequestHandler): threading.Thread.__init__(self)