使用 python3.10、Debian、python-Nmap 和 Flask 框架创建一个 Nmap API,可以快速在线进行扫描,并且易于部署。
这是我们大学 PCL 项目的一个实现,该项目仍在开发中并持续更新。
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}
| 参数 | 类型 | 描述 |
|---|---|---|
auth_key | string | 必需。API 认证密钥 gebe |
target | string | 必需。目标主机名和 IP |
GET /api/p1/
GET /api/p2/
GET /api/p3/
GET /api/p4/
GET /api/p5/
GET /api/p6/
GET /api/p7/
GET /api/p8/
GET /api/p9/
GET /api/p10/
GET /api/p11/
GET /api/p12/
GET /api/p13/
| 参数 | 返回数据 | 描述 | Nmap 命令 |
|---|---|---|---|
p1 | json | 有效扫描 | -Pn -sV -T4 -O -F |
p2 | json | 简单扫描 | -Pn -T4 -A -v |
p3 | json | 低功耗扫描 | -Pn -sS -sU -T4 -A -v |
p4 | json | 部分高强度扫描 | -Pn -p- -T4 -A -v |
p5 | json | 完整高强度扫描 | -Pn -sS -sU -T4 -A -PE -PP -PY -g 53 --script=vuln |
p6 | json | 全面服务版本检测 | -Pn -sV -p- -A |
p7 | json | 带操作系统检测的激进扫描 | -Pn -sS -sV -O -T4 -A |
p8 | json | 常见漏洞脚本扫描 | -Pn -sC |
p9 | json | 高强度扫描,所有 TCP 端口 | -Pn -p 1-65535 -T4 -A -v |
p10 | json | UDP 扫描 | -Pn -sU -T4 |
p11 | json | 常见端口的服务与版本检测 | -Pn -sV --top-ports 100 |
p12 | json | 使用 NSE 漏洞脚本的激进扫描 | -Pn -sS -sV -T4 --script=default,discovery,vuln |
p13 | json | 常见端口的快速扫描 | -Pn -F |
GET /register/<int:user_id>/<string:password>
| 参数 | 类型 | 描述 |
|---|---|---|
ID | Int | 用户 ID |
Passwd | String | 用户密码 |
新增了带有分块模块的 GPT 功能。
该方法基于 Langchain GPT embeddings 的工作原理。基本操作流程如下:
Data -> Chunks_generator ─┐ ┌─> AI_Loop -> Data_Extraction -> Return_Data
├─> Chunk1 ─┤
├─> Chunk2 ─┤
├─> Chunk3 ─┤
└─> Chunk N ─┘
AI 代码:
def AI(analize: str) -> dict[str, any]:
prompt = f"""
Do a NMAP scan analysis on the provided NMAP scan information
The NMAP output must return in a JSON format accorging to the provided
output format. The data must be accurate in regards towards a pentest report.
The data must follow the following rules:
1) The NMAP scans must be done from a pentester point of view
2) The final output must be minimal according to the format given.
3) The final output must be kept to a minimal.
4) If a value not found in the scan just mention an empty string.
5) Analyze everything even the smallest of data.
6) Completely analyze the data provided and give a confirm answer using the output format.
The output format:
{{
"critical score": [""],
"os information": [""],
"open ports": [""],
"open services": [""],
"vulnerable service": [""],
"found cve": [""]
}}
NMAP Data to be analyzed: {analize}
"""
messages = [{"content": prompt, "role": "assistant"}]
response = openai.ChatCompletion.create(
model=model_engine,
messages=messages,
max_tokens=2500,
n=1,
stop=None,
)
response = response['choices'][0]['message']['content']
ai_output = {
"markdown": response
}
return ai_output
默认密钥:e43d4
更新仍在进行中