From 417e0a6c48675c294fad4e23a9558fbd0df1cbb9 Mon Sep 17 00:00:00 2001 From: morpheuslord <70637311+morpheuslord@users.noreply.github.com> Date: Sun, 25 Jun 2023 11:09:37 +0530 Subject: [PATCH] env and new docker added --- .env | 1 + .pre-commit-config.yaml | 41 + .vscode/settings.json | 6 + Dockerfile | 4 +- Makefile | 2 + README.md | 14 +- __pycache__/app.cpython-310.pyc | Bin 6223 -> 6824 bytes .../test_app.cpython-310-pytest-7.3.2.pyc | Bin 0 -> 4760 bytes app.py | 100 +- auth_keys.db | Bin 12288 -> 12288 bytes nmap.xsl | 1071 ----------------- package/LICENSE | 21 + package/MANIFEST.in | 2 + package/README.md | 118 ++ package/nmap_api/__init__.py | 0 .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 137 bytes .../nmap_api/__pycache__/main.cpython-310.pyc | Bin 0 -> 2879 bytes .../nmap_api/__pycache__/p.cpython-310.pyc | Bin 0 -> 1743 bytes package/nmap_api/app.py | 211 ++++ package/nmap_api/requirements.txt | 30 + package/pyproject.toml | 6 + package/setup.cfg | 18 + package/setup.py | 73 ++ setuo.cfg | 25 + static/index.js | 2 +- templates/404.html | 6 +- templates/add.html | 2 +- templates/base.html | 22 +- templates/del.html | 2 +- templates/index.css | 22 +- templates/index.js | 2 +- templates/results.html | 2 +- templates/results.json | 2 +- templates/scanner.html | 2 +- test_app.py | 98 -- xml.xml | Bin 6172 -> 0 bytes 36 files changed, 658 insertions(+), 1247 deletions(-) create mode 100644 .env create mode 100644 .pre-commit-config.yaml create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 __pycache__/test_app.cpython-310-pytest-7.3.2.pyc delete mode 100644 nmap.xsl create mode 100644 package/LICENSE create mode 100644 package/MANIFEST.in create mode 100644 package/README.md create mode 100644 package/nmap_api/__init__.py create mode 100644 package/nmap_api/__pycache__/__init__.cpython-310.pyc create mode 100644 package/nmap_api/__pycache__/main.cpython-310.pyc create mode 100644 package/nmap_api/__pycache__/p.cpython-310.pyc create mode 100644 package/nmap_api/app.py create mode 100644 package/nmap_api/requirements.txt create mode 100644 package/pyproject.toml create mode 100644 package/setup.cfg create mode 100644 package/setup.py create mode 100644 setuo.cfg delete mode 100644 test_app.py delete mode 100644 xml.xml diff --git a/.env b/.env new file mode 100644 index 0000000..7728939 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +API_KEY = '' \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..90bee2f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,41 @@ +# Borrowed initially from https://github.com/lyft/cartography +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-vcs-permalinks + # Disabling this as it is giving false positives for sam templates + # - id: check-yaml + # args: ['--unsafe'] # Just check the syntax + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 +- repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.5.7 + hooks: + - id: autopep8 + # disable a few rewrites which will cause autopep8 to reflow + args: [--in-place, '--ignore=E265,E501,W504'] +- repo: https://github.com/asottile/reorder_python_imports + rev: v2.6.0 + hooks: + - id: reorder-python-imports + args: [--py3-plus] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.0.0 + hooks: + - id: mypy + exclude: ^pb/ + additional_dependencies: + - types-requests + - types-PyYAML + - types-python-dateutil diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3ecb8fc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} diff --git a/Dockerfile b/Dockerfile index bf05302..ab82eaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,4 +24,6 @@ RUN apt update && apt upgrade -y RUN apt install nmap -y RUN pip install -r requirements.txt -CMD [ "python", "./app.py" ] \ No newline at end of file +ENV OPENAI_API_KEY='' + +CMD [ "sh", "-c","python ./app.py ${OPENAI_API_KEY}" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..40015cf --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +lint: + pre-commit run --all-files --show-diff-on-failure diff --git a/README.md b/README.md index 65ca3fa..fc85def 100644 --- a/README.md +++ b/README.md @@ -45,28 +45,29 @@ This is a implementation for our college PCL project which is still under develo #### Auth and User management ```text - GET /register// + GET /register/// ``` | Parameter | Type | Description | | :-------- | :------- | :------------------------- | |`ID`|`Int`|user ID| |`Passwd`| `String`| User Passwd| +|`Unique_Key`| `String`| User Unique_Key| ## Improvements Added GPT functionality with chunking module. The methodology is based on how `Langchain GPT embeddings` operate. Basically the operation goes like this: ```text -Data -> Chunks_generator ─┐ ┌─> AI_Loop -> Data_Extraction -> Return_Data - ├─> Chunk1 ─┤ - ├─> Chunk2 ─┤ +Data -> Chunks_generator ─┐ ┌─> AI_Loop -> Data_Extraction -> Return_Dat + (GPT3 - 1500 TOKENS) ├─> Chunk1 ─┤ + (GPT4 - 3500 TOKENS) ├─> Chunk2 ─┤ ├─> Chunk3 ─┤ └─> Chunk N ─┘ ``` AI code: ```python -def AI(analize: str) -> dict[str, any]: +def AI(analyze: str) -> dict[str, any]: # Prompt about what the query is all about prompt = f""" Do a vulnerability analysis report on the following JSON data and @@ -113,4 +114,5 @@ def AI(analize: str) -> dict[str, any]: return ai_output ``` -**Default_Key**: **e43d4c3b79** +#### Default User Keys +**Default_Key**: **cff649285012c6caae4d** diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index 5d58bea247823f22302f76d81ff6c76816adc211..4bb8aec38f54a72ba9563f5f328444ba858e3b23 100644 GIT binary patch literal 6824 zcma)A&2tn-map$BwOXwYg!wRL$}+ZTtd>9me_+7KAUuq*U_ti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a%i%G-yLw`BYZq3U}@h$i(B`Ub1ZGC+3p9(>7!G0FL fpsghO4DK%acV$$wS(SdKe$22fbIf5@xyJqr4^Rqv literal 0 HcmV?d00001 diff --git a/app.py b/app.py index 9aac695..d500b8b 100644 --- a/app.py +++ b/app.py @@ -1,14 +1,23 @@ -import nmap -import sqlite3 -import re -import openai -import os import hashlib import json -from flask import Flask, render_template -from flask_restful import Api, Resource +import os +import re +import sqlite3 +from typing import Any +from typing import Callable +from typing import cast -openai.api_key = "__API__KEY__" +import nmap +import openai + +from dotenv import load_dotenv +from flask import Flask +from flask import render_template +from flask_restful import Api +from flask_restful import Resource + +load_dotenv() +openai.api_key = os.getenv('API_KEY') model_engine = "text-davinci-003" app = Flask(__name__) @@ -19,25 +28,27 @@ # Index and Docx page @app.route('/', methods=['GET']) -def home() -> any: +def home() -> Any: return render_template("index.html") @app.route('/doc', methods=['GET']) -def doc() -> any: +def doc() -> Any: return render_template("doc.html") -@app.route('/register//') -def store_auth_key(user_id: int, password: str) -> str: +@app.route('/register///') +def store_auth_key(user_id: int, password: str, unique_key: str) -> str: sanitized_username = user_id sanitized_passwd = password - # Hash the user's ID and password together + sanitized_key = unique_key + # Hash the user's ID, password, and unique key together hash = hashlib.sha256() hash.update(str(sanitized_username).encode('utf-8')) hash.update(sanitized_passwd.encode('utf-8')) + hash.update(sanitized_key.encode('utf-8')) # Use the hash to generate the auth key - auth_key = hash.hexdigest()[:20] # Get the first 10 characters + auth_key = hash.hexdigest()[:20] # Get the first 20 characters db_file = 'auth_keys.db' need_create_table = not os.path.exists(db_file) conn = sqlite3.connect(db_file) @@ -45,10 +56,16 @@ def store_auth_key(user_id: int, password: str) -> str: if need_create_table: cursor.execute('''CREATE TABLE auth_keys (user_id INT PRIMARY KEY NOT NULL, - auth_key TEXT NOT NULL);''') + auth_key TEXT NOT NULL, + unique_key TEXT NOT NULL);''') + query = ( + "INSERT INTO auth_keys " + "(user_id, auth_key, unique_key) " + "VALUES (?, ?, ?)" + ) cursor.execute( - "INSERT INTO auth_keys (user_id, auth_key) VALUES (?, ?)", - (sanitized_passwd, auth_key) + query, + (sanitized_username, auth_key, sanitized_key) ) conn.commit() @@ -57,6 +74,10 @@ def store_auth_key(user_id: int, password: str) -> str: return auth_key +def to_int(s: str) -> int: + return int(s) + + def sanitize(input_string: str) -> str: if not re.match("^[a-zA-Z0-9]*$", input_string): raise ValueError("Invalid characters in string") @@ -64,16 +85,14 @@ def sanitize(input_string: str) -> str: return input_string -def chunk_output( - scan_output: str, max_token_size: int -) -> list[dict[str, any]]: - scan_output_dict = json.loads(scan_output) +def chunk_output(scan_output: dict, + max_token_size: int) -> list[dict[str, Any]]: output_chunks = [] current_chunk = {} current_token_count = 0 # Convert JSON to AI usable chunks - for ip, scan_data in scan_output_dict.items(): + for ip, scan_data in scan_output.items(): new_data_token_count = len(json.dumps({ip: scan_data}).split()) if current_token_count + new_data_token_count <= max_token_size: @@ -90,7 +109,7 @@ def chunk_output( return output_chunks -def AI(analize: str) -> dict[str, any]: +def AI(analize: str) -> dict[str, Any]: # Prompt about what the query is all about prompt = f""" Do a vulnerability analysis report on the following JSON data and @@ -118,7 +137,7 @@ def AI(analize: str) -> dict[str, any]: n=1, stop=None, ) - response = completion.choices[0].text + response = completion.choices[0]['text'] # Assuming extract_ai_output returns a dictionary extracted_data = extract_ai_output(response) @@ -152,7 +171,7 @@ def authenticate(auth_key: str) -> bool: return False -def extract_ai_output(ai_output: str) -> dict[str, any]: +def extract_ai_output(ai_output: str) -> dict[str, Any]: result = { "open_ports": [], "closed_ports": [], @@ -169,13 +188,16 @@ def extract_ai_output(ai_output: str) -> dict[str, any]: # If found, convert string of ports to list if open_ports_match: result["open_ports"] = list( - map(int, open_ports_match.group(1).split(','))) + map(cast(Callable[[Any], str], int), + open_ports_match.group(1).split(','))) if closed_ports_match: result["closed_ports"] = list( - map(int, closed_ports_match.group(1).split(','))) + map(cast(Callable[[Any], str], int), + closed_ports_match.group(1).split(','))) if filtered_ports_match: result["filtered_ports"] = list( - map(int, filtered_ports_match.group(1).split(','))) + map(cast(Callable[[Any], str], int), + filtered_ports_match.group(1).split(','))) # Match and extract criticality score criticality_score_match = re.search( @@ -186,24 +208,23 @@ def extract_ai_output(ai_output: str) -> dict[str, any]: return result -def profile(auth: str, url: str, argument: str) -> dict[str, any]: +def profile(auth: str, url: str, argument: str) -> dict[str, Any]: ip = url # Nmap Execution command usernamecheck = authenticate(auth) if usernamecheck is False: - return [{"error": "passwd or username error"}] + return {"error": "passwd or username error"} else: nm.scan('{}'.format(ip), arguments='{}'.format(argument)) scan_data = nm.analyse_nmap_xml_scan() - analize = scan_data["scan"] - # chunk_data = str(chunk_output(analize, 500)) - # all_outputs = [] - # for chunks in chunk_data: - # string_chunks = str(chunks) - # data = AI(string_chunks) - # all_outputs.append(data) - # return json.dumps(all_outputs) - return analize + analyze = scan_data["scan"] + chunk_data = str(chunk_output(analyze, 500)) + all_outputs = [] + for chunks in chunk_data: + string_chunks = str(chunks) + data = AI(string_chunks) + all_outputs.append(data) + return json.dumps(all_outputs) # Effective Scan @@ -257,5 +278,6 @@ def get(self, auth, url): api.add_resource( p5, "/api/p5//") + if __name__ == '__main__': app.run(host="0.0.0.0", port="80") diff --git a/auth_keys.db b/auth_keys.db index 6531b4e66e357518096e951f06cff08a4a8b7594..a6b5c4a2b6fa35bc02b041369d8270b1d6ffad71 100644 GIT binary patch delta 114 zcmV-&0FD2EV1QtdX$KDQ01ogE#j$aK4hn%%0S6Z!9|3}MlPnLIlavn{26b*}adl;r zvJX@Q-~bQcvk?&14=Nr31PL`6V`gSHG&wRjH83$UV>V-9VP!OAaA9+EcVr3x0003G U`~VO9vk@TW50Ov}1Oo#J2{OMS@Bjb+ delta 97 zcmZojXh@il$i`iW=uZ9@5J(&f&cYpL4}9> x^1_VFl8Ob1#l__*sV2rLCdtN0=9XLx3=E9?-x&D60TsRG=Vst!mgIye0su?Z8%Y2F diff --git a/nmap.xsl b/nmap.xsl deleted file mode 100644 index 30764ed..0000000 --- a/nmap.xsl +++ /dev/null @@ -1,1071 +0,0 @@ - - - - - - - -0.9c - - - - - - - - - - - - - - - - - - - - -generated with nmap.xsl - version by Benjamin Erb - http://www.benjamin-erb.de/nmap_xsl.php - - - - Nmap Scan Report - Scanned at <xsl:value-of select="$start" /> - - - - - - - - -
- -

Nmap Scan Report - Scanned at

- -
- - - scansummary - - - - -

Scan Summary

- -

- Nmap was initiated at with these arguments:
-
-

-

- Verbosity: ; Debug level -

- -

- -

- - - - - - - - - -
- - - - -
- - - - - - - - - - - - host_ - - - - - -

- - - - - / - - - - (online) -

- -
- - -

- - - - - / - - - - - javascript:toggle('hostblock_'); - host_down - (click to expand) - - (offline)

-
- -
- - - - hostblock_ - - - - unhidden - - - - hidden - - - - - -

Address

- -
    - -
  • - - - - - - - () -
  • -
    -
-
- - - - -
- - - javascript:toggle('metrics_'); - Misc Metrics (click to expand) - - - - - metrics_ - hidden - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MetricValue
Ping Results - - from - - -
System Uptime seconds (last reboot: ) -
Network Distance hops
TCP Sequence PredictionDifficulty= ()
IP ID Sequence Generation
-
- -
- -
- - - - - - - -

Hostnames

-
- - - - - -
  • ()
  • -
    - - - - - - -

    Ports

    - - -

    The ports scanned but not shown below are in state:

    -
    - -
      - - -
    • ports replied with:

    • -
      -
      -
    -
    - - - - - - - - - - - porttable_ - 1 - - - Port - State - - javascript:togglePorts('porttable_','closed'); - (toggle closed [] - - - javascript:togglePorts('porttable_','filtered'); - | filtered []) - - - Service - Reason - Product - Version - Extra info - - - - - -
    - - - - - - - - - - - - -   - - - from - - - -   -   -   - - - - - -   - -
      
    - - - -
    -
    - - - - - - -   - - - from - - - -   -   -   - - - - - - - - -   - - - from - - - -   -   -   - - - - - - - - -   - - - from - - - -   -   -   - - - -
    -
    - - - - - -

    Remote Operating System Detection

    - -

    Unable to identify operating system.

    - -
      - -
    • Used port: / ()
    • -
      - - -
    • OS match: (%)
    • -
      -
    - - - -
    - - - - - - - - - - - - -
      -
    • Cannot determine exact operating system. Fingerprint provided below.
    • -
    • If you know what OS is running on it, see https://nmap.org/submit/
    • -
    - - - - - - - -
    Operating System fingerprint
    - -
    - - -
      -
    • OS identified but the fingerprint was requested at scan time. - - - javascript:toggle('osblock_'); - (click to expand) - -
    • -
    - - - osblock_ - hidden - - - - - - - - -
    Operating System fingerprint
    - -
    - -
    - -
    - -
    - - - - - - - - - - prescript - - -

    Pre-Scan Script Output

    - - - - - - - - - - - - - - -
    Script NameOutput
    -   - -
    -           
    -        
    -
    -
    - - - - - - - - - - postscript - - -

    Post-Scan Script Output

    - - - - - - - - - - - - - - -
    Script NameOutput
    -   - -
    -           
    -        
    -
    -
    - - - - - - -

    Host Script Output

    - - - - - - - - - - - - - - -
    Script NameOutput
    -   - -
    -              
    -          
    -
    -
    - - - - - -

    Smurf Responses

    -
      -
    • responses counted
    • -
    -
    -
    - - - - - - - - - - - - - - javascript:toggle('trace_'); - Traceroute Information (click to expand) - - - - trace_ - hidden - - - - -
    • Traceroute data generated using port /
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    HopRttIPHost
    --
    -
    - -
    -
    - -
    diff --git a/package/LICENSE b/package/LICENSE new file mode 100644 index 0000000..705963e --- /dev/null +++ b/package/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 morpheuslord + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/package/MANIFEST.in b/package/MANIFEST.in new file mode 100644 index 0000000..1a64c4c --- /dev/null +++ b/package/MANIFEST.in @@ -0,0 +1,2 @@ +include nmap_api/*.py +include nmap_api/*.txt \ No newline at end of file diff --git a/package/README.md b/package/README.md new file mode 100644 index 0000000..994f9f3 --- /dev/null +++ b/package/README.md @@ -0,0 +1,118 @@ + +# Nmap API + +Uses python3.10, Debian, python-Nmap, and flask framework to create a Nmap API that can do scans with a good speed online and is easy to deploy. + +This is a implementation for our college PCL project which is still under development and constantly updating. + + +## API Reference + +#### Get all items + +```text + GET /api/p1/{auth_key}/{target} + GET /api/p2/{auth_key}/{target} + GET /api/p3/{auth_key}/{target} + GET /api/p4/{auth_key}/{target} + GET /api/p5/{auth_key}/{target} +``` + +| Parameter | Type | Description | +| :-------- | :------- | :------------------------- | +| `auth_key` | `string` | **Required**. The API auth key gebe | +| `target`| `string`| **Required**. The target Hostname and IP| + +#### Get item + +```text + GET /api/p1/ + GET /api/p2/ + GET /api/p3/ + GET /api/p4/ + GET /api/p5/ +``` + +| Parameter | Return data | Description | Nmap Command | +| :-------- | :------- | :-------------------------------- | :---------| +| `p1` | `json` | Effective Scan | `-Pn -sV -T4 -O -F`| +| `p2` | `json` | Simple Scan | `-Pn -T4 -A -v`| +| `p3` | `json` | Low Power Scan | `-Pn -sS -sU -T4 -A -v`| +| `p4` | `json` | Partial Intense Scan | `-Pn -p- -T4 -A -v`| +| `p5` | `json` | Complete Intense Scan | `-Pn -sS -sU -T4 -A -PE -PP -PY -g 53 --script=vuln`| + + +#### Auth and User management + +```text + GET /register/// +``` +| Parameter | Type | Description | +| :-------- | :------- | :------------------------- | +|`ID`|`Int`|user ID| +|`Passwd`| `String`| User Passwd| +|`Unique_Key`| `String`| User Unique_Key| + +## Improvements +Added GPT functionality with chunking module. +The methodology is based on how `Langchain GPT embeddings` operate. Basically the operation goes like this: + +```text +Data -> Chunks_generator ─┐ ┌─> AI_Loop -> Data_Extraction -> Return_Dat + (GPT3 - 1500 TOKENS) ├─> Chunk1 ─┤ + (GPT4 - 3500 TOKENS) ├─> Chunk2 ─┤ + ├─> Chunk3 ─┤ + └─> Chunk N ─┘ +``` + +AI code: +```python +def AI(analyze: str) -> dict[str, any]: + # Prompt about what the query is all about + prompt = f""" + Do a vulnerability analysis report on the following JSON data and + follow the following rules: + 1) Calculate the criticality score. + 2) Return all the open ports within the open_ports list. + 3) Return all the closed ports within the closed_ports list. + 4) Return all the filtered ports within the filtered_ports list. + + output format: {{ + "open_ports": [], + "closed_ports": [], + "filtered_ports": [], + "criticality_score": "" + }} + + data = {analize} + """ + try: + # A structure for the request + completion = openai.Completion.create( + engine=model_engine, + prompt=prompt, + max_tokens=1024, + n=1, + stop=None, + ) + response = completion.choices[0].text + + # Assuming extract_ai_output returns a dictionary + extracted_data = extract_ai_output(response) + except KeyboardInterrupt: + print("Bye") + quit() + + # Store outputs in a dictionary + ai_output = { + "open_ports": extracted_data.get("open_ports"), + "closed_ports": extracted_data.get("closed_ports"), + "filtered_ports": extracted_data.get("filtered_ports"), + "criticality_score": extracted_data.get("criticality_score") + } + + return ai_output +``` + +#### Default User Keys +**Default_Key**: **cff649285012c6caae4d** diff --git a/package/nmap_api/__init__.py b/package/nmap_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/package/nmap_api/__pycache__/__init__.cpython-310.pyc b/package/nmap_api/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1c425d3b256c344ea62c779a1cb0c823c2aa01c9 GIT binary patch literal 137 zcmd1j<>g`kf}b;WQ$X}%5P=LBfgA@QE@lA|DGb33nv8x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sXwKZzY~!8^~Rer;^U92p#gTe6DC*TJXlmjv?Uhkyh5W17Nrc+Da^A zuZ7Wh2ej;C5Uy_Mj^5M_12q?PN4H(~pQ^6AN2<2m|6tv$tiQUZqqlV%T4#0pU$)&e zU0mT;(ZThd;ShHi4m;PW0|`3y1n~SCn5gR~5#(`}t)!)%o@laCXS9iVePu#Ef#6eD zbt(2K!d8I23@f@YT^}-1_4xgUAGN$aKBhK4RbBvePlF+LOta;tIw-ZP1JfqvgX0GV z{@qAXnvf2vC~?&wG-suSQXyVBRk`;(9ACVS0vSC;2LF8whbLTu8AT|+IPXLW%R~My zvOnvAa5Tic`dw1B4JiXXVHt*QLjpnBguY5QEc@TCZ9~g3Yy)cak?AZrSDTP-{s)xX B)^7j+ literal 0 HcmV?d00001 diff --git a/package/nmap_api/__pycache__/p.cpython-310.pyc b/package/nmap_api/__pycache__/p.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b6e2deda13c7698b58f00ecbc85e9ee1a7bc66d GIT binary patch literal 1743 zcmb_c&2Jk;6rY*>^x6&yYL$l1xgb%*qBM3ysR|;L4*?=rGA-&TlC|BLrt8|X!|XVX zUHd}0_RcX8Cm;ED_R1;e-hxVaQpO+B& z%`X1_5mDvcTDMBpCb4s!%La1RmlxXZnt5c9du1JD5vc@1>PBVGqx z;|<;f9dX=6mzR#w5P2phK89U=}}uFsP3?J|I(c z2pG8Ym|)mDa1PN7Pce7b(2PtjaStNMA)YzL?R$OS1XIW2f?I@-y_q|8`+#l@^=mWl zdnA`#WTNpkjO;LV9zDXK8;@Xh8%g{C_NJcQ;|Q?Vw~xug*<>Z|NE#QnX#8E9#^2KT z^EqaS@50zojFxl^!{JxMyi6tCva;0r->3lL4 z^JYopPey)T}G8Wx{{~ZXE<&ycS7KssMW0-R> z=v7CvAibAoseqf>CoEUK7UMg4qWPE72(3rTl%CR=G^P8)C^K`Pkxa3gy-ANJCSidE zkWGZPG-Ofw{Jc<$Lglg$bEGeU^Z2b#uk9o{y_fBY9k_5`q^8*U;?`EI#wxSMj(Sgx zOQNpSAiQ`R#04C}AlM}^Pke`fT@C;D<)8t+2$Me=j(!D#PvzW`33$)MxwZetxvAHM z=LFVWe=+N<|AFP2b^yVoxgeV*+7^xXG!OwTUQ^ow(Sa4VOtiiJ;@Nf6T2R(VuUcW# zScx^TAX6I@^pkf${8y%y0@rOkwV8A=d8%K7@KbZ8Uj^@9h%Z*<(S;JZS(V6nA#c48 z=jhk1c;oDNs&ZBF`C@6?-dJII^Xyo@c~NdUpV7F}f!V#f{%*V70&A<)y7~d=o9*>0 z8=GLCAFaQ7m literal 0 HcmV?d00001 diff --git a/package/nmap_api/app.py b/package/nmap_api/app.py new file mode 100644 index 0000000..894b96f --- /dev/null +++ b/package/nmap_api/app.py @@ -0,0 +1,211 @@ +import json +import re +from typing import Any +from typing import Callable +from typing import cast + +import nmap +import openai +from flask import Flask +from flask_restful import Api +from flask_restful import Resource + +openai.api_key = "__API__KEY__" +model_engine = "text-davinci-003" + +app = Flask(__name__) +api = Api(app) + +nm = nmap.PortScanner() + + +def to_int(s: str) -> int: + return int(s) + + +def sanitize(input_string: str) -> str: + if not re.match("^[a-zA-Z0-9]*$", input_string): + raise ValueError("Invalid characters in string") + else: + return input_string + + +def chunk_output( + scan_output: str, max_token_size: int +) -> list[dict[str, Any]]: + scan_output_dict = json.loads(scan_output) + output_chunks = [] + current_chunk = {} + current_token_count = 0 + + # Convert JSON to AI usable chunks + for ip, scan_data in scan_output_dict.items(): + new_data_token_count = len(json.dumps({ip: scan_data}).split()) + + if current_token_count + new_data_token_count <= max_token_size: + current_chunk[ip] = scan_data + current_token_count += new_data_token_count + else: + output_chunks.append(current_chunk) + current_chunk = {ip: scan_data} + current_token_count = new_data_token_count + # The Chunks list that is returned + if current_chunk: + output_chunks.append(current_chunk) + + return output_chunks + + +def AI(analize: str) -> dict[str, Any]: + # Prompt about what the query is all about + prompt = f""" + Do a vulnerability analysis report on the following JSON data and + follow the following rules: + 1) Calculate the criticality score. + 2) Return all the open ports within the open_ports list. + 3) Return all the closed ports within the closed_ports list. + 4) Return all the filtered ports within the filtered_ports list. + + output format: {{ + "open_ports": [], + "closed_ports": [], + "filtered_ports": [], + "criticality_score": "" + }} + + data = {analize} + """ + try: + # A structure for the request + completion = openai.Completion.create( + engine=model_engine, + prompt=prompt, + max_tokens=1024, + n=1, + stop=None, + ) + response = completion.choices[0]['text'] + + # Assuming extract_ai_output returns a dictionary + extracted_data = extract_ai_output(response) + except KeyboardInterrupt: + print("Bye") + quit() + + # Store outputs in a dictionary + ai_output = { + "open_ports": extracted_data.get("open_ports"), + "closed_ports": extracted_data.get("closed_ports"), + "filtered_ports": extracted_data.get("filtered_ports"), + "criticality_score": extracted_data.get("criticality_score") + } + + return ai_output + + +def extract_ai_output(ai_output: str) -> dict[str, Any]: + result = { + "open_ports": [], + "closed_ports": [], + "filtered_ports": [], + "criticality_score": "" + } + + # Match and extract ports + open_ports_match = re.search(r'"open_ports": \[([^\]]*)\]', ai_output) + closed_ports_match = re.search(r'"closed_ports": \[([^\]]*)\]', ai_output) + filtered_ports_match = re.search( + r'"filtered_ports": \[([^\]]*)\]', ai_output) + + # If found, convert string of ports to list + if open_ports_match: + result["open_ports"] = list( + map(cast(Callable[[Any], str], int), + open_ports_match.group(1).split(','))) + if closed_ports_match: + result["closed_ports"] = list( + map(cast(Callable[[Any], str], int), + closed_ports_match.group(1).split(','))) + if filtered_ports_match: + result["filtered_ports"] = list( + map(cast(Callable[[Any], str], int), + filtered_ports_match.group(1).split(','))) + + # Match and extract criticality score + criticality_score_match = re.search( + r'"criticality_score": "([^"]*)"', ai_output) + if criticality_score_match: + result["criticality_score"] = criticality_score_match.group(1) + + return result + + +def profile(url: str, argument: str) -> dict[str, Any]: + ip = url + # Nmap Execution command + nm.scan('{}'.format(ip), arguments='{}'.format(argument)) + scan_data = nm.analyse_nmap_xml_scan() + analize = scan_data["scan"] + chunk_data = str(chunk_output(analize, 500)) + all_outputs = [] + for chunks in chunk_data: + string_chunks = str(chunks) + data = AI(string_chunks) + all_outputs.append(data) + return json.dumps(all_outputs) + + +# Effective Scan +class p1(Resource): + def get(self, url): + argument = '-Pn -sV -T4 -O -F' + scan = profile(url, argument) + return scan + + +# Simple Scan +class p2(Resource): + def get(self, url): + argument = '-Pn -T4 -A -v' + scan = profile(url, argument) + return scan + + +# Low Power Scan +class p3(Resource): + def get(self, url): + argument = '-Pn -sS -sU -T4 -A -v' + scan = profile(url, argument) + return scan + + +# partial Intense Scan +class p4(Resource): + def get(self, url): + argument = '-Pn -p- -T4 -A -v' + scan = profile(url, argument) + return scan + + +# Complete Intense scan +class p5(Resource): + def get(self, url): + argument = '-Pn -sS -sU -T4 -A -PE -PP -PY -g 53 --script=vuln' + scan = profile(url, argument) + return scan + + +api.add_resource( + p1, "/api/p1/") +api.add_resource( + p2, "/api/p2/") +api.add_resource( + p3, "/api/p3/") +api.add_resource( + p4, "/api/p4/") +api.add_resource( + p5, "/api/p5/") + + +def start_api(): + app.run(host="0.0.0.0", port="80") diff --git a/package/nmap_api/requirements.txt b/package/nmap_api/requirements.txt new file mode 100644 index 0000000..46b4814 --- /dev/null +++ b/package/nmap_api/requirements.txt @@ -0,0 +1,30 @@ +aiohttp==3.8.4 +aiosignal==1.3.1 +aniso8601==9.0.1 +async-timeout==4.0.2 +attrs==22.2.0 +autopep8==2.0.2 +certifi==2022.12.7 +charset-normalizer==3.1.0 +click==8.1.3 +colorama==0.4.6 +Flask==2.2.3 +Flask-RESTful==0.3.9 +frozenlist==1.3.3 +idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.1.2 +lxml==4.9.2 +MarkupSafe==2.1.2 +multidict==6.0.4 +openai==0.27.4 +pycodestyle==2.10.0 +python-nmap==0.7.1 +pytz==2023.3 +requests==2.28.2 +six==1.16.0 +tomli==2.0.1 +tqdm==4.65.0 +urllib3==1.26.15 +Werkzeug==2.2.3 +yarl==1.8.2 \ No newline at end of file diff --git a/package/pyproject.toml b/package/pyproject.toml new file mode 100644 index 0000000..d754819 --- /dev/null +++ b/package/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=54", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/package/setup.cfg b/package/setup.cfg new file mode 100644 index 0000000..3c75a9f --- /dev/null +++ b/package/setup.cfg @@ -0,0 +1,18 @@ +[metadata] +name = Nmap_API +version = 0.1.1 +author = Chiranjeevi G +author_email = morpheuslord@protonmail.com +description = Nmap API vuln analysis with python and ChatGPT +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/morpheuslord/Nmap-API +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +packages = find: +python_requires = >=3.10 +include_package_data = True diff --git a/package/setup.py b/package/setup.py new file mode 100644 index 0000000..3e47b95 --- /dev/null +++ b/package/setup.py @@ -0,0 +1,73 @@ +from setuptools import setup, find_packages +import codecs +import os + +here = os.path.abspath(os.path.dirname(__file__)) + +with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh: + long_description = "\n" + fh.read() + +VERSION = '0.1.1' +DESCRIPTION = 'Python Project for Nmap-API with GPT integration' +LONG_DESCRIPTION = """ +Uses python3.10, Debian, python-Nmap, and flask framework +to create a Nmap API that can do scans with a good speed +online and is easy to deploy. This is a implementation +for our college PCL project which is still under +development and constantly updating. +""" + +# Setting up +setup( + name="Nmap_API", + version=VERSION, + author="Chiranjeevi G", + author_email="morpheuslord@protonmail.com", + description=DESCRIPTION, + long_description_content_type="text/markdown", + long_description=long_description, + packages=find_packages(), + package_data={ + 'nmap_api': ['nmap_api/auth_keys.db'], + }, + install_requires=['aiohttp==3.8.4', + 'aiosignal==1.3.1', + 'aniso8601==9.0.1', + 'async-timeout==4.0.2', + 'attrs==22.2.0', + 'autopep8==2.0.2', + 'certifi==2022.12.7', + 'charset-normalizer==3.1.0', + 'click==8.1.3', + 'colorama==0.4.6', + 'Flask==2.2.3', + 'Flask-RESTful==0.3.9', + 'frozenlist==1.3.3', + 'idna==3.4', + 'itsdangerous==2.1.2', + 'Jinja2==3.1.2', + 'lxml==4.9.2', + 'MarkupSafe==2.1.2', + 'multidict==6.0.4', + 'openai==0.27.4', + 'pycodestyle==2.10.0', + 'python-nmap==0.7.1', + 'pytz==2023.3', + 'requests==2.28.2', + 'six==1.16.0', + 'tomli==2.0.1', + 'tqdm==4.65.0', + 'urllib3==1.26.15', + 'Werkzeug==2.2.3', + 'yarl==1.8.2'], + keywords=['python', 'GPT', 'vulnerability', + 'ai', 'vulnerability-assessment', 'network-scanning'], + classifiers=[ + "Development Status :: 1 - Planning", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3", + "Operating System :: Unix", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + ] +) diff --git a/setuo.cfg b/setuo.cfg new file mode 100644 index 0000000..4fae008 --- /dev/null +++ b/setuo.cfg @@ -0,0 +1,25 @@ +[flake8] +format = pylint +max-line-length = 120 + +[pep8] +max-line-length = 120 + +[mypy] +disable_error_code = import +disallow_any_generics = false +disallow_untyped_decorators = true +implicit_reexport = false +show_error_codes = true +warn_redundant_casts = true +warn_unused_configs = true +warn_unused_ignores = true +# required for `warn_unused_configs = true` +incremental = true +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_untyped_calls = true +disallow_untyped_defs = true +strict_equality = true +no_implicit_optional = true +warn_unreachable = true diff --git a/static/index.js b/static/index.js index b4a08e2..26b35d4 100644 --- a/static/index.js +++ b/static/index.js @@ -12,7 +12,7 @@ $(document).ready(function(){ }); }); -var width = $(window).width(); +var width = $(window).width(); window.onscroll = function(){ if ((width >= 900)){ diff --git a/templates/404.html b/templates/404.html index 94390d3..cfd45a4 100644 --- a/templates/404.html +++ b/templates/404.html @@ -3,9 +3,9 @@ or any file you want--> {% block title %}Page Not Found{% endblock %} {% block body %} - +

    Oops! Looks like the page doesn't exist anymore

    To go to the Home Page

    - + -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/add.html b/templates/add.html index d97cb6b..fab2867 100644 --- a/templates/add.html +++ b/templates/add.html @@ -16,4 +16,4 @@

    Add User To Database

    -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/base.html b/templates/base.html index 43051da..b013399 100644 --- a/templates/base.html +++ b/templates/base.html @@ -232,21 +232,21 @@ color: #fff; text-decoration: none; } - + .made-with-love a:hover { text-decoration: underline; } - + ::-webkit-scrollbar { width: 6px; - } + } ::-webkit-scrollbar-track { - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); - } - + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + } + ::-webkit-scrollbar-thumb { - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); } table{ @@ -311,7 +311,7 @@ .container td, .container th { padding-bottom: 2%; padding-top: 2%; - padding-left:2%; + padding-left:2%; } .container tr:nth-child(odd) { @@ -555,13 +555,13 @@ height:5px; } ::-webkit-scrollbar-track { - background: #f1f1f1; + background: #f1f1f1; } ::-webkit-scrollbar-thumb { - background: #000; + background: #000; } ::-webkit-scrollbar-thumb:hover { - background: #555; + background: #555; } @-webkit-keyframes Gradient { 0% {background-position: 0% 50%} diff --git a/templates/del.html b/templates/del.html index 8a7a80d..38ae237 100644 --- a/templates/del.html +++ b/templates/del.html @@ -15,4 +15,4 @@

    Delete User from Database

    -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/index.css b/templates/index.css index a378001..33ae2b1 100644 --- a/templates/index.css +++ b/templates/index.css @@ -149,21 +149,21 @@ body,html { color: #fff; text-decoration: none; } - + .made-with-love a:hover { text-decoration: underline; } - + ::-webkit-scrollbar { width: 6px; - } + } ::-webkit-scrollbar-track { - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); - } - + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + } + ::-webkit-scrollbar-thumb { - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); } table{ @@ -228,7 +228,7 @@ table{ .container td, .container th { padding-bottom: 2%; padding-top: 2%; - padding-left:2%; + padding-left:2%; } .container tr:nth-child(odd) { @@ -472,13 +472,13 @@ button:focus { height:5px; } ::-webkit-scrollbar-track { - background: #f1f1f1; + background: #f1f1f1; } ::-webkit-scrollbar-thumb { - background: #000; + background: #000; } ::-webkit-scrollbar-thumb:hover { - background: #555; + background: #555; } @-webkit-keyframes Gradient { 0% {background-position: 0% 50%} diff --git a/templates/index.js b/templates/index.js index b4a08e2..26b35d4 100644 --- a/templates/index.js +++ b/templates/index.js @@ -12,7 +12,7 @@ $(document).ready(function(){ }); }); -var width = $(window).width(); +var width = $(window).width(); window.onscroll = function(){ if ((width >= 900)){ diff --git a/templates/results.html b/templates/results.html index 1c54c88..b637816 100644 --- a/templates/results.html +++ b/templates/results.html @@ -1 +1 @@ -
    nmap
    command_linenmap -oX - -Pn -sV -T4 -O -F 127.0.0.1
    scaninfo
    tcp
    methodsyn
    services7,9,13,21-23,25-26,37,53,79-81,88,106,110-111,113,119,135,139,143-144,179,199,389,427,443-445,465,513-515,543-544,548,554,587,631,646,873,990,993,995,1025-1029,1110,1433,1720,1723,1755,1900,2000-2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000-6001,6646,7070,8000,8008-8009,8080-8081,8443,8888,9100,9999-10000,32768,49152-49157
    scanstats
    timestrFri Oct 21 10:58:48 2022
    elapsed8.78
    uphosts1
    downhosts0
    totalhosts1
    scan
    127.0.0.1
    hostnames
    nametype
    kubernetes.docker.internalPTR
    addresses
    ipv4127.0.0.1
    vendor
    status
    stateup
    reasonuser-set
    uptime
    seconds8067
    lastbootFri Oct 21 08:44:21 2022
    tcp
    135
    stateopen
    reasonsyn-ack
    namemsrpc
    productMicrosoft Windows RPC
    version
    extrainfo
    conf10
    cpecpe:/o:microsoft:windows
    445
    stateopen
    reasonsyn-ack
    namemicrosoft-ds
    product
    version
    extrainfo
    conf3
    cpe
    3306
    stateopen
    reasonsyn-ack
    namemysql
    productMySQL
    version8.0.30
    extrainfo
    conf10
    cpecpe:/a:mysql:mysql:8.0.30
    5000
    stateopen
    reasonsyn-ack
    namehttp
    productWerkzeug httpd
    version1.0.1
    extrainfoPython 3.10.7
    conf10
    cpecpe:/a:python:python:3.10.7
    portused
    stateprotoportid
    opentcp135
    closedtcp7
    closedudp37469
    osmatch
    nameaccuracylineosclass
    Microsoft Windows 10 160710069751
    typevendorosfamilyosgenaccuracycpe
    general purposeMicrosoftWindows10100
    • cpe:/o:microsoft:windows_10:1607
    \ No newline at end of file +
    nmap
    command_linenmap -oX - -Pn -sV -T4 -O -F 127.0.0.1
    scaninfo
    tcp
    methodsyn
    services7,9,13,21-23,25-26,37,53,79-81,88,106,110-111,113,119,135,139,143-144,179,199,389,427,443-445,465,513-515,543-544,548,554,587,631,646,873,990,993,995,1025-1029,1110,1433,1720,1723,1755,1900,2000-2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000-6001,6646,7070,8000,8008-8009,8080-8081,8443,8888,9100,9999-10000,32768,49152-49157
    scanstats
    timestrFri Oct 21 10:58:48 2022
    elapsed8.78
    uphosts1
    downhosts0
    totalhosts1
    scan
    127.0.0.1
    hostnames
    nametype
    kubernetes.docker.internalPTR
    addresses
    ipv4127.0.0.1
    vendor
    status
    stateup
    reasonuser-set
    uptime
    seconds8067
    lastbootFri Oct 21 08:44:21 2022
    tcp
    135
    stateopen
    reasonsyn-ack
    namemsrpc
    productMicrosoft Windows RPC
    version
    extrainfo
    conf10
    cpecpe:/o:microsoft:windows
    445
    stateopen
    reasonsyn-ack
    namemicrosoft-ds
    product
    version
    extrainfo
    conf3
    cpe
    3306
    stateopen
    reasonsyn-ack
    namemysql
    productMySQL
    version8.0.30
    extrainfo
    conf10
    cpecpe:/a:mysql:mysql:8.0.30
    5000
    stateopen
    reasonsyn-ack
    namehttp
    productWerkzeug httpd
    version1.0.1
    extrainfoPython 3.10.7
    conf10
    cpecpe:/a:python:python:3.10.7
    portused
    stateprotoportid
    opentcp135
    closedtcp7
    closedudp37469
    osmatch
    nameaccuracylineosclass
    Microsoft Windows 10 160710069751
    typevendorosfamilyosgenaccuracycpe
    general purposeMicrosoftWindows10100
    • cpe:/o:microsoft:windows_10:1607
    diff --git a/templates/results.json b/templates/results.json index 879995e..b725c30 100644 --- a/templates/results.json +++ b/templates/results.json @@ -189,4 +189,4 @@ "@level": "0" } } -} \ No newline at end of file +} diff --git a/templates/scanner.html b/templates/scanner.html index 2d24955..b10b649 100644 --- a/templates/scanner.html +++ b/templates/scanner.html @@ -53,4 +53,4 @@

    Scanner Input Section

    -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/test_app.py b/test_app.py deleted file mode 100644 index 57f7aa3..0000000 --- a/test_app.py +++ /dev/null @@ -1,98 +0,0 @@ -from app import chunk_output - -data = """ -{ - "127.0.0.1": { - "hostnames": [ - { - "name": "kubernetes.docker.internal", - "type": "PTR" - } - ], - "addresses": { - "ipv4": "127.0.0.1" - }, - "vendor": {}, - "status": { - "state": "up", - "reason": "user-set" - }, - "uptime": { - "seconds": "130186", - "lastboot": "Sun Jun 18 20:15:24 2023" - }, - "tcp": { - "80": { - "state": "open", - "reason": "syn-ack", - "name": "http", - "product": "Werkzeug/2.2.3 Python/3.10.0", - "version": "", - "extrainfo": "", - "conf": "10", - "cpe": "" - }, - "135": { - "state": "open", - "reason": "syn-ack", - "name": "msrpc", - "product": "Microsoft Windows RPC", - "version": "", - "extrainfo": "", - "conf": "10", - "cpe": "cpe:/o:microsoft:windows" - }, - "445": { - "state": "open", - "reason": "syn-ack", - "name": "microsoft-ds", - "product": "", - "version": "", - "extrainfo": "", - "conf": "3", - "cpe": "" - } - }, - "portused": [ - { - "state": "open", - "proto": "tcp", - "portid": "80" - }, - { - "state": "closed", - "proto": "tcp", - "portid": "7" - }, - { - "state": "closed", - "proto": "udp", - "portid": "41433" - } - ], - "osmatch": [ - { - "name": "Microsoft Windows 10 1607", - "accuracy": "100", - "line": "69748", - "osclass": [ - { - "type": "general purpose", - "vendor": "Microsoft", - "osfamily": "Windows", - "osgen": "10", - "accuracy": "100", - "cpe": [ - "cpe:/o:microsoft:windows_10:1607" - ] - } - ] - } - ] - } -} -""" -d = str(data) -return_d = chunk_output(d, 10) -print(return_d) -print(type(return_d)) diff --git a/xml.xml b/xml.xml deleted file mode 100644 index af71907b51447865f3f05a246a9615140a78dbaf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6172 zcmds*%WhjY5Qe!;fxd%~ZLL_=#gYxT-4sC=1rpRjkzJrjaxK)B4NG#Hmv8fbGp0!% z9r}WJRR|J!$eEvW=N$d_?@9PM{1Yz2Md*avun0F{9hTuLtiq4sbvOubLQi8yR6m99 z!*}5%OhtQf_w-87D{)W5wP-fsi^hd<&V@45%IkYdXlFvcH2PJThfl&;iht4IU5oF= zI1_ePoF7HkweNdzF<*y2Z2S<0HomjpxB5K@{V+D^(cq1qPr`oneAn$&K*qJGroujT+rFN|z`Ec$Mkh;mQA6a5~@l29GktZO5?JcGm-&luVB;O=>- zedve!KnFJCk&OeP^E@=4F*-dXI76MvI1&dqjQ;F&BjaFyXmXBh#`DDVITROi9vTwb zj7?rn?`fS8`59gAo+QC4Xx!JT>&6o^PIZ09+VwSNagFm`yPoYr!v~8qA`7#jA>#|a ztc^9|fq~J1jO2aOiZk8*%-mwwcVa$4bGPQ`p4Vqc&kU>i>`+h4(8t&Cgs%;>?lFLt zeWQ!^8|frIZduoDWSsDV>RS2?WT^4po-lj%#rjScXA{}Q*N~JMUtf#S=MllKfAAI3 zb1qu*ac@OzWFPBf;ubp-F@4d*`PedRZ51zNPo7=W3(xAb%38BN z=+$GXs!0A)`D!_QYM7nyPPJwuDym#ZHW-Fu(~Do~AhFfg$2G{2ldPP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