-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||
| <?php | ||||||||||||||||
|
|
||||||||||||||||
| if( isset( $_GET[ 'Submit' ] ) ) { | ||||||||||||||||
| // Get input | ||||||||||||||||
| $id = $_GET[ 'id' ]; | ||||||||||||||||
| $exists = false; | ||||||||||||||||
|
|
||||||||||||||||
| switch ($_DVWA['SQLI_DB']) { | ||||||||||||||||
| case MYSQL: | ||||||||||||||||
| // Check database | ||||||||||||||||
| $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; | ||||||||||||||||
| try { | ||||||||||||||||
| $result = mysqli_query($GLOBALS["___mysqli_ston"], $query ); // Removed 'or die' to suppress mysql errors | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: SAST violation: 'Unsanitized external input in SQL query'. Severity: Critical DescriptionUsing unsanitized data, such as user input or request data, or externally influenced data passed to a function, in SQL query exposes your application to SQL injection attacks. This vulnerability arises when externally controlled data is directly included in SQL statements without proper sanitation, allowing attackers to manipulate queries and access or modify data. Cycode Remediation Guideline✅ Do
$sortingOrder = $_GET['sortingOrder'] === 'DESC' ? 'DESC' : 'ASC';
private function validatedTableName($table_name)
{
if in_array($table_name, $ALLOWED_TABLE_NAMES) {
return $table_name
}
// handle invalid table name
}
$stmt = $pdo->prepare("SELECT * FROM products WHERE id LIKE ? ORDER BY price {$sortingOrder}");
$stmt->execute(["%{$productId}%"]);
$ok = mysqli_real_escape_string($conn, $_GET['ok']);❌ Don't
$sortingOrder = $_GET['untrusted'];
$query = "SELECT id, name FROM products ORDER BY name LIMIT 20 $sortingOrder;"; // unsafe📋 References🎥 Learning materials (by Secure Code Warrior)Tell us what how you wish to proceed using one of the following commands:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #cycode_ai_remediation
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Cycode is processing your request. This may take up to one minute. Please, wait...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vulnerability ExplanationThe vulnerability is caused by directly including user input ($id) in the SQL query without proper sanitization. This allows an attacker to manipulate the query and potentially access or modify sensitive data. The issue is evident in the lines where the $query is constructed, specifically: $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";. By using user input directly in the query, the application is exposed to SQL injection attacks. Remediation InstructionsTo fix the vulnerability, we need to use prepared statements to separate the SQL logic from the external input. Here's a step-by-step guide:
Suggested FixAI Confidence score ✨ The Cycode AI Confidence Score estimates the quality of the suggested code fix. Please review it carefully before applying. --- jwr-low.php
+++ jwr-low.php
@@ -1,3 +1,4 @@
+
<?php
if( isset( $_GET[ 'Submit' ] ) ) {
@@ -8,9 +9,11 @@
switch ($_DVWA['SQLI_DB']) {
case MYSQL:
// Check database
- $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
+ $stmt = $GLOBALS["___mysqli_ston"]->prepare("SELECT first_name, last_name FROM users WHERE user_id = ?");
+ $stmt->bind_param("i", $id);
try {
- $result = mysqli_query($GLOBALS["___mysqli_ston"], $query ); // Removed 'or die' to suppress mysql errors
+ $stmt->execute();
+ $result = $stmt->get_result();
} catch (Exception $e) {
print "There was an error.";
exit;
@@ -29,10 +32,11 @@
case SQLITE:
global $sqlite_db_connection;
- $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
+ $stmt = $sqlite_db_connection->prepare("SELECT first_name, last_name FROM users WHERE user_id = :id");
+ $stmt->bindValue(':id', $id, SQLITE3_INTEGER);
try {
- $results = $sqlite_db_connection->query($query);
- $row = $results->fetchArray();
+ $result = $stmt->execute();
+ $row = $result->fetchArray();
$exists = $row !== false;
} catch(Exception $e) {
$exists = false;
Tell us what to do with one of the following hashtags:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Cycode has finished processing your request. Please review your status checks. |
||||||||||||||||
| } catch (Exception $e) { | ||||||||||||||||
| print "There was an error."; | ||||||||||||||||
| exit; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| $exists = false; | ||||||||||||||||
| if ($result !== false) { | ||||||||||||||||
| try { | ||||||||||||||||
| $exists = (mysqli_num_rows( $result ) > 0); | ||||||||||||||||
| } catch(Exception $e) { | ||||||||||||||||
| $exists = false; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); | ||||||||||||||||
| break; | ||||||||||||||||
| case SQLITE: | ||||||||||||||||
| global $sqlite_db_connection; | ||||||||||||||||
|
|
||||||||||||||||
| $query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; | ||||||||||||||||
| try { | ||||||||||||||||
| $results = $sqlite_db_connection->query($query); | ||||||||||||||||
| $row = $results->fetchArray(); | ||||||||||||||||
| $exists = $row !== false; | ||||||||||||||||
| } catch(Exception $e) { | ||||||||||||||||
| $exists = false; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| break; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if ($exists) { | ||||||||||||||||
| // Feedback for end user | ||||||||||||||||
| $html .= '<pre>User ID exists in the database.</pre>'; | ||||||||||||||||
| } else { | ||||||||||||||||
| // User wasn't found, so the page wasn't! | ||||||||||||||||
| header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' ); | ||||||||||||||||
|
|
||||||||||||||||
| // Feedback for end user | ||||||||||||||||
| $html .= '<pre>User ID is MISSING from the database.</pre>'; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| ?> | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.