FUSE: Finding File Upload Bugs Via Penetration Testing Taekjin Lee, Seongil Wi, Suyoung Lee, Sooel Son KAIST Upload Functionality
Total Page:16
File Type:pdf, Size:1020Kb
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 Uploading Procedure Web server PHP interpreter Web application File Content-filtering Extractor checks Disable uploading NDSS.png specified file types NDSS.png Upload request User A [HTTP(S) POST] 3 File Uploading Procedure Web server PHP interpreter Web application File Content-filtering Extractor checks https://wsplab.com/NDSS.png NDSS.png NDSS.png Download Upload Access request https://wsplab.com/NDSS.png User A User B 4 Disable Uploading Malicious Files Web server PHP interpreter Web application File Content-filtering Extractor Discard checks webshell.php <?php system(‘ls’); ?> webshell.php Upload request Attacker 5 Content-filtering Checks Content-filtering checks <?php php $black_list = array(‘js’,‘php’,‘html’,...) if (!in_array(ext($file_name), $black_list)) { <?php Error: move($file_name, $upload_path); system(‘ls’); forbidden } ?> file type else { webshell.php message('Error: forbidden file type'); PHP interpreter } ?> 6 File Upload Vulnerabilities - Server Side Web server What will be happening? PHP interpreter Web application File Content-filtering Extractor Discard checks webshell.php <?php system(‘ls’);UnrestrictedPotential File code Upload ?> <?php execution(UFU) system(‘ls’); webshell.php ?> webshell.php Upload request Attacker 7 File Upload Vulnerabilities - Server Side ArbitraryUnrestricted code Executable execution Web server File Uploadvia a URL (UEFU) PHP interpreter Web application File Content-filtering Extractor checks UnrestrictedPotential File code Upload <?php execution(UFU) system(‘ls’); ?> webshell.php Access https://wsplab.com/webshell.php Attacker 8 File Upload Vulnerabilities - Client Side ArbitraryUnrestricteD coDe Executable execution Web server File Uploadvia a URL (UEFU) PHP interpreter Web application File Content-filtering <html> Extractor https://wsplab.com/xss.html <script> checks alert(‘xss’); </script> UnrestricteD File UploaD <html> </html> <script> (UFU) alert(‘xss’); xss.html </script> </html> xss.html UploaD Access request https://wsplab.com/xss.html Attacker Victim 9 How to Find UEFU Vulnerabilities? Web server PHP interpreter Web application File Content-filtering Extractor checks #1: Bypassing application-specific checks Executable Upload request Attacker 10 How to Find UEFU Vulnerabilities? #2: Preserving the Web server execution semantic PHP interpreter Web application File Content-filtering Extractor checks https://wsplab.com/Executable #1: Bypassing application-specific checks Executable Upload request Attacker Victim 11 #2: Preserving the Execution Semantic Web server PHP interpreter Web application File Content-filtering Extractor checks <?php system(‘ls’); #1: Bypassing ?> <?php application-specific checks system(‘ls’); webshell.foo php → foo ?> webshell.foo Upload request Attacker 12 #2: Preserving the ExecutionA web Semantic server does not #2: Preserving the execute webshell.foo execution semantic Web server (Not a php-style extension) PHP interpreter Web application File Content-filtering Extractor checks Potential#1: Bypassing code <?php applicationexecution-specific checks system(‘ls’); ?> webshell.foo Access https://wsplab.com/webshell.foo Attacker 13 Summary #2: Preserving the Web server execution semantic PHP interpreter Web application File Content-filtering Extractor checks https://wsplab.com/Executable #1: Bypassing application-specific checks Executable Upload request Attacker Victim 14 Previous Studies • Static analysis − Pixy, Oakland ’06 − Merlin, PLDI ’09 • Dynamic analysis Few studies have addressed − Saner, Oakland ’08 finding U(E)FU vulnerabilities! − Riding out DOMsday, NDSS ’18 • Symbolic execution − NAVEX, USENIX ’18 − SAFERPHP, PLAS ’11 15 How we address all the challenges? 16 We propose FUSE 17 Our Approach Web server PHP interpreter Web application File Content-filtering Extractor Rejected checks Initial upload FUSE request 18 Our Approach - Mutate Upload Request Web server PHP interpreter Web application File Content-filtering Extractor Rejected checks UEFU vulnerability Mutated upload FUSE request 19 Our Approach Analyze#2: Preserving web servers the Web server executionand browsers semantic PHP interpreter Web application File Content-filtering Extractor checks https://wsplab.com/Executable Investigate#1: Bypassing root causes applicationof U(E)FU-specific bugs checks Executable Initial upload FUSE request Victim 20 Our Approach Analyze web servers Web server and browsers PHP interpreter Web application File Content-filtering Extractor checks https://wsplab.com/Executable Investigate root causes of U(E)FU bugs Web server Executable Initial upload FUSE request Victim 21 Mutate Upload Request Investigate root causes Analyze web servers of U(E)FU bugs and browsers Web server Design 13 Initial upload Mutate FUSE request mutation operations 22 Our Goal: Finding U(E)FU Bugs Mutator Uploader Mutated upload request 23 Our Goal: Finding U(E)FU Bugs Mutator Uploader Validator Mutated Upload upload request information UFU and UEFU vulnerabilities 24 Upload Request filename content-type content Web server Upload FUSE request 25 Upload Request filename xss.html content-type <html> text/html <script> content alert(‘xss’); </script> <html><script>al </html> ert(‘xss’)</scri pt></html> xss.html Upload request 26 Five objectives that trigger Mutation Objectives common mistakes in implementing checks filename Content-filtering checks xss.html content-type if (finfo_file(content) not in expected_type) text/html reject(file); content if (ext(file_name) not in expected_ext) reject(file); <html><script>al if (expected_keyword in content) ert(‘xss’)</scri reject(file); pt></html> if (content_type not in expected_type) reject(file); accept(file) Upload request 27 Mutation Objectives #1 filename Content-filtering checks xss.html content-type if (finfo_file(content) == ‘text/html’) text/html reject(file); content if (ext(file_nameExploiting) == the‘php ’)absence of reject(file);content-filtering checks <html><script>al if (‘<?php’ in content) ert(‘xss’)</scri reject(file); pt></html> if (content_type == ‘text/html’) reject(file); accept(file) Upload No mutation request 28 Mutation Objectives #2 ‘image/png’ filename Content-filtering checks xss.html content-type if (finfo_file(content) == ‘text/html’) text/html reject(file); content if (ext(file_name) == ‘php’) \x89\x50\x4e\x47 reject(file); <html><script>al\x0d\x0a\x1a... if (‘<?php’ inCausingcontent) incorrect type <html><script>alert(‘xss’)</scri reject(file);inferences based on PNG header ert(pt></‘xsshtml>’)</scri if (content_type == ‘text/html’)content pt></html> reject(file); accept(file) Upload M1: Prepending a resource header request 29 Mutation Objectives #3 filename Content-filtering checks webshell.php5webshell.php ‘php5’ content-type if (finfo_file(content) == ‘text/html’) application/x-php reject(file); content if (ext(file_name) == ‘php’) reject(file); <?php if (‘<?php’ in content) system(‘ls’); reject(file);Exploiting incomplete ?> if (content_type ==blacklist ‘text/html’) based on reject(file); accept(file) extension Upload M4: Changing a file extension request 30 Mutation Objectives #4 filename Content-filtering checks webshell.php Bypassing keyword content-type if (finfo_file(content) == ‘text/html’) application/x-php reject(file);checks based on content content if (ext(file_name) == ‘php’) reject(file); <?php if (‘<?php’ in content) systemsystem((‘ls’); reject(file); ?> if (content_type == ‘text/html’)‘<?’ reject(file); accept(file) Upload M5: Replace PHP tags with short tags request 31 Mutation Objectives #5 filename Content-filtering checks xss.html content-type if (finfo_file(content) == ‘text/html’) text/htmlimage/png reject(file);Bypassing filtering logic content if (ext(file_namebased) == ‘onphp ’) reject(file); content-type <html><script>al ‘image/if (‘<?pngphp’’in content) ert(‘xss’)</scri reject(file); pt></html> if (content_type == ‘text/html’) reject(file); accept(file) Upload M3: Changing the content-type of an upload request request 32 Combinations of Mutation Operations filename Content-filtering checks xss.html content-type if (finfo_file(content) == ‘text/html’) text/htmlimage/png reject(file); content if (ext(file_name) == ‘image/‘php’) png’ \x89\x50\x4e\x47 reject(file); co <html><script>al\x0d\x0a\x1a... ‘image/if (‘<?pngphp’’in content) <html><script>alert(‘xss’)</scri reject(file); ert(pt></‘xsshtml>’)</scri if (content_type == ‘text/html’) pt></html> reject(file); accept(file) Upload M1: Prepending a resource header request + M3: Changing the content-type of an upload request 33 More in the Paper • M2: Inserting a seed into metadata • M6: Converting HTML into EML • M7: Removing a file extension • M8: Converting a file in SVG • M9: Prepending an HTML comment • M10: CHanging a file extension to an arbitrary string • M11: Converting a file extension to uppercase • M12: Prepending a file extension • M13: Appending a resource Header 34 Evaluation Mutator Uploader Validator Mutated Upload upload request information UFU and UEFU vulnerabilities 35 Experimental Setup • 33 popular PHP web applications 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