So, here is a piece of code I came across.
<?php $name = $_GET['name']; if (!empty($name)) { $name = str_replace("<", "<", $name); //line 1 $name = str_replace(">", ">", $name); //line 2 $name = urldecode($name); //line 3 echo $name; } ?> This code I found in one of the ethical hacking practicing frameworks named bWAPP at security level 1. The potential solution to bypass this technique is to URL encode the XSS string twice.
Let's assume my XSS string is
<script>alert('XSS');</script> //checkpoint alpha Then, encoding it once should give me
%3Cscript%3Ealert%28%27XSS%27%29%3C%2fscript%3E //checkpoint beta PROBLEM 1:
If I trace it down, on line 1 and 2 nothing happens. But on line 3 it gets decoded. And so, the resultant string I get back becomes checkpoint alpha. So, when I echo it, I should get an alert poped up.
CONTRADICTION 1:
Nothing like this happens and I just get the checkpoint alpha displayed in clear text.
PROBLEM 2:
When, I double encode it,(which is the potential solution to this problem), I get,
%253Cscript%253Ealert%2528%2527XSS%2527%2529%253C%252fscript%253E Now, this statement again passes through line 1 and 2, and on stumbling upon line 3, it gets decoded to checkpoint beta and gets echoed.
CONTRADICTION 2:
When it gets echoed, I should get checkpoint beta in clear text but Suddenly the browser pops up the alert box with XSS working perfectly.
I am new in this field and currently trying to clear my basic concepts related to web development. Please pardon my incorrect statement formation. Thank you.