김승현
[webhacking.kr] old-06 6번 문제 write up 본문
문제 분석
접속하면 이런 어두운 화면에 소스 보기와 id, pw를 볼 수 있다. 소스부터 확인해 보자.
<?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;
}
?>
<html>
<head>
<title>Challenge 6</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
</style>
</head>
<body>
<?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);
}
?>
</body>
</html>
이번 문제는 되게 간단한 문제이다.
대충 코드를 분석해보면
- val_id에 guest, val_pw에123qw를 저장
- val_id와 val_pw를 20번 base64 인코딩 함
- 두 변수들에 있는 1~8의 숫자들을 새로운 특수문자로 인코딩 함.
- user이라는 쿠키에 val_id 값을 저장, password라는 쿠키에 val_pw 값을 저장(time()내용은 만료시간인데 신경x)
- --------------------------------------------인코딩 파트↑ ↓디코딩 파트---------------------------------------------------------------
- decode_id, decoe_pw에 위의 쿠키값들을 저장
- 이후 decode_id와 decode_pw에 있는 일부 특수문자들을 1~8까지의 숫자로 변환
- base64 디코딩을 20번 진행
- 이후 decode_id가 admin이고 decode_pw가 nimda면 문제가 풀리는 방식
여기서 중요하게 볼 부분은 그냥 base64을 20번 진행한다는 내용인 것 같다. 해당 코드를 작성해보자.
import base64
id = "admin".encode()
pw = "nimda".encode()
for _ in range(20):
id = base64.b64encode(id)
pw = base64.b64encode(pw)
print("id = " + str(id) + " pw = " + str(pw))
id와 pw라는 변수에 각각 admin과 nimda를 인코딩 해서 저장
id, pw 변수들에 대해 base64 인코딩을 20번 진행
해당 내용을 출력
출력된 내용은 아래에 있다.
id
Vm0wd2QyUXlVWGxWV0d4V1YwZDRWMVl3WkRSV01WbDNXa1JTVjAxV2JETlhhMUpUVmpBeFYySkVUbGhoTVVwVVZtcEJlRll5U2tWVWJHaG9UVlZ3VlZadGNFSmxSbGw1VTJ0V1ZXSkhhRzlVVmxaM1ZsWmFjVkZ0UmxSTmJFcEpWbTEwYTFkSFNrZGpS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jFGZVZWclpHRldNMmhJV1RJeFMxSXhjRWhpUm1oVFZsaENTMVp0TVRCVk1VMTRWbGhvV0ZkSGFGbFpiWGhoVm14c2NscEhPV3BTYkhCNFZrY3dOVll4V25OalJXaFlWa1UxZGxsV1ZYaFhSbFp5WVVaa1RtRnNXbFZXYTJRMFdWWktjMVJ1VG1oU2JGcFlXV3hhUm1ReFduRlJiVVphVm0xU1NWWlhkRzloTVVwMFlVWlNWVlpXY0dGVVZscGhZekZ3UlZWdGNFNVdNVWwzVmxSS01HRXhaRWhUYkdob1VqQmFWbFp0ZUhkTk1WcHlWMjFHYWxacmNEQmFSV1F3VmpKS2NsTnJhRmRTTTJob1ZrUktSMVl4VG5WVmJFSlhVbFJXV1ZaR1l6RmlNV1JIWWtaV1VsZEhhRlJVVm1SVFpXeHNWbGRzVG1oU1ZFWjZWVEkxYjFZeFdYcFZiR2hZVm14d1lWcFZXbXRrVmtwelZtMXNWMUl6YURWV01XUXdXVmRSZVZaclpGZGliRXB5Vld0V1MySXhiRmxqUldSc1ZteEtlbFp0TURWWFIwcEhZMFpvV2sxSGFFeFdNbmhoVjBaV2NscEhSbGROTW1oSlYxUkplRk14U1hoalJXUmhVbXMxV0ZZd1ZrdE5iRnAwWTBWa1dsWXdWalJXYkdodlYwWmtTR0ZHV2xwaVdHaG9WbTE0YzJOc1pISmtSM0JUWWtad05GWlhNVEJOUmxsNFYyNU9hbEpYYUZoV2FrNVRWRVpzVlZGWWFGTldhM0I2VmtkNFlWVXlTa1pYV0hCWFZsWndSMVF4V2tOVmJFSlZUVVF3UFE9PQ==
위와 같이 나왔다.
이렇게 쿠키에 저장을 하고 새로고침을 해보자.
이미 풀어서 그렇지만 old6 pwned!인가 이런 식으로 해결됐다고 뜬다. 이번 내용은 되게 쉬워서 간단하게 풀 수 있었다.
'Web > webhacking.kr' 카테고리의 다른 글
[webhacking.kr] old-08 8번 문제 write up (0) | 2023.03.29 |
---|---|
[webhacking.kr] old-07 7번 문제 write up (0) | 2023.03.11 |
[webhacking.kr] old-05 5번 문제 write up (0) | 2023.03.09 |
[webhacking.kr] old-04 4번 문제 write up (0) | 2023.03.09 |
[webhacking.kr] old-03 3번문제 write up (1) | 2023.03.07 |