Absolutely! Here's a comprehensive step-by-step guide to help you create a tool in C that can scan a website for SSTI (Server-Side Template Injection) vulnerabilities.
🔧 C-Based SSTI Scanner Tool — Full Developer Guide
✅ What is This?
A simple C program that sends specially crafted HTTP requests containing SSTI payloads to a web application's input fields (URL query parameters), and checks the response to determine if the server evaluates the template code — indicating a potential SSTI vulnerability.
👨💻 Prerequisites
Before we build the tool, make sure you have:
📦 Dependencies
libcurl → to make HTTP requests (install with: sudo apt-get install libcurl4-openssl-dev on Debian/Ubuntu)
- A C compiler (e.g.,
gcc)
🧠 Skills
- Basic C programming
- Understanding of how SSTI works
🧪 Knowledge about SSTI
- Injection payload:
${7*7} (Used to detect if the server evaluates templates)
- If response contains
49, there's a chance SSTI is present (49 = 7*7)
📁 Project Structure
ssti_scanner/
│
├── ssti_scanner.c // Main program
└── payloads.txt // (Optional) External payload list
1️⃣ Basic Tool Design
🔎 Tool Workflow:
- User provides a target URL with a parameter (example:
http://example.com/search?query=)
- Tool appends SSTI payloads into the target parameter
- Sends HTTP GET request per payload
- Analyzes the server response:
- If it contains results like
49, flag as potentially vulnerable
2️⃣ Writing the C Code
✍️ ssti_scanner.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
// Response data buffer
#define MAX_RESPONSE_SIZE 10000
// Write callback to store HTTP response
size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
strncat((char *)userp, contents, size * nmemb);
return size * nmemb;
}
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: %s <target_url_with_param=> <parameter_name>\n", argv[0]);
printf("Example: ./ssti_scanner \"http://test.com/search?query=\" query\n");
return 1;
}
// Inputs
char *base_url = argv[1]; // e.g. http://example.com/?q=
char *param_name = argv[2];
// Common SSTI payloads
char *payloads[] = {
"${7*7}", // Jinja2, Twig
"{{7*7}}", // Jinja2, Handlebars
"<%= 7*7 %>", // EJS
"${{7*7}}", // JSP
"*{7*7}", // Thymeleaf
"#{7*7}" // Spring EL
};
int num_payloads = sizeof(payloads) / sizeof(payloads[0]);
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (!curl) {
fprintf(stderr, "Failed to initialize libcurl.\n");
return 1;
}
char response[MAX_RESPONSE_SIZE] = {0};
for (int i = 0; i < num_payloads; i++) {
// Build full URL
char full_url[1024];
snprintf(full_url, sizeof(full_url), "%s%s", base_url, payloads[i]);
printf("\n[>] Testing payload: %s\n", payloads[i]);
// Clear response buffer
memset(response, 0, sizeof(response));
// Set curl options
curl_easy_setopt(curl, CURLOPT_URL, full_url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
res = curl_easy_perform(curl);
// Handle errors
if (res != CURLE_OK) {
fprintf(stderr, "[-] Request failed: %s\n", curl_easy_strerror(res));
continue;
}
// Analyze server response
if (strstr(response, "49")) {
printf("[!!!] Potential SSTI vulnerability found with payload: %s\n", payloads[i]);
printf("[URL] %s\n", full_url);
} else {
printf("[ ] No SSTI detected for this payload.\n");
}
}
// Cleanup
curl_easy_cleanup(curl);
curl_global_cleanup();
return 0;
}
3️⃣ How to Compile the Tool
Use gcc and link the libcurl library:
gcc ssti_scanner.c -o ssti_scanner -lcurl
4️⃣ Example Usage
./ssti_scanner "http://testvuln.com/page?search=" "search"
For each payload, it sends:
GET http://testvuln.com/page?search=${7*7}
And checks if 49 appears in the content. If yes 👉 possible SSTI!
5️⃣ Testing Locally (Optional)
You can test your tool locally using:
python3 -m http.server 8080
Or create a vulnerable Flask app for testing with SSTI:
# vulnerable_app.py
from flask import Flask, request, render_template_string
app = Flask(__name__)
@app.route("/search")
def search():
query = request.args.get("query", "")
return render_template_string(query)
app.run(port=5000)
Run it:
python3 vulnerable_app.py
Then scan:
./ssti_scanner "http://localhost:5000/search?query=" "query"
6️⃣ Output Example
[>] Testing payload: ${7*7}
[!!!] Potential SSTI vulnerability found with payload: ${7*7}
[URL] http://localhost:5000/search?query=${7*7}
[>] Testing payload: {{7*7}}
[!!!] Potential SSTI vulnerability found with payload: {{7*7}}
...
✅ Summary
| Feature | Status |
|---|
| Written in C | ✅ |
| Uses libcurl | ✅ |
| Detects SSTI | ✅ |
| Easy to extend | ✅ |
🔒 Ethical Note
Only use this tool on systems you own or are authorized to test. Unauthorized use may violate Computer Misuse laws.
🚀 Possible Improvements
- Multi-threaded scanning (using
pthreads)
- POST request support
- Load payloads from
payloads.txt
- Detect more template engines
- Regex-based response analysis
- HTML parsing (with
libxml2, gumbo, or similar)
Would you like me to extend this tool with:
- POST request support
- Automatic parameter discovery
- Reading payloads from file
Let me know!