ASIS CTF Quals 2023 Writeup

この大会は2023/9/22 23:30(JST)~2023/9/23 23:30(JST)に開催されました。
今回もチームで参戦。結果は152点で656チーム中86位でした。
自分で解けた問題をWriteupとして書いておきます。

Greetings! (Warm-up)

問題にフラグが書いてあった。

ASIS{w3lc0m3_70_4S1S_C7F!_H3r3'5_70_4n_3xc171n6_4nd_ch4113n63_3xp3r13nc3!}

Grid (Reverse)

Ghidraでデコンパイルする。

undefined4 FUN_00101080(void)

{
  char *__s;
  int iVar1;
  size_t sVar2;
  char cVar3;
  long lVar4;
  char *pcVar5;
  undefined4 local_b8;
  undefined4 uStack_b4;
  undefined4 uStack_b0;
  undefined4 uStack_ac;
  undefined4 local_a8;
  undefined4 uStack_a4;
  undefined4 uStack_a0;
  undefined2 uStack_9c;
  undefined2 uStack_9a;
  undefined2 uStack_98;
  undefined4 uStack_96;
  undefined4 uStack_92;
  undefined4 uStack_8e;
  char acStack_89 [129];
  
  __s = acStack_89 + 1;
  local_b8 = 0xb932b9be;
  uStack_b4 = 0x7ce330ef;
  uStack_b0 = 0xa9ee7d38;
  uStack_ac = 0x6a35bb7d;
  local_a8 = 0x542be367;
  uStack_a4 = 0x38de617d;
  uStack_a0 = 0xde597de7;
  uStack_9c = 0xa54;
  uStack_9a = 0xd4f5;
  uStack_98 = 0x1c7d;
  uStack_96 = 0x27cfbee3;
  uStack_92 = 0x61443ab6;
  uStack_8e = 0xeeeee;
  puts("Can you guess the flag ? :D");
  fgets(__s,0x80,stdin);
  sVar2 = strlen(__s);
  acStack_89[sVar2] = '\0';
  sVar2 = strlen(__s);
  pcVar5 = __s;
  if (sVar2 != 0) {
    do {
      lVar4 = 0;
      do {
        if (*pcVar5 == (&DAT_00104040)[lVar4 * 2]) {
          cVar3 = (&DAT_00104041)[lVar4 * 2];
          goto LAB_00101127;
        }
        lVar4 = lVar4 + 1;
      } while (lVar4 != 0xff);
      cVar3 = '\0';
LAB_00101127:
      *pcVar5 = cVar3;
      pcVar5 = pcVar5 + 1;
    } while (pcVar5 != __s + sVar2);
    if (sVar2 == 0x2d) {
      iVar1 = strncmp(__s,(char *)&local_b8,0x2e);
      if (iVar1 != 0) {
        puts("Incorrect :|");
        return 1;
      }
      puts("Good job :) ");
      return 0;
    }
  }
  puts("Incorrect :( ");
  return 1;
}

                             DAT_00104040                                    XREF[4]:     FUN_00101080:001010eb(*), 
                                                                                          FUN_00101080:0010111d(R), 
                                                                                          FUN_00101280:00101282(*), 
                                                                                          FUN_00101280:0010129c(R)  
        00104040 01              undefined1 01h
                             DAT_00104041                                    XREF[2]:     FUN_00101080:00101122(R), 
                                                                                          FUN_00101280:001012a2(R)  
        00104041 76              undefined1 76h
                             DAT_00104042                                    XREF[2]:     FUN_00101080:0010111d(R), 
                                                                                          FUN_00101280:0010129c(R)  
        00104042 02              undefined1 02h
        00104043 2c              ??         2Ch    ,
        00104044 03              ??         03h
        00104045 3b              ??         3Bh    ;
        00104046 04              ??         04h
        00104047 45              ??         45h    E
        00104048 05              ??         05h
        00104049 bd              ??         BDh
        0010404a 06              ??         06h
        0010404b f2              ??         F2h
        0010404c 07              ??         07h
        0010404d 92              ??         92h
        0010404e 08              ??         08h
        0010404f 5d              ??         5Dh    ]
        00104050 09              ??         09h
        00104051 91              ??         91h
        00104052 0a              ??         0Ah
        00104053 2d              ??         2Dh    -
        00104054 0b              ??         0Bh
        00104055 2e              ??         2Eh    .
        00104056 0c              ??         0Ch
        00104057 7f              ??         7Fh    
        00104058 0d              ??         0Dh
        00104059 e9              ??         E9h
        0010405a 0e              ??         0Eh
        0010405b 3c              ??         3Ch    <
        0010405c 0f              ??         0Fh
        0010405d 78              ??         78h    x
        0010405e 10              ??         10h
        0010405f 9f              ??         9Fh
        00104060 11              ??         11h
        00104061 8a              ??         8Ah
        00104062 12              ??         12h
        00104063 a5              ??         A5h
        00104064 13              ??         13h
        00104065 71              ??         71h    q
        00104066 14              ??         14h
        00104067 94              ??         94h
        00104068 15              ??         15h
        00104069 3f              ??         3Fh    ?
        0010406a 16              ??         16h
        0010406b a7              ??         A7h
        0010406c 17              ??         17h
        0010406d db              ??         DBh
        0010406e 18              ??         18h
        0010406f e8              ??         E8h
        00104070 19              ??         19h
        00104071 f6              ??         F6h
        00104072 1a              ??         1Ah
        00104073 a4              ??         A4h
        00104074 1b              ??         1Bh
        00104075 99              ??         99h
        00104076 1c              ??         1Ch
        00104077 e6              ??         E6h
        00104078 1d              ??         1Dh
        00104079 22              ??         22h    "
        0010407a 1e              ??         1Eh
        0010407b 40              ??         40h    @
        0010407c 1f              ??         1Fh
        0010407d ff              ??         FFh
        0010407e 20              ??         20h     
        0010407f dc              ??         DCh
        00104080 21              ??         21h    !
        00104081 ee              ??         EEh
        00104082 22              ??         22h    "
        00104083 ea              ??         EAh
        00104084 23              ??         23h    #
        00104085 24              ??         24h    $
        00104086 24              ??         24h    $
        00104087 6d              ??         6Dh    m
        00104088 25              ??         25h    %
        00104089 58              ??         58h    X
        0010408a 26              ??         26h    &
        0010408b 02              ??         02h
        0010408c 27              ??         27h    '
        0010408d a2              ??         A2h
        0010408e 28              ??         28h    (
        0010408f dd              ??         DDh
        00104090 29              ??         29h    )
        00104091 86              ??         86h
        00104092 2a              ??         2Ah    *
        00104093 9e              ??         9Eh
        00104094 2b              ??         2Bh    +
        00104095 a1              ??         A1h
        00104096 2c              ??         2Ch    ,
        00104097 e1              ??         E1h
        00104098 2d              ??         2Dh    -
        00104099 19              ??         19h
        0010409a 2e              ??         2Eh    .
        0010409b e0              ??         E0h
        0010409c 2f              ??         2Fh    /
        0010409d 64              ??         64h    d
        0010409e 30              ??         30h    0
        0010409f 6a              ??         6Ah    j
        001040a0 31              ??         31h    1
        001040a1 b3              ??         B3h
        001040a2 32              ??         32h    2
        001040a3 5e              ??         5Eh    ^
        001040a4 33              ??         33h    3
        001040a5 2b              ??         2Bh    +
        001040a6 34              ??         34h    4
        001040a7 bb              ??         BBh
        001040a8 35              ??         35h    5
        001040a9 38              ??         38h    8
        001040aa 36              ??         36h    6
        001040ab 4f              ??         4Fh    O
        001040ac 37              ??         37h    7
        001040ad 30              ??         30h    0
        001040ae 38              ??         38h    8
        001040af 53              ??         53h    S
        001040b0 39              ??         39h    9
        001040b1 44              ??         44h    D
        001040b2 3a              ??         3Ah    :
        001040b3 75              ??         75h    u
        001040b4 3b              ??         3Bh    ;
        001040b5 65              ??         65h    e
        001040b6 3c              ??         3Ch    <
        001040b7 f9              ??         F9h
        001040b8 3d              ??         3Dh    =
        001040b9 4b              ??         4Bh    K
        001040ba 3e              ??         3Eh    >
        001040bb c1              ??         C1h
        001040bc 3f              ??         3Fh    ?
        001040bd 23              ??         23h    #
        001040be 40              ??         40h    @
        001040bf b2              ??         B2h
        001040c0 41              ??         41h    A
        001040c1 be              ??         BEh
        001040c2 42              ??         42h    B
        001040c3 d5              ??         D5h
        001040c4 43              ??         43h    C
        001040c5 05              ??         05h
        001040c6 44              ??         44h    D
        001040c7 80              ??         80h
        001040c8 45              ??         45h    E
        001040c9 61              ??         61h    a
        001040ca 46              ??         46h    F
        001040cb fe              ??         FEh
        001040cc 47              ??         47h    G
        001040cd 60              ??         60h    `
        001040ce 48              ??         48h    H
        001040cf e3              ??         E3h
        001040d0 49              ??         49h    I
        001040d1 32              ??         32h    2
        001040d2 4a              ??         4Ah    J
        001040d3 85              ??         85h
        001040d4 4b              ??         4Bh    K
        001040d5 f4              ??         F4h
        001040d6 4c              ??         4Ch    L
        001040d7 cf              ??         CFh
        001040d8 4d              ??         4Dh    M
        001040d9 5a              ??         5Ah    Z
        001040da 4e              ??         4Eh    N
        001040db 3a              ??         3Ah    :
        001040dc 4f              ??         4Fh    O
        001040dd 43              ??         43h    C
        001040de 50              ??         50h    P
        001040df d6              ??         D6h
        001040e0 51              ??         51h    Q
        001040e1 6f              ??         6Fh    o
        001040e2 52              ??         52h    R
        001040e3 54              ??         54h    T
        001040e4 53              ??         53h    S
        001040e5 b9              ??         B9h
        001040e6 54              ??         54h    T
        001040e7 cc              ??         CCh
        001040e8 55              ??         55h    U
        001040e9 f5              ??         F5h
        001040ea 56              ??         56h    V
        001040eb b5              ??         B5h
        001040ec 57              ??         57h    W
        001040ed 59              ??         59h    Y
        001040ee 58              ??         58h    X
        001040ef 16              ??         16h
        001040f0 59              ??         59h    Y
        001040f1 e7              ??         E7h
        001040f2 5a              ??         5Ah    Z
        001040f3 a9              ??         A9h
        001040f4 5b              ??         5Bh    [
        001040f5 ae              ??         AEh
        001040f6 5c              ??         5Ch    \
        001040f7 f1              ??         F1h
        001040f8 5d              ??         5Dh    ]
        001040f9 08              ??         08h
        001040fa 5e              ??         5Eh    ^
        001040fb 3e              ??         3Eh    >
        001040fc 5f              ??         5Fh    _
        001040fd 7d              ??         7Dh    }
        001040fe 60              ??         60h    `
        001040ff e4              ??         E4h
        00104100 61              ??         61h    a
        00104101 de              ??         DEh
        00104102 62              ??         62h    b
        00104103 c6              ??         C6h
        00104104 63              ??         63h    c
        00104105 1c              ??         1Ch
        00104106 64              ??         64h    d
        00104107 eb              ??         EBh
        00104108 65              ??         65h    e
        00104109 b6              ??         B6h
        0010410a 66              ??         66h    f
        0010410b 97              ??         97h
        0010410c 67              ??         67h    g
        0010410d 15              ??         15h
        0010410e 68              ??         68h    h
        0010410f 51              ??         51h    Q
        00104110 69              ??         69h    i
        00104111 7c              ??         7Ch    |
        00104112 6a              ??         6Ah    j
        00104113 ad              ??         ADh
        00104114 6b              ??         6Bh    k
        00104115 cd              ??         CDh
        00104116 6c              ??         6Ch    l
        00104117 27              ??         27h    '
        00104118 6d              ??         6Dh    m
        00104119 0a              ??         0Ah
        0010411a 6e              ??         6Eh    n
        0010411b 35              ??         35h    5
        0010411c 6f              ??         6Fh    o
        0010411d 5f              ??         5Fh    _
        0010411e 70              ??         70h    p
        0010411f d4              ??         D4h
        00104120 71              ??         71h    q
        00104121 13              ??         13h
        00104122 72              ??         72h    r
        00104123 a0              ??         A0h
        00104124 73              ??         73h    s
        00104125 14              ??         14h
        00104126 74              ??         74h    t
        00104127 67              ??         67h    g
        00104128 75              ??         75h    u
        00104129 7a              ??         7Ah    z
        0010412a 76              ??         76h    v
        0010412b 8c              ??         8Ch
        0010412c 77              ??         77h    w
        0010412d 4a              ??         4Ah    J
        0010412e 78              ??         78h    x
        0010412f 72              ??         72h    r
        00104130 79              ??         79h    y
        00104131 2f              ??         2Fh    /
        00104132 7a              ??         7Ah    z
        00104133 da              ??         DAh
        00104134 7b              ??         7Bh    {
        00104135 ef              ??         EFh
        00104136 7c              ??         7Ch    |
        00104137 49              ??         49h    I
        00104138 7d              ??         7Dh    }
        00104139 0e              ??         0Eh
        0010413a 7e              ??         7Eh    ~
        0010413b d3              ??         D3h
        0010413c 7f              ??         7Fh    
        0010413d fa              ??         FAh
        0010413e 80              ??         80h
        0010413f 3d              ??         3Dh    =
        00104140 81              ??         81h
        00104141 c0              ??         C0h
        00104142 82              ??         82h
        00104143 33              ??         33h    3
        00104144 83              ??         83h
        00104145 66              ??         66h    f
        00104146 84              ??         84h
        00104147 aa              ??         AAh
        00104148 85              ??         85h
        00104149 ce              ??         CEh
        0010414a 86              ??         86h
        0010414b fc              ??         FCh
        0010414c 87              ??         87h
        0010414d b0              ??         B0h
        0010414e 88              ??         88h
        0010414f 62              ??         62h    b
        00104150 89              ??         89h
        00104151 93              ??         93h
        00104152 8a              ??         8Ah
        00104153 41              ??         41h    A
        00104154 8b              ??         8Bh
        00104155 d7              ??         D7h
        00104156 8c              ??         8Ch
        00104157 48              ??         48h    H
        00104158 8d              ??         8Dh
        00104159 bf              ??         BFh
        0010415a 8e              ??         8Eh
        0010415b ca              ??         CAh
        0010415c 8f              ??         8Fh
        0010415d c8              ??         C8h
        0010415e 90              ??         90h
        0010415f 03              ??         03h
        00104160 91              ??         91h
        00104161 7e              ??         7Eh    ~
        00104162 92              ??         92h
        00104163 0f              ??         0Fh
        00104164 93              ??         93h
        00104165 9b              ??         9Bh
        00104166 94              ??         94h
        00104167 cb              ??         CBh
        00104168 95              ??         95h
        00104169 56              ??         56h    V
        0010416a 96              ??         96h
        0010416b d8              ??         D8h
        0010416c 97              ??         97h
        0010416d 79              ??         79h    y
        0010416e 98              ??         98h
        0010416f 52              ??         52h    R
        00104170 99              ??         99h
        00104171 a3              ??         A3h
        00104172 9a              ??         9Ah
        00104173 ab              ??         ABh
        00104174 9b              ??         9Bh
        00104175 68              ??         68h    h
        00104176 9c              ??         9Ch
        00104177 42              ??         42h    B
        00104178 9d              ??         9Dh
        00104179 ed              ??         EDh
        0010417a 9e              ??         9Eh
        0010417b 81              ??         81h
        0010417c 9f              ??         9Fh
        0010417d 84              ??         84h
        0010417e a0              ??         A0h
        0010417f 9c              ??         9Ch
        00104180 a1              ??         A1h
        00104181 10              ??         10h
        00104182 a2              ??         A2h
        00104183 5b              ??         5Bh    [
        00104184 a3              ??         A3h
        00104185 0b              ??         0Bh
        00104186 a4              ??         A4h
        00104187 1a              ??         1Ah
        00104188 a5              ??         A5h
        00104189 70              ??         70h    p
        0010418a a6              ??         A6h
        0010418b f8              ??         F8h
        0010418c a7              ??         A7h
        0010418d 63              ??         63h    c
        0010418e a8              ??         A8h
        0010418f a6              ??         A6h
        00104190 a9              ??         A9h
        00104191 af              ??         AFh
        00104192 aa              ??         AAh
        00104193 20              ??         20h     
        00104194 ab              ??         ABh
        00104195 98              ??         98h
        00104196 ac              ??         ACh
        00104197 01              ??         01h
        00104198 ad              ??         ADh
        00104199 34              ??         34h    4
        0010419a ae              ??         AEh
        0010419b 29              ??         29h    )
        0010419c af              ??         AFh
        0010419d e2              ??         E2h
        0010419e b0              ??         B0h
        0010419f fb              ??         FBh
        001041a0 b1              ??         B1h
        001041a1 17              ??         17h
        001041a2 b2              ??         B2h
        001041a3 9a              ??         9Ah
        001041a4 b3              ??         B3h
        001041a5 ac              ??         ACh
        001041a6 b4              ??         B4h
        001041a7 04              ??         04h
        001041a8 b5              ??         B5h
        001041a9 5c              ??         5Ch    \
        001041aa b6              ??         B6h
        001041ab 36              ??         36h    6
        001041ac b7              ??         B7h
        001041ad ba              ??         BAh
        001041ae b8              ??         B8h
        001041af d9              ??         D9h
        001041b0 b9              ??         B9h
        001041b1 b1              ??         B1h
        001041b2 ba              ??         BAh
        001041b3 f7              ??         F7h
        001041b4 bb              ??         BBh
        001041b5 c3              ??         C3h
        001041b6 bc              ??         BCh
        001041b7 50              ??         50h    P
        001041b8 bd              ??         BDh
        001041b9 d1              ??         D1h
        001041ba be              ??         BEh
        001041bb bc              ??         BCh
        001041bc bf              ??         BFh
        001041bd e5              ??         E5h
        001041be c0              ??         C0h
        001041bf 90              ??         90h
        001041c0 c1              ??         C1h
        001041c1 25              ??         25h    %
        001041c2 c2              ??         C2h
        001041c3 0c              ??         0Ch
        001041c4 c3              ??         C3h
        001041c5 88              ??         88h
        001041c6 c4              ??         C4h
        001041c7 b8              ??         B8h
        001041c8 c5              ??         C5h
        001041c9 12              ??         12h
        001041ca c6              ??         C6h
        001041cb d2              ??         D2h
        001041cc c7              ??         C7h
        001041cd 1b              ??         1Bh
        001041ce c8              ??         C8h
        001041cf 47              ??         47h    G
        001041d0 c9              ??         C9h
        001041d1 4d              ??         4Dh    M
        001041d2 ca              ??         CAh
        001041d3 c4              ??         C4h
        001041d4 cb              ??         CBh
        001041d5 07              ??         07h
        001041d6 cc              ??         CCh
        001041d7 1e              ??         1Eh
        001041d8 cd              ??         CDh
        001041d9 87              ??         87h
        001041da ce              ??         CEh
        001041db 7b              ??         7Bh    {
        001041dc cf              ??         CFh
        001041dd 57              ??         57h    W
        001041de d0              ??         D0h
        001041df f0              ??         F0h
        001041e0 d1              ??         D1h
        001041e1 fd              ??         FDh
        001041e2 d2              ??         D2h
        001041e3 55              ??         55h    U
        001041e4 d3              ??         D3h
        001041e5 1d              ??         1Dh
        001041e6 d4              ??         D4h
        001041e7 69              ??         69h    i
        001041e8 d5              ??         D5h
        001041e9 df              ??         DFh
        001041ea d6              ??         D6h
        001041eb 6c              ??         6Ch    l
        001041ec d7              ??         D7h
        001041ed 2a              ??         2Ah    *
        001041ee d8              ??         D8h
        001041ef ec              ??         ECh
        001041f0 d9              ??         D9h
        001041f1 6e              ??         6Eh    n
        001041f2 da              ??         DAh
        001041f3 c7              ??         C7h
        001041f4 db              ??         DBh
        001041f5 28              ??         28h    (
        001041f6 dc              ??         DCh
        001041f7 8e              ??         8Eh
        001041f8 dd              ??         DDh
        001041f9 c2              ??         C2h
        001041fa de              ??         DEh
        001041fb 82              ??         82h
        001041fc df              ??         DFh
        001041fd 9d              ??         9Dh
        001041fe e0              ??         E0h
        001041ff 4e              ??         4Eh    N
        00104200 e1              ??         E1h
        00104201 18              ??         18h
        00104202 e2              ??         E2h
        00104203 73              ??         73h    s
        00104204 e3              ??         E3h
        00104205 95              ??         95h
        00104206 e4              ??         E4h
        00104207 c9              ??         C9h
        00104208 e5              ??         E5h
        00104209 0d              ??         0Dh
        0010420a e6              ??         E6h
        0010420b 89              ??         89h
        0010420c e7              ??         E7h
        0010420d 8d              ??         8Dh
        0010420e e8              ??         E8h
        0010420f 6b              ??         6Bh    k
        00104210 e9              ??         E9h
        00104211 8b              ??         8Bh
        00104212 ea              ??         EAh
        00104213 46              ??         46h    F
        00104214 eb              ??         EBh
        00104215 11              ??         11h
        00104216 ec              ??         ECh
        00104217 21              ??         21h    !
        00104218 ed              ??         EDh
        00104219 74              ??         74h    t
        0010421a ee              ??         EEh
        0010421b 4c              ??         4Ch    L
        0010421c ef              ??         EFh
        0010421d 09              ??         09h
        0010421e f0              ??         F0h
        0010421f f3              ??         F3h
        00104220 f1              ??         F1h
        00104221 c5              ??         C5h
        00104222 f2              ??         F2h
        00104223 d0              ??         D0h
        00104224 f3              ??         F3h
        00104225 83              ??         83h
        00104226 f4              ??         F4h
        00104227 b7              ??         B7h
        00104228 f5              ??         F5h
        00104229 1f              ??         1Fh
        0010422a f6              ??         F6h
        0010422b 37              ??         37h    7
        0010422c f7              ??         F7h
        0010422d b4              ??         B4h
        0010422e f8              ??         F8h
        0010422f 26              ??         26h    &
        00104230 f9              ??         F9h
        00104231 06              ??         06h
        00104232 fa              ??         FAh
        00104233 31              ??         31h    1
        00104234 fb              ??         FBh
        00104235 96              ??         96h
        00104236 fc              ??         FCh
        00104237 39              ??         39h    9
        00104238 fd              ??         FDh
        00104239 a8              ??         A8h
        0010423a fe              ??         FEh
        0010423b 77              ??         77h    w
        0010423c ff              ??         FFh
        0010423d 8f              ??         8Fh

DAT_00104040以降がインデックスと値のペアのテーブルになっている。local_b8以降の値になるインデックスを抽出すれば、フラグになる。

#!/usr/bin/env python3

with open('grid.elf', 'rb') as f:
    data = f.read()[0x3040:0x323e]

dic = {}
for i in range(0, len(data), 2):
    dic[data[i+1]] = data[i]

enc = b''
enc += (0xb932b9be).to_bytes(4, 'little')
enc += (0x7ce330ef).to_bytes(4, 'little')
enc += (0xa9ee7d38).to_bytes(4, 'little')
enc += (0x6a35bb7d).to_bytes(4, 'little')
enc += (0x542be367).to_bytes(4, 'little')
enc += (0x38de617d).to_bytes(4, 'little')
enc += (0xde597de7).to_bytes(4, 'little')
enc += (0xa54).to_bytes(2, 'little')
enc += (0xd4f5).to_bytes(2, 'little')
enc += (0x1c7d).to_bytes(2, 'little')
enc += (0x27cfbee3).to_bytes(4, 'little')
enc += (0x61443ab6).to_bytes(4, 'little')
enc += (0xeeeee).to_bytes(3, 'little')

flag = b''
for c in enc:
   flag += bytes([dic[c]])
flag = flag.decode()
print(flag)
ASIS{7Hi5_!Z_4n0tH3R_Ea5Y_WaRmUp_cHALleN9E!!}

Renamiara (Cryptography)

サーバの処理概要は以下の通り。

・ans: 入力→小文字
・ansが'y'の場合
 ・NBIT = 32
 ・STEP = 40
 ・c = 1
 ・cがSTEP以下の間以下繰り返し
  ・nbit = NBIT * c
  ・p: nbit素数
  ・pを表示
  ・g: 数値入力
  ・xy: ","区切りでx, yの数値入力
  ・x, y: xyの数値
  ・xがp-1以上またはxが1以下またはyがp-1以上またはxが1以下またはx=yの場合エラー
  ・gが2**24以下またはgがp-1以上の場合エラー
  ・pow(g, x + y, p) ==  x * y % pの場合
   ・cがSTEPの場合、フラグを表示
   ・cがSTEP以外の場合、c+=1
  ・pow(g, x + y, p) ==  x * y % pでない場合、終了
・ansが'n'の場合、終了
・ansが'y', 'n'以外の場合、再度入力

x + y が p になるものを考える。このとき、以下の式が成り立つ。

pow(g, x + y, p) = g

例えば、以下で考える。

x = 2
y = p - 2

この場合、以下の式になる。

x * y % p = p - 4

つまりgにこの値を指定すればよい。

#!/usr/bin/env python3
import socket

def recvuntil(s, tail):
    data = b''
    while True:
        if tail in data:
            return data.decode()
        data += s.recv(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('45.153.241.194', 31337))

for _ in range(6):
    data = recvuntil(s, b'\n').rstrip()
    print(data)

print('Y')
s.sendall(b'Y\n')
data = recvuntil(s, b'\n').rstrip()
print(data)

for i in range(40):
    print('|||| Level %d ||||' % (i + 1))
    data = recvuntil(s, b'\n').rstrip()
    print(data)
    p = int(data.split(' ')[-1])
    data = recvuntil(s, b'\n').rstrip()
    print(data)

    g = p - 4
    print(g)
    s.sendall(str(g).encode() + b'\n')
    data = recvuntil(s, b'\n').rstrip()
    print(data)

    x = 2
    y = p - 2

    ans = str(x) + ',' + str(y)
    print(ans)
    s.sendall(ans.encode() + b'\n')
    data = recvuntil(s, b'\n').rstrip()
    print(data)

実行結果は以下の通り。

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  Greetings and welcome to the Renamiara cryptography challenge! The  |
|  objective of this mission is to tackle an exceptionally difficult   |
|  and unique discrete logarithm problem in the real world. Are you    |
|  prepared and willing to take on this challenge? [Y]es or [N]o?      |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Y
| In each step solve the given equation and send the solution for x, y |
|||| Level 1 ||||
| p = 2370582451
| First send the base g:
2370582447
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,2370582449
| Good job, try to solve the next level!
|||| Level 2 ||||
| p = 17689568593606603829
| First send the base g:
17689568593606603825
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,17689568593606603827
| Good job, try to solve the next level!
|||| Level 3 ||||
| p = 40247553800243553430470554483
| First send the base g:
40247553800243553430470554479
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,40247553800243553430470554481
| Good job, try to solve the next level!
                :
                :
|||| Level 38 ||||
| p = 804988671819336772776103528657461948969597892284892987049514653005967369833765800984945523969507886110533084761787498026023251086385532364177600828409080659615725541868289482532508040122518156097356063840526001054111142313757389938871303677639250109176503284604281487161724999983757348940429442143639297973479596274000170724488772966362595373631115089664918344045809
| First send the base g:
804988671819336772776103528657461948969597892284892987049514653005967369833765800984945523969507886110533084761787498026023251086385532364177600828409080659615725541868289482532508040122518156097356063840526001054111142313757389938871303677639250109176503284604281487161724999983757348940429442143639297973479596274000170724488772966362595373631115089664918344045805
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,804988671819336772776103528657461948969597892284892987049514653005967369833765800984945523969507886110533084761787498026023251086385532364177600828409080659615725541868289482532508040122518156097356063840526001054111142313757389938871303677639250109176503284604281487161724999983757348940429442143639297973479596274000170724488772966362595373631115089664918344045807
| Good job, try to solve the next level!
|||| Level 39 ||||
| p = 3302716828040756546734281929216909688844707896538920095705262749118917080193824022674877605414095917253244684733544844096092446568522332495650671180519790739410406277497102150725039543046017333034404870817975977932957682330069844262728454966300761111540285917547141357679174781985260031716188474758777250683541981744222591463530506244229302453914192703322303933503870003193497
| First send the base g:
3302716828040756546734281929216909688844707896538920095705262749118917080193824022674877605414095917253244684733544844096092446568522332495650671180519790739410406277497102150725039543046017333034404870817975977932957682330069844262728454966300761111540285917547141357679174781985260031716188474758777250683541981744222591463530506244229302453914192703322303933503870003193493
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,3302716828040756546734281929216909688844707896538920095705262749118917080193824022674877605414095917253244684733544844096092446568522332495650671180519790739410406277497102150725039543046017333034404870817975977932957682330069844262728454966300761111540285917547141357679174781985260031716188474758777250683541981744222591463530506244229302453914192703322303933503870003193495
| Good job, try to solve the next level!
|||| Level 40 ||||
| p = 12539046998921893760890418655747498992549495205034292327680811147810504716208675226870384408327610946926812618337262975891415641943924691177390165910008831823729585937205938591000836096407047195800914417165764718097151179511059505914901913101699912044354182906007856231802083483550396285332715234504448051962464522845272094006316507219971118688162961774660956206724195768918734293207501
| First send the base g:
12539046998921893760890418655747498992549495205034292327680811147810504716208675226870384408327610946926812618337262975891415641943924691177390165910008831823729585937205938591000836096407047195800914417165764718097151179511059505914901913101699912044354182906007856231802083483550396285332715234504448051962464522845272094006316507219971118688162961774660956206724195768918734293207497
| Send the solutions for pow(g, x + y, p) = x * y, as x and y:
2,12539046998921893760890418655747498992549495205034292327680811147810504716208675226870384408327610946926812618337262975891415641943924691177390165910008831823729585937205938591000836096407047195800914417165764718097151179511059505914901913101699912044354182906007856231802083483550396285332715234504448051962464522845272094006316507219971118688162961774660956206724195768918734293207499
| Congratulation! the flag is: ASIS{_An07H3r_F1XeD_PoInt5_f0r_DLP!!}
ASIS{_An07H3r_F1XeD_PoInt5_f0r_DLP!!}