You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: document/4-Web_Application_Security_Testing/10-Business_Logic_Testing/09-Test_Upload_of_Malicious_Files.md
+21-16
Original file line number
Diff line number
Diff line change
@@ -95,34 +95,40 @@ If the application extracts archives (such as ZIP files), then it may be possibl
95
95
96
96
A test against Archive Directory Traversal should include two parts:
97
97
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.
99
99
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:
- 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 <zipfilename> <directoryname>
125
+
7. Validate files compressed
126
+
jar -tvf <zipfilename>
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
+
114
130
- Include a unit test to upload an infected compressed file then execute the extraction method.
115
131
- 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:
thrownewArchiverException("Entry is outside of the target dir: "+ e.getName());
124
-
}
125
-
```
126
132
127
133
#### ZIP Bombs
128
134
@@ -188,5 +194,4 @@ Fully protecting against malicious file upload can be complex, and the exact ste
188
194
-[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)
189
195
-[CWE-434: Unrestricted Upload of File with Dangerous Type](https://cwe.mitre.org/data/definitions/434.html)
0 commit comments