Root-me PHP register globals
Root-me PHP register globals
PHP - register globals
1
2
3
4
5
Author
g0uZ, 8 October 2011
Statement
It seems that the developper often leaves backup files around...
Solution
- register_globals와 취약점
- stackoverflow.com/questions/3593210/what-are-register-globals-in-php
- https://lactea.kr/entry/php-registerglobals-on-취약점
문제에서 백업 파일이 있다고 했다. 따라서 url 뒤에 index.php.bak
을 입력하면 백업파일이 다운로드 된다.
아래는 파일 내용이다.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
function auth($password, $hidden_password){
$res=0;
if (isset($password) && $password!=""){
if ( $password == $hidden_password ){
$res=1;
}
}
$_SESSION["logged"]=$res;
return $res;
}
function display($res){
$aff= '
<html>
<head>
</head>
<body>
<h1>Authentication v 0.05</h1>
<form action="" method="POST">
Password <br/>
<input type="password" name="password" /><br/><br/>
<br/><br/>
<input type="submit" value="connect" /><br/><br/>
</form>
<h3>'.htmlentities($res).'</h3>
</body>
</html>';
return $aff;
}
session_start();
if ( ! isset($_SESSION["logged"]) )
$_SESSION["logged"]=0;
$aff="";
include("config.inc.php");
if (isset($_POST["password"]))
$password = $_POST["password"];
if (!ini_get('register_globals')) {
$superglobals = array($_SERVER, $_ENV,$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
extract($superglobal, 0 );
}
}
if (( isset ($password) && $password!="" && auth($password,$hidden_password)==1) || (is_array($_SESSION) && $_SESSION["logged"]==1 ) ){
$aff=display("well done, you can validate with the password : $hidden_password");
} else {
$aff=display("try again");
}
echo $aff;
?>
- extract 함수가 사용된 것이 보인다.
- bbolmin.tistory.com/53
우리는 hidden_password
를 알아내야 할 것이다.
우선 알아내려면 조건을 통과해야하는데, 세선 값은 auth를 통과해야 생긴다.
따라서 우선, auth를 통과하기 위해서 파라미터로 hidden_password
값을 보내주는데 password
값과 동일한 값으로 설정하고 요청을 보낸다.
요청을 보내면 logged
세선 값이 생성이 됬기 때문에, 우리가 알아내야 할 실제 hidden_password
값을 구하기 위해서는 다시 auth를 통과해야 한다.
auth 통과 조건을 보면 res
변수가 1로 설정이 되어야 하기 때문에, ?res=1
로 요청을 보내면 비밀번호가 출력된다.
This post is licensed under CC BY 4.0 by the author.