Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: PHP Code Executer

  1. #1
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Question PHP Code Executer

    Hi,
    I am making A "Test-It" php tester, where a code is provided in a textarea and the user can edit the code as they like and then a new, simple php page opens, like this:
    PHP Code:
    <?php
    //this is the page that executes whatever the user writes
    $code=$_POST['code']
    some_function_to_execute_code($code);
    ?>
    <br>This is just a test document
    I will also have to use the "eregi" function to see if they are trying to change my site from the inside, e.g. make chmod 777 and add stupid text to the index file or even delete something, or find out my Database info by typing "echo $dbhost;" or somthing. Is there a way?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No. It's a Turing-complete language, there are too many possibilities. For example, you may be able to detect echo $dbhost;, but it's unlikely that you'd be able to detect:
    Code:
    $c1 = 'echo';
    $c2 = 'd';
    $c3 = 'h';
    $c4 = 's';
    $c5 = 'o';
    $c6 = 't';
    $c7 = 'b';
    eval(implode(' ', array($c1, '$' . implode('', array($c2, $c7, $c3, $c5, $c4, $c6)))) . ';');
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Thanks, but I figured out A way around this, over every page with information there will be the folwing:
    PHP Code:
    <?
    define
    (IN_WEBSITE"true);
    $ipaddr=$_SERVER['REMOTE_ADDRESS'];
    if(!isset(IN_WEBSITE)
    {
    echo "
    ERRORYou are trying to acess this page\\'s  variables form an outside source, Your ip,<b>$ipaddr</b>, is sent to the webmaster, your ip may be banned";
    mail("me@myemail", "Website Intruder", "The Intruder\'s ip: $ipaddr\r\nPage:$_SERVER['
    PHP_SELF']\\r\\nThanks, Your Website");
    }
    else
    {
    //website
    }
    ?>
    BTW: What I ment by "Is there a way?" is that Is there a way to execute code from a string?
    P.S. I could always disable impload.
    Last edited by fileserverdirect; 09-04-2007 at 04:03 PM. Reason: php typo
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Thanks, but I figured out A way around this, over every page with information there will be the folwing:
    All the attacker has to do is write define(IN_WEBSITE, true); and they're done. They can discover this information by reading the source of any page: print file_get_contents('index.php');
    Last edited by Twey; 09-04-2007 at 05:23 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Doesn't print file_get_contents('index.php'); only show the html of the document. If so than anyone could find out what google's or ebay's secert (if they were good enogh). besides, there's always encryption (which Is probally not Ideal for a constantly-updated site.
    EDIT: I got the Idea for the try-it from W3 School's HTML Try-it thingey. That page is run by .asp so anyone could simply type in an asp code and boom. (I can't give an example because I don't know any asp).
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Doesn't print file_get_contents('index.php'); only show the html of the document.
    No, because it's accessing the file directly, not processing it as PHP.
    If so than anyone could find out what google's or ebay's secert (if they were good enogh).
    Simple: they don't let people execute code on their servers.
    besides, there's always encryption (which Is probally not Ideal for a constantly-updated site.
    Also not possible: if the code runs with the permissions of the process that's used to decrypt the code, the malicious user can access the key and decrypt the pages too.
    EDIT: I got the Idea for the try-it from W3 School's HTML Try-it thingey. That page is run by .asp so anyone could simply type in an asp code and boom.
    It doesn't process ASP. The ASP examples are not editable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Well, you got me, I guess I won't have a try-it where the user can FULLY edit the code. Here is another what if,(you're problally tired of me by now) what if you could for example have a user type in (a single line one) in what they want to say, (this would be a basic HELLO WORLD Script) and the php script outputed the code to say hello world or whatever they inserted. It would not display a test document so people couldn't echo "" . $dbhost . "";, but just a block of code THEY can test. This is a fool-prof alternative.
    Last edited by fileserverdirect; 09-07-2007 at 12:03 AM. Reason: typo
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    A single block of code like:
    Code:
    shell_exec('rm -rf /var/www');
    perhaps?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Well then I will just eregi for it and the echo will be enclosed in single quotes so no code can be exicuted and if they try to type a " ' . shell_exec('rm -rf /var/www') . ' " I will check for a single quote and place a "\" before it, and if they try to double slash, a slash will be takken off. If there is any more suggestions, please post.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    So you're now just echoing the input data directly rather than parsing it?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •