他们分别是:
出题团队简介
赛题设计思路
kctf2021 战队:98k,队长QQ:1485032842
flag:
题目设计说明:
因为需要渲染latex,让大家更好理解其中的原理,详细的过程在攻击脚本的“kanxue_ctf_2022_98k.pdf”中。
破解思路:
攻击脚本参见攻击脚本目录下的 ipynb。
赛题解析
本赛题解析由看雪论坛专家 Zuni-W 给出:
逆向部分
int genNumber() {
unsigned long r = genrand_int32();
return r % 127;
}
int ANS1[32]={0x37, 0x5A, 0x53, 0x4B, 0x03, 0x3C, 0x25, 0x4F, 0x38, 0x05, 0x16, 0x64, 0x59, 0x17, 0x1F, 0x0F,
0x44, 0x0B, 0x48, 0x1C, 0x27, 0x4A, 0x23, 0x63, 0x66, 0x79, 0x2A, 0x21, 0x44, 0x43, 0x65, 0x32};
int K1 = 0;
int ANS2[32]={0x5B, 0x6B, 0x75, 0x5A, 0x48, 0x6A, 0x6A, 0x23, 0x2C, 0x57, 0x14, 0x6B, 0x6B, 0x35, 0x0E, 0x64,
0x65, 0x1A, 0x23, 0x39, 0x73, 0x34, 0x02, 0x3E, 0x19, 0x06, 0x21, 0x46, 0x1C, 0x4B, 0x00, 0x61};
int K2 = 0;
int main() {
init_genrand(0x0000000091941ABB); // K1 K2
int FLAG[16]={0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
int s0[1024]={0};
for (int i = 0; i < 1024; i++) { //32
int a = genNumber();
s0[i]=a;
//printf("%.2x n", a);
}
int s1[32]={0};
for (int i = 0; i < 16; i++) {
s1[i]=FLAG[i];
}
for (int i = 16; i < 32; i++) { //16
int a = genNumber();
s1[i]=a;
//printf("%.2x n", a);
}
int s2[32]={0};
for (int i = 0; i < 32; i++) { //32 & 1
int a = genNumber() & 1;
s2[i] = a*29;
//printf("%.2x n", a);
}
//Start Calc
int sA[32]={0};
for(int i=0;i<32;i++){
int s = 0;
for(int j=0;j<32;j++){
int temp = s1[j] * s0[32*i+j];
s+= temp%0x7f;
}
sA[i]=s;
}
for(int i=0;i<32;i++){
sA[i] = (sA[i] + s2[i]) % 0x7f;
printf("%.2x ", sA[i]);
}
puts("");
}
int genNumber() {
unsigned long r = genrand_int32();
return r % 127;
}
char A1[8]={0x78, 0x36, 0x4D, 0x3B, 0x3B, 0x61, 0x1F, 0x41};
char A2[8]={0x4D, 0x52, 0x57, 0x24, 0x64, 0x26, 0x2D, 0x6B};
int main() {
for (unsigned long long K = 0xffffffff; K >= 0x1; K--) {
init_genrand(K);
char s[8] = { 0 };
for (int i = 0; i < 8; i++) { //1024 cmp
int a = genNumber();
s[i] = a;
}
if (memcmp(s, A1, 8) == 0) {
printf("A1:%xn", K);
}
if (memcmp(s, A2, 8) == 0) {
printf("A2:%xn", K);
}
}
}
密码部分
算法模型
基础理论
格基构造
参数调整
迭代后寻找最后一列绝对值为t,第三部分绝对值均为一个L的值即为合法解。这时第二部分的值即为负的lr对应值,特殊的,第二部分前16位即为输入负值%127后的结果。
代码记录
sage: MK1=Matrix(ZZ,64*2+48+1,64*2+48+1)
sage: for i in range(64):
....: MK1[i,i]=127*127*127*127*127
....: MK1[i+64+48,i+64+48]=127*127*2
....: MK1[i+64+48,i]=29*127*127*127*127
....:
....:
sage: for i in range(16):
....: for j in range(32):
....: MK1[i+64,j]=ZZ(A[j,i])*127*127*127*127
....: MK1[i+64,j+32]=ZZ(B[j,i])*127*127*127*127
....: MK1[i+64+16,j]=ZZ(A[j,i+16])*127*127*127*127
....: MK1[i+64+32,j+32]=ZZ(B[j,i+16])*127*127*127*127
....: MK1[i+64,i+64]=1
....: MK1[i+64+16,i+64+16]=1
....: MK1[i+64+32,i+64+32]=1
....:
sage: MK1[-1,-65:-1]=vector([127*127]*64)
sage: MK1[-1,64:64+48]=vector([0]*48)
sage: MK1[-1,:64]=vector(ZZ,ans1+ans2)*127*127*127*127
sage: MK1[-1,-1]=127
sage: ANS=MK1.LLL()
sage: for i in ANS:
....: if i[-1] in {127,-127} :
....: i[:64],-i[64:64+48]*i[-1]/abs(i[-1]),i[-65:]/(127*i[-1])
....:
....:
((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(-15, 50, 36, 13, -33, -37, 29, 14, 2, 28, 4, -26, -18, 43, -3, -51, -56, 40, 23, -61, 9, 46, -26, 36, 25, -63, 25, -62, 47, -62, 31, -62, 35, 25, -33, -40, -58, -34, 53, 27, 3, 41, -35, 7, 48, -8, -12, 56),
(-1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1/127))
((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(55, -37, -40, -31, 5, 23, -52, 12, -54, 17, 31, 60, -13, -17, 4, 35, -55, -5, 14, -36, 61, -57, -18, -36, -39, -7, 15, -46, 9, -51, -13, 20, 8, 48, 31, 30, -33, 53, 31, 20, 20, 44, 16, -37, 4, -58, 58, 36),
(1, 3, 1, 5, 5, -5, 5, -3, 1, 1, 1, -3, -1, -1, 1, -3, 1, 1, -1, -3, -3, 3, -3, -3, 1, -3, -3, 1, 5, 3, 1, -3, -5, -3, 1, 1, 1, -1, 1, -1, -1, -1, 3, 3, 3, -3, 1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 3, 1, 1, -1, 1, 1, 1/127))
……
结语
看雪 2022 KCTF春季赛圆满结束!
【最佳人气奖】投票开启:https://bbs.pediy.com/thread-273214.htm
【新思路奖】投票开启:https://bbs.pediy.com/thread-273215.htm
投票通道关闭时间:6/15 15:30
球分享
球点赞
球在看
原文始发于微信公众号(看雪学苑):看雪2022 KCTF 春季赛 | 第12题设计思路及解析