Results 1 to 6 of 6

Thread: eval()'d code error

  1. #1
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default eval()'d code error

    Error:

    Warning: fgets(): supplied argument is not a valid stream resource in /user/public_html/decode/unlock.php(49) : eval()'d code on line 1

    Warning: fgets(): supplied argument is not a valid stream resource in /user/public_html/decode/unlock.php(49) : eval()'d code on line 1

    Warning: fgets(): supplied argument is not a valid stream resource in /user/public_html/decode/unlock.php(49) : eval()'d code on line 1


    Code:
    PHP Code:
    <?php

    $input 
    file_get_contents$filename 'index.php');
    if (
    ereg(
    "[$]([^=]+)=[_][_]FILE[_][_][;]"
    "[$]([^=]+)=[_][_]LINE[_][_][;]"
    "[$]([^=]+)[=]([0-9]+)[;]"
    "eval.*(base64_decode.['][^']*['].)"$input$x)) {
    // first pass
    $ifilename $x[1];
    $ilinenum
    $x[2];
    $ioffset
    $x[3];
    $offset
    $x[4];
    $decoder
    $x[5];
    // get the decoder
    $decoder = eval("return $decoder;");
    // decipher the decoder
    ereg("[$]([^=]+)[=].*[$]([^=]+)=.base64",$decoder,$x);
    $ihandle $x[1];
    $iout
    $x[2];
    $decoder str_replace($iout
    ,'output'
    ,$decoder);
    $decoder str_replace($ihandle
    ,'handle'
    ,$decoder);
    $decoder str_replace($ilinenum ,'line'
    ,$decoder);
    $decoder str_replace($ifilename,'filename',$decoder);
    // the decoder is our slave!
    $decoder str_replace('eval($output);','return $output;',$decoder);
    $decoder '$line=2;'.$decoder;
    // sandbox
    $next
    = eval($decoder);
    // remove expiration time
    $next ereg_replace("^if[^;]+;",'',$next);
    // some more deciphering
    ereg('^[$]([^=]+)=',$next,$x);
    $next str_replace($ihandle,
    'handle',
    $next);
    $next str_replace($ifilename,'filename',$next);
    $next str_replace($x[1]
    ,
    'output',
    $next);
    $next str_replace($ioffset,
    'offset',
    $next);
    // the decoder is our slave, again!
    $next str_replace('eval($output)','return $output',$next);
    // final pass
    $code = eval($next);
    // finish
    echo '<','?php',$code,'?','>',"\n";
    } else die(
    "Failed. No base64_decode anymore.\n");
    ?>

    what am i doing wrong?

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

    Default

    I think the question is more, "what are you doing?"

    Print the strings before passing them to eval() to see what you're really evaluating.
    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
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yes. If the string type isn't a number/integer/float etc, it won't work.
    I think the question is more, "what are you doing?"
    Heh... I find that quite funny.

    Back to the question...
    In javascript a simple way to see what type of variable your testing, is to use the typeof construct. It outputs the type, so in PHP all I would assume to do is to echo it or something to see what - as Twey mentioned - your are trying to evaluate.
    - Mike

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

    Default

    No, it's definitely a string, but there's some interpolation going on with data from an external file, so what s/he's evaluating might not be what s/he thinks s/he is.

    Nevertheless, this looks to be a completely pointless venture overall, as so many things using eval() are. It's certainly not possible to give a definitive answer without the contents of that file.
    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
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    file_get_contents outputs html: using this on a .php file won't output the php. In Firefox the php code shows up like this (devistating if databse info is shown):

    <?php
    ...
    ?>
    - Mike

  6. #6
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    nevermind, my hosting made that problem.

    The script is suppose to decode a type of Base64 code if anyone was wondering.

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
  •