Skip to content

Commit 7d2ef7c

Browse files
committed
Add support for run based on HTTP capture
1 parent de40f13 commit 7d2ef7c

4 files changed

Lines changed: 230 additions & 4 deletions

File tree

README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,60 @@ sqlmap-ai -u "http://example.com/page.php?id=1"
104104
sqlmap-ai -u "http://example.com/page.php?id=1" --ai-provider groq
105105
```
106106

107+
### HTTP Request File Testing (NEW!)
108+
109+
```bash
110+
# Test using HTTP request capture file
111+
sqlmap-ai -r request.txt
112+
113+
# Enhanced mode with request file and adaptive testing
114+
sqlmap-ai --enhanced --adaptive -r request.txt
115+
116+
# With specific AI provider
117+
sqlmap-ai --enhanced -r request.txt --ai-provider groq
118+
119+
# Simple mode with request file
120+
sqlmap-ai --simple -r request.txt
121+
```
122+
123+
**Request File Format:**
124+
```http
125+
POST /login.php HTTP/1.1
126+
Host: example.com
127+
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
128+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
129+
Content-Type: application/x-www-form-urlencoded
130+
Content-Length: 38
131+
132+
username=admin&password=test
133+
```
134+
135+
**Creating Request Files:**
136+
137+
1. **From Browser Developer Tools:**
138+
- Open Developer Tools (F12)
139+
- Go to Network tab
140+
- Perform the action you want to test
141+
- Right-click the request → Copy → Copy as cURL
142+
- Convert cURL to HTTP format
143+
144+
2. **From Burp Suite:**
145+
- Intercept the request
146+
- Right-click → Save item
147+
- Save as .txt file
148+
149+
3. **From OWASP ZAP:**
150+
- Right-click request → Export → HTTP Message
151+
- Save as .txt file
152+
153+
**Supported Request Types:**
154+
- [x] GET requests with parameters
155+
- [x] POST requests with form data
156+
- [x] POST requests with JSON data
157+
- [x] Requests with cookies
158+
- [x] Requests with custom headers
159+
- [x] Multipart form data
160+
107161
### Advanced Testing
108162

109163
```bash
@@ -112,6 +166,9 @@ sqlmap-ai --adaptive
112166

113167
# Simple mode (basic SQLMap without AI)
114168
sqlmap-ai --simple -u "http://example.com/page.php?id=1"
169+
170+
# Enhanced mode with custom options
171+
sqlmap-ai --enhanced -u "http://example.com/page.php?id=1" --level 3 --risk 2
115172
```
116173

117174
### AI Provider Selection
@@ -130,6 +187,90 @@ sqlmap-ai -u "http://example.com/page.php?id=1" --ai-provider openai
130187
sqlmap-ai -u "http://example.com/page.php?id=1" --ai-provider auto
131188
```
132189

190+
### Complete Testing Workflow
191+
192+
```bash
193+
# 1. Basic scan with URL
194+
sqlmap-ai -u "http://example.com/page.php?id=1"
195+
196+
# 2. Enhanced scan with request file
197+
sqlmap-ai --enhanced --adaptive -r captured_request.txt
198+
199+
# 3. Advanced scan with custom options
200+
sqlmap-ai --enhanced -r request.txt --level 4 --risk 3 --threads 10
201+
202+
# 4. Simple mode for quick testing
203+
sqlmap-ai --simple -r request.txt --batch
204+
```
205+
206+
## Testing Modes
207+
208+
### Enhanced Mode (Default)
209+
Full AI-powered testing with advanced features:
210+
211+
```bash
212+
# Basic enhanced scan
213+
sqlmap-ai --enhanced -u "http://example.com/page.php?id=1"
214+
215+
# With request file
216+
sqlmap-ai --enhanced -r request.txt
217+
218+
# Adaptive testing with AI analysis
219+
sqlmap-ai --enhanced --adaptive -r request.txt --ai-provider groq
220+
```
221+
222+
**Features:**
223+
- AI-powered vulnerability analysis
224+
- Adaptive testing strategies
225+
- WAF evasion techniques
226+
- Beautiful HTML reports
227+
- Risk assessment and remediation guidance
228+
- Interactive CLI with progress tracking
229+
- Multiple AI providers (Groq, OpenAI, Anthropic, Ollama)
230+
- Advanced configuration management
231+
- Request file support (NEW!)
232+
233+
### Simple Mode
234+
Basic SQL injection testing without AI features:
235+
236+
```bash
237+
# Basic simple scan
238+
sqlmap-ai --simple -u "http://example.com/page.php?id=1"
239+
240+
# With request file
241+
sqlmap-ai --simple -r request.txt
242+
243+
# Quick batch mode
244+
sqlmap-ai --simple -r request.txt --batch
245+
```
246+
247+
**Features:**
248+
- Basic SQL injection detection
249+
- Standard SQLMap functionality
250+
- Minimal dependencies
251+
- Fast execution
252+
- Request file support (NEW!)
253+
- Simple text output
254+
- Basic result saving
255+
256+
### Adaptive Mode
257+
Intelligent step-by-step testing that adapts to the target:
258+
259+
```bash
260+
# Full adaptive testing
261+
sqlmap-ai --enhanced --adaptive -r request.txt
262+
263+
# With specific AI provider
264+
sqlmap-ai --enhanced --adaptive -r request.txt --ai-provider groq
265+
```
266+
267+
**Adaptive Steps:**
268+
1. **🟢 Initial Assessment** - Check for SQL injection vulnerabilities
269+
2. **🟠 DBMS Identification** - Detect database type (MySQL, PostgreSQL, etc.)
270+
3. **🔴 Enhanced Testing** - Try more aggressive techniques
271+
4. **🟣 Data Extraction** - Extract valuable data from identified tables
272+
5. **🤖 AI Analysis** - Get AI recommendations for next steps
273+
133274
## AI Providers Comparison
134275

135276
| Provider | Setup | Speed | Privacy | Cost |
@@ -203,6 +344,17 @@ ui:
203344
- Run `sqlmap-ai --config-wizard` to fix setup
204345
- Check `sqlmap-ai --validate-config` for issues
205346

347+
**5. "Request file not working"**
348+
- Ensure request file has proper HTTP format
349+
- Check that Host header is present
350+
- Verify request file path is correct
351+
- Try with `--simple` mode first: `sqlmap-ai --simple -r request.txt`
352+
353+
**6. "URL validation failed"**
354+
- When using request files, the URL is automatically extracted
355+
- Ensure request file contains valid HTTP request
356+
- Check that the Host header matches the target domain
357+
206358
### Getting Help
207359

208360
```bash

sqlmap_ai/main.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from sqlmap_ai.advanced_reporting import report_generator
2525
from sqlmap_ai.evasion_engine import evasion_engine
2626
from utils.ai_providers import ai_manager, get_available_ai_providers
27+
from typing import Optional
2728
def main():
2829
"""Enhanced main function with improved CLI and security"""
2930
# Create enhanced CLI parser
@@ -45,15 +46,14 @@ def main():
4546
return
4647

4748
# Check if we have a target
48-
if not args.url and not args.request_file:
49+
target_url = get_target_url_from_args(args)
50+
if not target_url:
4951
if args.interactive:
5052
target_url = get_target_url()
5153
else:
5254
print_error("No target specified. Use -u/--url or -r/--request-file")
5355
print_info("Use --help for usage information")
5456
return
55-
else:
56-
target_url = args.url
5757

5858
try:
5959
# Security validation
@@ -108,6 +108,10 @@ def build_sqlmap_options(args) -> list:
108108

109109
config = get_config()
110110

111+
# Add request file if provided
112+
if args.request_file:
113+
options.extend(["-r", args.request_file])
114+
111115
# Add risk and level
112116
risk = args.risk or config.sqlmap.default_risk
113117
level = args.level or config.sqlmap.default_level
@@ -425,6 +429,55 @@ def confirm_additional_step():
425429
else:
426430
print("Please answer with 'y' or 'n'.")
427431

432+
def extract_url_from_request_file(request_file_path: str) -> Optional[str]:
433+
"""Extract target URL from HTTP request file"""
434+
try:
435+
with open(request_file_path, 'r', encoding='utf-8') as f:
436+
content = f.read().strip()
437+
438+
# Parse the first line to get the request line
439+
lines = content.split('\n')
440+
if not lines:
441+
return None
442+
443+
# First line should be: METHOD /path HTTP/1.1
444+
request_line = lines[0].strip()
445+
parts = request_line.split()
446+
if len(parts) < 2:
447+
return None
448+
449+
# Find Host header
450+
host = None
451+
for line in lines[1:]:
452+
if line.lower().startswith('host:'):
453+
host = line.split(':', 1)[1].strip()
454+
break
455+
456+
if not host:
457+
return None
458+
459+
# Determine protocol (default to http)
460+
protocol = 'https' if 'https://' in content.lower() else 'http'
461+
462+
# Construct URL
463+
path = parts[1]
464+
if not path.startswith('/'):
465+
path = '/' + path
466+
467+
return f"{protocol}://{host}{path}"
468+
469+
except Exception as e:
470+
print_warning(f"Failed to extract URL from request file: {e}")
471+
return None
472+
473+
def get_target_url_from_args(args) -> Optional[str]:
474+
"""Get target URL from either URL argument or request file"""
475+
if args.url:
476+
return args.url
477+
elif args.request_file:
478+
return extract_url_from_request_file(args.request_file)
479+
return None
480+
428481
def main_simple():
429482
"""Simple mode - basic SQL injection testing without AI features"""
430483
print("🔧 SQLMap AI Simple Mode")

sqlmap_ai/runner.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,20 @@ def run_sqlmap(self, target_url: str, options: Union[List[str], str], timeout: i
414414
task_id = self._create_new_task()
415415
if not task_id:
416416
return None
417+
418+
# Check if we're using a request file
419+
using_request_file = False
420+
if isinstance(options, list):
421+
using_request_file = any(opt.startswith('-r') or opt.startswith('--request-file') for opt in options)
422+
elif isinstance(options, str):
423+
using_request_file = '-r' in options or '--request-file' in options
424+
425+
# Build command string
426+
if using_request_file:
427+
command_str = "sqlmap"
428+
else:
429+
command_str = f"sqlmap -u {target_url}"
417430

418-
command_str = f"sqlmap -u {target_url}"
419431
if isinstance(options, list):
420432
command_str += " " + " ".join(options)
421433
else:

testphp.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GET /product.php?pic=1 HTTP/1.1
2+
Host: testphp.vulnweb.com
3+
Accept-Language: en-US,en;q=0.9
4+
Upgrade-Insecure-Requests: 1
5+
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0
6+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
7+
Referer: http://testphp.vulnweb.com/listproducts.php?cat=1
8+
Accept-Encoding: gzip, deflate, br
9+
Connection: keep-alive

0 commit comments

Comments
 (0)