Below is a detailed, step-by-step roadmap for developing a C-based tool to scan websites for Server-Side Template Injection (SSTI) vulnerabilities. This roadmap builds on the previous discussions, incorporating refinements for clarity, modularity, and best practices. It's designed for a solo developer or small team, with an estimated timeline of 10-14 weeks. The tool, named SSTIHunter, will use libraries like libcurl for HTTP requests and pcre for pattern matching.
This roadmap assumes basic C programming knowledge and focuses on creating a robust, maintainable tool. Phases are sequential but can overlap for efficiency.
SSTIHunter Development Roadmap: C-Based SSTI Scanner
Project Overview
- Tool Description: A command-line application that injects SSTI payloads into website parameters (e.g., URLs, headers, forms) and analyzes responses for vulnerabilities.
- Key Features:
- Support for GET/POST requests.
- Payload management and injection.
- Response analysis with engine fingerprinting.
- Multi-threading for performance.
- Output in multiple formats (console, JSON, HTML).
- Dependencies: libcurl (HTTP), pcre (regex), json-c (for JSON handling), pthreads (threading).
- Estimated Timeline: 10-14 weeks.
- Ethical Note: This tool is for educational and authorized testing only. Always obtain permission before scanning.
Phase 1: Research and Planning (Weeks 1-2)
Objective: Lay the groundwork by understanding SSTI and setting up the environment.
Tasks:
-
SSTI Vulnerability Research (3-4 days):
- Study template engines (e.g., Jinja2:
{{7*7}}, Freemarker: ${7*7}).
- Compile a payload database:
// payloads.h
typedef struct {
char* syntax; // e.g., "{{7*7}}"
char* engine; // e.g., "Jinja2"
char* expected; // e.g., "49"
int severity; // 1-10 scale
} SSTIPayload;
static SSTIPayload payloads[] = {
{"{{7*7}}", "Jinja2", "49", 8},
{"${7*7}", "Freemarker", "49", 8},
{"<%= 7*7 %>", "EJS", "49", 7},
// Add more based on research
};
int payload_count = sizeof(payloads) / sizeof(SSTIPayload);
- Document evasion techniques (e.g., URL encoding).
-
Development Environment Setup (2-3 days):
- Install tools:
# Ubuntu
sudo apt update && sudo apt install build-essential libcurl4-openssl-dev libpcre3-dev libjson-c-dev valgrind gdb
# macOS
brew install curl pcre json-c
- Create project structure:
sstihunter/
├── src/ # Source files
├── include/ # Headers
├── tests/ # Unit tests
├── payloads/ # Payload files
├── docs/ # Documentation
└── Makefile # Build script
-
Requirements Definition (1 day):
- Features: Multi-threading, WAF bypass, JSON reporting.
- Constraints: Cross-platform compatibility, low memory footprint.
Deliverables:
- Research document with payload list.
- Configured environment and project skeleton.
- Initial Makefile.
Phase 2: Architecture Design (Weeks 3-4)
Objective: Design a modular system for scalability.
Tasks:
-
High-Level Architecture:
- Components:
- HTTP Client: Handles requests using libcurl.
- Payload Manager: Manages and injects payloads.
- Analysis Engine: Detects SSTI in responses.
- Scanner Core: Coordinates scanning and threading.
- Reporting Module: Generates outputs.
- Utilities: Error handling, logging.
-
Data Structures and Interfaces:
// include/sstihunter.h
typedef struct {
char* url;
char* method; // "GET", "POST"
char* body;
char** headers;
} HTTPRequest;
typedef struct {
int status_code;
char* body;
double response_time;
} HTTPResponse;
typedef struct {
bool is_vulnerable;
char* engine;
char* evidence;
int confidence;
} ScanResult;
-
Threading Model:
- Use pthreads for a thread pool to handle concurrent requests.
Deliverables:
- Architecture diagram.
- Header files with function prototypes.
Phase 3: Core Implementation (Weeks 5-8)
Objective: Build the main functionality.
Tasks:
-
HTTP Client Implementation (Week 5):
// src/http/http_client.c
#include <curl/curl.h>
size_t write_callback(void* contents, size_t size, size_t nmemb, void* userp) {
strncat((char*)userp, contents, size * nmemb);
return size * nmemb;
}
HTTPResponse* send_request(HTTPRequest* req) {
CURL* curl = curl_easy_init();
char buffer[8192] = {0};
curl_easy_setopt(curl, CURLOPT_URL, req->url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
// Parse and return response
}
-
Payload and Injection Logic (Week 6):
- Load and inject payloads into requests.
-
Analysis Engine (Week 7):
- Use regex to match responses:
// src/analysis/analysis_engine.c
#include <pcre.h>
bool detect_ssti(HTTPResponse* response, SSTIPayload* payload) {
pcre* re = pcre_compile(payload->expected, 0, NULL, NULL, NULL);
int ovector[30];
return pcre_exec(re, NULL, response->body, strlen(response->body), 0, 0, ovector, 30) >= 0;
}
-
Scanner Core and Threading (Week 8):
- Integrate threading for parallel scans.
Deliverables:
- Working core modules.
- Basic CLI integration.
Phase 4: Advanced Features (Weeks 9-10)
Objective: Enhance with WAF bypass and blind SSTI detection.
Tasks:
-
WAF Bypass Techniques:
- Implement payload encoding functions.
-
Blind SSTI Detection:
- Time-based and DNS exfiltration methods.
Deliverables:
- Advanced detection capabilities.
Phase 5: Testing and Optimization (Week 11)
Objective: Validate and optimize the tool.
Tasks:
-
Unit and Integration Tests:
- Use a testing framework to cover edge cases.
-
Performance Testing:
- Run with Valgrind for memory leaks.
Deliverables:
- Test suite and benchmarks.
Phase 6: Documentation and Release (Week 12)
Objective: Prepare for deployment.
Tasks:
- User Documentation: Write README and guides.
- Build and Package: Create installers.
Deliverables:
- Full documentation and release packages.
Post-Release and Maintenance
- Monitor for updates and add features like GraphQL support.
- Track metrics: Code coverage, user adoption.
This roadmap ensures a thorough development process. If you need code for a specific phase, let me know! 🚀