I am trying to learn how to exploit poorly secured $_GET parameters on my own website for research purpose. I just want to execute basic stuff like phpinfo(). The vulnerable code is like so :

if(isset($_GET['s_location'])) {
    $search_location = $_GET['s_location'];

$search_location is then printed on the webpage :

<div id="recap_location" class="recap-item"><span class="text"><?php print $search_location; ?></span></div>

I tried many ways without any results:

  • URL/?s_location=phpinfo();

  • URL/?s_location=eval(chr(112).chr(104).chr(112).chr(105).chr(110).chr(102).chr(111).chr(40).chr(41).chr(59));

  • URL/?s_location=eval('phpinfo();');


You won't be able to exploit code execution that way. Your code is vulnerable to cross-site scripting (XSS), but not code execution. For that you would need something like eval(), or a more subtle implicit php eval call.

However, you can exploit XSS in the above example by injecting Javascript, try something like <script> alert(1) </script> for your user input and see the popup come up in Javascript. :) An attacker could use this to pass a link with the attacker's javascript to an unsuspecting user, who when opens the link, runs the attackers javascript, potentially giving away anything from the application UI or client-side storages to the attacker. The attacker would then be able to do anything Javascript can do, when run in a user's browser in the application context (ie. running on the application origin).

A lot more info on XSS is here for example.

Update (exploiting code execution)

So you cannot execute PHP from user input this way. To make it vulnerable to code execution (ie. to be able to run PHP from user input) you need to use a variable with user input in something like eval(), like for example <?php eval($search_location) ?> in your example.

Another typical way an application would be vulnerable to this is include($_GET['myinclude']), in which case you could try providing http://some.site.tld/yourscript.php as myinclude and see how it is loaded and run on the application server.

Yet another example to make it run php code would be to use the e modifier to a regular expression with user input, as described here.

There may be many more, but simply printing a variable is "only" XSS, not code execution (fortunately, given how many websites are actually vulnerable to XSS). :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.