【Pwn】maze - writrup

vstral發表於2024-07-28

1.執行函式,收集字串

image

獲取關鍵詞字串:luck

2.尋找字串引用程式碼

image

3.生成虛擬碼

image

4.獲得main函式的C語言程式碼

image

5.分析程式邏輯

check函式:
image

image

main函式

int __fastcall main(int argc, const char **argv, const char **envp)

{

  unsigned int v3; // edx

  char v5; // [rsp+23h] [rbp-Dh]

  unsigned int v6; // [rsp+28h] [rbp-8h]

  unsigned int v7; // [rsp+2Ch] [rbp-4h]

  

  _main(argc, argv, envp);

  puts("Welcome to the maze. You need to find the exit, which is at point C. Your current position is marked as @.");

  puts("flag{\"The shortest route\"},good luck!!");

  v7 = 14;

  v6 = 0;

  while ( (unsigned int)check(v7, v6) != 1 )

  {

    while ( 1 )

    {

      v5 = getchar();

      if ( v5 == 108 )

        break;

      if ( v5 > 108 )

      {

        if ( v5 == 115 )

        {

          ++v7;

          goto LABEL_15;

        }

        if ( v5 == 121 )

        {

          --v7;

          goto LABEL_15;

        }

      }

      else if ( v5 == 99 )

      {

        ++v6;

        goto LABEL_15;

      }

    }

    --v6;

LABEL_15:

    if ( (unsigned int)check_1(v7, v6) )

    {

      puts("you've hit a wall!!bro@!");

      if ( v5 == 108 )

      {

        ++v6;

      }

      else if ( v5 > 108 )

      {

        if ( v5 == 115 )

        {

          --v7;

        }

        else if ( v5 == 121 )

        {

          ++v7;

        }

      }

      else if ( v5 == 99 )

      {

        --v6;

      }

    }

    else

    {

      puts("You are one step closer to victory!!");

      v3 = idx++;

      str[v3] = v5;

    }

  }

  puts("you are win!!");

  sleep(60LL);

  return 0;

}

發現 ‘s' 'l' 'y ' 'c' 為控制上下左右移動

image

要使map[10 * a1 + a2] == 67 為真
提取map陣列資料,獲取得到地圖
image
替換方便檢視
image
觀察發現 0屬於路,1屬於牆
由於當check(v7,v6) !=1時跳出迴圈,遊戲勝利,所以需要設法構建使得check函式返回1
image

由check函式分析得出,67為迷宮出口
image
由此可得67為出口,64為起點
image
image
由以上演算法可得 c為向右 y向上 s向下 l向左
故路徑為cyyyyyyyyyccccssscccssssssc

不過這裡應該有個什麼指令碼可以可以。(BFS //不過我還沒學過hhh)