<?php
include "../../config.php";
if($_GET['view_source']) view_source();
if(!$_COOKIE['user']){
$val_id="guest";
$val_pw="123qwe";
for($i=0;$i<20;$i++){
$val_id=base64_encode($val_id);
$val_pw=base64_encode($val_pw);
}
$val_id=str_replace("1","!",$val_id);
$val_id=str_replace("2","@",$val_id);
$val_id=str_replace("3","$",$val_id);
$val_id=str_replace("4","^",$val_id);
$val_id=str_replace("5","&",$val_id);
$val_id=str_replace("6","*",$val_id);
$val_id=str_replace("7","(",$val_id);
$val_id=str_replace("8",")",$val_id);
$val_pw=str_replace("1","!",$val_pw);
$val_pw=str_replace("2","@",$val_pw);
$val_pw=str_replace("3","$",$val_pw);
$val_pw=str_replace("4","^",$val_pw);
$val_pw=str_replace("5","&",$val_pw);
$val_pw=str_replace("6","*",$val_pw);
$val_pw=str_replace("7","(",$val_pw);
$val_pw=str_replace("8",")",$val_pw);
Setcookie("user",$val_id,time()+86400,"/challenge/web-06/");
Setcookie("password",$val_pw,time()+86400,"/challenge/web-06/");
echo("<meta http-equiv=refresh content=0>");
exit;
}
?>
<?php
$decode_id=$_COOKIE['user'];
$decode_pw=$_COOKIE['password'];
$decode_id=str_replace("!","1",$decode_id);
$decode_id=str_replace("@","2",$decode_id);
$decode_id=str_replace("$","3",$decode_id);
$decode_id=str_replace("^","4",$decode_id);
$decode_id=str_replace("&","5",$decode_id);
$decode_id=str_replace("*","6",$decode_id);
$decode_id=str_replace("(","7",$decode_id);
$decode_id=str_replace(")","8",$decode_id);
$decode_pw=str_replace("!","1",$decode_pw);
$decode_pw=str_replace("@","2",$decode_pw);
$decode_pw=str_replace("$","3",$decode_pw);
$decode_pw=str_replace("^","4",$decode_pw);
$decode_pw=str_replace("&","5",$decode_pw);
$decode_pw=str_replace("*","6",$decode_pw);
$decode_pw=str_replace("(","7",$decode_pw);
$decode_pw=str_replace(")","8",$decode_pw);
for($i=0;$i<20;$i++){
$decode_id=base64_decode($decode_id);
$decode_pw=base64_decode($decode_pw);
}
echo("<hr><a href=./?view_source=1 style=color:yellow;>view-source</a><br><br>");
echo("ID : $decode_id<br>PW : $decode_pw<hr>");
if($decode_id=="admin" && $decode_pw=="nimda"){
solve(6);
}
?>
첫 번째 php 코드는 6번 문제에 처음 접속하면 실행된다. user라는 이름의 쿠키가 없기 때문이다. guest와 123qwe를 20번 base64 인코딩 후 특수문자를 숫자로 치환한다. 그 후 결과값을 user, password 이름의 쿠키에 세팅한다.
이제 두 번째 php 코드가 실행된다. user, password 이름의 쿠키 값을 대상으로 숫자를 특수문자로 치환하고 base64 디코딩을 20번 진행한다. 즉, 첫 번째 php 코드에서 했던 과정을 역으로 수행한다. 그리고 결과값을 출력한다. 그래서 6번 문제 처음 접속하면 guest와 123qwe가 출력된다.
주목할 것은 두 번째 코드다. user와 password 쿠키에 대해 admin과 nimda를 각각 두 번째 php 코드의 과정을 역으로 수행한 값을 입력해주면 된다. 즉, 두 번째 과정을 거치기 전의 값을 찾는 것이다. 그렇다면 두 번째 과정을 거치면서 admin과 nimda가 될 것이기 때문이다.
import base64
val_id="admin".encode()
val_pw="nimda".encode()
for i in range(20):
val_id = base64.b64encode(val_id)
val_pw = base64.b64encode(val_pw)
val_id = val_id.decode()
val_pw = val_pw.decode()
val_id.replace("1","!")
val_id.replace("2","@")
val_id.replace("3","$")
val_id.replace("4","^")
val_id.replace("5","&")
val_id.replace("6","*")
val_id.replace("7","(")
val_id.replace("8",")")
val_pw.replace("1","!")
val_pw.replace("2","@")
val_pw.replace("3","$")
val_pw.replace("4","^")
val_pw.replace("5","&")
val_pw.replace("6","*")
val_pw.replace("7","(")
val_pw.replace("8",")")
print("id : ", val_id)
print("pw : ", val_pw)
base64 인코딩을 20번 하고 숫자를 특수문자로 바꾼다. base64 인코딩을 하려면 encode를 먼저 해야한다. encode 함수는 bytes 자료형으로 변환한다. decode 함수는 str 자료형으로 변환한다. 코드는 단순해서 쉽게 이해될 것이다.
id
더보기
Vm0wd2QyUXlVWGxWV0d4V1YwZDRWMVl3WkRSV01WbDNXa1JT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eG9RMVJHVW5KWGJFcHNVbTFTZWxsVldsTmhWa3AxVVd4d1YySllVbGhhUkVaYVpVZEtTVk5zYUdoTk1VcFdWbGN4TkdReVZrZFdXR3hyVWpCYWNGVnRlSGRsYkZsNVpVaGtXRkl3VmpSWk1GSlBWMjFGZVZWclpHRldNMmhJV1RJeFMxSXhjRWhpUm1oVFZsaENTMVp0TVRCVk1VMTRWbGhvV0ZkSGFGbFpiWGhoVm14c2NscEhPV3BTYkhCNFZrY3dOVll4V25OalJXaFlWa1UxZGxsV1ZYaFhSbFp5WVVaa1RtRnNXbFZXYTJRMFdWWktjMVJ1VG1oU2JGcFlXV3hhUm1ReFduRlJiVVphVm0xU1NWWlhkRzloTVVwMFlVWlNWVlpXY0dGVVZscGhZekZ3UlZWdGNFNVdNVWwzVmxSS01HRXhaRWhUYkdob1VqQmFWbFp0ZUhkTk1WcHlWMjFHYWxacmNEQmFSV1F3VmpKS2NsTnJhRmRTTTJob1ZrUktSMVl4VG5WVmJFSlhVbFJXV1ZaR1l6RmlNV1JIWWtaV1VsZEhhRlJVVm1SVFpXeHNWbGRzVG1oU1ZFWjZWVEkxYjFZeFdYcFZiR2hZVm14d1lWcFZXbXRrVmtwelZtMXNWMUl6YURWV01XUXdXVmRSZVZaclpGZGliRXB5Vld0V1MySXhiRmxqUldSc1ZteEtlbFp0TURWWFIwcEhZMFpvV2sxSGFFeFdNbmhoVjBaV2NscEhSbGROTW1oSlYxUkplRk14U1hoalJXUmhVbXMxV0ZZd1ZrdE5iRnAwWTBWa1dsWXdWalJXYkdodlYwWmtTR0ZHV2xwaVdHaG9WbTE0YzJOc1pISmtSM0JUWWtad05GWlhNVEJOUmxsNFYyNU9hbEpYYUZoV2FrNVRWRVpzVlZGWWFGTldhM0I2VmtkNFlWVXlTa1pYV0hCWFZsWndSMVF4V2tOVmJFSlZUVVF3UFE9PQ==
결과값을 EditThisCookie를 이용하거나 개발자 옵션에서 쿠키를 수정 후 새로고침하면 admin과 nimda가 웹 페이지에 출력될 것이다. 문제가 풀린다.