buuctf:摆烂杯(web_一行代码)

打开链接

给了一长串代码

<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2021-11-18 21:25:22
# @Last Modified by:   h1xa
# @Last Modified time: 2021-11-18 22:14:12
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/



echo !(!(include "flag.php")||(!error_reporting(0))||stripos($_GET['filename'],'.')||($_GET['id']!=0)||(strlen($_GET['content'])<=7)||(!eregi("ctfsho".substr($_GET['content'],0,1),"ctfshow"))||substr($_GET['content'],0,1)=='w'||(file_get_contents($_GET['filename'],'r') !== "welcome2ctfshow"))?$flag:str_repeat(highlight_file(__FILE__), 0);

echo !()?xxx:yyy,这是一个条件判断句,首先把条件整理出来,如下

需要保证该条件为真,如下

!(!(include "flag.php")||(!error_reporting(0))||stripos($_GET['filename'],'.')||($_GET['id']!=0)||(strlen($_GET['content'])<=7)||(!eregi("ctfsho".substr($_GET['content'],0,1),"ctfshow"))||substr($_GET['content'],0,1)=='w'||(file_get_contents($_GET['filename'],'r') !== "welcome2ctfshow"))
上面的条件为true则输出flag,那么需要下面的表达式为false
!(include "flag.php")||(!error_reporting(0))||stripos($_GET['filename'],'.')||($_GET['id']!=0)||(strlen($_GET['content'])<=7)||(!eregi("ctfsho".substr($_GET['content'],0,1),"ctfshow"))||substr($_GET['content'],0,1)=='w'||(file_get_contents($_GET['filename'],'r') !== "welcome2ctfshow")

因为是或(||)的关系,所以必须保证每个条件都为flase

  1. !(include "flag.php")===False;
  2. (!error_reporting(0))===False;
  3. stripos($_GET['filename'],'.')===False;
  4. ($_GET['id']!=0)===False;
  5. (strlen($_GET['content'])<=7)===False;
  6. (!eregi("ctfsho".substr($_GET['content'],0,1),"ctfshow"))===False;
  7. (substr($_GET['content'],0,1)=='w')===False;
  8. (file_get_contents($_GET['filename'],'r') !== "welcome2ctfshow")===False

第一、二个条件是一定成立的;

3.stripos() 函数查找字符串在另一字符串中第一次出现的位置(不区分大小写)。stripos(string,find,start)有三个参数,string(必须)是需要操作的字符串,find(必须)是需要查找的字符,start(可选)是开始查找的位置,若start不选即默认从零号位开始查找find数据在string第一次出现的位置.第三个是要$filename中没有.

4.第四个是$id=0

5.第五个是$_GET['content'] 长度必须大于7

6.eregi(string,string)   作用:用后一个字符串匹配前一个字符串,若后一个字符串存在前一个则返回true反之返回false,并且该函数不区分大小写。substr(string,start,length),substr() 函数返回字符串的一部分。第六个是让ctfsho$content的第一个字符拼接后值为ctfshow

7.第七个是$_GET['content'] 第一个字符不能是w,因此这里可以用大写W绕过;

8.第八个是$_GET['filename']读取后,值为welcome2ctfshow

构造playload

GET:
?id=0&content=W1111111&filename=php://input

POST:
welcome2ctfshow

 

web签到

 

 

 随意输入三个数

 

发现在逻辑上并不能让其等于114,输入其他字符则返回hacker!!!!

 

 但是我们可以用数学符号

 所以可以构造

 

 即

A=114)+(0 B=1 C=-1

从而获得flag

 

 

posted @ 2022-01-05 21:34  微草wd  阅读(214)  评论(0)    收藏  举报