zer0pts CTF 2022 && VishwaCTF 2022

[zer0pts CTF 2022 Misc]MathHash

import struct
import math
import signal
import os

def MathHash(m):
    hashval = 0
    for i in range(len(m)-7):
        c = struct.unpack('<Q', m[i:i+8])[0]
        t = math.tan(c * math.pi / (1<<64))
        hashval ^= struct.unpack('<Q', struct.pack('<d', t))[0]
    return hashval

if __name__ == '__main__':
    FLAG = os.getenv('FLAG', 'zer0pts<sample_flag>').encode()
    assert FLAG.startswith(b'zer0pts')

    signal.alarm(1800)
    try:
        while True:
            key = bytes.fromhex(input("Key: "))
            assert len(FLAG) >= len(key)

            flag = FLAG
            for i, c in enumerate(key):
                flag = flag[:i] + bytes([(flag[i] + key[i]) % 0x100]) + flag[i+1:]

            h = MathHash(flag)
            print("Hash: " + hex(h))
    except:
        exit(0)

先简单看一下,要输入16进制数,并且长度不能超过flag的长度。因此先一直输入00来找到flag长度看看
在这里插入图片描述
好的,长度为25。那么本地假定一个flag为zer0pts{abcdefghijklmnop}
windows上运行会在signal.alarm(1800)处报错,直接删掉就可以了,这个是linux下信号处理的,超过1800秒断开用户的连接。

然后本地输入测试
在这里插入图片描述
可以发现这里就是(flag[i] + key[i]) % 0x100过程
那么重点就在MathHash函数中,在每次的结尾都print一下,即print(c,t,hashval)
细心的可以发现,单单修改开头字节对结果的影响不大,再看一下mathhash函数中,是使用的<Q,那么前面是低位后面是高位。

这里又突然想到,既然每次是8位8位的取,而且开头8位已知。
这里能够很轻松的得到使得第一次为全0的输入为869b8ed0908c8d85
在这里插入图片描述
再注意到,hashval的值是采用异或操作得到的
hashval ^= struct.unpack('<Q', struct.pack('<d', t))[0]
再因为是小端,只要修改最右边的一位,第一组的数字将会非常之大

在这里插入图片描述
因此如果是正确的值,会得当前c的值为0,相当于会少一次异或的操作,这样得到的hash值的变化会非常大。所以这道题的做法应该为侧信道攻击。

但是由于对自动化取值没啥想法(简称不会写)也不想去写(嗯),因此就自己人工判断了,相当于半自动化。
如果在运行中卡住了,这里因为很贴心的输出了flag的值,所以可以修改flag的值重新运行脚本。

from pwn import *
p = remote('misc.ctf.zer0pts.com',10001)
# real_flag = 'zer0pts{s1gn+|3xp^|fr4c.}'
flag = 'zer0pts{'
p.recvuntil(b'Key:')
while 1:
    hex_flag = ''
    for i in flag:
        hex_flag += hex(256-ord(i))[2:].zfill(2)
    for i in range(115,233):
        hex2_flag = hex_flag + hex(i)[2:].zfill(2)
        p.sendline(hex2_flag.encode())
        rec = p.recvuntil(b'Key:')
        print(hex(i),hex(255-i),chr(255-i),rec)
    real = input('请输入你观察到的hex数:(第一列的,如0x66)')
    flag += chr(255-eval(real))
    print(flag)

举个栗子(前两位)
在这里插入图片描述
此时为变化点,因此为s,脚本后输入0x8c

在这里插入图片描述
因此输入0xce
一直这样下去,最后得到flag

zer0pts{s1gn+|3xp^|fr4c.}

[VishwaCTF 2022 Forensic]So Forgetful!

Once my friend was connected to my network, he did some office work and left. Next day he called me that he forgot his password, and wanted me to rescue him ❤️

在这里插入图片描述
找到base64编码后的密码,解码得到KN1Z6PXVy9

vishwactf{KN1Z6PXVy9}

[VishwaCTF 2022 Forensic]The Last Jedi

010查看图片文件,发现尾部有额外数据,看到 Rar文件头判断为rar,手动分离,解压Rar得到另一张图片,在该图片文件尾得到flag

flag:{H1DD3N_M34N1NG}

[VishwaCTF 2022 Forensic]Keep the flag high

The great Pirate Narao Gosco has your flag but pirates are hard to fight. Can you rotate the ch4n7es in your favor?

下载下来是一个bmp文件,但用010打开发现IHDRIDATIEND字样,判断为PNG文件,因此修复文件头为png的头,能够得到一张二维码,扫码后跳转云盘,是一张jpg图片,下载下来。

在文件尾发现异常数据在这里插入图片描述
都是printable的范围,尝试rot47,发现flag字样,只不过是倒过来的,因此再reverse一次
在这里插入图片描述

VishwaCTF{f0r3nsic5_is_t3di0us}

[VishwaCTF 2022 Forensic]Garfeld?

Garfeld can hide secrets pretty well.

wav文件,用Au打开
默认频率0~8000,因此改成很大再看一下

在这里插入图片描述
选中该部分看一下
在这里插入图片描述

发现链接,放大查看
在这里插入图片描述

https://pastebin.com/kTX7HTmm
访问得到一串hex,转换一下得到一张jpg图片
010查看文件头异常,修改一下

在这里插入图片描述
得到xjslxjKCH{j_hidtqw_npvi_mjajioa}
flag格式为vishwaCTF,如果是rot那么x不可能同时代表v和w。
猜测变异凯撒,尝试后发现无规律
猜测维吉尼亚,首先用密文做密文,flag格式做key,解密得到开头为cbaebjIJC
将其作为key解密,得到vishwaCTF{h_gizsho_enth_mfzaafy}
然后想到key的开头结尾都为C,尝试将cbaebjIJ作为key,得到flag

vishwaCTF{i_heckin_love_lasagna}

[VishwaCTF 2022 Steganography]Incomplete

Why do i feel that this is incomplete?

打开png图片,发现一段英文和一个钥匙。
010打开png,发现文件尾有很长一段的额外数据
拉到最下面,发现oursecret特征块
在这里插入图片描述
猜测带key的oursecret,密码在图片上
在这里插入图片描述
YKIXKZ SKKZOTM GZ ZNK VGRGIK
rot13 偏移20得到key
SECRET MEETING AT THE PALACE
得到flag.alg文件

打开看一下文件头,发现是wav文件
因此修改为flag.wav,用AU打开,查看频谱得到flag

在这里插入图片描述

VishwaCTF{sp3c70gram_crack3d}

[VishwaCTF 2022 Steganography]Vision

刚开始flag还放错了,联系了管理才改对的。

一张png图片,010打开,再次在文件尾发现oursecret特征
在这里插入图片描述
此次该文件不需要key,直接解出文件
得到一张图片
在这里插入图片描述

根据解码方式,判断这张图很可能是piet
在这里插入图片描述

VishwaCTF{bl1nd3d_by_th3_col0r5}

[VishwaCTF 2022 Web]Hey Buddy!

Hum,输入123回显hello 123,而且url很明显的?name=,猜测ssti
fuzz的时候发现好像只过滤了空格,因此用${IFS}绕过
payload:https://h3y-buddy.vishwactf.com/submit?name={ {x.__init__.__globals__[%27__builtins__%27].eval(%27__import__(%22os%22).popen(%22cat${IFS}flag.txt%22).read()%27)}}
得到flag

VishwaCTF{S3rv3r_1s_4fraiD_of_inj3c7ion}

[VishwaCTF 2022 Web]My Useless Website

万能密码登录即可
https://my-us3l355-w3b51t3.vishwactf.com/?user=1%27%20or%201=1–+&pass=1

VishwaCTF{I_Kn0w_Y0u_kn0W_t1hs_4lr3ady}

[VishwaCTF 2022 Web]Stock Bot

发送../../../../../../etc/passwd发现能够读到文件,再看代码发现/Products/check.php?product='+msgif(!msg.includes('Flag'))
Hum,直接php://伪协议读一下Flag

注意要在/Products/check.php?product=页面去发包,因为直接在输入框发包会被前端拦下
在这里插入图片描述
https://st0ck-b0t.vishwactf.com/Products/check.php?product=php://filter/convert.base64-encode/resource=Flag

得到flag

VishwaCTF{b0T_kn0w5_7h3_s3cr3t}

[VishwaCTF 2022 Reverse Engineering]Corrupted Image

Hum,不知道为啥放Re,总之将文件头的00 00改成42 4D即可得到flag

VishwaCTF{Windows.lul}

[VishwaCTF 2022 Cryptography]Tallest Header

一个损坏的jpg文件,看文件尾的时候发现zip,于是手动分离
得到两个文件
一个encryption文件

def encrypt(key, plaintext):
    plaintext = "".join(plaintext.split(" ")).upper()
    ciphertext = ""
    for pad in range(0, len(plaintext) % len(key) * -1 % len(key)):
        plaintext += "X"
    for offset in range(0, len(plaintext), len(key)):
        for element in [a - 1 for a in key]:
            ciphertext += plaintext[offset + element]
        ciphertext += " "
    return ciphertext[:-1]

一个info文件

key = [2,1,3,5,4]

ciphertext = RT1KC _YH43 3DRW_ T1HP_ R3M7U TA1N0

阅读代码后可以发现就是交换位置,那么再交换一次就可以得到正确flag

因此直接在后面加上

key = [2,1,3,5,4]
plaintext = 'RT1KC _YH43 3DRW_ T1HP_ R3M7U TA1N0'
encrypt(key,plaintext)

然后在函数中添加print("".join(ciphertext.split(" ")).lower())
得到的结果包裹vishwaCTF提交

vishwaCTF{tr1cky_h34d3r_w1th_p3rmu7at10n}

[VishwaCTF 2022 Miscellaneous]I don’t need sleep, I need answers

Discord profile pictures are circular. But are they? VSauce music plays The Librarian is all knowing, maybe try confronting him? (refer “The Library” challenge, OSINT)

根据题目描述,回答为什么discord头像是圆的,猜测原图是方形被discord压缩成圆形。因此在网页版discord审查元素查看原头像。可以看到flag
在这里插入图片描述

vishwaCTF{h3h3_sn3akyy}
``1

猜你喜欢

转载自blog.csdn.net/qq_42880719/article/details/123596827