1、CATION FLAWS,COMMON APPLI,Objective Provide an overview of common application flaws No exploitation techniques Discussion based, to provide an understanding To provoke thinkingOriginally going to provide a Tokemon walkthrough Wont work over conference call,Back To Basics,Slide 2,Cross Site Scripting
2、 alert()Injection Flaws SQL, LDAP, XML, etc File Execution Scripting, RFI, shell executionDirect Object Reference /access.asp?record=#Cross Site Request Forgery Session riding, Accessing internal device,OWASP Top Ten Summary,Slide 3,Information Leakage and Error Handling Every bit of information hel
3、ps an attackerBroken Authentication and Session Management Login bypass, cookie manipulationInsecure Cryptographic Storage Static keys, Non seeded encryptionInsecure Communications HTTP, Clear text internal web servicesFailure to Restrict URL Access /adminportal/adminfunction?action=adduser&user=me,
4、OWASP Top Ten Summary,Slide 4,Comes from many places Passed on the URL, or as a parameter Passed in posted data, hidden fields Passed in HTTP headers, referer Cookie data, client certificates, files for import, etc,User Supplied Input Is The Cause,Slide 5,THE USER CAN NOT BE TRUSTED. EVER,Validate A
5、LL user input, server side Cint(), isDate(), len() = x, isAlphaNumeric() Whitelist, NOT blacklist Decode input, in the correct order, and in the right case Filter Output at use Different uses of data, require different filters,function cleanrequest(theID)theID = lcase(theID)if instr(theID,“;“) 0 the
6、ntheID = left(theID,instr(theID,“;“)-1)end ifif instr(theID,“exec “) 0 thentheID = left(theID,instr(theID,“exec “)-1)end if,Faulty Filters Worse Than No Filters,Slide 6,Function To Filter User Input,Looks For The Use Of A Semi Colon,Looks For The Term exec followed by a space,This Filter Can Be Bypa
7、ssed By Using A Tab Character As A Separator /page.aspx?theID=1%09exec%09xp_cmdshell serverpwnage.exe;,/page.aspx?theID=1;exec xp_cmdshell serverpwnage.exe;,function displayText(htmlInput)htmlInput=str_ireplace(“script“, “,htmlInput)echo htmlInput,Faulty Filters Worse Than No Filters,Slide 7,Functio
8、n To Display User Input,Looks For The Term script And Remove It,Display The Filtered Data,These Types Of Filters Are Just Rubbish! /page.php?htmlInput=alert(),/page.php?htmlInput=alert(),Robots.txt / Sitemap.xml Often reveal more than they should Spiders dont have to obeyThings that dont belong Site
9、 archives .svn trees .inc, .cfg, .txt, bak, .backup Admin portals hidden paths Virtual sites,The Clean Server,Slide 8,Dont Want It Indexed? Dont Link It!,Dont Want It Found? Dont Put It There,http:/www.owasp.org/_admin/,http:/www.owasp.org/_database/,http:/www.owasp.org/_debug/,http:/www.owasp.org/_
10、debuglogs/,http:/www.owasp.org/_includes/,http:/www.owasp.org/admin/,http:/www.owasp.org/adminportal/,http:/www.owasp.org/adminsite/,http:/www.owasp.org/console/,http:/www.owasp.org/backups/,http:/www.owasp.org/logs/,http:/www.owasp.org/maintentance/,http:/www.owasp.org/sites/,http:/www.owasp.org/sy
11、sadmin/,http:/www.owasp.org/admin/admin.,http:/www.owasp.org/admin/admin.asp,http:/www.owasp.org/admin/admin.bak,http:/www.owasp.org/admin/admin.inc,http:/www.owasp.org/admin/admin.log,http:/www.owasp.org/admin/admin.jsp,http:/www.owasp.org/admin/admin.php,http:/www.owasp.org/admin/adminpage.,http:/
12、www.owasp.org/admin/adminpage.asp,http:/www.owasp.org/admin/adminpage.bak,http:/www.owasp.org/admin/adminpage.inc,http:/www.owasp.org/admin/adminpage.jsp,http:/www.owasp.org/admin/adminpage.php,Manipulation of the SQL query stringBecomesOr,SQL Injection,Slide 9,sqlString= select * from users where n
13、ame =+userinput+and password=+userinput,select * from users where name =admin;-and password=anything,select * from users where name =admin and password=anything or 1=1,Syntax Grouping,Where (name =admin) (and (password=anything) or (1=1) ),Syntax Grouping,Use parameterized queries asp, .net, java, p
14、hp, python, flex? Use stored procedures Type cast variables Dont use dynamic SQL inside procedure Often seen in search procedures Use the QuoteName function,SQL Injection,Slide 10,Yes. Of course your flash application can be vulnerable to injection attacks,DO NOT BUILD SQL STATEMENTS DYNAMICALLY,SEL
15、ECT SQL = SELECT * from USERS WHERE NAME =+ UsernameEXEC SQL,Application vs SQL The form data is stored varies between the twoMySQL MySQL will truncate data during an insertPHP asks MYSQL “Any users by this name?” MYSQL responds “No, I dont know that person” PHP says “Ok add a user by this name” MYS
16、QL says “Sure, his name is too long Ill shorten it for you”,SQL Truncation Attacks,Slide 11,User=“adminx”,GEE THANKS,MSSQL Data is truncated when calling stored proceduresSQL returns record for adminData mailed to both admin and attacker,SQL Truncation Attacks,Slide 12,User=“;”,Create procedure Find
17、Userusername VARCHAR(100) .,Input To A Forgotten Password Page,Parameter Has A Length 100,Stored within the webroot /dbase/dbase.mdb Flat files etcRunning as ROOT or SYSTEM Or worse. A domain accountEncryption Of Data If the server or application is compromised, is the data?Unique record ID of the u
18、ser account User supplied password,Databases,Slide 13,Dont Use A Static Key,Do Seed With User Specific Data,Microsoft Used To Recommend This.,Encryption is difficult Do NOT roll your own XOR based encryption scheme BASE64 is not encryptionWeakness is in the implementation Verify your data is getting
19、 encrypted Use one way encryption for passwordsStoring the secrets Database credentials should never be stored clear text Encryption keys should not be stored in accessible configs,Cryptography,Slide 14,Often vulnerable to spam attacks SMTP is a text based protocol CR/LF pairs and new command can be
20、 insertedNormal communication with SMTP server,Application Email,Slide 15,Mail From: Rcpt To: Data Subject: This is a test email . quit,Injection through recipient field useruser.co.nz%0a%0drset%0a%0dMail From: spamfoo.Modified communication with SMTP server,Application Email,Slide 16,Mail From: Rcp
21、t To: rset Mail From: Rcpt To: Data Subject: This is a spam email blah blah spam spam . quit,RESET Injected,New Details Injected,The sending of user supplied input to the browser More than alert()Reflective Code passed as a parameter, usually on the URLPersistent Code stored and then displayed to us
22、erConsequences Cookie theft Site interaction Web application worms,Cross Site Scripting,Slide 17,JavaScript is a powerful programming language,Example flaw echo “hello “.$_GETusername.”welcome to the site”Normal output hello Brett welcome to the siteExploit output hello alert() welcome .,Cross Site
23、Scripting,Slide 18,Insert Any JavaScript Or Script Inclusion,Widely Known, Well Explained, Still Exists In Most Applications,Cross Site Request Forgery Attacking site causes browser to make a request to targetUser logs into banking.co.nz banking.co.nz sets an authentication cookie User leaves but do
24、esnt log outUser browses to attacking site Attacking site creates a post to banking.co.nz Users browser sends cookie with post Browser is already authenticated,CSRF,Slide 19,Defence Each post must contain a random parameter value,CSRF,Slide 20,Site redirection User supplied input used as target page
25、Can be used in phishing and scam attacksPage inclusion User supplied input use as source for frame, iframe, image,Other Related Attacks,Slide 21,http:/ Still Do This In Versions Of OWA, “,External Content Displayed In Browser,Dont store credentials in the cookie Set-cookie: user=adminSet the cookie
26、path Specifies which part of the application the cookie is sent to,Cookie Security,Slide 22,This Sort Of Thing Still Happens!,http:/Application,Secured Blog Posting Section http:/Application/secure/login,Insecure General Section http:/Application/general/read,Requires Auth Cookie Set,If The Cookie P
27、ath Is Not Set A Vulnerability In The General Section Can Read The Secure Section Cookie,Set the SECURE flag Prevents the cookie been sent in HTTP requests Cookie sent even if target site not listening on HTTPSet the HTTPOnly Flag Prevents access to the cookie through JavaScript Defence against cros
28、s site scripting,Cookie Security,Slide 23,Attacker Needs Access To Sniff The Traffic,File uploading is dangerous Provides the ability for the user to create data on server Usual attacks involve uploading a script file for accessCheck the file extension Check the portion after the last . Compare agai
29、nst WHITELISTCheck the file data Valid graphic, csv, numeric dataStore as blob in database Do NOT store as raw file under webroot,File Uploading,Slide 24,Beware The NULL (%00) byte,Local file include Occurs when user can affect or supply a file path Leads to disclosure of source and other sensitive
30、itemsRemote file include Occurs in PHP (usually), when an HTTP reference is provided Is disabled in modern versions of PHP.Net LoadControl Can be used to load arbitrary controls that exist on serverIf you must accept paths from a user Reject anything that is suspect. Ie; / %xx,File Include Attacks,Slide 25,http:/ is wrong with these?,Configuration,Slide 26,order deny,allowdeny from allallow from 203.10.1.104allow from 192.168.1.1 ,.htaccess,Web.config,,