Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen3.5-0.8B
|
| 4 |
+
tags:
|
| 5 |
+
- cybersecurity
|
| 6 |
+
- web-attack-detection
|
| 7 |
+
- fine-tuned
|
| 8 |
+
- chain-of-thought
|
| 9 |
+
- http-payload
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# 🔐 Qwen3.5-0.8B — Web Attack Classifier
|
| 16 |
+
|
| 17 |
+
A fine-tuned **Qwen3.5-0.8B** model that analyzes raw HTTP request payloads to detect web attacks. Given an HTTP request, the model reasons through the payload step by step and returns a structured JSON result identifying the attack type and the specific malicious syntax.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## How It Works
|
| 22 |
+
|
| 23 |
+
The model uses **chain-of-thought (CoT) reasoning** — before producing a final answer, it thinks through the request structure, anomaly signals, and attack patterns inside a `<think>` block. This reasoning is accessible via the OpenAI-compatible SDK using the `reasoning` field on the response message.
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
<think>
|
| 27 |
+
1. [Structure Analysis] GET request with query parameter 'id' containing user input
|
| 28 |
+
2. [Anomaly Detection] Single quote (') detected — attempting to break SQL string context
|
| 29 |
+
3. [Pattern Mapping] OR 1=1 is a tautology used to bypass authentication
|
| 30 |
+
4. [Evasion Technique] Double dash (--) comments out the rest of the original query
|
| 31 |
+
5. [Attack Classification] SQL Injection via GET parameter manipulation
|
| 32 |
+
</think>
|
| 33 |
+
{"attack_type": "SQL Injection", "attack_syntax": "' OR 1=1--"}
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## Supported Attack Types
|
| 39 |
+
|
| 40 |
+
| Label | Description |
|
| 41 |
+
|---|---|
|
| 42 |
+
| `Normal` | Benign HTTP traffic |
|
| 43 |
+
| `SQL Injection` | SQL syntax injected into parameters |
|
| 44 |
+
| `Cross Site Scripting (XSS)` | Script injection via input fields or URLs |
|
| 45 |
+
| `Command Injection` | OS command injection via HTTP parameters |
|
| 46 |
+
| `Path Traversal` | Directory traversal using `../` patterns |
|
| 47 |
+
| `Forced Browsing` | Direct access to hidden or restricted paths |
|
| 48 |
+
| `Brute Force` | Repeated authentication attempts |
|
| 49 |
+
| `Cookie Manipulation` | Tampering with cookie values |
|
| 50 |
+
| `File Upload` | Malicious file upload attempts |
|
| 51 |
+
| `File Download` | Unauthorized file download attempts |
|
| 52 |
+
| `Host Discovery` | Network/host reconnaissance via HTTP |
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## Usage
|
| 57 |
+
|
| 58 |
+
The model is served via a vLLM-compatible endpoint and accessed through the **OpenAI SDK**. Enable thinking mode via `chat_template_kwargs` to get the full CoT reasoning.
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
import asyncio
|
| 62 |
+
from openai import AsyncOpenAI
|
| 63 |
+
|
| 64 |
+
client = AsyncOpenAI(
|
| 65 |
+
base_url="http://your-server:8000/v1",
|
| 66 |
+
api_key="EMPTY"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
http_request = """GET /index.php?id=1' OR 1=1-- HTTP/1.1
|
| 70 |
+
Host: example.com
|
| 71 |
+
User-Agent: Mozilla/5.0"""
|
| 72 |
+
|
| 73 |
+
async def analyze(payload: str):
|
| 74 |
+
response = await client.chat.completions.create(
|
| 75 |
+
model="Qwen3.5-0.8B",
|
| 76 |
+
messages=[
|
| 77 |
+
{
|
| 78 |
+
"role": "system",
|
| 79 |
+
"content": "You are a cybersecurity analysis AI. Analyze the given HTTP payload and determine whether it contains an attack."
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"role": "user",
|
| 83 |
+
"content": payload
|
| 84 |
+
}
|
| 85 |
+
],
|
| 86 |
+
max_tokens=2048,
|
| 87 |
+
temperature=0.0,
|
| 88 |
+
top_p=0.95,
|
| 89 |
+
presence_penalty=1.5,
|
| 90 |
+
extra_body={
|
| 91 |
+
"chat_template_kwargs": {"enable_thinking": True},
|
| 92 |
+
"top_k": 20,
|
| 93 |
+
"min_p": 0.0,
|
| 94 |
+
"repetition_penalty": 1.0,
|
| 95 |
+
},
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
content = response.choices[0].message.content # JSON result
|
| 99 |
+
reasoning = response.choices[0].message.reasoning # CoT process inside <think>
|
| 100 |
+
|
| 101 |
+
return content, reasoning
|
| 102 |
+
|
| 103 |
+
content, reasoning = asyncio.run(analyze(http_request))
|
| 104 |
+
print("Reasoning:\n", reasoning)
|
| 105 |
+
print("Result:\n", content)
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### Output
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
# reasoning → the full <think>...</think> process
|
| 112 |
+
# content → final JSON
|
| 113 |
+
{"attack_type": "SQL Injection", "attack_syntax": "' OR 1=1--"}
|
| 114 |
+
```
|