Two Error-Based SQLi in courses.aspx on ██████████
The crs_id parameter in courses.aspx is vulnerable to error-based SQL injection, causing unhandled exceptions that reveal database table and column names and seven lines of C# code. An attacker could use these errors to gather information about the internal database structure and application code.
- Triaged in 8 hours
- Fixed in 14 months
- Disclosed after 2.6 years
Summary:
The server at ████ contains two SQL injection vulnerabilities in the courses.aspx file. These are error-based SQLi vulnerabilities. The resulting errors reveal seven lines of C# code, including inline SQL which reveals internal database information. Note that this is one of two reports I'm going to submit for error-based SQLi; I'm grouping them by their vulnerable source code file.
Description:
The crs_id parameter, when sent with a GET to courses.aspx, triggers an Unhandled Exception if its value is set to either %0a or 0. The vulnerable code is on lines 174 and 177, respectively.
Impact
-
Leakage of:
- Database table names and column names.
- Seven lines of C# code, including inline SQL.
- Server and framework version information.
-
Unhandled exceptions containing SQL errors are attractive indicators that hackers look for. Even though these vulnerabilities do not allow an attacker to execute arbitrary SQL, the errors do make for a much larger and more promising attack surface. Combining parts of the two error outputs reveals seven lines of C# code, with some inline SQL:
C
Line 173: sqlcrs = CCommonServices.GetCourseSQL(Request.QueryString("crs_id")) Line 174: rscrs.open(sqlcrs, connectionString) Line 175: sqlCrcf = "SELECT Career_Field.CF_Name FROM Career_CORE_PLUS Join Career_Field on Career_Field.CF_ID = Career_CORE_PLUS.CF_ID join CRS_Detail on CRS_Detail.ID = Career_CORE_PLUS.CRS_ID where Career_CORE_PLUS.CRS_ID =" + Request.QueryString("crs_id") Line 176: rsCrcf.Open(sqlCrcf, ConfigurationManager.ConnectionStrings("VbConnect").ToString()) Line 177: crs = rscrs("crs_header").value Line 178: crs_id_print = Request.QueryString("crs_id") Line 179: rsData = oCommonServices.getCLPbyCOURSE(Request.QueryString("crs_id"))
The SQL from line 175, revealing the names of tables and columns, is most interesting to an attacker:
```sql
SELECT Career_Field.CF_Name
FROM Career_CORE_PLUS
Join Career_Field on Career_Field.CF_ID = Career_CORE_PLUS.CF_ID
join CRS_Detail on CRS_Detail.ID = Career_CORE_PLUS.CRS_ID
where Career_CORE_PLUS.CRS_ID =
Step-by-step Reproduction Instructions
- Send a
GETrequest tohttp://████████/onlinecatalog/courses.aspx?crs_id=%0a - The server returns the following error:
Error converting data type varchar to numeric.and indicates line 174 ofC:\Web_Data\iCatalog\onlinecatalog\courses.aspx. ██████ - Send a
GETrequest tohttp://██████/onlinecatalog/courses.aspx?crs_id=0 - The server returns the following error:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.and indicates line 177 of the same file. ███
Product, Version, and Configuration (If applicable)
- Microsoft .NET Framework Version:4.0.30319
- ASP.NET Version:4.6.1590.0
- IIS 7.5
Suggested Mitigation/Remediation Actions
-
Add code to validate that the value of the
crs_idparameter is an integer. -
Add code to return a
404error page if the value of thecrs_idparameter does not reference a valid object. Alternatively, you could set a default value to that of a known-good object reference. -
Add code to return something other than the familiar
Invalid name parametererror when thecrs_idparameter is set to an invalid character. E.g., setting the value toä:http://██████████/onlinecatalog/courses.aspx?crs_id=%C3%A4
Returns this terse error:
Invalid name parameterä
Although seemingly a less sensitive error message, I found this behavior useful. It gave me a fourth option when distinguishing between various behaviors based on my fuzzing of the aforementioned parameter:
200/OKand a proper page render when the parameter is set to a valid value.- TCP reset sent when the web application firewall (WAF) blocks a known-malicious value like
ORDER BY. - Unhandled exceptions by the application code (as shown above).
- Invalid input caught and appended to the
Invalid name parametermessage.
My recommendations, generally, are that you modify the source code of the courses.aspx file so that you can eliminate these latter two behaviors.
Please let me know if you have any questions.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the application concatenates user input directly into SQL queries without proper validation or parameterisation, causing database errors that expose internal details.
Impact
The errors leak database table and column names, seven lines of C# code including inline SQL, and server and framework version information, which could aid further attacks.
What the attacker needed
None
The fix
The application should validate that the crs_id parameter is an integer and return a generic error page instead of detailed exceptions.
How it was found
- Send a GET request to courses.aspx with crs_id set to %0a.
- Observe the error message revealing line 174 and database type conversion error.
- Send a GET request to courses.aspx with crs_id set to 0.
- Observe the error message revealing line 177 and recordset error.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The web page takes a number from the URL and puts it directly into a database query without checking it. By sending special characters, an attacker can make the database throw an error that includes hidden details like table names and source code. This is called an error-based SQL injection because the error messages leak information.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.