FUSE: Finding File Upload Bugs via Penetration Testing
Taekjin Lee, Seongil Wi, Suyoung Lee, Sooel Son KAIST
FUSE: Finding File Upload Bugs via Penetration Testing Taekjin Lee, - - PowerPoint PPT Presentation
FUSE: Finding File Upload Bugs via Penetration Testing Taekjin Lee, Seongil Wi , Suyoung Lee, Sooel Son KAIST Upload Functionality Sharing user-provided content has become a de facto standard feature of modern web applications 2 File
Taekjin Lee, Seongil Wi, Suyoung Lee, Sooel Son KAIST
standard feature of modern web applications
2
3
NDSS.png Upload request PHP interpreter File Web application
Web server
NDSS.png Content-filtering checks [HTTP(S) POST]
Disable uploading specified file types
Extractor User A
4
User B Access
https://wsplab.com/NDSS.png
Download
https://wsplab.com/NDSS.png
User A NDSS.png Upload request PHP interpreter File Web application
Web server
NDSS.png Extractor Content-filtering checks
5
Attacker Upload request
5
PHP interpreter File Web application
Web server
Extractor Content-filtering checks Discard webshell.php
webshell.php <?php system(‘ls’); ?>
6
<?php $black_list = array(‘js’,‘php’,‘html’,...) if (!in_array(ext($file_name), $black_list)) { move($file_name, $upload_path); } else { message('Error: forbidden file type'); } ?>
Content-filtering checks
php
webshell.php <?php system(‘ls’); ?> PHP interpreter Error: forbidden file type
7
Attacker Upload request
7
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
webshell.php <?php system(‘ls’); ?> webshell.php <?php system(‘ls’); ?>
What will be happening?
Discard webshell.php
Potential code execution Unrestricted File Upload (UFU)
8
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
webshell.php <?php system(‘ls’); ?>
Potential code execution Unrestricted File Upload (UFU)
Attacker Access
https://wsplab.com/webshell.php
Arbitrary code execution via a URL Unrestricted Executable File Upload (UEFU)
9
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
xss.html <html> <script> alert(‘xss’); </script> </html> <html> <script> alert(‘xss’); </script> </html> xss.html
Victim Access
https://wsplab.com/xss.html
https://wsplab.com/xss.html
Attacker Upload request
Arbitrary code execution via a URL Unrestricted Executable File Upload (UEFU) Unrestricted File Upload (UFU)
10
Attacker Upload request
10
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
#1: Bypassing application-specific checks
Executable
11
Attacker Upload request
11
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
#1: Bypassing application-specific checks
Executable
Victim
https://wsplab.com/Executable
#2: Preserving the execution semantic
12
Attacker Upload request
12
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
webshell.foo <?php system(‘ls’); ?> webshell.foo <?php system(‘ls’); ?>
php → foo
#1: Bypassing application-specific checks
13 13
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
webshell.foo <?php system(‘ls’); ?>
Potential code execution
#1: Bypassing application-specific checks
13
Attacker Access
https://wsplab.com/webshell.foo
A web server does not execute webshell.foo (Not a php-style extension) #2: Preserving the execution semantic
14
Attacker Upload request
14
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
#1: Bypassing application-specific checks
Executable
Victim
https://wsplab.com/Executable
#2: Preserving the execution semantic
− Pixy, Oakland ’06 − Merlin, PLDI ’09
− Saner, Oakland ’08 − Riding out DOMsday, NDSS ’18
− NAVEX, USENIX ’18 − SAFERPHP, PLAS ’11
15
Few studies have addressed finding U(E)FU vulnerabilities!
16
17
18 18
PHP interpreter File Web application
Web server
Extractor Content-filtering checks Initial upload request
FUSE
Rejected
19 19
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
FUSE
Rejected Mutated upload request UEFU vulnerability
20 20
PHP interpreter File Web application
Web server
Extractor Content-filtering checks Initial upload request
FUSE
Executable
#1: Bypassing application-specific checks #2: Preserving the execution semantic
Victim
https://wsplab.com/Executable
Investigate root causes
Analyze web servers and browsers
21 21
PHP interpreter File Web application
Web server
Extractor Content-filtering checks Initial upload request
FUSE
Executable
Victim
https://wsplab.com/Executable
Analyze web servers and browsers Investigate root causes
Analyze web servers and browsers
Web server
22 22
Initial upload request
FUSE
Investigate root causes
Analyze web servers and browsers
Web server
Design 13 mutation operations
Mutate
23
Uploader
Mutated upload request
Mutator
24
Uploader
UFU and UEFU vulnerabilities
Mutated upload request Upload information
Mutator Validator
25
FUSE
Web server
filename content-type content
Upload request
26
xss.html
<html> <script> alert(‘xss’); </script> </html> Upload request
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html
27
if (finfo_file(content) not in expected_type) reject(file); if (ext(file_name) not in expected_ext) reject(file); if (expected_keyword in content) reject(file); if (content_type not in expected_type) reject(file); accept(file)
Content-filtering checks Five objectives that trigger common mistakes in implementing checks
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html Upload request
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
Content-filtering checks
28
Exploiting the absence of content-filtering checks
No mutation
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html Upload request
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
Content-filtering checks
29
Causing incorrect type inferences based on content
M1: Prepending a resource header
‘image/png’
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html \x89\x50\x4e\x47 \x0d\x0a\x1a... <html><script>al ert(‘xss’)</scri pt></html>
PNG header
Upload request
webshell.php webshell.php5
application/x-php
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
30
Content-filtering checks
Exploiting incomplete blacklist based on extension
M4: Changing a file extension
‘php5’
filename content-type content
<?php system(‘ls’); ?> Upload request
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
31
Content-filtering checks
Bypassing keyword checks based on content
M5: Replace PHP tags with short tags
‘<?’
application/x-php filename content-type content
webshell.php <?php system(‘ls’); ?> <? system(‘ls’); ?> Upload request
32
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
Content-filtering checks
Bypassing filtering logic based on content-type
M3: Changing the content-type of an upload request
‘image/png’
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html image/png Upload request
33
if (finfo_file(content) == ‘text/html’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
Content-filtering checks
co
filename content-type content
xss.html <html><script>al ert(‘xss’)</scri pt></html> text/html \x89\x50\x4e\x47 \x0d\x0a\x1a... <html><script>al ert(‘xss’)</scri pt></html>
+
image/png
‘image/png’ ‘image/png’
M1: Prepending a resource header M3: Changing the content-type of an upload request Upload request
34
35
Uploader
UFU and UEFU vulnerabilities
Mutated upload request Upload information
Mutator Validator
36
WordPress Joomla Concrete5 OsCommerce2 Monstra Drupal ZenCart Bludit Textpattern CMSMadeSimple Pagekit Backdrop CMSimple Composr OctoberCMS phpBB3 Elgg Microweber XE SilverStripe ECCube3 GetSimpleCMS DotPlant2 MyBB HotCRP Subrion SymphonyCMS AnchorCMS WeBid Collabtive X2engine ClipperCMS Codiad
distinct upload request −WordPress, Concrete5, OsCommerce2, ZenCart, …
−15 CVEs from 9 applications
37
<?php system(‘ls’); ?>
38
if (finfo_file(content) == ‘application/x-php’) reject(file); if (ext(file_name) == ‘php’) reject(file); if (‘<?php’ in content) reject(file); if (content_type == ‘text/html’) reject(file); accept(file)
Content-filtering checks
co
M13: Appending a resource header + M4: Changing a file extension
application/x-php filename content-type content
webshell.php <?php system(‘ls’); ?> \xff\xd8\xff\xee \x00\x10JF webshell.pht
‘application/octet-stream’ ‘pht’
8 bytes header
Upload request
platform for web application security testing
39
Vulnerability (Seed) FUSE Fuxploider UploadScanner UEFU (PHP) 12 7 5 UEFU (HTML) 23 N/A 14 UFU (JS) 26 N/A 21
40
Vulnerability (Seed) FUSE Fuxploider UploadScanner UEFU (PHP) 12 7 5 UEFU (HTML) 23 N/A 14 UFU (JS) 26 N/A 21
41
Causes Description UFU + UEFU Bugs Found #1 Exploiting the absence of checks 27 #2 Causing incorrect type inferences based on content 5 #3 Exploiting incomplete blacklist based on extension 35 #4 Bypassing keyword checks based on content 6 #5 Bypassing checks based on content-type 5 #2+#3 Combined Operation 6 #2+#3+#4 Combined Operation 1 Inferring upload file types based on user-provided extensions opens a door for further attacks
consider
PHP interpreters
42
U(E)FU vulnerabilities
content-filtering checks, but to remain executable in target execution environments
applications
43
44
https://github.com/WSP-LAB/FUSE
45
46
Attacker Upload request
46
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
Conducting symbolic execution
Executable PHP
47
Attacker Upload request
47
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
Executable PHP
#1: Bypassing application-specific checks
#2: Preserving the execution semantic Reachability constraint Extension constraint
48
Attacker Upload request
48
PHP interpreter File Web application
Web server
Extractor Content-filtering checks
Executable PHP
Reachability constraint Extension constraint Require deep understanding Limited search space
Found only 3 bugs from 9,160 WordPress plugins
in code executions (CEs) or potential code executions (PCEs) in Web execution environments.
49
50
penetration testing
51
function is different
52
administrator-level privilege for their exploitation
administrators from the host management
53
68, eight different versions of Apache mod_php modules, and PHP 5.6 interpreter engines
54
start tag (i.e., <?php or <?)
have one of the seven PHP-style file extensions (e.g., php3, phar) for its execution via direct URL invocations
executable HTML file must start with pre-defined start tags within its first 512 bytes with subsequent valid HTML code
HTML case but requires the presence of xmlns tags
55
56
57
58
(M2) as when
vector, or
M2 unnecessary.
59
60
− Common prefix of URLs − Upload response and summary webpage − File Monitor
− PHP: Sting checking − HTML, JS, XHTML: Checks whether the Content-Type header in the response is among our selections of 10 MIME types
61