题目名:大佬请喝coffee
分类:re
来源:moectf
链接:https://www.moectf.online/challenges
思路:
题目给了一个.class文件,这个是java生成的二进制文件,可以通过在线工具反编译成Java的文本文件.java。
在线反编译工具:http://www.javadecompilers.com/
或者 http://www.javare.cn/
反编译得到源代码如下:
package coffee;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Coffee {
public static void main(String[] var0) {
System.out.println("<--- moectf2021 --->");
System.out.println(" [coffee] Welcome to moectf2021.");
System.out.println("It will be quite ez for you. I guess.");
System.out.print("Input your flag : ");
String inputS = null;
try {
inputS = (new BufferedReader(new InputStreamReader(System.in))).readLine();
} catch (Exception var3) {
System.out.println("ERROR: Undefined Exception.");
}
if(inputS.length() != 9) {
System.out.println("QwQ. You are wrong.");
}
else {
char[] a = inputS.toCharArray();
if(a[0]*4778+a[1]*3659+a[2]*9011+a[3]*5734+a[4]*4076+a[5]*6812+a[6]*8341+a[7]*6765+a[8]*7435 == 5711942 &&
a[0]*4449+a[1]*5454+a[2]*4459+a[3]*5800+a[4]*6685+a[5]*6120+a[6]*7357+a[7]*3561+a[8]*5199 == 4885863 &&
a[0]*3188+a[1]*6278+a[2]*9411+a[3]*5760+a[4]*9909+a[5]*7618+a[6]*7184+a[7]*4791+a[8]*8686 == 6387690 &&
a[0]*8827+a[1]*7419+a[2]*7033+a[3]*9306+a[4]*7300+a[5]*5774+a[6]*6588+a[7]*5541+a[8]*4628 == 6077067 &&
a[0]*5707+a[1]*5793+a[2]*4589+a[3]*6679+a[4]*3972+a[5]*5876+a[6]*6668+a[7]*5951+a[8]*9569 == 5492294 &&
a[0]*9685+a[1]*7370+a[2]*4648+a[3]*7230+a[4]*9614+a[5]*9979+a[6]*8309+a[7]*9631+a[8]*9272 == 7562511 &&
a[0]*6955+a[1]*8567+a[2]*7949+a[3]*8699+a[4]*3284+a[5]*6647+a[6]*3175+a[7]*8506+a[8]*6552 == 5970432 &&
a[0]*4323+a[1]*4706+a[2]*8081+a[3]*7900+a[4]*4862+a[5]*9544+a[6]*5211+a[7]*7443+a[8]*5676 == 5834523 &&
a[0]*3022+a[1]*8999+a[2]*5058+a[3]*4529+a[4]*3940+a[5]*4279+a[6]*4606+a[7]*3428+a[8]*8889 == 4681110) {
System.out.println("Congratulations.");
System.out.println("Here is your flag : moectf{"+inputS+"}");
} else {
System.out.println("You still need learn more!");
System.out.println("Fighting!!!");
}
}
}
}
代码的意思是这样:给出一个9*9的矩阵A,用ASCII编码把你输入的9个字符的字符串inputS转为一个9行1列的矩阵b,最后给出一个9行1列的矩阵C,如果有Ab=C,那么返回正确,输出flag:moectf{inputS}。
既然有Ab=C,那么可得b=inv(A)*C,再把b还原成字符串即可。
用matlab写破解脚本如下:
a = [
[4778,3659,9011,5734,4076,6812,8341,6765,7435];
[4449,5454,4459,5800,6685,6120,7357,3561,5199];
[3188,6278,9411,5760,9909,7618,7184,4791,8686];
[8827,7419,7033,9306,7300,5774,6588,5541,4628];
[5707,5793,4589,6679,3972,5876,6668,5951,9569];
[9685,7370,4648,7230,9614,9979,8309,9631,9272];
[6955,8567,7949,8699,3284,6647,3175,8506,6552];
[4323,4706,8081,7900,4862,9544,5211,7443,5676];
[3022,8999,5058,4529,3940,4279,4606,3428,8889]
];
c = [
5711942;
4885863;
6387690;
6077067;
5492294;
7562511;
5970432;
5834523;
4681110
];
b = inv(a)*c;
bs = round(b');
ss = char(bs)
得到的ss加上头尾即为flag。



