Skip to content

Commit 850db57

Browse files
author
doverh
committed
Update testing steps
1 parent 509f2b1 commit 850db57

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

document/4-Web_Application_Security_Testing/10-Business_Logic_Testing/09-Test_Upload_of_Malicious_Files.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,40 @@ If the application extracts archives (such as ZIP files), then it may be possibl
9595

9696
A test against Archive Directory Traversal should include two parts:
9797

98-
1. A malicious archive that breaks out of the target directory when extracted. This malicious archive can contain two files: a 'notinfected.sh' file, extracted into the target directory, and also an 'infected.sh' file, that attempts to navigate up the directory tree to hit the root folder - adding a file into the tmp directory. A malicious path can contain many levels of '../' (i.e. ../../../../../../../../tmp/infected.sh) to stand a better chance of reaching the root directory.
98+
1. A malicious archive that breaks out of the target directory when extracted. This malicious archive can contain two files: a 'base' file, extracted into the target directory, and also an 'traversed' file, that attempts to navigate up the directory tree to hit the root folder - adding a file into the tmp directory. A malicious path can contain many levels of '../' (i.e. ../../../../../../../../tmp/traversed) to stand a better chance of reaching the root directory.
9999
2. A functionality, that is required to extract compressed files, either using custom code or a library. Archive Directory Traversal vulnerabilities exist when the extraction functionality doesn’t validate file paths in the archive. The example below shows a vulnerable implementation in Java:
100100

101101
```java
102102
Enumeration<ZipEntry>entries=​​zip​.g​etEntries();
103103
while(entries​.h​asMoreElements()){
104-
ZipEntry e ​=​entries.nextElement();
104+
ZipEntry e ​= ​entries.nextElement();
105105
File f = new File(destinationDir, e.getName());
106-
InputStream input =zip​.g​etInputStream(e);
106+
InputStream input = zip​.g​etInputStream(e);
107107
IOUtils.c​opy(input, write(f));
108108
}
109109
```
110110

111111
Additional testing techniques:
112112

113-
- Upload a malicious ZIP file and try to remote access this file when upload is completed. [Watch it in action here](https://www.youtube.com/watch?v=l1MT5lr4p9o)
113+
- Upload a malicious ZIP file and try to remote access this file when upload is completed.
114+
1. Open a new terminal and create a new folder:
115+
mkdir ZipFiles
116+
2. Create a base file:
117+
touch base.txt
118+
3. Open this file, add a simple note and save it.
119+
4. Create a traversed file that matches a local or remote directory:
120+
touch ../../../../../../../../tmp/traversed
121+
5. Open this file and a message to echo (executing this file should echo this message):
122+
echo "Your message here"
123+
6. Create the zip file:
124+
zip -r <zip file name> <directory name>
125+
7. Validate files compressed
126+
jar -tvf <zip file name>
127+
8. Load this zip file in the target application.
128+
9. Verify that the two files are located within different folders on the web server after the archive has been extracted.
129+
114130
- Include a unit test to upload an infected compressed file then execute the extraction method.
115131
- Validate that libraries being used have been [patched for this vulnerability.](https://github.com/snyk/zip-slip-vulnerability#affected-libraries)
116-
- Include a validation that throws an exception when vulnerabilities is included, like in the example below:
117-
118-
```java
119-
StringcanonicalDestinationDirPath=destinationDir.getCanonicalPath();
120-
Filedestinationfile=newFile(destinationDir,e.getName());
121-
StringcanonicalDestinationFile=destinationfile.getCanonicalPath();
122-
if(!canonicalDestinationFile.startsWith(canonicalDestinationDirPath+File.separator)){
123-
throw new ArchiverException("Entry is outside of the target dir: " + e.getName());
124-
}
125-
```
126132

127133
#### ZIP Bombs
128134

@@ -188,5 +194,4 @@ Fully protecting against malicious file upload can be complex, and the exact ste
188194
- [How to Tell if a File is Malicious](https://web.archive.org/web/20210710090809/https://www.techsupportalert.com/content/how-tell-if-file-malicious.htm)
189195
- [CWE-434: Unrestricted Upload of File with Dangerous Type](https://cwe.mitre.org/data/definitions/434.html)
190196
- [Implementing Secure File Upload](https://infosecauditor.wordpress.com/tag/malicious-file-upload/)
191-
- [Metasploit Generating Payloads](https://www.offensive-security.com/metasploit-unleashed/Generating_Payloads)
192-
- [ZIP Slip](https://res.cloudinary.com/snyk/image/upload/v1528192501/zip-slip-vulnerability/technical-whitepaper.pdf)
197+
- [Metasploit Generating Payloads](https://www.offensive-security.com/metasploit-unleashed/Generating_Payloads)

0 commit comments

Comments
 (0)