首页
社区
课程
招聘
[原创]2019看雪CTF 晋级赛Q2 第4题-丛林的秘密
2019-6-25 09:21 6367

[原创]2019看雪CTF 晋级赛Q2 第4题-丛林的秘密

2019-6-25 09:21
6367

初步分析程序

    protected void onCreate(Bundle arg3) {
        class  implements View$OnClickListener {
            (MainActivity arg1) {
                MainActivity.this = arg1;
                super();
            }
            public void onClick(View arg2) {
                if(gogogoJNI.check_key(MainActivity.this.eText1.getText().toString()) == 1) {
                    MainActivity.this.txView1.setText("Congratulations!");
                }
                else {
                    MainActivity.this.txView1.setText("Not Correct!");
                }
            }
        }

        super.onCreate(arg3);
        this.setContentView(2131296284);
        this.eText1 = this.findViewById(2131165238);
        this.txView1 = this.findViewById(2131165322);
        this.findViewById(2131165318).loadUrl(this.u);
        this.findViewById(2131165318).getSettings().setJavaScriptEnabled(true);
        this.button1 = this.findViewById(2131165218);
        this.button1.setOnClickListener(new (this));
    }
}
onCreate处理中中有个loadUrl(),url地址如下:
int __fastcall Java_com_example_assemgogogo_gogogoJNI_sayHello(int a1)
{
  int v1; // r11
  int v2; // r4
  int i; // r0
  int v5; // [sp+0h] [bp-98h]
  char v6; // [sp+15h] [bp-83h]
  int v7; // [sp+88h] [bp-10h]

  v7 = v1;
  v2 = a1;
  _aeabi_memclr8(&v5, 128);
  for ( i = 0; i != 21; ++i )
    *((_BYTE *)&v5 + i) = byte_2D28[i] ^ 0x66;
  v6 = 0;
  return (*(int (__fastcall **)(int, int *))(*(_DWORD *)v2 + 668))(v2, &v5);
}
在JNI_OnLoad中的inti_proc()有socket操作,在函数开始有一段解密操作。
  v0 = &mm0;
  v1 = 34291;
  v9 = 1;
  while ( v1 )
  {
    --v1;
    *v0 ^= 0x67u;
    ++v0;
  }
还原这段数据我们可以得到对应的html
`.trim().split(/[\s\r\n]+/g).map(str => parseInt(str, 16))
)).then(module => {
  new WebAssembly.instantiate(module).then(results => {
  instance = results;
}).catch(console.error);})
function check_flag(){
  var value = document.getElementById("key_value").value;
  if(value.length != 32)
  {
  document.getElementById("tips").innerHTML = "Not Correct!";
	return;
  }
  instance.exports.set_input_flag_len(value.length);
  for(var ii=0;ii<value.length;ii++){
      instance.exports.set_input_flag(value[ii].charCodeAt(),ii);
  }
  var ret =  instance.exports.check_key();

  if (ret == 1){
   document.getElementById("tips").innerHTML = "Congratulations!"
  }
  else{
    document.getElementById("tips").innerHTML = "Not Correct!"
  }
}
这是一道关于 WebAssembly的题。

求解

使用wasm2c反编译成c(wasm),这个C比较难看,使用gcc重新编译生成.o后,再使用IDA分析,舒服多了。
check_key()函数如下:
BOOL check_key()
{
  BOOL result; // eax

  if ( ++wasm_rt_call_stack_depth > 0x1F4u )
    wasm_rt_trap(7);
  o(1024, 1025, 1026, 1027);
  oo(1028, 1029, 1030, 1031);
  ooo(1032, 1033, 1034, 1035);
  oooo(1036, 1037, 1038, 1039);
  ooooo(1040, 1041, 1042, 1043);
  oooooo(1044, 1045, 1046, 1047);
  ooooooo(1048, 1049, 1050, 1051);
  oooooooo(1052, 1053, 1054, 1055);
  result = xxx();
  --wasm_rt_call_stack_depth;
  return result;
}
o函数4个一组处理(异或)key,最终的判断再xxx中,是一个32元方程组。
解方程求解
import numpy as np
from scipy.linalg import solve
a = np.array(
    [[108, 111, 92, 194, 124, 240, 126, 81, 144, 103, 161, 50, 67, 15, 127, 232, 188, 19, 233, 153, 231, 40, 112, 106,
      135, 90, 67, 20, 248, 45, 48, 174],
     [227, 78, 195, 81, 10, 248, 186, 171, 148, 194, 40, 180, 17, 212, 104, 90, 178, 26, 225, 209, 32, 169, 94, 156,
      154, 56, 244, 149, 120, 131, 13, 101],
     [83, 44, 95, 131, 30, 55, 46, 36, 67, 109, 69, 251, 8, 248, 40, 154, 251, 86, 112, 9, 174, 197, 38, 14, 202, 60,
      117, 188, 136, 145, 240, 53],
     [152, 162, 112, 57, 102, 182, 10, 139, 30, 7, 145, 127, 148, 5, 165, 109, 110, 234, 113, 33, 192, 45, 65, 105, 140,
      116, 35, 48, 155, 25, 234, 25],
     [101, 189, 236, 118, 141, 148, 197, 7, 108, 104, 45, 130, 39, 164, 88, 241, 108, 107, 76, 34, 210, 29, 156, 90,
      139, 151, 10, 97, 209, 46, 82, 113],
     [182, 13, 50, 102, 155, 230, 3, 225, 237, 163, 38, 176, 115, 105, 203, 26, 72, 111, 96, 240, 139, 117, 153, 120,
      151, 25, 49, 90, 98, 7, 179, 72],
     [170, 150, 226, 101, 110, 99, 127, 101, 203, 209, 187, 100, 226, 186, 252, 39, 65, 67, 225, 174, 1, 187, 214, 22,
      74, 99, 129, 254, 13, 97, 156, 61],
     [1, 88, 118, 232, 60, 252, 133, 177, 185, 222, 32, 48, 1, 242, 240, 218, 81, 22, 73, 171, 139, 72, 106, 62, 156,
      134, 220, 19, 77, 94, 154, 117],
     [189, 173, 41, 39, 26, 232, 75, 75, 95, 7, 117, 96, 211, 130, 228, 143, 91, 247, 43, 122, 131, 52, 48, 29, 111, 38,
      19, 242, 162, 70, 220, 151],
     [236, 136, 147, 104, 79, 204, 220, 25, 38, 233, 165, 20, 174, 120, 214, 18, 233, 119, 244, 143, 126, 226, 77, 33,
      189, 5, 150, 160, 14, 112, 231, 92],
     [191, 38, 193, 250, 212, 175, 39, 94, 183, 172, 171, 163, 129, 165, 64, 170, 199, 2, 167, 2, 216, 252, 184, 187,
      97, 109, 98, 135, 192, 88, 50, 203],
     [203, 81, 252, 104, 248, 156, 199, 46, 208, 240, 149, 155, 102, 95, 51, 208, 208, 62, 58, 117, 72, 23, 193, 193,
      226, 217, 106, 147, 136, 16, 43, 196],
     [144, 69, 224, 107, 225, 83, 15, 10, 214, 152, 24, 136, 165, 208, 38, 67, 201, 180, 158, 75, 111, 65, 211, 220,
      135, 125, 216, 105, 122, 112, 80, 49],
     [143, 68, 127, 51, 152, 88, 153, 9, 149, 107, 178, 166, 190, 177, 99, 71, 63, 233, 58, 132, 109, 75, 152, 95, 74,
      195, 90, 251, 205, 8, 76, 129],
     [209, 146, 59, 38, 40, 56, 182, 245, 67, 202, 177, 183, 26, 126, 161, 95, 133, 123, 163, 30, 88, 219, 5, 86, 183,
      156, 253, 97, 43, 128, 31, 102],
     [146, 223, 137, 228, 226, 155, 170, 92, 77, 17, 22, 128, 20, 171, 142, 170, 192, 49, 200, 178, 154, 42, 5, 159,
      251, 152, 7, 247, 145, 39, 91, 136],
     [169, 204, 244, 26, 77, 134, 221, 205, 149, 47, 1, 197, 82, 195, 123, 219, 116, 80, 13, 231, 173, 192, 220, 224,
      108, 104, 56, 152, 84, 226, 121, 205],
     [184, 45, 176, 126, 118, 161, 142, 171, 215, 83, 233, 184, 171, 182, 126, 111, 118, 67, 92, 219, 70, 252, 194, 21,
      245, 204, 48, 150, 39, 85, 73, 95],
     [48, 224, 164, 138, 92, 3, 191, 94, 19, 50, 34, 167, 75, 72, 238, 15, 111, 216, 84, 40, 145, 112, 140, 204, 154,
      195, 175, 250, 202, 169, 170, 120],
     [112, 19, 189, 50, 247, 240, 164, 5, 139, 56, 19, 4, 23, 172, 96, 254, 63, 247, 149, 183, 128, 147, 213, 243, 172,
      144, 246, 25, 106, 176, 170, 68],
     [184, 22, 183, 128, 149, 174, 227, 113, 65, 159, 74, 170, 186, 174, 211, 1, 223, 156, 253, 223, 241, 252, 148, 93,
      41, 125, 27, 136, 78, 248, 41, 31],
     [155, 237, 242, 10, 145, 99, 239, 105, 3, 43, 46, 155, 208, 75, 140, 181, 197, 140, 10, 170, 142, 212, 186, 27,
      105, 118, 198, 243, 13, 113, 82, 39],
     [207, 206, 127, 58, 91, 87, 7, 17, 63, 180, 40, 96, 202, 185, 68, 72, 240, 36, 139, 199, 76, 229, 159, 136, 94, 19,
      3, 87, 45, 6, 136, 50],
     [115, 215, 40, 166, 87, 83, 74, 202, 235, 149, 114, 76, 204, 218, 63, 123, 9, 172, 38, 138, 35, 200, 221, 144, 235,
      108, 1, 245, 153, 184, 90, 12],
     [123, 190, 55, 180, 84, 231, 81, 116, 61, 3, 94, 85, 190, 187, 142, 62, 225, 240, 179, 150, 77, 85, 196, 12, 144,
      122, 28, 224, 248, 143, 114, 36],
     [2, 202, 40, 224, 154, 65, 30, 241, 13, 213, 176, 122, 30, 158, 14, 191, 80, 116, 74, 70, 32, 189, 76, 95, 158,
      103, 7, 201, 204, 91, 190, 122],
     [42, 154, 223, 165, 155, 101, 75, 95, 253, 14, 158, 199, 110, 89, 205, 202, 83, 162, 67, 30, 115, 83, 27, 31, 118,
      160, 248, 66, 88, 44, 5, 176],
     [34, 168, 72, 160, 243, 41, 146, 29, 62, 235, 185, 180, 10, 150, 208, 140, 125, 114, 35, 34, 38, 123, 163, 208, 5,
      29, 207, 111, 72, 65, 125, 84],
     [18, 11, 26, 175, 44, 128, 32, 100, 21, 116, 253, 213, 67, 16, 171, 178, 97, 7, 162, 152, 78, 167, 177, 97, 26,
      155, 127, 21, 243, 188, 140, 197],
     [140, 110, 164, 208, 72, 113, 9, 47, 179, 166, 51, 34, 91, 184, 89, 162, 233, 127, 156, 127, 244, 183, 193, 138,
      242, 90, 193, 7, 252, 113, 152, 7],
     [133, 105, 75, 146, 173, 27, 97, 142, 164, 15, 10, 177, 239, 141, 189, 67, 153, 108, 206, 210, 171, 252, 84, 249,
      7, 168, 100, 30, 196, 244, 197, 75],
     [147, 221, 57, 186, 69, 230, 167, 3, 220, 63, 218, 235, 156, 146, 75, 198, 204, 197, 59, 61, 179, 47, 221, 127,
      210, 218, 241, 135, 196, 185, 53, 79],
     ]
)
b = np.array([359512,387514,301487,296549,344514,346892,386678,348667,316884,372620,413102,428661,371484,350848,334408,382822,420160,402263,366968,384909,425203,372162,297509,372215,370337,314564,325974,307088,322340,380716,393331,430295])
x = solve(a, b)
print(x)
异或后获得flag: K9nXu3_2o1q2_w3bassembly_r3vers3

[培训]二进制漏洞攻防(第3期);满10人开班;模糊测试与工具使用二次开发;网络协议漏洞挖掘;Linux内核漏洞挖掘与利用;AOSP漏洞挖掘与利用;代码审计。

收藏
点赞1
打赏
分享
最新回复 (1)
雪    币: 2371
活跃值: (2237)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
gtict 2019-6-26 17:38
2
0
cipy.linalg 这。。
游客
登录 | 注册 方可回帖
返回