|
16 | 16 | AUTH = (os.getenv("SQLMAP_USERNAME"), os.getenv("SQLMAP_PASSWORD")) # Basic Auth |
17 | 17 |
|
18 | 18 |
|
| 19 | +def normalize_sqlmap_result(raw: dict) -> dict: |
| 20 | + result = { |
| 21 | + "success": raw.get("success", False), |
| 22 | + "error": raw.get("error", []), |
| 23 | + "data": {"target": {}, "injections": {}, "dbms": {}}, |
| 24 | + } |
| 25 | + |
| 26 | + for entry in raw.get("data", []): |
| 27 | + entry_type = entry.get("type") |
| 28 | + value = entry.get("value") |
| 29 | + |
| 30 | + # type 0 → 目标信息 |
| 31 | + if entry_type == 0 and isinstance(value, dict): |
| 32 | + result["data"]["target"] = value |
| 33 | + |
| 34 | + # type 1 → 注入点(一定是 list) |
| 35 | + elif entry_type == 1 and isinstance(value, list): |
| 36 | + for item in value: |
| 37 | + key = f"{item.get('place')}:{item.get('parameter')}" |
| 38 | + |
| 39 | + result["data"]["injections"][key] = { |
| 40 | + "place": item.get("place"), |
| 41 | + "parameter": item.get("parameter"), |
| 42 | + "ptype": item.get("ptype"), |
| 43 | + "prefix": item.get("prefix"), |
| 44 | + "suffix": item.get("suffix"), |
| 45 | + "clause": item.get("clause"), |
| 46 | + "notes": item.get("notes"), |
| 47 | + "payloads": item.get("data", {}), |
| 48 | + } |
| 49 | + |
| 50 | + # DBMS 信息(只记录一次即可) |
| 51 | + if not result["data"]["dbms"]: |
| 52 | + result["data"]["dbms"] = { |
| 53 | + "name": item.get("dbms"), |
| 54 | + "version": item.get("dbms_version"), |
| 55 | + } |
| 56 | + |
| 57 | + return result |
| 58 | + |
| 59 | + |
19 | 60 | @celery_app.task( |
20 | 61 | bind=True, |
21 | 62 | autoretry_for=(Exception,), |
@@ -63,15 +104,20 @@ def poll_single_sqlmap_task(self, task_id: str): |
63 | 104 | result_resp.raise_for_status() |
64 | 105 | data = result_resp.json() |
65 | 106 |
|
| 107 | + # 展平sqlmap返回日志 |
| 108 | + normalized = normalize_sqlmap_result(data) |
| 109 | + |
| 110 | + print(normalized) |
| 111 | + |
66 | 112 | # 解析 sqlmap 返回 |
67 | 113 | scan_result = SqlmapScanResult( |
68 | | - target_url=task.scan_url, |
69 | | - dbms=data.get("dbms"), |
70 | | - vulnerable=bool(data.get("data")), |
71 | | - injection_points=data.get("data"), |
72 | | - dump_data=data.get("dump"), |
73 | | - raw_output=data.get("raw"), |
74 | | - command=data.get("command", ""), |
| 114 | + target_url=normalized["data"]["target"]["url"], |
| 115 | + dbms=normalized["data"]["dbms"].get("name"), |
| 116 | + vulnerable=bool(normalized["data"]["injections"]), |
| 117 | + injection_points=normalized["data"]["injections"], |
| 118 | + dump_data=None, # 后续支持 sqlmap dump 再填 |
| 119 | + raw_output=normalized, |
| 120 | + command="", |
75 | 121 | started_at=datetime.utcnow(), |
76 | 122 | finished_at=datetime.utcnow(), |
77 | 123 | ) |
|
0 commit comments