欢迎来到赛兔子家园

Pikachu越权、目录遍历、敏感信息泄露

Over Permission(越权)

如果使用A用户的权限去操作B用户的数据,A的权限小于B的权限,如果能够成功操作,则称之为越权操作。

越权漏洞形成的原因是后台使用了 不合理的权限校验规则导致的。

一般越权漏洞容易出现在权限页面(需要登录的页面)增、删、改、查的的地方,当用户对权限页面内的信息进行这些操作时,后台需要对当前用户的权限进行校验,看其是否具备操作的权限,从而给出响应,而如果校验的规则过于简单则容易出现越权漏洞。

因此,在在权限管理中应该遵守:

1.使用最小权限原则对用户进行赋权

2.使用合理(严格)的权限校验规则

3.使用后台登录态作为条件进行权限判断,别动不动就瞎用前端传进来的条件

水平越权

源码:

<?php
/**
 * Created by runner.han
 * There is nothing new under the sun
 */


$SELF_PAGE = substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);

if ($SELF_PAGE = "op1_login.php"){
    $ACTIVE = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','active open','','active','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
}
$PIKA_ROOT_DIR =  "../../../";
include_once $PIKA_ROOT_DIR . 'header.php';
include_once $PIKA_ROOT_DIR.'inc/mysql.inc.php';
include_once $PIKA_ROOT_DIR.'inc/function.php';
include_once $PIKA_ROOT_DIR.'inc/config.inc.php';

$link=connect();
// 判断是否登录,没有登录不能访问
if(!check_op_login($link)){
    header("location:op1_login.php");
}
$html='';
if(isset($_GET['submit']) && $_GET['username']!=null){
    //没有使用session来校验,而是使用的传进来的值,权限校验出现问题,这里应该跟登录态关系进行绑定
    $username=escape($link, $_GET['username']);
    $query="select * from member where username='$username'";
    $result=execute($link, $query);
    if(mysqli_num_rows($result)==1){
        $data=mysqli_fetch_assoc($result);
        $uname=$data['username'];
        $sex=$data['sex'];
        $phonenum=$data['phonenum'];
        $add=$data['address'];
        $email=$data['email'];

        $html.=<<<A
<div id="per_info">
   <h1 class="per_title">hello,{$uname},你的具体信息如下:</h1>
   <p class="per_name">姓名:{$uname}</p>
   <p class="per_sex">性别:{$sex}</p>
   <p class="per_phone">手机:{$phonenum}</p>    
   <p class="per_add">住址:{$add}</p> 
   <p class="per_email">邮箱:{$email}</p> 
</div>
A;
    }
}


if(isset($_GET['logout']) && $_GET['logout'] == 1){
    session_unset();
    session_destroy();
    setcookie(session_name(),'',time()-3600,'/');
    header("location:op1_login.php");

}



?>





<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="../op.php">Over Permission</a>
                </li>
                <li class="active">op1 member</li>
            </ul><!-- /.breadcrumb -->
            <a href="#" style="float:right" data-container="body" data-toggle="popover" data-placement="bottom" title="tips(再点一下关闭)"
               data-content="这里可以查别人的信息吗?">
                点一下提示~
            </a>

        </div>
        <div class="page-content">
            <div id="mem_main">
                <p class="mem_title">欢迎来到个人信息中心  | <a style="color:bule;" href="op1_mem.php?logout=1">退出登录</a></p>
                <form class="msg1" method="get">
                    <input type="hidden" name="username" value="<?php echo $_SESSION['op']['username']; ?>" />
                    <input type="submit" name="submit" value="点击查看个人信息" />
                </form>
                <?php echo $html;?>

            </div>


        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->






<?php
include_once $PIKA_ROOT_DIR . 'footer.php';

?>
View Code

源码分析:

未使用session来校验,直接将username带入到查询,这样将username修改为其他用户,即可查看其它用户的个人信息。

修复:权限校验出现问题,这里应该跟登录态关系进行绑定。

if(isset($_GET['submit']) && $_GET['username']!=null){
  $username=escape($link, $_GET['username']);
  $query="select * from member where username='$username'";
  $result=execute($link, $query);

漏洞验证:

用户:lucy     用户:lili

使用lucy登录成功后,查看个人信息,修改url中username=lili

http://192.168.10.7:85/pikachu-master/vul/overpermission/op1/op1_mem.php?username=lili&submit=点击查看个人信息

垂直越权

管理员和普通用户之间越权。

管理员才可以添加用户,我们将管理员cookie:PHPSESSID替换成普通用户的cookie:PHPSESSID,即可用普通用户执行管理员才有的添加用户权限功能。

源码:

<?php
/**
 * Created by runner.han
 * There is nothing new under the sun
 */


$SELF_PAGE = substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);

if ($SELF_PAGE = "op2_admin_edit.php"){
    $ACTIVE = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','active open','','','active','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
}
$PIKA_ROOT_DIR =  "../../../";
include_once $PIKA_ROOT_DIR . 'header.php';
include_once $PIKA_ROOT_DIR.'inc/mysql.inc.php';
include_once $PIKA_ROOT_DIR.'inc/function.php';
include_once $PIKA_ROOT_DIR.'inc/config.inc.php';

$link=connect();
// 判断是否登录,没有登录不能访问
//这里只是验证了登录状态,并没有验证级别,所以存在越权问题。
if(!check_op2_login($link)){
    header("location:op2_login.php");
    exit();
}
if(isset($_POST['submit'])){
    if($_POST['username']!=null && $_POST['password']!=null){//用户名密码必填
        $getdata=escape($link, $_POST);//转义
        $query="insert into member(username,pw,sex,phonenum,email,address) values('{$getdata['username']}',md5('{$getdata['password']}'),'{$getdata['sex']}','{$getdata['phonenum']}','{$getdata['email']}','{$getdata['address']}')";
        $result=execute($link, $query);
        if(mysqli_affected_rows($link)==1){//判断是否插入
            header("location:op2_admin.php");
        }else {
            $html.="<p>修改失败,请检查下数据库是不是还是活着的</p>";

        }
    }
}


if(isset($_GET['logout']) && $_GET['logout'] == 1){
    session_unset();
    session_destroy();
    setcookie(session_name(),'',time()-3600,'/');
    header("location:op2_login.php");

}



?>





<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="../op.php">Over Permission</a>
                </li>
                <li class="active">op2 admin edit</li>
            </ul><!-- /.breadcrumb -->
            <a href="#" style="float:right" data-container="body" data-toggle="popover" data-placement="bottom" title="tips(再点一下关闭)"
               data-content="想知道当超级boss是什么滋味吗">
                点一下提示~
            </a>

        </div>
        <div class="page-content">
            <div id="edit_main">
                <p class="edit_title">hi,<?php if($_SESSION['op2']['username']){echo $_SESSION['op2']['username'];} ?>,欢迎来到后台管理中心 | <a style="color:bule;" href="op2_admin_edit.php?logout=1">退出登录</a>|<a href="op2_admin.php">回到admin</a></p>

                <form class="from_main" method="post">
                    <label>用户:<br /><input type="text" name="username" placeholder="必填"/></label><br />
                    <label>密码:<br /><input type="password" name="password" placeholder="必填"/></label><br />
                    <label>性别:<br /><input type="text" name="sex" /></label><br />
                    <label>电话:<br /><input type="text" name="phonenum" /></label><br />
                    <label>邮箱:<br /><input type="text" name="email" /></label><br />
                    <label>地址:<br /><input type="text" name="address" /></label><br />
                    <input class="sub" type="submit" name="submit" value="创建" />
                </form>


            </div>


        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->




<?php
include_once $PIKA_ROOT_DIR . 'footer.php';

?>
View Code

源码分析:

判断是否登录,没有登录不能访问
这里只是验证了登录状态,并没有验证级别,所以存在越权问题。
if(!check_op2_login($link)){
  header("location:op2_login.php");
  exit();
}

漏洞验证:

管理员账号:admin   普通用户:pikachu

使用管理员账号admin登录后,添加用户,将添加用户的数据包使用Burp抓包,发送到重发器中。

退出管理员,使用pikachu登录,使用pikachu用户的phpsessid替换重发器中管理员的phpsessid,进行添加用户:

 ../../(目录遍历)

目录遍历漏洞,在web功能设计中,很多时候我们会要将需要访问的文件定义成变量,从而让前端的功能便的更加灵活。

当用户发起一个前端的请求时,便会将请求的这个文件的值(比如文件名称)传递到后台,后台再执行其对应的文件。 在这个过程中,如果后台没有对前端传进来的值进行严格的安全考虑,则攻击者可能会通过“../”这样的手段让后台打开或者执行一些其他的文件。 从而导致后台服务器上其他目录的文件结果被遍历出来,形成目录遍历漏洞。

看到这里,你可能会觉得目录遍历漏洞和不安全的文件下载,甚至文件包含漏洞有差不多的意思,是的,目录遍历漏洞形成的最主要的原因跟这两者一样,都是在功能设计中将要操作的文件使用变量的 方式传递给了后台,而又没有进行严格的安全考虑而造成的,只是出现的位置所展现的现象不一样,因此,这里还是单独拿出来定义一下。

需要区分一下的是,如果你通过不带参数的url(比如:http://xxxx/doc)列出了doc文件夹里面所有的文件,这种情况,我们成为敏感信息泄露。 而并不归为目录遍历漏洞。

目录遍历

源码:

<?php
/**
 * Created by runner.han
 * There is nothing new under the sun
 */


$SELF_PAGE = substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);

if ($SELF_PAGE = "dir.php"){
    $ACTIVE = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','active open','','active','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
}

$PIKA_ROOT_DIR =  "../../";
include_once $PIKA_ROOT_DIR . 'header.php';

$html='';
if(isset($_GET['title'])){
    $filename=$_GET['title'];
    //这里直接把传进来的内容进行了require(),造成问题
    require "soup/$filename";
//    echo $html;
}
?>


<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="dir.php">目录遍历</a>
                </li>
                <li class="active">../../</li>
            </ul><!-- /.breadcrumb -->

            <a href="#" style="float:right" data-container="body" data-toggle="popover" data-placement="bottom" title="tips(再点一下关闭)"
               data-content="先好好读一下这两篇小短文在继续学习吧..">
                点一下提示~
            </a>

        </div>
        <div class="page-content">
            <div id="dt_main">
                <p class="dt_title">(1)it's time to get up!</p>
                <a class="dt_title" href="dir_list.php?title=jarheads.php">we're jarheads!</a>
                <p class="dt_title">(2)it's time to say goodbye!</p>
                <a class="dt_title" href="dir_list.php?title=truman.php">Truman's word!</a>
            </div>
            <br />
            <br />
            <div>
                <?php echo $html;?>
            </div>
        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->


<?php
include_once $PIKA_ROOT_DIR . 'footer.php';

?>
View Code

源码分析:

这里直接把传进来title进行了require(),造成问题

if(isset($_GET['title'])){
  $filename=$_GET['title'];
  require "soup/$filename";
  // echo $html;
}
?>

漏洞验证:

通过目录遍历漏洞读取服务器上的phpinfo.php文件

payload : ../../../../phpinfo.php

构造url--->http://192.168.10.7:85/pikachu-master/vul/dir/dir_list.php?title=../../../../phpinfo.php

敏感信息泄露

敏感信息泄露,由于后台人员的疏忽或者不当的设计,导致不应该被前端用户看到的数据被轻易的访问到。

例如:
  通过访问url下的目录,可以直接列出目录下的文件列表
  输入错误的url参数后报错信息里面包含操作系统、中间件、开发语言的版本或其他信息
  前端的源码(html,css,js)里面包含了敏感信息,比如后台登录地址、内网接口信息、甚至账号密码等

类似以上这些情况,我们成为敏感信息泄露。敏感信息泄露虽然一直被评为危害比较低的漏洞,但这些敏感信息往往给攻击着实施进一步的攻击提供很大的帮助,甚至“离谱”的敏感信息泄露也会直接造成严重的损失。

因此,在web应用的开发上,除了要进行安全的代码编写,也需要注意对敏感信息的合理处理。

lcanseeyourABC(敏感信息泄露)

源码:

<?php
/**
 * Created by runner.han
 * There is nothing new under the sun
 */


$SELF_PAGE = substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);

if ($SELF_PAGE = "findabc.php"){
    $ACTIVE = array('','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','active open','','active','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
}

$PIKA_ROOT_DIR =  "../../";
include_once $PIKA_ROOT_DIR.'header.php';
include_once $PIKA_ROOT_DIR.'inc/function.php';
include_once $PIKA_ROOT_DIR.'inc/mysql.inc.php';
include_once $PIKA_ROOT_DIR.'inc/config.inc.php';


$link=connect();
$html='';
if(isset($_GET['submit'])){
    if($_GET['username']!=null && $_GET['password']!=null){
        $username=escape($link, $_GET['username']);
        $password=escape($link, $_GET['password']);



        $query="select * from member where username='$username' and pw=md5('$password')";
        $result=execute($link, $query);
        if(mysqli_num_rows($result)==1){
            $data=mysqli_fetch_assoc($result);
            setcookie('abc[uname]',$_GET['username'],time()+36000);
            setcookie('abc[pw]',md5($_GET['password']),time()+36000);
            //登录时,生成cookie,10个小时有效期,供其他页面判断
            header("location:abc.php");
        }else{
            $query_username = "select * from member where username='$username'";
            $res_user = execute($link,$query_username);
            if(mysqli_num_rows($res_user) == 1){
                $html.="<p class='notice'>您输入的密码错误</p>";

            }else{
                $html.="<p class='notice'>您输入的账号错误</p>";
            }

        }
    }
}


?>


<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="infoleak.php">敏感信息泄露</a>
                </li>
                <li class="active">find abc</li>
            </ul>

            <a href="#" style="float:right" data-container="body" data-toggle="popover" data-placement="bottom" title="tips(再点一下关闭)"
               data-content="找找看,很多地方都漏点了...">
                点一下提示~
            </a>
        </div>
        <div class="page-content">

            <div class="form">
                <div class="form_main">
                    <h4 class="header blue lighter bigger">
                        <i class="ace-icon fa fa-coffee green"></i>
                        Please Enter Your Information
                    </h4>

                    <form method="get">
                        <!--            <fieldset>-->
                        <label>
                                                        <span>
                                                            <input type="text" name="username" placeholder="Username" />
                                                            <i class="ace-icon fa fa-user"></i>
                                                        </span>
                        </label>
                        </br>

                        <label>
                                                        <span>
                                                            <input type="password" name="password" placeholder="Password" />
                                                            <i class="ace-icon fa fa-lock"></i>
                                                        </span>
                        </label>


                        <div class="space"></div>

                        <div class="clearfix">
                            <label><input class="submit" name="submit" type="submit" value="Login" /></label>
                        </div>

                    </form>
                    <?php echo $html;?>


                </div><!-- 测试账号:lili/123456-->

            </div><!-- /.widget-body -->


        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->



<?php
include_once $PIKA_ROOT_DIR . 'footer.php';

?>
View Code

源码分析:

前端代码中泄露了测试账号和密码

漏洞验证

直接输入:http://192.168.10.7:85/pikachu-master/vul/infoleak/abc.php    即可登录,不需要输入用户名和密码。

 

posted on 2020-08-10 16:44  赛兔子  阅读(185)  评论(0编辑  收藏  举报

导航