快速搭建crypto交互型题目

搭建环境

vps使用的是Ubuntu20.04+docker

dockerfile一般用官方给出来的就行,或者找一个能交互的题目的dockerfile(比赛结束之后去discord或者github)。我的实例中没有用到socket库,这种docker不需要。

在这里不详细解释更细致的内容,一般情况下需要更改的部分是dockerfile中的python版本,额外的库,其他的直接按照部署docker的方式来就行,测试的时候如果中断可能是网络问题。

实例

这是一个交互计算的题目,需要通过计算100个乘法运算,获取最终的flag。

dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FROM python:3.10
# dockerfile of test
RUN apt update && apt upgrade -y
RUN apt install socat -y
RUN pip install pycryptodome
# modify here,from src to dst
ADD calculator.py task.py 
ADD secret.py secret.py
# modify EXEC:
CMD socat -T 2 -dd -v >/dev/stdout TCP-L:60000,fork,reuseaddr EXEC:"python -u task.py"

task script

calculator.py:

 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
import random
from secret import flag
rounds = 100
welcome = """ .----------------.  .----------------.  .----------------.  .----------------. 
| .--------------. || .--------------. || .--------------. || .--------------. |
| |  _________   | || |  _________   | || |    _______   | || |  _________   | |
| | |  _   _  |  | || | |_   ___  |  | || |   /  ___  |  | || | |  _   _  |  | |
| | |_/ | | \_|  | || |   | |_  \_|  | || |  |  (__ \_|  | || | |_/ | | \_|  | |
| |     | |      | || |   |  _|  _   | || |   '.___`-.   | || |     | |      | |
| |    _| |_     | || |  _| |___/ |  | || |  |`\____) |  | || |    _| |_     | |
| |   |_____|    | || | |_________|  | || |  |_______.'  | || |   |_____|    | |
| |              | || |              | || |              | || |              | |
| '--------------' || '--------------' || '--------------' || '--------------' |
 '----------------'  '----------------'  '----------------'  '----------------' """
def task():
    print(welcome)
    for _ in range(rounds):
        a,b = random.randint(1,1000),random.randint(1,1000)
        c = a*b
        cho = input(f"Please input your answer of {a}*{b}:")
        if cho == str(c):
            print("Right!")
        else:
            exit("Wrong...")
    print(f"Here is your flag:{flag}")
    
task()

secret.py:

1
2
3
4
from uuid import uuid1
# test = "flag{"+str(uuid1()) + "}"
# print(test)
flag = "flag{.....}"

write up

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# solve.py
from pwn import *
ip=""
port=
p = remote(ip,port)
pad = "Please input your answer of "
p.recvlines(11)  # 跳过welcome
while 1:
    res = p.recv()
    print(res)
    if b"flag{" in res:
        exit(res)
    l = res[len(pad):-1].split(b"*")
    ans = str(int(l[0])*int(l[1]))
    p.sendline(bytes(ans.encode()))
    a=p.recvline()
    print(a)

bash

1
2
3
4
docker build -t test .
# vps端口:容器端口, 容器名称:镜像名称
docker run -d -p 50000:60000 --name cryptotest test
# 这样容器一直在运行,只需要nc访问对应的端口就可以了

其他

ASCII艺术字

有时候题目开始的时候会有一个题目的名字显示,在终端中用ascii艺术字展示的,这里有网站可以实现这种方法(或者搜索ascii艺术字也可以):

艺术字网站:patorjk

域名+端口的说明

一些比赛给的靶机带有域名,可以使用反向代理,但是我没有试过,有时间可能会试试(可能有更简单的方法,有时间研究一下)。

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy