-2

Is it possible for someone to execute a code through a URL for example

http://localhost/page.php?code=echo 'something';

If yes then how can it be done and how can you prevent it from happening?

9
  • you mean executing PHP code ? you can't, unless your PHP script parses & handles the query string very well. Commented Jun 3, 2013 at 13:15
  • 1
    Execute code where? On the server? On the client? Commented Jun 3, 2013 at 13:16
  • You may go for javascript. check this: stackoverflow.com/questions/7279557/… Commented Jun 3, 2013 at 13:16
  • 1
    You can, if the server side code is severely broken. But you'd have to really try to make that kind of mistake. Commented Jun 3, 2013 at 13:17
  • 1
    @Juhana — It is hard to make the sort of mistake where PHP gets executed by accident, but very easy to allow JavaScript or SQL to be executed (W3Schools have plenty of tutorials that teach you how). Commented Jun 3, 2013 at 13:42

2 Answers 2

2

It's possible if something on the server takes the data in the URL and puts it somewhere where it might be treated as code (e.g. in an eval statement, in an SQL query or in an HTML document).

The defences are all specific to the place where you put the data, but usually involve escaping it.

See also SQL Injection, XSS, and the open web application security project.

Sign up to request clarification or add additional context in comments.

Comments

0

After looking around for a while, I found eval which is a function that is capable of executing any php code provided in a GET like my example above, I used the following code to test it.

<?php
$code = $_REQUEST['code'];
eval($code);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.