24.10.2014 Views

1BO4r2U

1BO4r2U

1BO4r2U

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

183 184<br />

Web Application Penetration Testing<br />

Web Application Penetration Testing<br />

es with the goal of successfully completing the business process<br />

while not completing the correct steps in the correct order.<br />

Test defenses against application mis-use<br />

(OTG-BUSLOGIC-007)<br />

Summary<br />

The misuse and invalid use of of valid functionality can identify attacks<br />

attempting to enumerate the web application, identify weaknesses,<br />

and exploit vulnerabilities. Tests should be undertaken to<br />

determine whether there are application-layer defensive mechanisms<br />

in place to protect the application.<br />

The lack of active defenses allows an attacker to hunt for vulnerabilities<br />

without any recourse. The application’s owner will thus not<br />

know their application is under attack.<br />

Example<br />

An authenticated user undertakes the following (unlikely) sequence<br />

of actions:<br />

[1] Attempt to access a file ID their roles is not permitted to download<br />

[2] Substitutes a single tick (‘) instead of the file ID number<br />

[3] Alters a GET request to a POST<br />

[4] Adds an extra parameter<br />

[5] Duplicates a parameter name/value pair<br />

The application is monitoring for misuse and responds after the 5th<br />

event with extremely high confidence the user is an attacker. For<br />

example the application:<br />

• Disables critical functionality<br />

• Enables additional authentication steps to the remaining functionality<br />

• Adds time-delays into every request-response cycle<br />

• Begins to record additional data about the user’s interactions (e.g.<br />

sanitized HTTP request headers, bodies and response bodies)<br />

If the application does not respond in any way and the attacker can<br />

continue to abuse functionality and submit clearly malicious content<br />

at the application, the application has failed this test case. In<br />

practice the discrete example actions in the example above are unlikely<br />

to occur like that. It is much more probable that a fuzzing tool is<br />

used to identify weaknesses in each parameter in turn. This is what<br />

a security tester will have undertaken too.<br />

How to Test<br />

This test is unusual in that the result can be drawn from all the other<br />

tests performed against the web application. While performing all<br />

the other tests, take note of measures that might indicate the application<br />

has in-built self-defense:<br />

• Changed responses<br />

• Blocked requests<br />

• Actions that log a user out or lock their account<br />

These may only be localised. Common localized (per function) defenses<br />

are:<br />

• Rejecting input containing certain characters<br />

• Locking out an account temporarily after a number of authentication<br />

failures<br />

Localized security controls are not sufficient. There are often no defenses<br />

against general mis-use such as:<br />

• Forced browsing<br />

• Bypassing presentation layer input validation<br />

• Multiple access control errors<br />

• Additional, duplicated or missing parameter names<br />

• Multiple input validation or business logic verification failures with<br />

values that cannot be the result user mistakes or typos<br />

• Structured data (e.g. JSPN, XML) of an invalid format is received<br />

• Blatant cross-site scripting or SQL injection payloads are received<br />

• Utilising the application faster than would be possible without automation<br />

tools<br />

• Change in continental geo-location of a user<br />

• Change of user agent<br />

• Accessing a multi-stage business process in the wrong order<br />

• Large number of, or high rate of use of, application-specific functionality<br />

(e.g. voucher code submission, failed credit card payments,<br />

file uploads, file downloads, log outs, etc).<br />

These defenses work best in authenticated parts of the application,<br />

although rate of creation of new accounts or accessing content (e.g.<br />

to scrape information) can be of use in public areas.<br />

Not all the above need to be monitored by the application, but there<br />

is a problem if none of them are. By testing the web application, doing<br />

the above type of actions, was any response taken against the<br />

tester? If not, the tester should report that the application appears<br />

to have no application-wide active defenses against misuse. Note<br />

it is sometimes possible that all responses to attack detection are<br />

silent to the user (e.g. logging changes, increased monitoring, alerts<br />

to administrators and and request proxying), so confidence in this<br />

finding cannot be guaranteed. In practice, very few applications (or<br />

related infrastructure such as a web application firewall) are detecting<br />

these types of misuse.<br />

Related Test Cases<br />

All other test cases are relevant.<br />

Tools<br />

The tester can use many of the tools used for the other test cases.<br />

References<br />

• Resilient Software, Software Assurance, US Department Homeland<br />

Security<br />

• IR 7684 Common Misuse Scoring System (CMSS), NIST<br />

• Common Attack Pattern Enumeration and Classification (CAPEC),<br />

The Mitre Corporation<br />

• OWASP_AppSensor_Project<br />

• AppSensor Guide v2, OWASP<br />

• Watson C, Coates M, Melton J and Groves G, Creating Attack-Aware<br />

Software Applications with Real-Time Defenses, CrossTalk The Journal<br />

of Defense Software Engineering, Vol. 24, No. 5, Sep/Oct 2011<br />

Test Upload of Unexpected File Types<br />

(OTG-BUSLOGIC-008)<br />

Summary<br />

Many application’s business processes allow for the upload and<br />

manipulation of data that is submitted via files. But the business<br />

process must check the files and only allow certain “approved” file<br />

types. Deciding what files are “approved” is determined by the business<br />

logic and is application/system specific. The risk in that by allowing<br />

users to upload files, attackers may submit an unexpected<br />

file type that that could be executed and adversely impact the application<br />

or system through attacks that may deface the web site,<br />

perform remote commands, browse the system files, browse the local<br />

resources, attack other servers, or exploit the local vulnerabilities,<br />

just to name a few.<br />

Vulnerabilities related to the upload of unexpected file types is<br />

unique in that the upload should quickly reject a file if it does not have<br />

a specific extension. Additionally, this is different from uploading malicious<br />

files in that in most cases an incorrect file format may not by<br />

it self be inherently “malicious” but may be detrimental to the saved<br />

data. For example if an application accepts Windows Excel files, if an<br />

similar database file is uploaded it may be read but data extracted<br />

my be moved to incorrect locations.<br />

The application may be expecting only certain file types to be uploaded<br />

for processing, such as .CSV, .txt files. The application may not validate<br />

the uploaded file by extension (for low assurance file validation)<br />

or content (high assurance file validation). This may result in unexpected<br />

system or database results within the application/system or<br />

give attackers additional methods to exploit the application/system.<br />

Example<br />

Suppose a picture sharing application allows users to upload a .gif or<br />

.jpg graphic file to the web site. What if an attacker is able to upload<br />

an html file with a tag in it or php file? The system may move<br />

the file from a temporary location to the final location where the php<br />

code can now be executed against the application or system.<br />

How to Test<br />

Generic Testing Method<br />

• Review the project documentation and perform some exploratory<br />

testing looking for file types that should be “unsupported” by the<br />

application/system.<br />

• Try to upload these “unsupported” files an verify that it are properly<br />

rejected.<br />

• If multiple files can be uploaded at once, there must be tests in<br />

place to verify that each file is properly evaluated.<br />

Specific Testing Method<br />

• Study the applications logical requirements.<br />

• Prepare a library of files that are “not approved” for upload that<br />

may contain files such as: jsp, exe, or html files containing script.<br />

• In the application navigate to the file submission or upload mechanism.<br />

• Submit the “not approved” file for upload and verify that they are<br />

properly prevented from uploading<br />

Related Test Cases<br />

• Test File Extensions Handling for Sensitive Information (OTG-CON-<br />

FIG-003)<br />

• Test Upload of Malicious Files (OTG-BUSLOGIC-009)<br />

References<br />

• OWASP - Unrestricted File Upload - https://www.owasp.org/<br />

index.php/Unrestricted_File_Upload<br />

• File upload security best practices: Block a malicious file<br />

upload - http://www.computerweekly.com/answer/File-upload-security-best-practices-Block-a-malicious-file-upload<br />

• Stop people uploading malicious PHP files via forms - http://<br />

stackoverflow.com/questions/602539/stop-people-uploadingmalicious-php-files-via-forms<br />

• CWE-434: Unrestricted Upload of File with Dangerous Type -<br />

http://cwe.mitre.org/data/definitions/434.html<br />

• Secure Programming Tips - Handling File Uploads - https://<br />

www.datasprings.com/resources/dnn-tutorials/artmid/535/<br />

articleid/65/secure-programming-tips-handling-file-uploads?AspxAutoDetectCookieSupport=1<br />

Remediation<br />

Applications should be developed with mechanisms to only accept<br />

and manipulate “acceptable“ files that the rest of the application<br />

functionality is ready to handle and expecting. Some specific<br />

examples include: Black or White listing of file extensions,<br />

using “Content-Type” from the header, or using a file type recognizer,<br />

all to only allow specified file types into the system.<br />

Test Upload of Malicious Files<br />

(OTG-BUSLOGIC-009)<br />

Summary<br />

Many application’s business processes allow for the upload of<br />

data/information. We regularly check the validity and security of<br />

text but accepting files can introduce even more risk. To reduce<br />

the risk we may only accept certain file extensions, but attackers<br />

are able to encapsulate malicious code into inert file types. Testing<br />

for malicious files verifies that the application/system is able<br />

to correctly protect against attackers uploading malicious files.<br />

Vulnerabilities related to the uploading of malicious files is<br />

unique in that these “malicious” files can easily be rejected<br />

through including business logic that will scan files during<br />

the upload process and reject those perceived as malicious.<br />

Additionally, this is different from uploading unexpected files in<br />

that while the file type may be accepted the file may still be malicious<br />

to the system.<br />

Finally, “malicious” means different things to different systems,<br />

for example Malicious files that may exploit SQL server vulnerabilities<br />

may not be considered a “malicious” to a main frame flat<br />

file environment.<br />

The application may allow the upload of malicious files that include<br />

exploits or shellcode without submitting them to malicious<br />

file scanning. Malicious files could be detected and stopped at<br />

various points of the application architecture such as: IPS/IDS,<br />

application server anti-virus software or anti-virus scanning by<br />

application as files are uploaded (perhaps offloading the scanning<br />

using SCAP).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!