0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF 2019 writeup reverse_cipher

0
Last updated at Posted at 2025-12-12

reverse_cipher (Reverse Engineering)

We have recovered a binary and a text file. Can you reverse the flag.

添付ファイル
・rev
・rev_this

revをデコンパイルする。

void main(void)

{
  size_t sVar1;
  char local_58 [23];
  char local_41;
  int local_2c;
  FILE *local_28;
  FILE *local_20;
  uint local_14;
  int local_10;
  char local_9;
  
  local_20 = fopen("flag.txt","r");
  local_28 = fopen("rev_this","a");
  if (local_20 == (FILE *)0x0) {
    puts("No flag found, please make sure this is run on the server");
  }
  if (local_28 == (FILE *)0x0) {
    puts("please run this on the server");
  }
  sVar1 = fread(local_58,0x18,1,local_20);
  local_2c = (int)sVar1;
  if ((int)sVar1 < 1) {
                    /* WARNING: Subroutine does not return */
    exit(0);
  }
  for (local_10 = 0; local_10 < 8; local_10 = local_10 + 1) {
    local_9 = local_58[local_10];
    fputc((int)local_9,local_28);
  }
  for (local_14 = 8; (int)local_14 < 0x17; local_14 = local_14 + 1) {
    if ((local_14 & 1) == 0) {
      local_9 = local_58[(int)local_14] + '\x05';
    }
    else {
      local_9 = local_58[(int)local_14] + -2;
    }
    fputc((int)local_9,local_28);
  }
  local_9 = local_41;
  fputc((int)local_41,local_28);
  fclose(local_28);
  fclose(local_20);
  return;
}

flag.txtから文字列を取得し、最初の8文字はそのまま、以降の文字は偶数番目の文字に0x5を加算、奇数番目の文字に0x2を減算している。最後の文字は別のところから取得している。
以上の処理により、rev_thisにはpicoCTF{w1{1wq85jc=2i0<}という文字列が書き込まれている。

この文字を逆算してflag.txtに書かれていた文字を復号する。
8文字目以降は、偶数番目の文字から0x5を減算し、奇数番目の文字に0x2を加算する処理を行なう。

フラグが得られた。

picoCTF{r3v3rs37ee84d27}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?