Repository navigation
Expand file tree
/
Copy pathex3.php
More file actions
63 lines (63 loc) · 1.62 KB
/
Copy pathex3.php
File metadata and controls
63 lines (63 loc) · 1.62 KB
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
<!DOCTYPE html>
<html>
<head><title>Ex 3: Bypass checks for Path Traversal</title></head>
<body>
<script>
var check = 0;
function solution() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
if(check == 0){
var unescaped_text = atob("cGhwOi8vZmlsdGVyL3Zhci93d3cvbXlQYWdlL3Jlc291cmNlPS9ldGMvcGFzc3dk");
var text_node = document.createTextNode(unescaped_text);
x.appendChild(text_node);
check = check + 1;
}
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<?php
if(isset($_GET['path'])){
//Begin Hackit:****************************************************************
define("BASEPATH","/var/www/mypage/");
if(!empty($_GET['path']) && !is_array($_GET['path'])){
$path = $_GET['path'];
if(stristr($path,'..')){
die("You used '..' -> goodbye");
}
if(!stristr($path,BASEPATH)){
die("Your given Path is not in my page root -> goodbye");
}
$out = "";
$file = fopen($path,"r");
if($file){
echo "<hr>Reading File..<br>";
while(($line = fgets($file)) !== false){
$out .= $line;
}
echo htmlspecialchars($out,ENT_QUOTES,'UTF-8');
echo "<hr>";
}
else{
die("Can't open file");
}
}
//End Hackit******************************************************************
}
else{
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$actual_link = $actual_link."?path=/var/www/mypage/";
header("Location: $actual_link");
die();
}
?>.
<br>
Show solution:<br>
<button onclick="solution()">Help me!</button>
<div id="myDIV" style="display:none">
</div>
</body>
</html>