330 likes | 407 Views
Application Security through a Hacker’s Eyes James Walden Northern Kentucky University waldenj@nku.edu. Why Do Hackers Target Web Apps?. Attack Surface. A system’s attack surface consists of all of the ways an adversary can enter the system. Merchant’s Bank Building.
E N D
Application Security through a Hacker’s EyesJames WaldenNorthern Kentucky Universitywaldenj@nku.edu IMI Security Symposium
Why Do Hackers Target Web Apps? IMI Security Symposium
Attack Surface A system’s attack surface consists of all of the ways an adversary can enter the system. Merchant’s Bank Building IMI Security Symposium
Defender’s View of Attack Surface web server firewall wireless VPN IMI Security Symposium
Firewalls don’t protect Web Apps telnet Firewall ftp Application DatabaseServer WebClient WebServer Application HTTP Traffic Port 80 IMI Security Symposium
SSL won’t stop injection attacks, XSS telnet Firewall ftp Application WebClient DatabaseServer WebServer Application HTTPS Traffic Port 443 IMI Security Symposium
Revised View of Attack Surface external web apps external web server firewall VPN wireless database IMI Security Symposium
Intranet Security Assumptions Since the firewall protects you • Patches don’t have to be up to date. • Passwords don’t have to be strong. • There’s no need to be careful when you code. • There’s no need to audit your source code. • There’s no need to run penetration tests. But do your users have web browsers? IMI Security Symposium
Javascript Malware controls Clients Intranet Firewall telnet Group Server Main Server ftp WebServer (Javascript malware) WebClient HTTP Traffic Port 80 Wiki IMI Security Symposium
Java can see your real IP address behind NAT router. Javascript can scan your intranet behind NAT router. IMI Security Symposium
Sources of Javascript Malware • Evil web site owner inserts in page. • Attacker inserts malware into defaced page. • Attacker inserts malware into a public comment or forum post (stored XSS.) • Attacker creates link that causes web site to echo malware to user (reflected XSS.) IMI Security Symposium
external web apps external web server internal web apps firewall VPN internal web servers wireless database Re-revised View of Attack Surface IMI Security Symposium
Web Applications external web apps external web server internal web apps firewall VPN internal web servers wireless database IMI Security Symposium
Web Application Vulnerabilities Input-based Security Problems • Injection Flaws • Insecure Remote File Inclusion • Unvalidated Input Authentication and Authorization • Authentication • Access Control • Cross-Site Attacks Other Bugs • Error Handling and Information Leakage • Insecure Storage • Insecure Communications IMI Security Symposium
SQL Injection Attacker • App sends form to user. • Attacker submits form with SQL exploit data. • Application builds string with exploit data. • Application sends SQL query to DB. • DB executes query, including exploit, sends data back to application. • Application returns data to user. ‘ or 1=1-- User Pass Firewall DB Server Web Server IMI Security Symposium
Cross-Site Scripting Web Server 8. Attacker hijacks user session. 1. Login Attacker User 2. Cookie 5. XSS URL 3. XSS Attack 6. Page with injected code. 7. Browser runs injected code. 4. User clicks on XSS link. Evil site saves ID. IMI Security Symposium
Web Application Attack Surface cookies form inputs HTTP headers URLs IMI Security Symposium
Traditional Web Applications HTTP Request (form submission) User waits Server processing HTTP Response (new web page) User interaction HTTP Request (form submission) Server processing User waits HTTP Response (new web page) IMI Security Symposium
AJAX Asynchronous Javascript and XML • User interacts with client-side Javascript. • Javascript makes asynchronous requests to server for data. • Continues to allow user to interact with application. • Updates when receives encoded data from server. IMI Security Symposium
AJAX Applications Client-side Code HTTP request (asynchronous) HTTP Response (data) Server processing User interaction partial update partial update HTTP request (asynchronous) User interaction Server processing HTTP Response (data) HTTP request (asynchronous) User interaction HTTP Response (data) partial update Server processing partial update IMI Security Symposium
Example Client-side Code var auth = checkPassword(user, pass); if (auth == false) { alert(‘Authentication failed.’); return; } var itemPrice = getPrice(itemID); debitAccount(user, itemPrice); downloadItem(itemID); IMI Security Symposium
client-side code client-side state cookies form inputs HTTP headers client-side data transforms URLs server API AJAX Application Attack Surface IMI Security Symposium
Drilling Down: Mapping the Application • Visible Content • Spider the site. • Browse site while using intercepting proxy. • Hidden Content • Unlinked sections of site. • Backup copies of live files. • Configuration and include files. • Source code. • Log files. IMI Security Symposium
Entry Points For each resource found, identify inputs: • Additional path parameters • Query string • POST parameters • Cookies • HTTP headers IMI Security Symposium
Database interaction Displays user-supplied data Error messages File upload/download Login SQL injection. Cross-site scripting. Information leakage. Path traversal. Authentication, session management, access control flaws. Application Feature Vulnerability Map IMI Security Symposium
Code Auditing Why? • Find vulnerabilities faster than testing. • Find different vulnerabilities than testing. What? • Identify modules of high business risk. • Use static analysis to find common vulnerabilities. • Manually review code + static analysis results. Who? • Developers, security team, outside auditors. When? • On a regular basis, at least once before release. IMI Security Symposium
Static Analysis Automated assistance for code auditing Speed: review code faster than humans can Accuracy: hundreds of secure coding rules Tools • Coverity • FindBugs • Fortify • Klocwork • Ounce Labs Results IMI Security Symposium
Fuzz Testing Fuzz testing consists of • Sending unexpected input. • Monitoring for exceptions. IMI Security Symposium
Monitoring for Exceptions Application mapping • Response code • Response size • Presence of string “not authorized” Password guessing • Response code • Response size • Presence of string “login incorrect” IMI Security Symposium
Prevention Guidelines • Use a standard, secure authentication scheme. • Check access control on every transaction. • Avoid using interpreters where possible. • Don’t leak sensitive information in error pages. • Encrypt sensitive data in transit and on disk. • Encode user data in output. • Don’t trust any data from the client. • Validate all input. IMI Security Symposium
Input Validation Blacklist: reject known bad input • Reject input matching list of bad strings/patterns. • Accept all other input. • Vulnerable to encoding attacks. Whitelist: accept known good input • Accept input matching list of good strings/patterns. • Reject all other input. • Highly effective, but not always feasible. IMI Security Symposium
Visible Content • Linked URLs. • Authenticated URLs. • Hidden Content • Unlinked sections of site. • Backup copies of live files. • Configuration/include files. • Source code. • Log files. client-side code client-side state cookies form inputs is nearly fractal. HTTP headers client-side data transforms URLs server API external web apps external web server A site’s attack surface internal web apps firewall VPN internal web servers database wireless IMI Security Symposium