http://natas11.natas.labs.overthewire.org/
natas11/U82q5TCMMQ9xuFoI3dYX61s7OZD9JKoK 로 로그인
쿠키는 XOR 암호화로 보호된다고 나와 있고, 배경색을 지정할 수 있게 되어 있다.
#000000을 입력하니 배경이 검정색으로 바뀐다.
소스코드는 아래와 같다.
Cookie 값 중 data가 존재하면, 해당 값을 base64로 디코딩하고 xor_encrypt() 함수를 거친 후 json 형태로 디코딩한다.
그리고, $data["showpassword"]가 yes면 패스워드를 보여준다.
따라서 showpassword가 yes가 되도록 Cookie 값을 세팅하면 된다.
우선 Cookie의 data 값을 가져왔다.
ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw%3D 를 이용해 php 코드를 작성해보자.
<?php
function xor_encrypt() {
$defaultdata = array( "showpassword"=>"no", "bgcolor"=>"#ffffff");
$text = base64_decode("ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw%3D");
$outText = json_encode($defaultdata);
$key = '';
for($i=0;$i<strlen($text);$i++) {
$key .= $outText[$i] ^ $text[$i % strlen($text)];
}
return $key;
}
echo "key : ". xor_encrypt();
?>
먼저 text에 아까 구한 데이터를 base64_decode에 씌워 넣어준다.
그리고 outText에 $defaultdata를 json 인코딩한 값을 넣어준다.
XOR 연산에 의해 A^B=C 일 때, A^C=B 이 성립하기 때문에,
원래 $outText .= $text[$i] ^ $key[$i % strlen($key)]; 였던 부분을
$key .= $outText[$i] ^ $Text[$i % strlen($key)]; 로 바꾸어 $key를 구했다.
실행해보니 아래와 같다.
key는 qw8J 다.
이제 이 값을 가지고 다시 코드를 작성한다.
<?php
function xor_encrypt() {
$defaultdata = array( "showpassword"=>"yes", "bgcolor"=>"#ffffff");
$text = json_encode($defaultdata);
$outText = '';
$key = 'qw8J';
// Iterate through each character
for($i=0;$i<strlen($text);$i++) {
$outText .= $text[$i] ^ $key[$i % strlen($key)];
}
return base64_encode($outText);
}
echo "Cookie : ". xor_encrypt();
?>
이때, showpassword를 반드시 yes로 바꿔줘야 한다.
실행 결과를 확인해보자.
ClVLIh4ASCsCBE8lAxMacFMOXTlTWxooFhRXJh4FGnBTVF4sFxFeLFMK
마지막으로 이 쿠키 값을 natas11 페이지에 대입해보자.
이렇게 바꿔주고, Set color 버튼을 누른다.
이렇게 패스워드를 확인할 수 있다.
Password: EDXp0pS26wLKHZy1rDBPUZk0RKfLGIR3
'WEB > Natas' 카테고리의 다른 글
[Natas] Level 12 → Level 13 (0) | 2021.05.19 |
---|---|
[Natas] Level 11 → Level 12 (0) | 2021.05.19 |
[Natas] Level 9 → Level 10 (0) | 2021.05.13 |
[Natas] Level 8 → Level 9 (0) | 2021.05.07 |
[Natas] Level 7 → Level 8 (0) | 2021.05.07 |