-
Notifications
You must be signed in to change notification settings - Fork 0
Create vulnerable-example.jsp #27
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
Changes from all commits
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,95 @@ | ||||||||
| <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> | ||||||||
| <%@ page import="java.sql.*" %> | ||||||||
| <!DOCTYPE html> | ||||||||
| <html> | ||||||||
| <head> | ||||||||
| <title>User Search - Vulnerable Example</title> | ||||||||
| </head> | ||||||||
| <body> | ||||||||
| <h1>User Search Portal</h1> | ||||||||
|
|
||||||||
| <% | ||||||||
| // Hardcoded credentials - Security violation | ||||||||
| String dbPassword = "MySecretP@ssw0rd123!"; | ||||||||
| String apiKey = "sk-1234567890abcdefghijklmnop"; | ||||||||
|
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: Secret of type: 'Generic Password' was found. DescriptionA generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable. Cycode Remediation Guideline❗ How to revoke
Tell us how you wish to proceed using one of the following commands:
|
||||||||
|
|
||||||||
| // SQL Injection vulnerability - User input directly concatenated into SQL query | ||||||||
| String userInput = request.getParameter("username"); | ||||||||
| String searchQuery = request.getParameter("search"); | ||||||||
|
|
||||||||
| if (userInput != null && !userInput.isEmpty()) { | ||||||||
| try { | ||||||||
| // Insecure database connection with hardcoded credentials | ||||||||
| String dbUrl = "jdbc:mysql://localhost:3306/userdb"; | ||||||||
| String dbUser = "admin"; | ||||||||
| Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); | ||||||||
|
|
||||||||
| // SQL Injection vulnerability - no prepared statement | ||||||||
| Statement stmt = conn.createStatement(); | ||||||||
| String sql = "SELECT * FROM users WHERE username = '" + userInput + "' OR email = '" + userInput + "'"; | ||||||||
| ResultSet rs = stmt.executeQuery(sql); | ||||||||
|
|
||||||||
| out.println("<h2>Search Results:</h2>"); | ||||||||
| out.println("<table border='1'>"); | ||||||||
|
|
||||||||
| while (rs.next()) { | ||||||||
| // XSS vulnerability - unescaped output | ||||||||
| out.println("<tr>"); | ||||||||
| out.println("<td>" + rs.getString("username") + "</td>"); | ||||||||
| out.println("<td>" + rs.getString("email") + "</td>"); | ||||||||
| out.println("<td>" + rs.getString("role") + "</td>"); | ||||||||
| out.println("</tr>"); | ||||||||
| } | ||||||||
|
|
||||||||
| out.println("</table>"); | ||||||||
|
|
||||||||
| rs.close(); | ||||||||
| stmt.close(); | ||||||||
| conn.close(); | ||||||||
|
|
||||||||
| } catch (Exception e) { | ||||||||
| // Information disclosure - exposing stack trace | ||||||||
| out.println("<pre>"); | ||||||||
| e.printStackTrace(new java.io.PrintWriter(out)); | ||||||||
| out.println("</pre>"); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // XSS vulnerability - reflecting user input without sanitization | ||||||||
| if (searchQuery != null) { | ||||||||
| out.println("<p>You searched for: " + searchQuery + "</p>"); | ||||||||
| } | ||||||||
| %> | ||||||||
|
|
||||||||
| <form method="GET" action=""> | ||||||||
| <label>Username:</label> | ||||||||
| <input type="text" name="username" /> | ||||||||
| <br/><br/> | ||||||||
| <label>Search:</label> | ||||||||
| <input type="text" name="search" /> | ||||||||
| <br/><br/> | ||||||||
| <input type="submit" value="Search" /> | ||||||||
| </form> | ||||||||
|
|
||||||||
| <!-- Debug information exposure --> | ||||||||
| <div style="display:none;"> | ||||||||
| <!-- API Key: <%= apiKey %> --> | ||||||||
| <!-- DB Password: <%= dbPassword %> --> | ||||||||
| </div> | ||||||||
|
|
||||||||
| <% | ||||||||
| // Command injection vulnerability | ||||||||
| String command = request.getParameter("cmd"); | ||||||||
| if (command != null) { | ||||||||
| Runtime.getRuntime().exec(command); | ||||||||
| } | ||||||||
|
|
||||||||
| // Path traversal vulnerability | ||||||||
| String filename = request.getParameter("file"); | ||||||||
| if (filename != null) { | ||||||||
| java.io.FileInputStream fis = new java.io.FileInputStream("/var/www/files/" + filename); | ||||||||
| } | ||||||||
| %> | ||||||||
|
|
||||||||
| </body> | ||||||||
| </html> | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗Cycode: Secret of type: 'Generic Password' was found.
Severity: Medium
Confidence Score: 94%
SHA: 2c3544790f
Description
A generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable.
Cycode Remediation Guideline
❗ How to revoke
Tell us how you wish to proceed using one of the following commands: