Upload 3 files
Browse files- README.md +42 -8
- app.py +170 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,15 +1,49 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
license:
|
| 12 |
-
short_description:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SENTINEL Autonomous Pentesting Agent
|
| 3 |
+
emoji: 🛡️
|
| 4 |
+
colorFrom: red
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.36.1
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: Fine-tuned Llama-3-8B that autonomously exploits web vulns
|
| 12 |
+
tags:
|
| 13 |
+
- security
|
| 14 |
+
- llama-3
|
| 15 |
+
- autonomous-agent
|
| 16 |
+
- web-pentesting
|
| 17 |
+
- sql-injection
|
| 18 |
+
- cybersecurity
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# 🛡️ SENTINEL — Autonomous Web Pentesting Agent
|
| 22 |
+
|
| 23 |
+
**SENTINEL** is a fine-tuned **Llama-3-8B-Instruct** model trained via SFT+GRPO to autonomously reason about web application vulnerabilities and generate exploit payloads.
|
| 24 |
+
|
| 25 |
+
## What it does
|
| 26 |
+
|
| 27 |
+
Given a **goal** (e.g. `AUTHENTICATED`, `DATA_EXFILTRATED`) and an **HTML snippet** (the current page DOM), SENTINEL outputs a single structured JSON action — exactly like a human pentester would decide their next move.
|
| 28 |
+
|
| 29 |
+
```json
|
| 30 |
+
{
|
| 31 |
+
"Thought": "Login form with username/password fields on a .php endpoint — classic SQLi target.",
|
| 32 |
+
"Action": "SQL_INJECT",
|
| 33 |
+
"Action_Input": {
|
| 34 |
+
"target_url": "http://target/login.php",
|
| 35 |
+
"method": "POST",
|
| 36 |
+
"parameters": {"username": "admin'--", "password": "x"},
|
| 37 |
+
"rationale": "OR-tautology bypass on username field"
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## Model Details
|
| 43 |
+
|
| 44 |
+
- **Base model:** `meta-llama/Meta-Llama-3-8B-Instruct`
|
| 45 |
+
- **Fine-tuning:** SFT on curated web-exploit trajectories + GRPO reward shaping
|
| 46 |
+
- **Quantization:** Q5_K_M GGUF (~5.7 GB), served via `llama-cpp-python`
|
| 47 |
+
- **The GGUF weights** are hosted in a separate model repo and downloaded at runtime to bypass the Space 1 GB git limit.
|
| 48 |
+
|
| 49 |
+
> ⚠️ **Authorized testing only.** SENTINEL is designed for use against intentionally vulnerable targets (DVWA, Juice Shop, HackTheBox, etc.). Do not use against systems you do not own.
|
app.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# ==========================================
|
| 7 |
+
# Set this to YOUR model repo on Hugging Face
|
| 8 |
+
# Format: "YourUsername/your-model-repo-name"
|
| 9 |
+
# This should be the SEPARATE MODEL repo where you uploaded model-q5_k_m.gguf
|
| 10 |
+
# NOT the Space repo itself.
|
| 11 |
+
# Example: "Niranjan/SENTINEL-Llama3-GGUF"
|
| 12 |
+
# ==========================================
|
| 13 |
+
HF_REPO_ID = "niranjan2777/SENTINEL-q5_k_m-GGUF"
|
| 14 |
+
MODEL_FILENAME = "model-q5_k_m.gguf"
|
| 15 |
+
|
| 16 |
+
print("Downloading model from Hugging Face... this will take a few minutes the first time.")
|
| 17 |
+
try:
|
| 18 |
+
# This downloads the file to the Space's local cache so it fits in the ephemeral disk
|
| 19 |
+
# and bypasses the 1 GB git repository limit!
|
| 20 |
+
MODEL_PATH = hf_hub_download(repo_id=HF_REPO_ID, filename=MODEL_FILENAME)
|
| 21 |
+
print("Download complete. Loading model...")
|
| 22 |
+
|
| 23 |
+
llm = Llama(
|
| 24 |
+
model_path=MODEL_PATH,
|
| 25 |
+
n_ctx=2048,
|
| 26 |
+
n_threads=4, # Adjust based on CPU cores available in HF Space
|
| 27 |
+
n_gpu_layers=0 # Standard free HF Space is CPU-only
|
| 28 |
+
)
|
| 29 |
+
except Exception as e:
|
| 30 |
+
llm = None
|
| 31 |
+
print(f"Error downloading or loading model: {e}")
|
| 32 |
+
print(f"Make sure you created a MODEL repo, uploaded the .gguf there, and changed HF_REPO_ID in this script.")
|
| 33 |
+
|
| 34 |
+
SENTINEL_SYSTEM_PROMPT = """You are SENTINEL, an autonomous web-exploitation agent. Given an HTML snippet and a goal (and optionally prior agent turns), you reason about vulnerabilities and emit a single JSON action that advances the exploit loop:
|
| 35 |
+
|
| 36 |
+
observe -> identify attack surface -> select exploit -> generate payload -> interpret response -> adapt and retry -> detect success -> STOP
|
| 37 |
+
|
| 38 |
+
Prioritize vulnerability sinks: form action, input value, src, href, hidden fields, query parameters, JSON body fields, and reflected DOM contexts. Infer the backend from HTML evidence (.php, .aspx, __VIEWSTATE, .jsp, /rest/, <app-*>, wp-content, etc.) and choose context-appropriate payloads.
|
| 39 |
+
|
| 40 |
+
Output a single JSON object with exactly these keys:
|
| 41 |
+
- Thought: <=4 sentences, <=80 words; cite the specific sink, backend inference, injection context, and payload-class justification (or signal classification for ANALYZE_RESPONSE / success indicator for STOP).
|
| 42 |
+
- Action: one of SQL_INJECT | XSS_INJECT | RETRY_MUTATED | ANALYZE_RESPONSE | CRAWL_DEEPER | WAIT | STOP.
|
| 43 |
+
- Action_Input: object with target_url, method, parameters, headers, rationale, plus action-specific fields (mutation_class for RETRY_MUTATED; signal + next_recommended for ANALYZE_RESPONSE; success_state + evidence for STOP).
|
| 44 |
+
|
| 45 |
+
Output ONLY the JSON. No prose, no markdown fences, no commentary."""
|
| 46 |
+
|
| 47 |
+
def generate_action(goal, html_snippet):
|
| 48 |
+
if not llm:
|
| 49 |
+
return "Error: Model file not found. Ensure model-q5_k_m.gguf is uploaded to the Space."
|
| 50 |
+
|
| 51 |
+
# Construct the user prompt to match the fine-tuning format
|
| 52 |
+
user_prompt = f"GOAL: {goal}\n\nHTML_SNIPPET:\n{html_snippet}"
|
| 53 |
+
|
| 54 |
+
# Llama-3 ChatML format
|
| 55 |
+
prompt = f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{SENTINEL_SYSTEM_PROMPT}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{user_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
response = llm(
|
| 59 |
+
prompt,
|
| 60 |
+
max_tokens=256,
|
| 61 |
+
temperature=0.0,
|
| 62 |
+
stop=["<|eot_id|>", "<|end_of_text|>"],
|
| 63 |
+
echo=False
|
| 64 |
+
)
|
| 65 |
+
return response["choices"][0]["text"].strip()
|
| 66 |
+
except Exception as e:
|
| 67 |
+
return f"Inference Error: {str(e)}"
|
| 68 |
+
|
| 69 |
+
# Define the Gradio Interface
|
| 70 |
+
with gr.Blocks(title="SENTINEL Autonomous Pentesting Agent", theme=gr.themes.Soft()) as app:
|
| 71 |
+
gr.Markdown("# 🛡️ SENTINEL Autonomous Pentesting Agent")
|
| 72 |
+
gr.Markdown("""
|
| 73 |
+
**SENTINEL** is a fine-tuned Llama-3-8B model trained to autonomously navigate, analyze, and exploit web vulnerabilities.
|
| 74 |
+
|
| 75 |
+
### How to use this demo:
|
| 76 |
+
1. Provide a pentesting **Goal** (e.g., `AUTHENTICATED`, `XSS_VULNERABILITY`).
|
| 77 |
+
2. Paste an **HTML Snippet** (the DOM of the page the agent is currently looking at).
|
| 78 |
+
3. Click **Analyze & Generate Action** to see the agent's internal thought process and the exact JSON payload it decides to execute.
|
| 79 |
+
|
| 80 |
+
*Try clicking one of the examples below to load it automatically!*
|
| 81 |
+
""")
|
| 82 |
+
|
| 83 |
+
with gr.Row():
|
| 84 |
+
with gr.Column(scale=1):
|
| 85 |
+
goal_input = gr.Textbox(label="Goal", value="AUTHENTICATED", lines=1)
|
| 86 |
+
html_input = gr.Code(label="HTML Snippet (DOM)", language="html", lines=15,
|
| 87 |
+
value='<form action="/login" method="POST">\n <input type="text" name="username">\n <input type="password" name="password">\n <button type="submit">Login</button>\n</form>')
|
| 88 |
+
submit_btn = gr.Button("🚀 Analyze & Generate Action", variant="primary")
|
| 89 |
+
|
| 90 |
+
with gr.Column(scale=1):
|
| 91 |
+
output_json = gr.Code(label="SENTINEL Output (JSON)", language="json", lines=20)
|
| 92 |
+
|
| 93 |
+
submit_btn.click(
|
| 94 |
+
fn=generate_action,
|
| 95 |
+
inputs=[goal_input, html_input],
|
| 96 |
+
outputs=output_json
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
gr.Markdown("### 📚 Example Scenarios")
|
| 100 |
+
gr.Examples(
|
| 101 |
+
examples=[
|
| 102 |
+
[
|
| 103 |
+
"AUTHENTICATED",
|
| 104 |
+
"""<div class="login-container">
|
| 105 |
+
<h2>Admin Login</h2>
|
| 106 |
+
<form action="/rest/user/login" method="POST" id="loginForm">
|
| 107 |
+
<label for="email">Email Address:</label>
|
| 108 |
+
<input type="email" id="email" name="email" required>
|
| 109 |
+
|
| 110 |
+
<label for="password">Password:</label>
|
| 111 |
+
<input type="password" id="password" name="password" required>
|
| 112 |
+
|
| 113 |
+
<button type="submit" id="loginButton">Log In</button>
|
| 114 |
+
</form>
|
| 115 |
+
</div>"""
|
| 116 |
+
],
|
| 117 |
+
[
|
| 118 |
+
"XSS_VULNERABILITY",
|
| 119 |
+
"""<div class="header">
|
| 120 |
+
<form action="/search" method="GET">
|
| 121 |
+
<input type="text" name="q" placeholder="Search products...">
|
| 122 |
+
<button type="submit">Search</button>
|
| 123 |
+
</form>
|
| 124 |
+
</div>
|
| 125 |
+
<div class="results">
|
| 126 |
+
<p>You searched for: <span id="search-term">apple</span></p>
|
| 127 |
+
</div>"""
|
| 128 |
+
],
|
| 129 |
+
[
|
| 130 |
+
"AUTHENTICATED",
|
| 131 |
+
"""<nav class="navbar">
|
| 132 |
+
<a href="/home">Home</a>
|
| 133 |
+
<a href="/about">About Us</a>
|
| 134 |
+
<a href="/contact">Contact</a>
|
| 135 |
+
</nav>
|
| 136 |
+
<div class="main-content">
|
| 137 |
+
<h1>Welcome to our Store</h1>
|
| 138 |
+
<p>We sell the best juice in the world.</p>
|
| 139 |
+
<img src="juice.png" alt="Juice Bottle">
|
| 140 |
+
</div>"""
|
| 141 |
+
],
|
| 142 |
+
[
|
| 143 |
+
"DATA_EXFILTRATED",
|
| 144 |
+
"""<form action="/api/v1/update-profile" method="POST">
|
| 145 |
+
<input type="text" name="first_name" value="John">
|
| 146 |
+
<input type="text" name="last_name" value="Doe">
|
| 147 |
+
<!-- Developer note: role should always be user -->
|
| 148 |
+
<input type="hidden" name="role" value="user">
|
| 149 |
+
<button type="submit">Update Profile</button>
|
| 150 |
+
</form>"""
|
| 151 |
+
],
|
| 152 |
+
[
|
| 153 |
+
"AUTHENTICATED",
|
| 154 |
+
"""<div class="registration">
|
| 155 |
+
<form action="/register.php" method="POST">
|
| 156 |
+
<input type="text" name="username" placeholder="Username">
|
| 157 |
+
<input type="password" name="password" placeholder="Password">
|
| 158 |
+
<input type="password" name="confirm_password" placeholder="Confirm Password">
|
| 159 |
+
<button type="submit">Register</button>
|
| 160 |
+
</form>
|
| 161 |
+
<p>Already have an account? <a href="/login.php">Log in here</a></p>
|
| 162 |
+
</div>"""
|
| 163 |
+
]
|
| 164 |
+
],
|
| 165 |
+
inputs=[goal_input, html_input],
|
| 166 |
+
label="Click an example below to load it into the inputs:"
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
if __name__ == "__main__":
|
| 170 |
+
app.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.36.1
|
| 2 |
+
llama-cpp-python==0.2.79
|
| 3 |
+
huggingface-hub
|