-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rajapandi1234 <[email protected]>
- Loading branch information
1 parent
31d34c9
commit af87f20
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
|
||
public class VulnerableApp { | ||
public static void main(String[] args) { | ||
String userInput = "test'; DROP TABLE users; --"; // Simulated malicious input | ||
|
||
try { | ||
// Connect to the database | ||
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "password"); | ||
|
||
// Vulnerable: User input directly concatenated into SQL query | ||
String query = "SELECT * FROM users WHERE username = '" + userInput + "'"; | ||
Statement statement = connection.createStatement(); | ||
ResultSet resultSet = statement.executeQuery(query); | ||
|
||
// Print the results | ||
while (resultSet.next()) { | ||
System.out.println("User: " + resultSet.getString("username")); | ||
} | ||
|
||
connection.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |