当前位置:   article > 正文

XY_RE复现(五)

XY_RE复现(五)

一,给阿姨倒一杯卡布奇诺

是一道魔改TEA加密

给出了一些初始化,然后输入的flag拆分,两两一组,通过for循环放入encrypt加密函数

  1. #include <stdio.h>
  2. #define uint32_t unsigned int
  3. void decrypt(uint32_t *v, uint32_t *key)
  4. {
  5. static uint32_t data1 = 0x5F797274;
  6. static uint32_t data2 = 0x64726168;
  7. int i; // [rsp+20h] [rbp-10h]
  8. uint32_t sum; // [rsp+24h] [rbp-Ch]
  9. uint32_t v1; // [rsp+28h] [rbp-8h]
  10. uint32_t v0; // [rsp+2Ch] [rbp-4h]
  11. sum = 0x6E75316C * 32;
  12. uint32_t data1_tmp = v[0];
  13. uint32_t data2_tmp = v[1];
  14. v0 = v[0];
  15. v1 = v[1];
  16. for (i = 31; i >= 0; i--)
  17. {
  18. v1 -= ((v0 >> 5) + key[3]) ^ (v0 + sum) ^ (key[2] + 16 * v0) ^ (sum + i);
  19. v0 -= ((v1 >> 5) + key[1]) ^ (v1 + sum) ^ (key[0] + 16 * v1) ^ (sum + i);
  20. sum -= 0x6E75316C;
  21. }
  22. v[0] = v0 ^ data1;
  23. v[1] = v1 ^ data2;
  24. data1 = data1_tmp;
  25. data2 = data2_tmp;
  26. }
  27. int main()
  28. {
  29. uint32_t key[4]; // [rsp+60h] [rbp-40h] BYREF
  30. uint32_t array[8]; // [rsp+70h] [rbp-30h]
  31. array[0] = 0x9B28ED45;
  32. array[1] = 0x145EC6E9;
  33. array[2] = 0x5B27A6C3;
  34. array[3] = 0xE59E75D5;
  35. array[4] = 0xE82C2500;
  36. array[5] = 0xA4211D92;
  37. array[6] = 0xCD8A4B62;
  38. array[7] = 0xA668F440;
  39. key[0] = 0x65766967;
  40. key[1] = 0x756F795F;
  41. key[2] = 0x7075635F;
  42. key[3] = 0x6165745F;
  43. for (int i = 0; i <= 7; i += 2)
  44. {
  45. decrypt(array + i, key);
  46. }
  47. for(int i=0; i<32; i++)
  48. {
  49. printf("%c", ((char*)array)[i]);
  50. }
  51. return 0;
  52. }
  53. // 133bffe401d223a02385d90c5f1ca377

二,ez_rand

  1. int __cdecl main(int argc, const char **argv, const char **envp)
  2. {
  3. unsigned __int64 v3; // rbx ,无符号64位整数型
  4. unsigned __int16 v4; // ax , 无符号16位整数型
  5. int v5; // edi
  6. __int64 v6; // rsi
  7. int v7; // eax
  8. int v9[7]; // [rsp+20h] [rbp-50h]
  9. char v10; // [rsp+3Ch] [rbp-34h]
  10. __int16 v11; // [rsp+3Dh] [rbp-33h]
  11. __int128 v12; // [rsp+40h] [rbp-30h]
  12. __int64 v13; // [rsp+50h] [rbp-20h]
  13. int v14; // [rsp+58h] [rbp-18h]
  14. __int16 v15; // [rsp+5Ch] [rbp-14h]
  15. char v16; // [rsp+5Eh] [rbp-12h]
  16. v13 = 0i64;
  17. v12 = 0i64;
  18. v14 = 0;
  19. v15 = 0;
  20. v16 = 0;
  21. print((char *)&Format);
  22. scanf("%s");
  23. v9[0] = -362017699;
  24. v11 = 0;
  25. v3 = -1i64;
  26. v9[1] = 888936774;
  27. v9[2] = 119759538;
  28. v9[3] = -76668318;
  29. v9[4] = -1443698508;
  30. v9[5] = -2044652911;
  31. v9[6] = 1139379931;
  32. v10 = 77;
  33. do
  34. ++v3;
  35. while ( *((_BYTE *)&v12 + v3) );
  36. v4 = time64(0i64);
  37. srand(v4);
  38. v5 = 0;
  39. if ( v3 )
  40. {
  41. v6 = 0i64;
  42. do
  43. {
  44. v7 = rand();
  45. if ( (*((_BYTE *)&v12 + v6) ^ (unsigned __int8)(v7
  46. + ((((unsigned __int64)(2155905153i64 * v7) >> 32) & 0x80000000) != 0i64)
  47. + ((int)((unsigned __int64)(2155905153i64 * v7) >> 32) >> 7))) != *((_BYTE *)v9 + v6) )
  48. {
  49. print("Error???\n");
  50. exit(0);
  51. }
  52. ++v5;
  53. ++v6;
  54. }
  55. while ( v5 < v3 );
  56. }
  57. print("Right???\n");
  58. system("pause");
  59. return 0;
  60. }

就是随机数v7与v9异或

随机数种子是通过time来取的,C语言中的srand(time)是伪随机,直接爆破,题目描述给出了flag头为"XYCTF",根据这个信息去爆破随机数种子,即我们将v9的前5位与生成的前五位随机数做异或,如果结果与“XYCTF”相同,则那个随机数种子就是我们需要求的结果 

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. unsigned char str[5] = { 0x5D, 0x0C, 0x6C, 0xEA, 0x46 };
  7. unsigned char random[6] = { 0 };
  8. unsigned char flag[6] = { 'X', 'Y', 'C', 'T', 'F', '\0' };
  9. for (int i = 0xFFFF; i >= 0; i--) {
  10. srand(i);
  11. for (int j = 0; j < 5; j++) {
  12. random[j] = rand() % 0xFF;
  13. }
  14. bool found = true;
  15. for (int j = 0; j < 5; j++) {
  16. if ((random[j] ^ str[j]) != flag[j]) {
  17. found = false;
  18. break;
  19. }
  20. }
  21. if (found) {
  22. cout << "Found! It is: " << i << endl;
  23. break;
  24. }
  25. else
  26. cout << "Not " << i << " Nope" << endl;
  27. }
  28. return 0;
  29. }
  30. //Found! It is: 21308

 爆破出随机数种子:21308

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. srand(21308);
  7. for (int i = 0; i < 29; i++) {
  8. int num = rand();
  9. cout << num << ",";
  10. }
  11. return 0;
  12. }
  13. //得到随机数4085,19210,5147,22630,16830,25853,6039,15416,9400,1281,32764,16374,8177,18485,16126,29528,5590,4777,18044,26256,25694,24259,10836,5327,13701,7138,5244,22538,13308,

 

随机数是16位的: 可以int num = rand() % 0xFF ;

得到:16位key

  1. v9=[ 0x5D, 0x0C, 0x6C, 0xEA, 0x46, 0x19, 0xFC, 0x34, 0xB2, 0x62,
  2. 0x23, 0x07, 0x62, 0x22, 0x6E, 0xFB, 0xB4, 0xE8, 0xF2, 0xA9,
  3. 0x91, 0x12, 0x21, 0x86, 0xDB, 0x8E, 0xE9, 0x43, 0x4D]
  4. key=[5,85,47,190,0,98,174,116,220,6,124,54,17,125,61,203,235,187,194,246,194,34,126,227,186,253,144,98,48]
  5. flag=''
  6. for i in range(len(v9)):
  7. flag+=chr(v9[i]^key[i])
  8. print(flag)
  9. #XYCTF{R@nd_1s_S0_S0_S0_easy!}

为什么就是v12^v7!=v9(?)

三,ez_cube

  1. __int64 sub_140012930()
  2. {
  3. int i; // [rsp+44h] [rbp+24h]
  4. char v2; // [rsp+64h] [rbp+44h]
  5. int v3; // [rsp+84h] [rbp+64h]
  6. sub_140011384(&unk_1400240A2);
  7. for ( i = 0; i < 9; ++i )
  8. {
  9. top[i] = &unk_14001CC24; // red
  10. under[i] = "Blue";
  11. right[i] = "Green";
  12. left[i] = "Orange";
  13. advance[i] = "Yellow";
  14. below[i] = "White";
  15. }
  16. under[1] = &unk_14001CC24;
  17. top[1] = "Green";
  18. right[1] = "Blue";
  19. while ( 1 )
  20. {
  21. do
  22. v2 = getchar();
  23. while ( v2 == 10 );
  24. switch ( v2 )
  25. {
  26. case 'R':
  27. sub_140011375();
  28. break;
  29. case 'U':
  30. sub_1400113BB();
  31. break;
  32. case 'r':
  33. sub_140011366();
  34. break;
  35. case 'u':
  36. sub_14001115E();
  37. break;
  38. }
  39. ++dword_14001F1C0;
  40. v3 = j_check();
  41. if ( v3 == 1 )
  42. break;
  43. if ( v3 == 2 )
  44. goto LABEL_19;
  45. }
  46. print(aGreatYouAreAGo);
  47. LABEL_19:
  48. system("pause");
  49. return 0i64;
  50. }

'R' 'U' 'r' 'u'操作每一步

  1. _QWORD *sub_1400117F0()
  2. {
  3. _QWORD *result; // rax
  4. __int64 v1; // [rsp+28h] [rbp+8h]
  5. __int64 v2; // [rsp+48h] [rbp+28h]
  6. __int64 v3; // [rsp+68h] [rbp+48h]
  7. __int64 v4; // [rsp+88h] [rbp+68h]
  8. __int64 v5; // [rsp+A8h] [rbp+88h]
  9. sub_140011384(&unk_1400240A2);
  10. v1 = top[2];
  11. v2 = top[5];
  12. v3 = top[8];
  13. top[2] = below[2];
  14. top[5] = below[5];
  15. top[8] = below[8];
  16. below[2] = left[6];
  17. below[5] = left[3];
  18. below[8] = left[0];
  19. left[0] = advance[8];
  20. left[3] = advance[5];
  21. left[6] = advance[2];
  22. advance[2] = v1;
  23. advance[5] = v2;
  24. advance[8] = v3;
  25. v4 = right[1];
  26. right[1] = right[3];
  27. right[3] = right[7];
  28. right[7] = right[5];
  29. right[5] = v4;
  30. v5 = right[0];
  31. right[0] = right[6];
  32. right[6] = right[8];
  33. right[8] = right[2];
  34. result = right;
  35. right[2] = v5;
  36. return result;
  37. }

嗯,自己玩分析可能有点麻烦,想想应该可以直接写脚本。(自己用c++写了一下,不知道怎么搞四个字符操作那里,有点麻烦)先借一下别人的脚本吧

爆破的脚本还是需要再学一下。

四,What's this

Lua bytecode

可以找一个lua在线反编译网站。Lua 工具箱 (luatool.cn)

应该先变字符然后base64解密 ,发现不对,前面应该还有一些操作

  1. function Xor(num1, num2)
  2. local tmp1 = num1
  3. local tmp2 = num2
  4. local str = ""
  5. repeat
  6. local s1 = tmp1 % 2
  7. local s2 = tmp2 % 2
  8. if s1 == s2 then
  9. str = "0" .. str
  10. else
  11. str = "1" .. str
  12. end
  13. tmp1 = math.modf(tmp1 / 2)
  14. tmp2 = math.modf(tmp2 / 2)
  15. until tmp1 == 0 and tmp2 == 0
  16. return tonumber(str, 2)
  17. end
  18. value = ""
  19. output = ""
  20. i = 1
  21. while true do
  22. local temp = string.byte(flag, i)
  23. temp = string.char(Xor(temp, 8) % 256)
  24. value = value .. temp
  25. i = i + 1
  26. if i > string.len(flag) then
  27. break
  28. end
  29. end
  30. for _ = 1, 1000 do
  31. x = 3
  32. y = x * 3
  33. z = y / 4
  34. w = z - 5
  35. if w == 0 then
  36. print("This line will never be executed")
  37. end
  38. end
  39. for i = 1, string.len(flag) do
  40. temp = string.byte(value, i)
  41. temp = string.char(temp + 3)
  42. output = output .. temp
  43. end
  44. result = output:rep(10)
  45. invalid_list = {
  46. 1,
  47. 2,
  48. 3
  49. }
  50. for _ = 1, 20 do
  51. table.insert(invalid_list, 4)
  52. end
  53. for _ = 1, 50 do
  54. result = result .. "A"
  55. table.insert(invalid_list, 4)
  56. end
  57. for i = 1, string.len(output) do
  58. temp = string.byte(output, i)
  59. temp = string.char(temp - 1)
  60. end
  61. for _ = 1, 30 do
  62. result = result .. string.lower(output)
  63. end
  64. for _ = 1, 950 do
  65. x = 3
  66. y = x * 3
  67. z = y / 4
  68. w = z - 5
  69. if w == 0 then
  70. print("This line will never be executed")
  71. end
  72. end
  73. for _ = 1, 50 do
  74. x = -1
  75. y = x * 4
  76. z = y / 2
  77. w = z - 3
  78. if w == 0 then
  79. print("This line will also never be executed")
  80. end
  81. end
  82. require("base64")
  83. obfuscated_output = to_base64(output)
  84. obfuscated_output = string.reverse(obfuscated_output)
  85. obfuscated_output = string.gsub(obfuscated_output, "g", "3")
  86. obfuscated_output = string.gsub(obfuscated_output, "H", "4")
  87. obfuscated_output = string.gsub(obfuscated_output, "W", "6")
  88. invalid_variable = obfuscated_output:rep(5)
  89. if obfuscated_output == "==AeuFEcwxGPuJ0PBNzbC16ctFnPB5DPzI0bwx6bu9GQ2F1XOR1U" then
  90. print("You get the flag.")
  91. else
  92. print("F**k!")
  93. end

先异或8后+3

  1. import base64
  2. enc='==AeuFEcwxGPuJ0PBNzbC16ctFnPB5DPzI0bwx6bu9GQ2F1XOR1U'
  3. print(enc[::-1])
  4. str=list(enc[::-1])
  5. for i in range(len(str)):
  6. if str[i]=='3':
  7. str[i]='g'
  8. elif str[i]=='4':
  9. str[i]='H'
  10. elif str[i]=='6':
  11. str[i]="W"
  12. print(''.join(str))
  13. ant='U1ROX1F2QG9ubWxwb0IzPD5BPnFtcW1CbzNBP0JuPGxwcEFueA=='
  14. date=base64.b64decode(ant)
  15. flag = ""
  16. for i in date:
  17. flag += chr((i - 3) ^ 8)
  18. print(flag)
  19. #XYCTF{5dcbaed781363fbfb7d8647c1aee6c}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/526707
推荐阅读
相关标签
  

闽ICP备14008679号