-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex2.php
50 lines (50 loc) · 1.4 KB
/
ex2.php
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
<!DOCTYPE html>
<html>
<head><title>Ex 2: Bypass addslashes in Javascript context.</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("PC9zY3JpcHQ+PHNjcmlwdD5hbGVydCgxMzM3KTwvc2NyaXB0Pg==");
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['val'])){
//Begin Hackit:****************************************************************
if(!empty($_GET['val']) && !is_array($_GET['val'])){
$xp = addslashes($_GET['val']);
echo "Your input was: ".htmlspecialchars($_GET['val'],ENT_QUOTES,'UTF-8');
echo '<script>
function test(){
alert("'.$xp.'");
}
</script>';
}
//End Hackit******************************************************************
}
else{
$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$actual_link = $actual_link."?val=1";
header("Location: $actual_link");
die();
}
?>.
<br>
<button onclick="test()">Click me</button><br></br>
Show solution:<br>
<button onclick="solution()">Help me!</button>
<div id="myDIV" style="display:none">
</div>
</body>
</html>