CTF

[TsukuCTF] len_len

wermut 2025. 5. 3. 16:16

len_len.zip
0.01MB

 


 

// server.js

...

function chall(str = "[1, 2, 3]") {
  const sanitized = str.replaceAll(" ", ""); 
  if (sanitized.length < 10) { 
    return `error: no flag for you. sanitized string is ${sanitized}, length is ${sanitized.length.toString()}`;
  }
  const array = JSON.parse(sanitized);
  if (array.length < 0) { 
    // hmm...??
    return FLAG;
  }
  return `error: no flag for you. array length is too long -> ${array.length}`;
}

...

 

0. array 변수가 post 형식으로 받아졌을때 이를 갖고 연산을 시작
1. 입력값이 없을 경우 기본 값은 [1, 2, 3]으로 지정
2. 이 값은 공백이 제거된 후 sanitized로 변수에 저장
3. 이 값의 길이 < 10일 때 flag를 얻을 수 없음
4. 이 sanitized 변수를 JSON.parse 한 값이 array
5. 이때 array길이 < 0이어야 flag를 반환

 

위 과정을 거쳐 flag를 얻어내는 문제이다.

 

 

sanitized 가 유효한 JSON 문자열이기만 하면 JSON.parse 는 배열 뿐 아니라 객체도 파싱하기 때문에 JSON.parse('{"length":-1}') 와 같이 요청이 전달된다면 array.length의 값이 -1로 처리된다.

 

 

'CTF' 카테고리의 다른 글

[CodeGate 2025] Masquerade  (0) 2025.04.15
[CodeGate 2024] Cha s Wall  (0) 2025.03.22
[CodeGate 2023] AI  (0) 2025.03.21
[CodeGate 2023] CODEGATE Music Player  (0) 2025.03.21
[CodeGate 2023] Calculator  (0) 2025.03.20