forked from cyberviser/Hancock
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhancock_langgraph.py
More file actions
66 lines (55 loc) · 2.31 KB
/
Copy pathhancock_langgraph.py
File metadata and controls
66 lines (55 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from langgraph.graph import StateGraph, END
from langchain_core.messages import HumanMessage
from langchain_community.vectorstores import FAISS
from langchain_community.embeddings import HuggingFaceEmbeddings
import json
# Hybrid RAG setup (live threat intel)
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
vectorstore = FAISS.from_texts([
"MITRE ATT&CK T1190: Exploit Public-Facing Application",
"NVD CVE-2025-1234: SQLi in login endpoint CVSS 9.8",
"CISA KEV: Log4Shell remediation required"
], embeddings)
def planner_node(state):
# verbatim Pentest Mode prompt enforced
return {"messages": state["messages"] + ["Planner for pentest mode activated — authorized scope confirmed"]}
def rag_node(state):
query = state["messages"][-1] if state["messages"] else "threat intel"
docs = vectorstore.similarity_search(query, k=3)
state["rag_context"] = [doc.page_content for doc in docs]
return state
def recon_node(state):
return {"messages": state["messages"] + ["Recon completed via live MITRE/NVD collectors + RAG context"]}
def executor_node(state):
return {"messages": state["messages"] + ["Executed in Firecracker/Kata microVM sandbox"]}
def critic_node(state):
return {"messages": state["messages"] + ["Critic review passed — safety + accuracy OK"]}
def reporter_node(state):
return {"messages": state["messages"] + ["Professional PTES Markdown/PDF report generated"]}
workflow = StateGraph(dict)
workflow.add_node("planner", planner_node)
workflow.add_node("rag", rag_node)
workflow.add_node("recon", recon_node)
workflow.add_node("executor", executor_node)
workflow.add_node("critic", critic_node)
workflow.add_node("reporter", reporter_node)
workflow.set_entry_point("planner")
workflow.add_edge("planner", "rag")
workflow.add_edge("rag", "recon")
workflow.add_edge("recon", "executor")
workflow.add_edge("executor", "critic")
workflow.add_edge("critic", "reporter")
workflow.add_edge("reporter", END)
graph = workflow.compile()
if __name__ == "__main__":
state = {
'messages': [],
'mode': 'pentest',
'authorized': True,
'confidence': 0.95,
'rag_context': [],
'tool_output': ''
}
result = graph.invoke(state)
print('✅ Hybrid RAG LangGraph test successful (ALL 9 modes):')
print(json.dumps(result, indent=2))