๊ธ€ ์ž‘์„ฑ์ž: heogi
์ด ๋ฌธ์ œ๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ •ํ•ด์ง„ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž…๋ ฅ๊ฐ’์„ ๊ฒ€์ฆํ•˜์—ฌ correct ๋˜๋Š” wrong์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.
ํ•ด๋‹น ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ๋ถ„์„ํ•˜์—ฌ correct๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์ž…๋ ฅ๊ฐ’์„ ์ฐพ์œผ์„ธ์š”!

1. ํ”„๋กœ๊ทธ๋žจ ๋ถ„์„

ํ”„๋กœ๊ทธ๋žจ์„ IDA ํ†ตํ•ด ๋ถ„์„์„ ์ง„ํ–‰ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

int __fastcall main(int argc, const char **argv, const char **envp)
{
  char v4[256]; // [rsp+20h] [rbp-118h] BYREF

  memset(v4, 0, sizeof(v4));
  sub_1400011B0("Input : ", argv, envp);
  sub_140001210("%256s", v4);
  if ( (unsigned int)sub_140001000((__int64)v4) )
    puts("Correct");
  else
    puts("Wrong");
  return 0;
}

v4 ๋ณ€์ˆ˜์— 256๋ฐ”์ดํŠธ์˜ char ํƒ€์ž…์„ ์ƒ์„ฑํ•˜๊ณ  ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ์ดํ›„ sub_140001000 ํ•จ์ˆ˜์— ์ธ์ž๋กœ ๋„ฃ์–ด ์‹คํ–‰ํ•œ๋‹ค.
ํ•ด๋‹น ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜ ๊ฐ’์— ๋”ฐ๋ผ Correct ๋˜๋Š” Wrong์„ ์ถœ๋ ฅํ•œ๋‹ค.

2. sub_140001000 ํ•จ์ˆ˜ ๋ถ„์„

__int64 __fastcall sub_140001000(__int64 a1)
{
  int i; // [rsp+0h] [rbp-18h]

  for ( i = 0; (unsigned __int64)i < 24; ++i )
  {
    if ( byte_140003000[i] != (i ^ *(unsigned __int8 *)(a1 + i)) + 2 * i )
      return 0i64;
  }
  return 1i64;
}

byte_140003000์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅํ•œ ๊ฐ’๊ณผ ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ฐ’์— xor ํ•œ ๊ฐ’๊ณผ 2 * i ๊ฐ’์„ ๋”ํ•œ ๊ฐ’๊ณผ ๊ฐ™์€์ง€ ๋น„๊ตํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ์ด ์กด์žฌํ•œ๋‹ค.

 

๋จผ์ € byte_140003000์˜ ๊ฐ’์„ ํ™•์ธํ•ด๋ณด๋ฉด ์•„๋ž˜ ๊ฐ’์œผ๋กœ ํ™•์ธ๋œ๋‹ค.

[+] 2 dup(105) ? 
duplicate์˜ ์•ฝ์–ด๋กœ ์ค‘๋ณต๋œ ๊ฐ’์„ dup๋กœ ํ‘œ์‹œํ•ด์ค€๋‹ค. 2 dup(105)๋Š” 105์˜ ๊ฐ’์„ 2๋ฒˆ ๋ฐ˜๋ณตํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

 

๋ฐ˜๋ณต๋ฌธ์ด ์ง„ํ–‰๋˜๋ฉฐ ๊ฐ ๋ฐ”์ดํŠธ ๊ฐ’๊ณผ ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ฐ’์˜ ๋ฐ”์ดํŠธ์— ๋ฐ˜๋ณต๋ฌธ์ด ์ง„ํ–‰๋จ์— ๋”ฐ๋ผ ์ฆ๊ฐ€ํ•˜๋Š” i ๊ฐ’๊ณผ 2 * i ๊ฐ’์„ ๋”ํ•˜์—ฌ ๋น„๊ตํ•œ๋‹ค.

3. ์กฐ๊ฑด ๋ถ„์„

AAA๋ฅผ ์ž…๋ ฅ๊ฐ’์œผ๋กœ ๊ฐ€์ •ํ•˜๊ณ  ์ฒซ ๋ฐ˜๋ณต๋ฌธ์˜ ์‹œ์ž‘ ์กฐ๊ฑด์„ ์ •๋ฆฌํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค

73 != (0 ^ 0x65) + 2 * 0

๋ฌธ์ œ ํ๋ฆ„์„ ๋ณด๋ฉด ์ž…๋ ฅํ•˜๋Š” ๊ฐ’์ด FLAG์ผ๊ฒƒ์œผ๋กœ ์ถ”์ธก๋œ๋‹ค.

 

XOR ์—ฐ์‚ฐ์˜ ํŠน์„ฑ์„ ์ด์šฉํ•˜์—ฌ ์ž…๋ ฅํ•ด์•ผํ•˜๋Š” ๊ฐ’์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋‹ค.

[+] XOR ์—ฐ์‚ฐ์˜ ํŠน์„ฑ
 - ๋‘ ๊ฐ’์˜ ๊ฐ ์ž๋ฆฟ์ˆ˜๋ฅผ ๋น„๊ตํ•ด, ๊ฐ’์ด ๊ฐ™์œผ๋ฉด 0, ๋‹ค๋ฅด๋ฉด 1์„ ์ถœ๋ ฅํ•œ๋‹ค.
 - A ^ B = C ์ด๋ฉด A ^ C = B ์ด๊ณ  B ^ C = A ์ด๋‹ค.

 

ํ•ด๋‹น ํŠน์„ฑ์„ ์ด์šฉํ•ด ์•„๋ž˜์˜ ์‹์„ ๋„์ถœํ•˜๊ณ  ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ†ตํ•ด ๊ณ„์‚ฐํ•œ๋‹ค.

FLAG[i] = byte_140003000[i] - (2 * i)
FLAG[i] = i ^ FLAG[i]

4. Exploit

#rev-basic-3 python exploit

#byte_140003000 DATA
x = "49, 60, 67, 74, 63, 67, 42, 66, 80, 78, 69, 69, 7B, 99, 6D, 88, 68, 94, 9F, 8D, 4D, A5, 9D ,45".replace(" ","").split(",")
flag = []

for i in range(0,24):
	v = int(x[i],16) - (2*i)
	v = i ^ v
	flag.append(chr(v))

print("flag : "+"DH{"+"".join(flag)+"}")

'๐Ÿ›ก๏ธCTF > DreamHack' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Shell_Basic  (0) 2023.10.08
rev-basic-4  (0) 2023.09.28
[BOB CTF 8th] - FileStroage  (0) 2022.09.13
[BOB CTF 8th] - Summer Fan  (0) 2022.09.13
Apache htaccess  (0) 2022.07.28