250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 공개키
- 머신러닝
- 웹
- StoredXSS
- db
- 딥러닝
- 인공지능
- 알고리즘
- 파일구조
- Database
- 프로그래머스
- SQL
- Cross Site Scripting
- dvwa
- 암호학
- RVA
- 기계학습
- SQL_Injection
- 디피헬먼
- injection
- 심층학습
- ReflectedXSS
- C언어
- codeup
- dsa
- 코드업
- 보안
- XSS
- RSA
- ImageBase
Archives
- Today
- Total
Ye0ngJae
[Webhacking.kr] Challenge Old 6 - 문제풀이 본문
728x90
문제
풀이
더보기
우선 view-source 버튼을 눌러 페이지의 소스코드를 확인하여 보자.
<?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>
코드는 크게 base64 인코딩을 하여 쿠키 값에 저장을 하는 부분과 쿠키 값을 base64 디코딩하여 아래 조건문을 통해 비교를 하는 부분으로 나눌 수 있다.
우선 base64 인코딩 부분을 살펴보자면, var_id와 var_pw 값을 20번정도 base64 인코딩 한 후에 특수문자들을 각각 다른 숫자로 치환하는 것을 확인할 수 있다. 이렇게 인코딩과 문자열 치환작업을 거친 var_id와 var_pw 값은 password와 user 쿠키에 저장되게 된다.
다음으로 base64 디코딩 부분을 살펴보자면 아까 문자열을 base64 인코딩 한 코드의 역순으로 다시 디코딩하는 것을 확인할 수 있다. 따라서 위 코드의 base64 인코딩 부분 코드를 따로 작성하여 var_id와 var_pw 값을 아래 조건문에서 비교하는 값인 admin과 nimda로 변경해주면 될 것 같다.
import base64
userid = 'admin'
userpw = 'nimda'
userid = userid.encode('ascii')
userpw = userpw.encode('ascii')
for i in range(0,20):
userid = base64.b64encode(userid)
userpw = base64.b64encode(userpw)
userid = userid.decode('ascii')
userpw = userpw.decode('ascii')
userid.replace('1','!')
userid.replace('2','@')
userid.replace('3','$')
userid.replace('4','^')
userid.replace('5','&')
userid.replace('6','*')
userid.replace('7','(')
userid.replace('8',')')
userpw.replace('1','!')
userpw.replace('2','@')
userpw.replace('3','$')
userpw.replace('4','^')
userpw.replace('5','&')
userpw.replace('6','*')
userpw.replace('7','(')
userpw.replace('8',')')
print(userid)
print(userpw)
파이썬을 이용하여 base64 인코딩 부분을 작성하였다. 그리고 해당 코드를 실행하면
Vm0wd2QyUXlVWGxWV0d4V1YwZDRWMVl3WkRSV01WbDNXa1JTVjAxV2JETlhhMUpUVmpBeFYySkVUbGhoTVVwVVZtcEJlRll5U2tWVWJHaG9UVlZ3VlZadGNFSmxSbGw1VTJ0V1ZXSkhhRzlVVmxaM1ZsWmFjVkZ0UmxSTmJFcEpWbTEwYTFkSFNrZGpSVGxhVmpOU1IxcFZXbUZrUjA1R1UyMTRVMkpIZHpGV1ZFb3dWakZhV0ZOcmFHaFNlbXhXVm1wT1QwMHhjRlpYYlVaclVqQTFSMWRyV25kV01ERkZVbFJHVjFaRmIzZFdha1poVjBaT2NtRkhhRk5sYlhoWFZtMXdUMVF3TUhoalJscFlZbGhTV0ZSV2FFTlNiRnBZWlVaT1ZXSlZXVEpWYkZKRFZqQXhkVlZ1V2xaaGExcFlXa1ZhVDJOc2NFZGhSMnhUVFcxb2IxWXhaREJaVmxsM1RVaG9hbEpzY0ZsWmJGWmhZMnhXY1ZGVVJsTk5WMUo1VmpKNFQxWlhTbFpYVkVwV1lrWktTRlpxUm1GU2JVbDZXa1prYUdFeGNHOVdha0poVkRKT2RGSnJhR2hTYXpWeldXeG9iMWRHV25STldHUlZUVlpHTTFSVmFHOWhiRX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ZeFdYcFZiR2hZVm14d1lWcFZXbXRrVmtwelZtMXNWMUl6YURWV01XUXdXVmRSZVZaclpGZGliRXB5Vld0V1MySXhiRmxqUldSc1ZteEtlbFp0TURWWFIwcEhZMFpvV2sxSGFFeFdNbmhoVjBaV2NscEhSbGROTW1oSlYxUkplRk14U1hoalJXUmhVbXMxV0ZZd1ZrdE5iRnAwWTBWa1dsWXdWalJXYkdodlYwWmtTR0ZHV2xwaVdHaG9WbTE0YzJOc1pISmtSM0JUWWtad05GWlhNVEJOUmxsNFYyNU9hbEpYYUZoV2FrNVRWRVpzVlZGWWFGTldhM0I2VmtkNFlWVXlTa1pYV0hCWFZsWndSMVF4V2tOVmJFSlZUVVF3UFE9PQ==
base64 인코딩된 userid 값과 userpw 값을 확인할 수 있다. 해당 base64 문자열을 문제의 쿠키 값으로 넣어주면. 문제가 풀리는 것을 확인할 수 있다.
728x90
'정보보안 > 워게임' 카테고리의 다른 글
[Webhacking.kr] Challenge old 14 - 문제풀이 (0) | 2022.12.21 |
---|---|
[Webhacking.kr] Challenge Old 1 - 문제풀이 (0) | 2022.12.21 |
[Dreamhack] Return to Shellcode - 문제풀이 (0) | 2022.09.26 |
[Dreamhack] basic_exploitation_000 문제 풀이 (0) | 2022.09.21 |
[pwnable.kr] BOF 문제풀이 (1) | 2022.09.20 |