Skip to content

Latest commit

 

History

History
166 lines (116 loc) · 5.6 KB

4.Examples.md

File metadata and controls

166 lines (116 loc) · 5.6 KB

4. Examples

4.1. Writing a finding

  1. We'll start with notes and a finding template. The notes are from a pentest on an application called Foo that's written in Java.

Notes

High risk. SQL-Injection via POST to /bar.
Caused by string concat at Bar controller in /src/bar: [code sample].
Example request: [screenshot].
Impact is full db access. Use prepared statements.

Template

[Title]
[Risk]

[Finding details]
	[Introduction paragraph, summarize finding and impact]

	[Technical details, reproduction steps and proof]

[Impact description]
	[Summarize details in sentence or paragraph]

	[Explain business risk]

[Recommendation]
	[One or more action statements with references if possible]
  1. Let us now re-order the information to fit the finding template.
Title: SQL-Injection via /bar
Risk: High

Finding
	Users from the Foo application can perform Bar to keep track of their stats.
	Allows SQL-Injection.

	Caused by string concat at /src/bar: [code sample].
	Example request: [screenshot].

Impact
	An authenticated attacker can use the Bar field of the Foo application to
	execute arbitrary SQL queries in the database. 

	Impact is full db access.

Recommendation
	Use prepared statements, Java PreparedStatement.
  1. We professionalize all elements by writing complete sentences and explanatory paragraphs. Note that we also update the title to match the story.
# Title: Database compromise via SQL-Injection in Bar page
### Risk: High

## Finding

Users from the Foo application can perform Bar to keep track of their stats.
A database query uses input from Bar, but it does not apply the proper encoding
to protect against SQL-Injection. An attacker can inject arbitrary queries to
obtain or modify all customer data.

The Bar controller at /src/bar use string concatenation to append the barType
variable to an SQL query.

/src/bar/barController.java
--------------------------------------
public RESTEndpoint getBar(Session session, string barType) {
	[...]
	sql.execute("SELECT * from bar_entries where user_id = " + 
		session.user_id + " and type = " + barType);
--------------------------------------

The barType variable is not properly encoded to prevent an attacker from adding
arbitrary SQL queries. Since the endpoint returns the complete output from the 
query, it is trivial to retrieve data from any table using the UNION statement. 
The screenshot below shows an attacker adding a UNION statement via the barType 
variable to obtain financial records from other users.

[screenshot]

## Impact

An authenticated attacker can use the Bar field of the Foo application to execute 
arbitrary SQL queries in the database. Arbitrary SQL queries allow the attacker 
to insert, modify and delete all data. The data includes customer PII and financial 
records. Extraction of such data is considered a data breach according to the GDPR 
and can result in large fines.

## Recommendation

Use prepared statements to separate user input from SQL queries. This can be done 
in Java using the PreparedStatement object. See also: 

https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

More information on SQL-Injection and other mitigating measures can be found on 
the following page from the OWASP Cheat Sheet series:

https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html

4.2. Writing a conclusion

  1. At the end of writing a report we'll start with a dump of findings and ideas:
SQL-Injection in the REST API

Administrative user had weak password

Cross-Site Scripting in Derp page

Some active users weren't working at Company anymore

Application wasn't pentested before, emphasis on the structural security
  1. We clump together findings with the same theme and expand on them a bit. Also add an introduction and part of a closing statement. Here I chose the following clusters:
Pentest Company performed a pentest on Application between 3 and 17 March 2023.
The application currently has a weak security posture.

SQL-Injection and XSS are both related to secure development in terms of basic
web security. Share security knowledge in the team. Implement static analysis. 

Weak password use and the outdated account are both related to user management.
Password use is onboarding and account management is offboarding. Improve process.

Structural security, future development.
  1. Now just write full sentences, shuffle the lines around, and there we go:
Pentest Company performed a pentest on Application between 3 and 17 March 2023.
The application currently has a weak security posture. High-risk vulnerabilities
show missing controls on basic web security and on user management.

Basic web security vulnerabilities allow attackers to compromise the database and
to hijack sessions from other users. The vulnerabilities can be prevented by using
security best practices from the Framework framework. It is recommended to share these 
practices among the development teams and to incorporate them in the development 
process. Static Code Analysis can also be implemented to aid in detecting these 
vulnerable patterns.

The user management process is missing security controls. A high-privileged user 
was found to have a weak password. Consider adding or improving password strength 
awareness in the onboarding process. Another finding showed that users weren't removed 
from the database during offboarding. Fortunately, that issue can be mitigated 
using automation.

Structural improvements are required for securing future development of
Application. Pentest Company advises to mitigate all vulnerabilities and to perform a
retest to validate the new security controls.