SQL Injection URL http crypto ee ncku edu

  • Slides: 28
Download presentation
SQL Injection (資料隱碼) 簡介 主講人: 陳培德 成大電機所博士候選人 密碼與網路安全研究室 URL: http: //crypto. ee. ncku. edu.

SQL Injection (資料隱碼) 簡介 主講人: 陳培德 成大電機所博士候選人 密碼與網路安全研究室 URL: http: //crypto. ee. ncku. edu. tw Email: peder@crypto. ee. ncku. edu. tw

大綱 n n n n 前言 什麼是SQL Injection 影響的系統 SQL Injection原理 SQL Injection攻擊 SQL

大綱 n n n n 前言 什麼是SQL Injection 影響的系統 SQL Injection原理 SQL Injection攻擊 SQL 帳號設定 如何防範SQL Injection Cryptology & Network Security Lab.

Cryptology & Network Security Lab.

Cryptology & Network Security Lab.

影響的系統 n n Apache、IIS、Domino、Netscape的網站系統, 透過ASP、PHP與JSP等程式碼,攻擊破壞各 種SQL資料庫。 影響的系統包括MSSQL、My. SQL、 Oracle、Sybase與DB 2等。 Cryptology & Network Security

影響的系統 n n Apache、IIS、Domino、Netscape的網站系統, 透過ASP、PHP與JSP等程式碼,攻擊破壞各 種SQL資料庫。 影響的系統包括MSSQL、My. SQL、 Oracle、Sybase與DB 2等。 Cryptology & Network Security Lab.

ASP程式碼中可能內含資料庫 之帳號密碼 Cryptology & Network Security Lab.

ASP程式碼中可能內含資料庫 之帳號密碼 Cryptology & Network Security Lab.

SQL Injection原理 n 一般輸入帳號密碼的網站的SQL語法 select * from member where UID =' "& request("ID") &"

SQL Injection原理 n 一般輸入帳號密碼的網站的SQL語法 select * from member where UID =' "& request("ID") &" ' And Passwd =' "& request("Pwd") & " ' n 如果正常使用者帳號A 123456789 ,密碼 1234 select * from member where UID ='A 123456789' And Passwd='1234' n 輸入的帳號與密碼等資訊會取代ASP( or PHP、JSP) 中的變數,並由兩個單引號(' ')所包住 Cryptology & Network Security Lab.

Cryptology & Network Security Lab.

Cryptology & Network Security Lab.

SQL Injection原理 (cont. ) select * from member where UID =' "& request("ID") &"

SQL Injection原理 (cont. ) select * from member where UID =' "& request("ID") &" ' And Passwd =' "& request("Pwd") & " ' 若攻擊者已知系統中已有一個Admin的管理者帳 號,則輸入Admin '-- ,即可不須輸入密碼而進入 資料庫 select * from member where UID =' Admin '-- ' n n And Passwd =' ' 註: -- 符號後的任何敘述都會被當作註解 (以上面為例,And子句將被SQL視為說明用) Cryptology & Network Security Lab.

正常連線狀態 ID=A 123456789 Passwd=1234 網際網 路 select * from member where UID ='A 123456789'

正常連線狀態 ID=A 123456789 Passwd=1234 網際網 路 select * from member where UID ='A 123456789' And Passwd='1234' Cryptology & Network Security Lab.

SQL Injection攻擊 ID=Admin' -Passwd=1234 網際網 路 select * from member where UID = 'Admin'

SQL Injection攻擊 ID=Admin' -Passwd=1234 網際網 路 select * from member where UID = 'Admin' --' And Passwd= '1234' Cryptology & Network Security Lab.

SQL Injection攻擊(範例一) 一旦惡意使用者輸入 使用者帳號' or 1=1 --,密碼asdf 1234(任意輸入 ) n select * from member

SQL Injection攻擊(範例一) 一旦惡意使用者輸入 使用者帳號' or 1=1 --,密碼asdf 1234(任意輸入 ) n select * from member where UID =' ' or 1=1 -- ' And Passwd = 'asdf 1234' Cryptology & Network Security Lab.

SQL Injection攻擊(範例二) n 一旦惡意使用者輸入 使用者帳號abcdefg (任意輸入) , 密碼asdf (任意輸入) ' or 1=1 -- select

SQL Injection攻擊(範例二) n 一旦惡意使用者輸入 使用者帳號abcdefg (任意輸入) , 密碼asdf (任意輸入) ' or 1=1 -- select * from member where UID =' abcdefg ' And Passwd = ' asdf ' or 1=1 -- ' Cryptology & Network Security Lab.

SQL Injection攻擊(範例三) SELECT * FROM my. Table WHERE some. Text =' " & request.

SQL Injection攻擊(範例三) SELECT * FROM my. Table WHERE some. Text =' " & request. form("inputdata") & " ' n 若使用者輸入以下字串 ' exec master. . xp_cmdshell 'net user testpass /ADD' -SELECT * FROM my. Table WHERE some. Text ='' exec master. . xp_cmdshell 'net user testpass /ADD'-- ' 如此一來,便可在SQL伺服器上新增一個使用者test帳號(密 碼testpass) Cryptology & Network Security Lab.

如何防範SQL Injection (cont. ) n 外部防護系統的控管 n n n 可藉由防火牆系統管制port 1433與1434的 連線 藉由防火牆限制網路登入者的身份 藉由Host-based

如何防範SQL Injection (cont. ) n 外部防護系統的控管 n n n 可藉由防火牆系統管制port 1433與1434的 連線 藉由防火牆限制網路登入者的身份 藉由Host-based IDS或Application-based IDS來監控系統運作的執行 Cryptology & Network Security Lab.

參考資料 n n n The Open Web Application Security Project http: //www. owasp. org/asac/input_validation/s

參考資料 n n n The Open Web Application Security Project http: //www. owasp. org/asac/input_validation/s ql. shtml 新波科技http: //www. diamondinfotech. com. tw/ 精誠公司安全通報 http: //www. sysware. com. tw/news/press/0204 24. shtml Cryptology & Network Security Lab.

參考資料 (cont. ) n 台灣微軟公司關於SQL Injection的相關 報導 n n n http: //www. microsoft. com/taiwan/sql/SQL_I

參考資料 (cont. ) n 台灣微軟公司關於SQL Injection的相關 報導 n n n http: //www. microsoft. com/taiwan/sql/SQL_I njection. htm http: //www. microsoft. com/taiwan/sql/SQL_I njection_G 1. htm SQL Server電子雜誌 http: //www. sqlserver. com. tw/ Cryptology & Network Security Lab.