NSSCTF靶场练习[HUBUCTF 2022 新生赛]

news/2024/5/19 22:48:16 标签: java, python, 学习, CTF

CTF_2022_simple_RE_2">[HUBUCTF 2022 新生赛]simple_RE

签到题

image-20231215130257668

一个base64编码,自定义了码表、

image-20231215130427216

image-20231215130352731


CTF_2022_ezPython_16">[HUBUCTF 2022 新生赛]ezPython

py逆向,用在线网站反编译一下

image-20231215130550656

先解一次base64,再解一次base58

image-20231215130657140

接着再把 password转换成 bytes的形式做一次md5加密就好

python">from Crypto.Util.number import *
import hashlib
flag = 22385992650816784030032474165
print(hashlib.md5(long_to_bytes(flag)).hexdigest())
# fd78ee3399dd6a3c1d0b637fdca0c075

CTF_2022_help_38">[HUBUCTF 2022 新生赛]help

迷宫题

image-20231215100236596

点开CreatMap,这里是创建迷宫,

image-20231215100256673

顺带运行一下程序,发现程序并没有我们打印出迷宫,所以自己把代码copy一下,得到

image-20231215100316353

由check可以知道,我们是从 (15,, 1)的位置开始的,没有结束位置,只有path长度为54这一条件,其实看迷宫就可以发现(13,15)应该就是出口。

EXP:

python">maze = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]


maze[16*13+15] = 2
# maze[x * 21 + y]
def check_point_valid(map, x, y):
    if (x >= 0) and (x < 16) and (y >= 0) and (y < 16):
        return (map[x * 16 + y] != 1) and ((map[x * 16 + y] == 0) or (map[x * 16 + y] == 2))
    else:
        return False


def gen_nex(map, x, y):
    all_dir = []
    # if check_point_valid(map, x - 1, y, z):
    # all_dir.append((x - 1, y, z, 'q'))
    # if check_point_valid(map, x + 1, y, z):
    # all_dir.append((x + 1, y, z, 'u'))
    if check_point_valid(map, x + 1, y):
        all_dir.append((x + 1, y, 's'))
    if check_point_valid(map, x - 1, y):
        all_dir.append((x - 1, y, 'w'))
    if check_point_valid(map, x, y - 1):
        all_dir.append((x, y - 1, 'a'))
    if check_point_valid(map, x, y + 1):
        all_dir.append((x, y + 1, 'd'))
    return all_dir


def check_success(map, x, y):
    if map[x * 16 + y] == 2:
        return True
    else:
        return False


def dfs(mapb, x, y, path):
    map = mapb.copy()
    if map[x * 16 + y] != 2:
        map[x * 16 + y] = 1
    if check_success(map, x, y):
        print(path)
        return True

    next_point = gen_nex(map, x, y)
    for n in next_point:
        pathn = path + n[2]
        dfs(map, n[0], n[1], pathn)


outpus = ""
dfs(maze, 15, 1, outpus)
# wwdddwwwaaawwwwwwwwwddddssssdddssdsssssssdddwwwwddsssd

之后再加上md5就好了。


CTF_2022_AngerAngr___116">[HUBUCTF 2022 新生赛]Anger?Angr (没解决)

image-20231215125826669

可以使用z3解,比较麻烦,约束条件全部复制出来处理一下。

预期解是angr符号执行。第一次接触,也不太懂。

在angr_ctf上面有很多练习。

这里先找到 puts("Correct!");的地址

image-20231215130039617

借用脚本:

python">import angr
import sys
import claripy

p = angr.Project('./anger', auto_load_libs = True)
initial_state = p.factory.entry_state(
    add_options = { angr.options.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
                    angr.options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS}
  )
s = p.factory.simgr(initial_state)
s.one_active.options.add(angr.options.LAZY_SOLVES)
def is_successful(state):
    stdout_output = state.posix.dumps(sys.stdout.fileno())
    if "Cor".encode() in stdout_output:
        return True
    else:
        return False

def should_abort(state):
    stdout_output = state.posix.dumps(sys.stdout.fileno())
    if "Incor".encode() in stdout_output:
        return True
    else:
        return False

s.explore(find=is_successful,avoid=should_abort)
f = s.found[0].posix.dumps(sys.stdin.fileno())
print(f)

这样可以爆破解出 一串字符串。

但是很奇怪,不太好解决。

还是用回z3了

python">from z3 import *

a1 =  [BitVec('a1%s' % i,8) for i in range(32) ]
print(a1)
s=Solver()
s.add(BV2Int(a1[10]) <= 40 , 24 * BV2Int(a1[30]) % 84 == 12 , BV2Int(a1[16]) != 66)
s.add(BV2Int(a1[4]) > 51 , BV2Int(a1[15]) > 90 , BV2Int(a1[18]) != 38)

s.add(BV2Int(a1[3]) <= 107 , 61 * BV2Int(a1[20]) % 95 == 2 , BV2Int(a1[27]) != 67)
s.add(BV2Int(a1[29]) <= 69 , 39 * BV2Int(a1[18]) % 57 == 27 , BV2Int(a1[29]) <= 90)
s.add(a1[21] > 42 , a1[0] > 35 , a1[7] != 74)
s.add(a1[19] <= 79 , a1[15] > 74 , a1[22] > 92)
s.add(a1[14]<=89,a1[24]!=95)
s.add( a1[26] > 36)
s.add(a1[22]>53,BV2Int(a1[12])!=33)
s.add( (29 * BV2Int(a1[6])) % 33 == 24)
s.add( 41 * BV2Int(a1[26]) % 31 == 27)
s.add(BV2Int(a1[16]) != 71  )
s.add( 22 * BV2Int(a1[24]) % 96 == 60)
s.add(a1[25] != 102  , a1[18] != 95)
s.add( 38 * BV2Int(a1[6]) % 54 == 36)
s.add(a1[4]>52)
s.add(a1[11]<=76)
s.add( 72 * BV2Int(a1[6]) % 86 == 42 )
s.add(a1[5] <= 109 , a1[9] > 44 , a1[8] > 77)
s.add(a1[28] != 107  , a1[17] > 73)
s.add( 69 * BV2Int(a1[5]) % 3==0)
s.add(a1[0] != 70 , a1[13] > 72 , a1[1] <= 108)
s.add(a1[14]!=97)
s.add(a1[1]<=90)
s.add( 87 * BV2Int(a1[31]) % 69 == 45)
s.add(a1[11] <= 99 , a1[24] != 107 , a1[26] <= 111)
s.add(a1[0] > 36 , a1[3] <= 65 , a1[2] > 41)
s.add(a1[23] != 84 , a1[16] != 101 , a1[13] <= 99)
s.add(a1[19] > 33 , a1[25] <= 122 , a1[28] != 67)
s.add(86 * BV2Int(a1[17]) % 74 == 64 , BV2Int(a1[10]) != 87 , BV2Int(a1[30]) <= 108)
s.add(BV2Int(a1[8])!=87)
s.add(46 * BV2Int(a1[12]) % 26 == 20 , 50 * BV2Int(a1[9]) % 52 == 22)
s.add(BV2Int(a1[8]) > 47 ,BV2Int(a1[21]) <= 100 , BV2Int(a1[11]) > 34)
s.add(BV2Int(a1[27]) != 127 , BV2Int(a1[21]) > 42 )
s.add( 5 * BV2Int(a1[10]) % 32 == 20)
s.add( BV2Int(a1[12]) <= 107)
s.add(BV2Int(a1[19]) != 91  , BV2Int(a1[29]) != 124)
s.add( 57 * BV2Int(a1[13]) % 13 == 2 , BV2Int(a1[27]) <= 100 , 61 * BV2Int(a1[22]) % 67 == 66)
s.add(BV2Int(a1[7]) <= 118 , BV2Int(a1[1]) != 64 , BV2Int(a1[30]) > 44)
s.add(BV2Int(a1[5]) != 43 , BV2Int(a1[31]) != 88 , BV2Int(a1[31]) > 35)
s.add(BV2Int(a1[20]) <= 101 , BV2Int(a1[15]) > 64 , BV2Int(a1[4]) != 43)

s.add(BV2Int(a1[17])>56)
s.add(BV2Int(a1[28])<=115)
s.add( (BV2Int(a1[25]) *64) % 21 == 4 )
s.add(BV2Int(a1[20]) != 43 , BV2Int(a1[2]) <= 82 , BV2Int(a1[2]) > 39)
s.add(BV2Int(a1[23]) > 34 , BV2Int(a1[7]) > 52 , BV2Int(a1[14]) > 44)
s.add(BV2Int(a1[3]) <= 83 , 59 * BV2Int(a1[9]) % 86 == 69 , BV2Int(a1[23]) <= 103)
for i in range(0,32):
    s.add(BV2Int(a1[i])<127)
    s.add(BV2Int(a1[i])>30)
s.check()
m=s.model()
print(m)
res=''
for i in range(0,32):
    res+=(chr(m[a1[i]].as_long()))
print(res)

别人的wp。可以用z3解

来源:https://www.nssctf.cn/note/set/1508

之后再把程序运行一下,输入字符串就可以得到flag了。


http://www.niftyadmin.cn/n/5268925.html

相关文章

用sqlite制作对局记录管理

1. sqlite简介 sqlite是一款非常轻便小巧的数据库&#xff0c;以C语言开发&#xff0c;已流行了数十年&#xff0c;据说是世界上部署最多的数据库。为什么是部署最多的呢&#xff1f;因为它根本不需要数据库服务器&#xff0c;且可以在任意设备、任意操作系统上部署。因此&…

在linux下正确安装部署locust

我们在安装python&#xff0c;pip之后&#xff0c;利用pip安装locust并不能执行相应的locust命令&#xff0c;原因是linux下面无像在windows下面pycharm一样的解释器&#xff0c;这个时候需要创建虚拟环境&#xff0c;在虚拟环境下面能运行的环境中&#xff0c;才能运行locust&…

在Linux上使用mysqldump备份MySQL数据库的详细步骤

MySQL数据库备份是确保数据安全性的关键步骤之一。在Linux系统上&#xff0c;使用mysqldump工具是一种常见、可靠的方法&#xff0c;它能够导出数据库的结构和数据&#xff0c;以便在需要时进行还原。以下是详细的备份步骤&#xff1a; 步骤 1&#xff1a;登录到MySQL服务器 …

Codeforces Round 915 (Div. 2)(A~C)

坐牢一个半小时...D、E待补(太菜了&#xff0c;做的题还是太少了&#xff09; A - Constructive 问题集 思路&#xff1a;手画一下发现&#xff1a;n个城市最多能重建n * n 的城市&#xff0c;所以n * m 需要重建max(n , m)个城市。 // Problem: A. Constructive Problems /…

ffmpeg踩坑之手动编译报错Unrecognized option ‘preset‘及rtsp/rtmp推流

本文解决的问题记录&#xff1a; 报错1&#xff1a;Unrecognized option preset. Error splitting the argument list: Option not found 报错2&#xff1a;ERROR: x264 not found using pkg-config 报错3&#xff1a;ffmpeg: error while loading shared libraries: libavd…

c# bitmap压缩导致png不透明的问题解决

新建.net 6控制台项目 安装System.Drawing.Common包 代码如下 using System.Drawing; using System.Drawing.Imaging;namespace PngCompress02 {internal class Program{static void Main(string[] args){CompressPngImage("E:\Desktop\6.png", "E:\Desktop\6…

npm install老是卡住是什么问题

最简单的vue项目我install的时候都出现了问题,给我苦恼的,经过我的仔细对比发现: 从网上搜索的这个镜像源是存在问题的,很多资源是下载不了的,没有深究为什么,就这个淘宝的: npm config set registry https://registry.npm.taobao.org/ 换成下面的这个国内镜像源就好了 n…

springboot服务或者gateway网关将http改为https

1.去阿里云服务器&#xff0c;搜索ssl证书&#xff0c;免费申请 2.下载证书 因为是springboot服务&#xff0c;所以使用Tomcat或者JKS(JDK支持的类型) 3.配置 server: ssl: enable: true key-store: classpath: 自定义ssl证书文件 key-store-t…