BUUCTF Reverse题解:第二部分(持续更新)

qjsswz / 2024-09-02 / 原文

Welcome again, to C12AK's Re journal !


目录
  • 题目传送门
  • 前言
  • 1. [GWCTF 2019]pyre


题目传送门


前言

就是不想上课……Re比上课有意思多了qwq


1. [GWCTF 2019]pyre

下载的文件是.pyc格式,它是.py经编译后的字节码文件,可以使用在线工具进行反编译。我们把文件放入,得到如下代码:

#!/usr/bin/env python
# visit https://tool.lu/pyc/ for more information
# Version: Python 2.7

print 'Welcome to Re World!'
print 'Your input1 is your flag~'
l = len(input1)
for i in range(l):
    num = ((input1[i] + i) % 128 + 128) % 128
    code += num

for i in range(l - 1):
    code[i] = code[i] ^ code[i + 1]

print code
code = [
    '%1f',
    '%12',
    '%1d',
    '(',
    '0',
    '4',
    '%01',
    '%06',
    '%14',
    '4',
    ',',
    '%1b',
    'U',
    '?',
    'o',
    '6',
    '*',
    ':',
    '%01',
    'D',
    ';',
    '%',
    '%13']

此处“%”表示十六进制数。代码逻辑比较简单,就是输入正确的flag,经过两次操作就能变成code字符串。可以直接编写脚本,由code逆向求出flag:

#include<bits/stdc++.h>
using namespace std;

int main(){
    char c[] = {
    '\x1f',
    '\x12',
    '\x1d',
    '(',
    '0',
    '4',
    '\x01',
    '\x06',
    '\x14',
    '4',
    ',',
    '\x1b',
    'U',
    '?',
    'o',
    '6',
    '*',
    ':',
    '\x01',
    'D',
    ';',
    '%',
    '\x13'};
    for(int i = 22; i >= 0; i--) c[i] ^= c[i + 1];
    for(int i = 0; i < 23; i++) c[i] = ((c[i] - i) % 128 + 128) % 128;
    for(int i = 0; i < 23; i++) cout << c[i];
    return 0;
}