Apprentice · updated

Information disclosure

PortSwigger Web Security Academy · Apprentice

  • #Information disclosure
LevelsApprenticePractitioner

Information Disclosure in Error Messages

The vulnerability

The product page expects a number. If you send something else, you get the full error message, including the version of the framework.

Fix: Show a general error message and keep the details in the log.

The lab

Open the lab on PortSwigger

This lab’s verbose error messages reveal that it is using a vulnerable version of a third-party framework. To solve the lab, obtain and submit the version number of this framework.

Solution

1. View a Product Detail Page: On the website, browse to any product detail page.

2. Intercept the Product Request: In Burp Suite, go to Proxy → HTTP history. Find the GET /product?productId=1 request and right-click to Send to Repeater.

3. Trigger an Error Message: In Repeater, change the productId parameter from a valid integer (e.g., 1) to an invalid string (e.g., x). Send the request.

4. Retrieve Framework Version: The response will be an HTTP/2 500 Internal Server Error. The body of the response will contain a stack trace. At the very bottom of the error message, the framework and version will be explicitly stated (e.g., Apache Struts 2 2.3.31). Submit this version number to solve the lab.

HTTP/2 500 Internal Server Error 
Content-Length: 1682  

Internal Server Error: java.lang.NumberFormatException: For input string: "x"     
[...] 
Apache Struts 2 2.3.31

Information Disclosure on Debug Page

The vulnerability

A phpinfo.php was left on the server. It shows the whole configuration, including the secret key.

Fix: Remove debug pages before you go live.

The lab

Open the lab on PortSwigger

This lab contains a debug page that discloses sensitive information about the application. To solve the lab, obtain and submit the SECRET_KEY environment variable.

Solution

1. Crawl the Website: Browse the website normally to populate your Burp Suite Site map.

2. Find Comments: In Burp Suite, go to the Target tab, select the lab entry in the Site map, right-click and select Engagement Tools -> Find comments.

3. Access the Debug Page: The comments panel will reveal a hidden file path, such as /cgi-bin/phpinfo.php. Go to this URL in your web browser.

4. Get the SECRET_KEY: The page displays a detailed PHP configuration. Search the page content for "secret" or "SECRET_KEY." The value of the environment variable will be disclosed. Submit this key to solve the lab.

Source Code Disclosure via Backup Files

The vulnerability

The /backup folder is open to everyone and contains a copy of the source code, with the database password in it.

Fix: Keep backups off the web server, and passwords out of the code.

The lab

Open the lab on PortSwigger

This lab leaks its source code via backup files in a hidden directory. To solve the lab, identify and submit the database password, which is hard-coded in the leaked source code.

Solution

1. Check for robots.txt: On the website, go to /robots.txt. The file will reveal a disallowed directory, /backup, which may contain interesting files.

2. Access the Backup Directory: Go to the /backup directory. Directory listing is enabled, and you will find a file named ProductTemplate.java.bak.

3. Retrieve Database Password: View the contents of ProductTemplate.java.bak. The Java source code will be displayed. Search the file for keywords like "password," "db," or "connect." The hardcoded database password will be clearly visible in the connection string. Submit this password to solve the lab.

package data.productcatalog; 
[...] 
public class ProductTemplate implements Serializable 
{ 
[...]     
   ConnectionBuilder connectionBuilder = ConnectionBuilder.from(             
      "org.postgresql.Driver",             
      "postgresql",             
      "localhost",             
      5432,             
      "postgres",             
      "postgres",             
      "7ggrshnlikjnieujgz80h0k5g4vqh8ng"     
   ).withAutoCommit(); 
[...] 
}

Authentication Bypass via Information Disclosure

The vulnerability

The admin page is only available for local users. A TRACE request shows which header the server uses to find that out, and then you can set it yourself.

Fix: Don’t trust a header the user can send, and switch off TRACE.

The lab

Open the lab on PortSwigger

This lab’s administration interface has an authentication bypass vulnerability, but it is impractical to exploit without knowledge of a custom HTTP header used by the front-end.

To solve the lab, obtain the header name then use it to bypass the lab’s authentication. Access the admin interface and delete the user carlos.

You can log in to your own account using the following credentials: wiener:peter

Solution

1. Log In and Test Admin Access: Log in to the application using the credentials wiener:peter. Try to access the /admin page. The application responds with HTTP/2 401 Unauthorized, as expected. Send this request to Repeater.

2. Discover the Custom Header: In Repeater, change the HTTP method from GET to TRACE and send the request. The response will be an HTTP/2 200 OK and its body will contain the full request, including all headers, revealing the custom header X-Custom-IP-Authorization.

3. Bypass Authentication: Change the HTTP method back to GET. Add the custom header X-Custom-IP-Authorization to the request with a valid internal IP address (e.g., X-Custom-IP-Authorization: 127.0.0.1). Send the request. An HTTP/2 200 OK response confirms that you have bypassed authentication and gained access to the admin panel.

4. Delete the Target User: Go to the URL for deleting a user (e.g., GET /admin/delete?username=carlos). The HTTP/2 302 Found response confirms that carlos has been deleted, and the lab is solved.