用户评论:

maxim at inbox dot ru (2012-06-11 13:55:29)

Another way to catch eval() error:

$exeption= eval($str);

If ($exeption===null)//all right, execution was correctelse//wasn't correct?>

vladimir at bashkirtsev dot com (2012-06-03 22:30:24)

Good way to intercept parse error in eval:

{

echo"Parse error: ".$code;

}?>

PS: it will work only in PHP >5.2.0

f3000d at gmail dot com (2012-05-27 17:02:39)

Below was given a way to prevent eval'd code for interfering with global variables. Otherwise fine idea, which sadly does not work with malicious code. Global variables can be reached from inside of function easily, with or without eval, thus not making eval a way to prevent access to global variables:

eval($code);

}$a="a";

echo'$a before eval code: '.$a."\n";// prints "a"localeval('$a = \'b\';');

echo'$a after localeval: '.$a."\n";// still prints "a"eval('$a = \'b\';');

echo'$a after eval: '.$a."\n";// prints "b"localeval('$GLOBALS["a"] = "c";');

echo'$a after another localeval: '.$a."\n";// will print "c"localeval('global $a;$a = "2097";');

echo'$a after third localeval: '.$a."\n";// will print "2097"?>

I personally find it slightly frustrating that PHP cannot be used for code that allows plugins, unless the code is extremely well designed.

wbcarts at juno dot com (2012-05-23 22:26:08)

PHP? OR JUST TEXT?

When I am testing code, sometimes I want to see the code ALONG WITH the output. For example, if I am testing this:

for($i = 0; $i

{

$die1 = rand(1, 6);  // roll die 1

$die2 = rand(1, 6);  // roll die 2

$dieTotal = $die1 + $die2;

echo "[$die1][$die2] = $dieTotal\n";

}

I want to see the entire thing outputted to my browser like so:

---- starting from here ----

for($i = 0; $i

{

$die1 = rand(1, 6);  // roll die 1

$die2 = rand(1, 6);  // roll die 2

$dieTotal = $die1 + $die2;

echo "[$die1][$die2] = $dieTotal\n";

}

[5][2] = 7

[1][5] = 6

[5][1] = 6

[3][2] = 5

[3][6] = 9

[5][1] = 6

[6][6] = 12

[1][2] = 3

[4][5] = 9

[1][2] = 3

---- all the way to here ----

With eval() AND a simple TEXT file, I can do that. Just copy the code you are testing into a 'test.txt' file. Note: NO PHP TAGS should be in this file, AND leave a couple of blank lines at the end of the file.

Now in the PHP script, be sure to include the HTML

 tags like so:

eval(file_get_contents('test.txt'));?>

When the contents of 'test.txt' is ran through the include() function, PHP does not consider it PHP code -- this is because there are no PHP tags in the file and gets outputted straight to the browser. However, when the contents are run through the eval() function, that is a different story -- it is nothing but, pure PHP code!

sc1n at yahoo dot com (2012-03-28 00:57:49)

If you would like to handle doing an eval on a string with mixed PHP and other stuff such as HTML, you can use the following:

Example:

$test_string='A friendly llama <?php  1 == 1 ? "spit on" : "hugged"; ?> me';$p= newPhpStringParser();

echo$p->parse($mixed_string);?>

Result:

A friendly llama spit on me

You can optionally make variables that are outside of the string you are parsing available to the eval level scope by passing them into the constructor.

Example:

$llama_action='hugged';$test_string='A friendly llama =$llama_action?> me';$p= newPhpStringParser(array('llama_action',$llama_action));

echo$p->parse($mixed_string);?>

Result:

A friendly llama hugged me

protected$variables;

public function__construct($variables= array())

{$this->variables=$variables;

}

protected functioneval_block($matches)

{

if(is_array($this->variables) &&count($this->variables) )

{

foreach($this->variablesas$var_name=>$var_value)

{

$$var_name=$var_value;

}

}$eval_end='';

if($matches[1] =='='||$matches[1] =='<?php =')

{

if($matches[2][count($matches[2]-1)] !==';')

{$eval_end=';';

}

}$return_block='';

eval('$return_block = '.$matches[2] .$eval_end);

return$return_block;

}

public functionparse($string)

{

returnpreg_replace_callback('/(\/', array(&$this,'eval_block'),$string);

}

}?>

bohwaz (2012-02-04 22:51:07)

If you want to allow math input and make sure that the input is proper mathematics and not some hacking code, you can try this:

$test='2+3*pi';// Remove whitespaces$test=preg_replace('/\s+/','',$test);$number='(?:\d+(?:[,.]\d+)?|pi|π)';// What is a number$functions='(?:sinh?|cosh?|tanh?|abs|acosh?|asinh?|atanh?|exp|log10|deg2rad|rad2deg|sqrt|ceil|floor|round)';// Allowed PHP functions$operators='[+\/*\^%-]';// Allowed math operators$regexp='/^(('.$number.'|'.$functions.'\s*\((?1)+\)|\((?1)+\))(?:'.$operators.'(?2))?)+$/';// Final regexp, heavily using recursive patternsif (preg_match($regexp,$q))

{$test=preg_replace('!pi|π!','pi()',$test);// Replace pi with pi functioneval('$result = '.$test.';');

}

else

{$result=false;

}?>

I can't guarantee you absolutely that this will block every possible malicious code nor that it will block malformed code, but that's better than the matheval function below which will allow malformed code like '2+2+' which will throw an error.

socram8888 at gmail dot com (2011-11-12 12:18:07)

It may be a bit obvious, but if you don't want eval'd code to interfere with main code variables, all you have to do is to call an eval from another function like this:

return eval($code);

};$a="a";

echo'$a before eval code: '.$a."\n";// prints "a"localeval('$a = \'b\';');

echo'$a after localeval: '.$a."\n";// still prints "a"eval('$a = \'b\';');

echo'$a after eval: '.$a."\n";// prints "b"?>

kevin at NOSPAM dot schinkenbraten dot de (2011-10-20 05:23:56)

Hey guys.

With the eval()-function it is possible to create functions with specific names.

Imagine if you have an Array and want to create some function of these names.

echo '".$j."
';

}";

eval($code);

}// Now we can run the functions easily now.func_foo();func_bar();func_test();func_foobar();?>

Output will be:

foo

bar

test

foobar

--------

The point is that you don't have to run the function from a variable [create_function()].

I hope this is helpful for someone. ;) Kevin

sfinktah at php dot spamtrak dot org (2011-04-09 04:17:08)

If you really want a bullet-proof eval, you can use a socket_pair and fork().  (Not tested under windows).

if ($lookup==false) foreach (array("E_ERROR","E_WARNING","E_PARSE","E_NOTICE","E_CORE_ERROR","E_CORE_WARNING","E_COMPILE_ERROR","E_COMPILE_WARNING","E_USER_ERROR","E_USER_WARNING","E_USER_NOTICE","E_STRICT","E_RECOVERABLE_"."ERROR","E_DEPRECATED","E_USER_DEPRECATED") as$k=>$v)$lookup[1<

return (!empty($lookup[$errno]) ?$lookup[$errno] :"UNKNOWN"); }

functionchild_exit_handler($socket=NULL) {

static$paired_socket=false;

if ($socket||$socket===false) return$paired_socket=$socket;

if ($paired_socket) {$e=error_get_last();$result="ERROR_".lookupErrorCode($e["type"]) .":{$e["message"]}";

if (socket_write($paired_socket,$result,strlen($result)) ===false)

echo"socket_write() failed. Reason: ".socket_strerror(socket_last_error($sockets[0]));socket_close($sockets[0]);

}

exit(2);# Child Process Dies, writing an error to it's paired socket.}

functionforked_eval($eval) {$sockets= array();/* On Windows we need to use AF_INET */$domain= (strtoupper(substr(PHP_OS,0,3)) =='WIN'?AF_INET:AF_UNIX);/* Setup socket pair */if (socket_create_pair($domain,SOCK_STREAM,0,$sockets) ===false) {

echo"socket_create_pair failed. Reason: ".socket_strerror(socket_last_error());

}

switch ($child=pcntl_fork()) {

case -1:

throw newException("Could not fork");

case0:# Child Threadregister_shutdown_function("child_exit_handler");child_exit_handler($sockets[0]);# Register the socket$result=serialize(eval($eval));child_exit_handler(false);# We didn't crashif (socket_write($sockets[0],$result,strlen($result)) ===false)

echo"socket_write() failed. Reason: ".socket_strerror(socket_last_error($sockets[0]));socket_close($sockets[0]);

exit(3);

default :# Parent Threadif (($nread=socket_recv($sockets[1],$data,1<<16,0)) <1)

echo"socket_read() failed. Reason: ".socket_strerror(socket_last_error($sockets[1]));

if (!strncmp($data,"ERROR_",6)) {

returnsubstr($data,6);# throw new Exception(substr($data, 6));}socket_close($sockets[1]);

returnunserialize($data);

}

}

functionsafe_eval($cmd,$str=false,$file=false,$line=false,$context=false) {

static$err_strings= array();

if ($cmd===true) returncount($err_strings) ?$err_strings:false;

if ($str!==false)

return ($err_strings[] =lookupErrorCode($cmd) .":$strin$fileon line$line") &&true;$err_strings= array();$old_error_handler=set_error_handler(__FUNCTION__,E_ALL);$rv= @eval("return true;$cmd") ?forked_eval($cmd)

: ($or=error_get_last()) &&call_user_func_array(__FUNCTION__,$or);restore_error_handler(); return$rv;

}

foreach (array("return sleep(2) && foobar();","return date('Y-m-d');","return touch('/error/error/error') ? 'OK' : 'Failed';","return ==","return 2 + array();","return foobar();","return 2;") as$cmd) {printf("\nAttempting to evaluate:$cmd\n");$rv=safe_eval($cmd);printf("%s\n", ($e=safe_eval(true)) ?"ERROR:$e":"Result:$rv"); }?>

Mark Simon (2011-03-01 03:29:11)

I have looked for a simple way of forcing PHP to interpolate strings after the event (that is, after they have already been assigned, say from a text file).

The following seems to work:

$text='$a + $b = $c';$a=2;$b=3;$c=$a+$b;

print eval("return<<

I have even tried it with some potentially evil code, but the context seems to preclude interpreting it as anything other than a string.

Mark

Jordan Rutty (2011-02-27 19:52:31)

This function is to automatically sort a 2 dimensional array (like that from mysql fetches) into unlimited dimension array's

@param $array mysql fetch array

@param $row_key array of rowkeys to be used ex array('country', 'state', 'city');

*/functionLoopRowKey($array,$row_key, &$result=null){

foreach($arrayas$key=>$value){$i='';$row_key= (array)$row_key;

foreach($row_keyas$var){

if(isset($value[$var])){$var=$value[$var];$i.="['$var']";

}

}

eval("\$result$i".'[]'." = \$value;");

}

return$result;

}//this function will turn:$array= array{

array{'id'=>'1','country'=>'canada','state'=>'QC','city'=>'montreal',

}

array{'id'=>'2','country'=>'canada','state'=>'ON','city'=>'toronto',

}

array{'id'=>'3','country'=>'canada','state'=>'QC','city'=>'quebec',

}

};$row_key= array('country','state');$result=LoopRowKey($array,$row_key);//will give$result= array{'canada'=> array{'QC'=> {'0'=> array{'id'=>'1','country'=>'canada','state'=>'QC','city'=>'montreal',

}'1'=> array{'id'=>'3','country'=>'canada','state'=>'QC','city'=>'quebec',

}

}

}'ON'=> {'0'=> array{'id'=>'2','country'=>'canada','state'=>'ON','city'=>'toronto',

}

}

};?>

piyush25378 at gmail dot com (2010-11-26 01:18:20)

When using the eval() function like

eval('?>' . $data['content'] . '');

Please be sure to check that the short_open_tag is on in php.ini. Otherwise it will append the opening tag to the string.

If you are using eval function like

eval('?>' . $data['content'] . '<?php '); and you have short_open_tag on there will be parse error. So if it is required to use function like this turn off short_open_tags.

Also it is advisable to put a space after <?php  to avoid any accidental error.

jason at joeymail dot net (2010-09-21 00:03:52)

An alternative to using eval to mimic include - is to just use include on an in-memory stream. This allows a user-cooked class to pretend it is a stream, so methods which expect a stream or URL will be happy (like include)

i) register a global variable stream wrapper using stream_wrapper_register(). (search the man page for "Example class registered as stream wrapper")

ii) use file_get_contents (or db read or...) to read your php script into a global variable.

eg

$GLOBALS['yourvar']=file_get_contents('somefile.php');

iii) call include with the URL you registered. Using the example wrapper above:

include 'var://yourvar';

Easy as. Not a magic regexp in sight! Enjoy.

php at rijkvanwel dot nl (2010-09-13 07:41:16)

To catch a parse error in eval()'ed code with a custom error handler, use error_get_last() (PHP >= 5.2.0).

$return= eval('parse error');

if ($return===false&& ($error=error_get_last() ) ) {myErrorHandler($error['type'],$error['message'],$error['file'],$error['line'],null);// Since the "execution of the following code continues normally", as stated in the manual,

// we still have to exit explicitly in case of an errorexit;

}?>

php at dynamicplus dot it (2010-07-02 15:53:39)

Please note that using

eval( 'return TRUE;?>' . $sPhpCode );

is not safe to check if syntax is correct... as this will procuce a fatal error (uncatchable)....

eval( 'return TRUE;?><?phpempty ( function($var) );?>' );

using empty() on a non-pure variable will produce a

compilation error!

darkhogg (foo) gmail (bar) com (2010-03-30 10:33:43)

The following code

<?phpeval ('?> foo <?php ');?>

does not throw any error, but prints the opening tag.

Adding a space after the open tag fixes it:

<?phpeval ('?> foo <?php  ');?>

vladimiroski at gmail dot com (2010-02-25 15:18:46)

Please note that when you do something like this:

<?phpeval ('?>'.$code.'');?>

You must end it with '' because the following will give you a parse error:

<?phpeval ('?>'.$code.'<?php ');?>

Somehow eval() only likes PHP opening short-tag AKA '' but fails with '<?php '

john dot risken at gmail dot com (2010-02-25 10:35:56)

A simple use of eval:

Sometimes you want to know both the value of a variable being passed to a function and its name. Passing by reference can get you there, but only through a lot of convolutions (as far as I can tell!)

But by using the stem of a variable's name, there are two methods to achieve this.

Say that

$emailName="me@example.com";?>

You can pass this information thusly:

First, if you have the stem, "emailName', in a string var

$theVarStem="emailName";?>

you can recover the value of the original variable like this:

$theVarValue=eval("return \$$theVarStem;");?>

Using 'return' inside the eval is the trick that makes it work - something inherent in the documentation  but not at all obvious to me.

Unless $emailName has global scope, this method won't work inside a function. For that purpose, you can do the following:

myFunction(compact("emailName"))

functionmyFunction($theInfo)

{$theVarStem=key($theInfo);$theVarValue=current($theInfo);//...}?>

I apologize if all this seems too obvious: it took me a lotta sloggin' to figure it out.

ajo at NO dot SPAM dot mydevnull dot net (2010-01-05 01:15:21)

Inspired from the users microvalen at NOSPAM dot microvalen dot com and javis, i combined their notes and came up with a very simple "template engine", for testing purposes (to save the time and trouble of downloading and including a real template engine like the Smarty):

$var='dynamic content';

echo eval('?>'.file_get_contents('template.phtml') .'');?>

and the  template.phtml:

=$var?>

This is something i use a lot (specially when studying new PHP Libraries or trying new jQuery plugins) and i think it might help others too.

Nico (2009-08-11 15:27:08)

eval and namespace

For those who wonder: since eval executes the code in another context than the current script, it is possible to evaluate code that uses a particular namespace without changing the current one (and it does not trigger an error if there is no namespace and the evaluated one is not at the top of the script).

Exemple:

echo'namespace 1: '.__NAMESPACE__."\n";

eval('namespace Bar;

class BarClass {}

echo \'namespace 2: \'.__NAMESPACE__."\n";');

echo'namespace 1 again: '.__NAMESPACE__."\n";?>

output:

namespace 1: Foo

namespace 2: Bar

namespace 1 again: Foo

And it will create the class Bar\BarClass.

Also, the eval code will not belong to the namespace of the code that do the eval:

echo'namespace 1: '.__NAMESPACE__."\n";

eval('class BarClass {}

echo \'namespace 2: \'.__NAMESPACE__."\n";');?>

output:

namespace 1: Foo

namespace 2: // global namespace

cmr at expansys dot com (2009-07-31 00:20:31)

Fixed matheval function when percentage is less than 10:

{$equation=preg_replace("/[^0-9+\-.*\/()%]/","",$equation);// fix percentage calcul when percentage value

// if you really, really want to fine-tune this equation$equation=preg_replace("/([0-9]+)(%)/",".\$1",$equation);

if ($equation=="")

{$return=0;

}

else

{

eval("\$return=".$equation.";");

}

return$return;

}?>

webmaster at drakkofox dot net (2009-05-29 09:08:09)

Never, Never ever forget the ";" on the end of the eval string, if you are adding it to eval a variable attribuition;

$data="$key"."_$sequence";

eval("\$idct=\$idedit_$data;");?>

we took a long time to discover that the problem was a ";" missing in the end.

JURGEN AT PERSON DOT BE (2009-03-12 13:46:22)

I updated my code because there are many abuses of the function eval() in phpscripts to break security, privacy, to perform callbacks, to execute commands on the server by remote.  This could not be allowed in a professional environment which often deals with sensitive, important or financial data.

Code obfuscation is not a safe solution to protect Your source at all. As I do disagree with some programmers to use any ( ! ) solution to encrypt php code. I advocate to not scramble code and to not implement call home events (which hit the firewall or reverse proxy anyway).   Call backs do violate privacy of the user.  It can be considered as spyware, theft of information.  All serverside code should be readable to to verify if no sensitive information is transfered to the vendor or to verify it is not malware.  Running scrambled code is as dangerous as to run a server without any security measures. That's why some hosting providers refuse to run scrambled code on their servers. As programmer, the best way You can do is to create many revisions of Your code,  as to provide additional plugins, services and support for registered users.  So do not encrypt a single line of code at all, do follow the opensource standard and do respect privacy and the right of verification of the user of your scripts.

So here is an updated version, to use with PHP-CLI  If it fails in the process, You can invoke with the verbose option so You can follow the process and alter this code.

----- snippet denest.php.sh -----------

#!/usr/bin/php

// perform chmod +x denest.php.shecho"\nDECODE nested eval(gzinflate()) by DEBO Jurgen \n\n";/* invokation php-cli:  #php denest.php   */$filename_full=$argv[1];$verbose= (bool)$argv[2];$filename_base=basename($filename_full,'.php');$content="";

echo"Using: ".$filename_base.".php\n";

echo"Read...\n";$fp1=fopen($filename_full,"r");$content=fread($fp1,filesize($filename_full));fclose($fp1);

echo"Decode...\n";

while (is_nested($content) )$content=denest($content);dump($content,TRUE);

functionis_nested($text) {

returnpreg_match("/eval\(gzinflate/",$text);

}

functiondenest($text) {

global$verbose;$text=preg_replace("//","",$text);

if ($verbose)dump($text,FALSE);

eval(preg_replace("/eval/","\$text=",$text));

if ($verbose)dump($text,FALSE);

return$text;

}

functiondump($text,$final) {

static$counter=0;

global$filename_base;$filename_new= ($final) ? ($filename_base.".done.php") : ($filename_base.".".sprintf("%04d", ++$counter).".php");

echo"Writing ".$filename_new."\n";$fp2=fopen($filename_new,"w");fwrite($fp2,trim($text));fclose($fp2);

}?>

----- snippet denest.php.sh -----------

microvalen at NOSPAM dot microvalen dot com (2009-02-21 22:44:46)

very simple example to includea html file:

$simple_var='This is a simple var';

eval("\$file=\"".addslashes(implode("",file("test.html"))) ."\";");

print$file;?>

and the html:

$simple_var

javis (2009-02-09 13:54:22)

you can actually run strings with html and php code. To do that you need to append ?> and  simbols like this:

<?phpeval ("?>".$code."");?>

php at stock-consulting dot com (2008-11-28 08:16:09)

Magic constants like __FILE__ may not return what you expect if used inside eval()'d code. Instead, it'll answer something like "c:\directory\filename.php(123) : eval()'d code" (under Windows, obviously, checked with PHP5.2.6) - which can still be processed with a function like preg_replace to receive the filename of the file containing the eval().

Example:

$filename=preg_replace('@\(.*\(.*$@','',__FILE__);

echo$filename;?>

maurice at chandoo dot de (2008-11-07 15:20:02)

//Signs

//Can't assign stuff$bl_signs= array("=");//Language constructs$bl_constructs= array("print","echo","require","include","if","else","while","for","switch","exit","break");//Functions$funcs=get_defined_functions();$funcs=array_merge($funcs['internal'],$funcs['user']);//Functions allowed

//Math cant be evil, can it?$whitelist= array("pow","exp","abs","sin","cos","tan");//Remove whitelist elementsforeach($whitelistas$f) {

unset($funcs[array_search($f,$funcs)]);

}//Append '(' to prevent confusion (e.g. array() and array_fill())foreach($funcsas$key=>$val) {$funcs[$key] =$val."(";

}$blacklist=array_merge($bl_signs,$bl_constructs,$funcs);//Check$status=1;

foreach($blacklistas$nono) {

if(strpos($code,$nono) !==false) {$status=0;

return0;

}

}//Evalreturn @eval($code);

}?>

Note: Try to include this after all of your other self-defined functions and consider whether the blacklist is appropriate for your purpose

I wouldn't recommend this function if you're going to use eval extensively in your script. However, it's worth a try if you are going to put user input into eval

alexis at amigo dot com (2008-11-04 20:20:11)

eval vs include

i have to make a script to take code from a database and excute it, but i'm not sure is eval was hight server load than include, so i take the example of Luke at chaoticlogic dot net and test it, the results are great for eval:

test.php

//one hundred million times$code="\$increment++;";//remember the time this test started$started=time();//execute $code on hundred million timesfor ($i=0;$i<100000;$i++) {

eval($code);

}//find out how long it took, in

//seconds$ended=time();$spent=$ended-$started;//tell the user thisprint"Eval()ed code took$spentseconds to execute 100,000 times.\n";//re-establish that same blank integer$increment=0;//remember the time this second test

//started$started=time();//execute the test again, with

//pre-parsed codefor ($i=0;$i<100000;$i++) {

include("increment.php");

}//find out how long it took, in

//seconds$ended=time();$spent=$ended-$started;//tell the user thisprint"Included file with Pre-parsed code took$spentseconds to execute 100,000 times.\n";?>

increment.php

$increment++;?>

Eval()ed code took 0 seconds to execute 100,000 times. Included file with Pre-parsed code took 17 seconds to execute 100,000 times.

i change 100,000,000 for 100,000 because the script take so much time

Mark dot Sheppard at disney dot com (2008-10-30 03:13:48)

One thing to note is that an exit() call inside an eval() exits the entire script, *not* just the eval(), which is what you'd expect if you've ever used eval() in any other language. This makes it somewhat useless in my opinion.

luke at cywh dot com (2008-09-17 13:12:31)

Finally, a good use for eval :)!

If you want to be able to check for syntax errors WITHOUT executing the code, add "return true;" before all the code. All execution of the code stops after that mark, and makes eval returns true on no syntax errors, and false on syntax errors.

This is especially useful for anyone making a template system.

Here's a working example:

return @eval('return true;'.$code);

}

print"No Code execution:
\n";$code="print \"hello! you don't want me...
\n\";";var_dump(check_syntax($code));// Good syntaxprint"
\n";var_dump(check_syntax($code.' =='));// Bad syntaxprint"
\n";

print"Code Executed...Bad:
\n";var_dump(eval($code) ===null);// Good syntaxprint"
\n";var_dump(@eval($code.' ==') ===null);// Bad syntax?>

asohn at aircanopy dot net (2008-09-11 13:45:04)

$hello[2][4][6][8][10] ='this is a test';$w="[2]";$o="[4]";$r="[6]";$l="[8]";$d="[10]";

echo'hello, '.eval("return \$hello$w$o$r$l$d;");?>The above will output:

hello, this is a test

marco at harddisk dot is-a-geek dot org (2008-06-30 10:44:53)

eval does not work reliably in conjunction with global, at least not in the cygwin port version.

So:

functionload_module($module) {

eval("global \$".$module."_var;");

eval("\$".$module."_var=&new foo();");//various stuff ... ...}load_module("foo");?>

becomes to working:

functionload_module($module) {

eval('$GLOBALS["'.$module.'_var"]=&new foo();');//various stuff ... ...}load_module("foo");?>

Note in the 2nd example, you _always_ need to use $GLOBALS[$module] to access the variable!

trukin at gmail dot com (2008-06-11 08:58:46)

The EVAL function can be used  as a fast Template system.

foreach ($paramsas$k=>$v) {

$$k=$v;

}ob_start();

eval("?>".implode("",file($template)) ."");$c=ob_get_contents();ob_end_flush();

return$c;

}?>

Example:

<?phpechoparseTemplate ("myTemplate.php", array('account'=>$row));?>

and myTemplate.php can be like

<?phpforeach ($accountas$k=>$v) :?>  <?phpecho $k;?>: <?phpecho $v;?>

Ivan Zahariev (2008-04-02 01:09:58)

It seems that the Magic constants (http://www.php.net/manual/en/language.constants.predefined.php) do NOT work in an eval()'ed code.

Probably because PHP substitutes these statically when it compiles the source code of your PHP script initially.

So the following will not work as expected:

echo"User function name: ".__FUNCTION__."\n";

eval('echo "in eval(): User function name: ".__FUNCTION__."\n";');

}?>

Calling user_func1() will output:

User function name: user_func1

User function name:

Luke at chaoticlogic dot net (2008-04-02 00:26:46)

I thought it was pertinent to demonstrate just how slow the eval() function is when compared to pre-parsed code, so I wrote this.

In my case, it took 54 seconds to execute the code 100,000,000 times through eval(), and only 4 seconds with pre-parsed code.

//one hundred million times$code="\$increment++;";//remember the time this test started$started=time();//execute $code on hundred million timesfor ($i=0;$i<10000000;$i++) {

eval($code);

}//find out how long it took, in

//seconds$ended=time();$spent=$ended-$started;//tell the user thisprint"Eval()ed code took$spentseconds to execute 100,000,000 times.\n";//re-establish that same blank integer$increment=0;//remember the time this second test

//started$started=time();//execute the test again, with

//pre-parsed codefor ($i=0;$i<10000000;$i++) {$increment++;

}//find out how long it took, in

//seconds$ended=time();$spent=$ended-$started;//tell the user thisprint"Pre-parsed code took$spentseconds to execute 100,000,000 times.\n";?>I wish there was some way to parse code, store the pre-parsed binary in a variable, and then tell PHP to execute that variable as if it was part of the program.

Ipseno at yahoo dot com (2008-02-25 10:24:25)

If you attempt to call a user defined function in eval() and .php files are obfuscated by Zend encoder, it will result in a fatal error.

Use a call_user_func() inside eval() to call your personal hand made functions.

This is user function

{

return$nmb*$nmb;

}?>

//Checking if eval sees it?

$code=var_export(function_exists('square_it') );

eval($code);//returns TRUE - so yes it does!?>

This will result in a fatal error:

PHP Fatal error:  Call to undefined function square_it()

$code='echo square_it(55);';

eval($code);?>

This will work

$code='echo call_user_func(\'square_it\', 55);';

eval($code);?>

pierrotevrard at gmail dot com (2007-07-03 08:58:15)

A wonderful world of eval() applications

You certainly know how to simulate an array as a constant using eval(), not ? See the code below:

{define('MY_ARRAY','return '.var_export( array(1,2,3,4,5) ,true) .';');

}?>

And far, far away in your code...

$my_array= eval(MY_ARRAY);?>

But the grandeur of eval is when you use it to customize some method of a class :

{

classmy_class{//private propretiesvar$_prop;

var$_custom_check='return true;';//of course, I want a default check code that return true

//PHP4 constructorfunctionmy_class()

{$this->_prop= eval(MY_ARRAY);

}

functioncustomize_check($code)

{$this->_custom_check=$code;

}

functioncheck($val)

{

return eval($this->_custom_check);

}

}

}$my_class= newmy_class();$check='return in_array( $val , $this -> _prop , true );';$my_class->customize_check($check);

print'

';

if($my_class->check(1) )

{

echo'1 is checked as true.'."\n";

}

else

{

echo'1 is checked as false.'."\n";

}//show: 1 is checked as true.if($my_class->check('1') )

{

echo'"1" is checked as true.'."\n";

}

else

{

echo'"1" is checked as false.'."\n";

}//show: "1" is checked as false.print'

';?>

The application of eval() using propreties of a class gives you so much possibilities...

Of course, combinate with a safer eval code, will be better but if you use it only in your code ( for framework project by example ) that's note necessary...

Have fun.

udo dot schroeter at gmail dot com (2007-05-26 11:40:12)

Safer Eval

eval() is used way to often. It slows down code, makes it harder to maintain and it created security risks. However, sometimes, I found myself wishing I could allow some user-controlled scripting in my software, without giving access to dangerous functions.

That's what the following class does: it uses PHP's tokenizer to parse a script, compares every function call against a list of allowed functions. Only if the script is "clean", it gets eval'd.

var$source,$allowedCalls;

functionSaferScript($scriptText) {$this->source=$scriptText;$this->allowedCalls= array();

}

functionallowHarmlessCalls() {$this->allowedCalls=explode(',','explode,implode,date,time,round,trunc,rand,ceil,floor,srand,'.'strtolower,strtoupper,substr,stristr,strpos,print,print_r');

}

functionparse() {$this->parseErrors= array();$tokens=token_get_all(''.'php '.$this->source.' ?'.'>');$vcall='';

foreach ($tokensas$token) {

if (is_array($token)) {$id=$token[0];

switch ($id) {

case(T_VARIABLE): {$vcall.='v'; break; }

case(T_STRING): {$vcall.='s'; }

case(T_REQUIRE_ONCE): case(T_REQUIRE): case(T_NEW): case(T_RETURN):

case(T_BREAK): case(T_CATCH): case(T_CLONE): case(T_EXIT):

case(T_PRINT): case(T_GLOBAL): case(T_ECHO): case(T_INCLUDE_ONCE):

case(T_INCLUDE): case(T_EVAL): case(T_FUNCTION): {

if (array_search($token[1],$this->allowedCalls) ===false)$this->parseErrors[] ='illegal call: '.$token[1];

}

}

}

else$vcall.=$token;

}

if (stristr($vcall,'v(') !='')$this->parseErrors[] = array('illegal dynamic function call');

return($this->parseErrors);

}

functionexecute($parameters= array()) {

foreach ($parametersas$k=>$v)

$$k=$v;

if (sizeof($this->parseErrors) ==0)

eval($this->source);

else

print('cannot execute, script contains errors');

}

}?>

Usage example:

$ls= newSaferScript('horribleCode();');$ls->allowHarmlessCalls();print_r($ls->parse());$ls->execute();?>

Of course it is not entirely safe, but it's a start ;-)

kai dot chan at kaisystems dot co dot uk (2007-03-16 03:06:21)

Since JSON started becoming popular. I've started applying the same idea to PHP arrays. Its an alternative to using XML or CSV. For example:

$from_external_source='( "a" => "1", "b" => array( "b1" => "2", "b2" => "3" ) )';

eval('$external_source_as_array = array'.$from_external_source.';');

if (is_array($external_source_as_array) ) {// now you can work with the external source as an arrayprint_r($external_source_as_array);

}?>It can be less verbose than XML, but provide more meta data than CSV, and unlike CSV, data ordering is not an issue.

I used it when I wanted to store log data externally in a text file.

Kai

f dot boender at electricmonk dot nl (2007-01-15 00:39:59)

Errors that occur in evaluated code are hard to catch. burninleo at gmx dot net posted some code below that will buffer the output of the evaluated code and search the output for errors. Another way you can do this would be using a custom error handler that's only in effect during the eval() of the code. A very (very) crude example:

$errors= array();

functionerror_hndl($errno,$errstr) {

global$errors;$errors[] = array("errno"=>$errno,"errstr"=>$errstr);

}

functionevale($code) {

global$errors;$errors= array();$orig_hndl=set_error_handler("error_hndl");

eval($code);restore_error_handler();

}evale('print("foo" . $bar);');// Undefined variable: barvar_dump($errors);//fooarray(1) {

//  [0]=>

//  array(2) {

//    ["errno"]=>

//    int(8)

//    ["errstr"]=>

//    string(23) "Undefined variable: bar"

//  }

//}?>

This will however not catch syntax errors in the code you're trying to eval. This can cause your script to stop with a fatal error inside the eval(). You can catch syntax errors using the Parsekit PECL extension. The parsekit_compile_string() function will try to compile a piece of PHP code and will catch syntax errors if they occur. To extend the earlier piece of code:

$errors= array();

functionerror_hndl($errno,$errstr) {

global$errors;$errors[] = array("errno"=>$errno,"errstr"=>$errstr);

}

functionevale($code) {

global$errors;$errors= array();// Reset errors$orig_hndl=set_error_handler("error_hndl");

if (parsekit_compile_string($code, &$errors,PARSEKIT_QUIET)) {

eval($code);

}restore_error_handler();

if (count($errors) >0) {

return(false);

} else {

return(true);

}

}

if (!evale('print("foo . $bar);')) {// syntax error, unexpected $end (no closing double quote)var_dump($errors);

}?>

(NOTE: Please do not use the code above directly in your program. It's merely a proof-of-concept).

Dale Kern, Salt Lake City (2006-10-10 10:16:40)

If you are trying to get eval()  to run a string as if it were from an include file, try this:

<?phpeval ("?>".$string);?>

Eval starts in PHP Script mode, break into html mode first thing and you're done.

Nova912 (2006-07-21 13:17:40)

Well let me just start off by saying that eval(); confused the heck out of me untill I read that you can use Return.

This will help anyone who wants to "Inject" code into an IF statement. My example is a survey site, some questions are required, some are only required if others are checked. So let me share with you my dynamic script and show you how I was able to make a Dynamic IF Statement.

The code below had been altered to be understandable.

$survey_number=3// The third survey. (Out of 10 Surveys)$rq[3] = array(1,2,3,4,5,6,8,9,11,13,15,17,19,20);// Required Questions  for Survey 3 - Some of these can not be "NULL" (not NULL) or they will stop the script from going any further. (In my script I replaced any questions that were not answered with "NULL" using a for loop based on the number of questions in the survey)$aa[3][4] =' && '.$q[3].' == "1"';// Added Arguments - 3 = Survey 3's Arguments, 4= Argument belongs to question 4, $q[1-20] (20 Questions total in this case.

//HERE IS THE DYNAMIC IF STATEMENT$count=count($rq[$survey_number]);

for ($i=0;$i

{$if_statement='$q['.$rq[$survey_number][$i].'] == "NULL"';

if(isset($aa[$survey_number][$rq[$survey_number][$i]]))

{$if_statement.=$aa[$survey_number][$rq[$survey_number][$i]];

}

if(eval("return ".$if_statement.";"))

{

echo$rq[$survey_number][$i].': Is NULL and IS NOT ok.
';

}

else

{

echo$rq[$survey_number][$i].': Is NULL and IS ok.
';

}

}?>

In my experiance with this the Added Argument needs to have an actual value inplanted into the string, it did not work by just putting $q[3], i had to use '.$q[3].' to place the value of question 3 in the string.

I hope this help someone, I spent so much time trying to figure this out and want to share how something this simple is done.

Thank you.

brettz9 a/- yah00 do/- com (2006-07-05 14:19:05)

I was trying to build a multidimensional array to an unknown dimension (within a loop or "while") and found that eval is, as far as I can tell, the only simple way to solve the problem.

$arr= array(2,

array("v","q",5,

array(5,8,"g"),"x"));$i=3;$key1="[1]";$key2="[".$i."]";// E.g., could build this conditionally within a loop$key3="[2]";$keys=$key1.$key2.$key3;// Can add as many keys as needed (could be done instead via a loop with repeated calls to .= )print$arr{$keys};// This does not workprint$arr[$keys];// This also does not work

// However...eval("\$value = \$arr{$keys};");

print$value;// Correctly prints "g"?>

burninleo at gmx dot net (2006-05-25 05:51:00)

The only way to retreive information on parse errors in eval'd code seems to be the output buffering.

echo$output;

} else {// Manually parse output for errors and

// generate usable information for the user

// especially content of error-lines.$pattern='/^\s*Parse error\s*:(.+) in (.+) on line (\d+)\s*$/m';etc...

}

jkuckartz1984 at hotmail dot com (2006-01-29 04:01:59)

Might you have to do eval in if statements, you will find it's quite some task to make it work.

The only way to make it work is to make a reference to the eval'd variable. This example will show the different usage of eval in if-statements. It simply becomes clear that an eval() in an if() is not working as you want to.

$total2=5;$total3=0;$i=2;

if (eval("\$total".$i.";")) {

echo"eval: total2 is full
";

} else {

echo"eval: total2 is empty
";

}// returns "empty"

// eval without the ";" will generate a warning$str="\$refer=&\$total".$i.";";

eval($str);

if ($refer) {

echo"eval: total2 is full
";

} else {

echo"eval: total2 is empty
";

}// returns "full"?>

Sarangan Thuraisingham (2006-01-20 17:47:07)

The eval function can be misused for Cross Site Scripting(XSS) as well. Les say we have this very trivial page that allows a user to enter a text and see it formated using different styles. If the site designer was lazy and used eval function to come up with somethig like this:

$mytxt=$_GET["text"];$strFormats= array('

$mytxt

','

$mytxt

','$mytxt');//so onforeach ($strFormatsas$style){

eval("echo$style;");

}?>This page could be a target for XSS, because user input is not validated. So the hacker could enter any valid PHP commands and the site will execute it. Imagine what could happen if the injected script reads files like config.php and passed it to the hacker's site.

If the file permissions are not set correctly, the injected script could modify the current script. A form's action parameter can be set to a hacker's site or worse every transaction could be secretly posted to another website from within the server. Injected script could be something like this:

$filename=basename($_SERVER['PHP_SELF']);$fp=fopen($filename,"a");$str= echo"";// could be any PHP commandfwrite($fp,$str);fclose($fp);?>

The golden rule is don't trust the user. Always validate data from the client side.

jurgen at person dot be (2005-12-18 09:27:18)

eval() is used to protect (read: hide) source code. A well known way to encrypt some php code is security through obscurity.  Someone used eval(base64_encode(".....")); - which basically had 10-16 nested calls to eval(base64_encode()) inside the data.

E.g.

However this can be decoded in this way:

<?phpecho "\nDECODE nested eval(gzinflate()) by DEBO Jurgen \n\n";

echo"1. Reading coded.txt\n";$fp1=fopen("coded.txt","r");$contents=fread($fp1,filesize("coded.txt"));fclose($fp1);

echo"2. Decoding\n";

while (preg_match("/eval\(gzinflate/",$contents)) {$contents=preg_replace("//","",$contents);

eval(preg_replace("/eval/","\$contents=",$contents));

}

echo"3. Writing decoded.txt\n";$fp2=fopen("decoded.txt","w");fwrite($fp2,trim($contents));fclose($fp2);?>

onlyphp (2005-11-24 06:59:28)

To simulate the register_globals setting in php.ini, you must put it in the top of your php page:

foreach($aras$ar_) {

foreach($ar_as $key=>$value) {

eval("\$".$key." = \"".$value."\";");

}

}

}?>

matt at mattsoft dot net (2005-09-10 10:23:55)

to load a php file to a variable then execute it, try this

$code=file_get_contents("file.php");$code=str_replace(''.trim($code).'

eval($code);?>

using , but insted adds ? > and

sadi at unicornsoftbd dot com (2005-09-03 06:49:17)

I m going to give you my recent exploration about eval. I think you dont need all those complex functions using regex to work HTML in your code. when ever you call eval(), php thinks that it is within  ?> tags. so all the problem rises. to solve the problem just close your php tag at first of the HTML string, then write the HTML string and then start the php tag.

this is some thing like:

$teststr="?>

this is the test<?php ";

eval($teststr);?>

i think this will work for you. at least this worked for me. if you find any problem with this please reply

zcox522 at gmail dot com (2005-08-17 12:03:21)

If you send headers after you call the eval() function, you may get this error:

PHP Error: (2) Cannot modify header information - headers already sent by (output started at something...)

In this case, surround your call to eval() with calls to some ob functions:

$eval="some code you want to execute";ob_start();

eval($eval);ob_end_clean();?>

admiral [at] nuclearpixel [dot] com (2005-08-15 13:02:59)

This function will take any combination of HTML and (properly opened and closed)PHP that is given in a string, and return a value that is the HTML and the RESULT of that PHP code and return them both combined in the order that they were originally written.

I tried using both the eval_html(gave me carp about using 's and "s in the HTML) and html_eval2(gave me the results of the PHP first, then all of the HTML afterwards) posted by the other users on this function's notes, but for some reason, neither of them would really work the way I had understood that they would work,(or in the case of some of my code, work at all)

So I combined the best of what I saw in both, and created eval_html3

return ('echo stripslashes("'.addslashes($arr[0]).'");');

}

functioneval_html3($string) {$string='<?php  ?>'.$string.'<?php  ?>';$string=str_replace('?>','',str_replace( array('<?php ','<?'),'',preg_replace_callback("/\?>(.*?)(

return eval($string);

}?>

Good luck!

jphansen at uga dot edu (2005-08-08 12:43:37)

I used eval() to restore a user's session data. I stored $_SESSION to a field in a database as

addslashes(var_export($_SESSION,TRUE))?>

To restore it, I executed this code:

Voila! Session restored.

Without eval(), $_SESSION = $session would have resulted in $_SESSION being a string instead of an array.

the dank (2005-07-29 16:26:18)

$foo1="the good,
";$foo2="the bad,
";$foo3="the ugly.";

for ($i=1;$i<=3;$i++)

{

eval("\$_SESSION['myVar$i'] = \$foo".$i.";");

}//use below to show what's in session:echo"

SESSION

";

echo"

echo"

";

echo"

Variable Name";

echo"

Value";

while(list($key,$val) =each($_SESSION))

{

echo"

$key$val";

}

echo"

";

die();/*---------------------------------------------------------

Prints:

myVar1    the good,

myVar2    the bad,

myVar3    the ugly.

*/?>

privat at timo-damm dot de (2005-07-29 01:03:26)

Using the html_eval() some notes above I experienced problems related to *dirty* html. This function is less critical:

returnpreg_replace_callback("//","my_eval",$string);

}

functionmy_eval($arr) {

return eval($arr[1]);

}?>

Timo

andrejkw (2005-06-23 17:50:16)

To use eval output as a variable without the user seeing the output, use this:

ob_start();

eval("whatever you want");$eval_buffer=ob_get_contents();ob_end_clean();

echo$eval_buffer;?>

Everything that eval produces will now be stored inside $eval_buffer.

Jesse (2005-06-18 13:25:24)

a cool way to use eval is to convert strings into variable names.

this is a subsitute for using arrays.

look at this code:

eval("$"."variable".$a."=".$a.";");

}?>this will create variables called variable1, variable2, and so on, that are equal to 1, 2, and so on.

i recently used this to help a friend make a Flash game that sent variables like that to PHP.

1413 at blargh dot com (2005-06-09 12:58:01)

Just a note when using eval and expecting return values - the eval()'ed string must do the returning.  Take the following example script:

{

return array("foo"=>1,"bar"=>2);

}$test= eval("ReturnArray();");

print("Got back$test(".count($test).")\n");$test= eval("return ReturnArray();");

print("Got back$test(".count($test).")\n");?>

You will get back:

Got back  (0)

Got back Array (2)

This ran me afoul for a little bit, but is the way eval() is supposed to work (eval is evaluating a new PHP script).

jtraenkner (2005-04-10 09:11:34)

Using eval inside loops is very slow, so try avoiding code like

eval('do_something()');

}?>

If you absolutely have to, include the entire loop in eval:

tom (2005-03-28 23:59:37)

Eval can't be used as a callback function so if you want to use the eval function name dynamically use this simple work around:

{

eval($stuff);

}

else

{$function_name($stuff);

}?>

Ben Grabkowitz (2005-03-26 18:57:21)

The eval function becomes incredibly useful when dealing with static class members and variables.

For instance:

Lets say you have 3 classes; Foo, BarA and BarB, where BarA and BarB are children of Foo.

Now lets also say that both BarA and BarB contain a static member function called getDataSource().

To call getDataSource() you would have to use the syntax:

BarA::getDataSource();BarB::getDataSource();?>

But lets say you need to access getDataSource() from inside class Foo during an instance of either BarA or BarB.

You can use eval to do something like this:

francois at bonzon dot com (2005-02-27 19:20:12)

An obvious security reminder, which I think wasn't yet mentioned here. Special care is required when variables entered by the user are passed to the eval() function. You should validate those user inputs, and really make sure they have the format you expect.

E.g., if you evaluate math expressions with something like

without any check on the $equation variable, a bad user could enter in the $equation field

""; echo file_get_contents('/etc/passwd')

- or whatever PHP code he wants! - which would evaluate to

$result=""; echofile_get_contents('/etc/passwd');?>

and seriously compromising your security!

avenger at buynet dot com dot br (2005-02-08 20:52:26)

This is a small code that uses 'eval' with a foreach (maybe 'for' loop), to fill variables. This is very useful in some hard situations:

for loop

$thing= array("a","b","c");$a="bah";$b="bleh2";$c="bluh3";

print("Vars b4:$a,$b,$c. ");

foreach ($thingas$thingy) {

print("$thingy, ");

eval("\$$thingy= \"$thingy\";");

};

print("vars aft:$a,$b,$c.");?>

arnico at c4 dot lv (2004-12-21 03:28:52)

Dynamically loading php pages!

In michael example ( 02-Sep-2004 05:16) is one big problem. Try to load php page with this content :

-----------------------

$a=1;

if($a==1){?>
ir?

<?php }?>------------------------

Ups? :) maybe easier way is to do something like that ? please comments :

<?phpfunctioneval_html ($string) {$string=preg_replace("/\?>(.*?)(","",$string);

return eval($string);

}$filename="page.php";$handle=fopen($filename,"r");$contents=fread($handle,filesize($filename));fclose($handle);

echoeval_html($contents);?>

The html source will be replaced with echo. and problem is gone :) or there are other problems ? please comments.

P.S. sorry about my bad English

mahaixing at hotmail dot com (2004-10-08 20:49:02)

When using Dynamic Proxy design pattern we must create a class automaticly. Here is a sample code.

$clazz="class SomeClass { var \$value = 'somevalue'; function show() { echo get_class(\$this);}}";

eval($clazz);$instance= newSomeClass;// Here output 'somevalue';echo$instance->value;

echo"
";//Here output 'someclass'$instance->show();?>

evildictaitor at hotmail dot com (2004-08-15 13:00:15)

Be careful when using eval() on heavy usage sites in PHP 4.0+ as it takes vastly longer to activate due to the limitations of the Zend engine.

The Zend engine changes the PHP to a binary structure at the START of the file, and then parses it. Every time an eval is called, however, it has to reactivate the parsing procedure and convert the eval()'d code into usable binary format again.

Basically, if you eval() code, it takes as long as calling a new php page with the same code inside.

(2004-07-12 09:37:26)

Kepp the following Quote in mind:

If eval() is the answer, you're almost certainly asking the

wrong question. -- Rasmus Lerdorf, BDFL of PHP

在php输出字符串时执行html标签,把字符串作为PHP代码执行相关推荐

  1. java解析shell命令_Android中执行java命令的方法及java代码执行并解析shell命令

    这篇文章给大家介绍Android中执行java命令的方法及java代码执行并解析shell命令,需要的朋友一起学习 android中执行java命令的方法大家都晓得吗,下面一段内容给大家带来了具体解析 ...

  2. python执行效果_使用tqdm显示Python代码执行进度功能

    在使用Python执行一些比较耗时的操作时,为了方便观察进度,通常使用进度条的方式来可视化呈现.Python中的tqdm就是用来实现此功能的. 先来看看tqdm的进度条效果: tqdm的基本用法 tq ...

  3. 对象 php 输出用字符串连接,在PHP中使用 在使用echo或print输出对象时将对象转化为字符串。_学小易找答案...

    [单选题]激光洗眉常出现下列哪种情况? [单选题]绪论1 你的青春就是一场远行,一场离自己的童年,离自己的少年,越来越远的一场远行.在我和你们一样大的时候,18岁,我正在一列,从上海到北京的火车上,我 ...

  4. 远程命令执行与代码执行(remote command/code execute)漏洞总结

    文章目录 前言: 一.基础知识 1.命令执行漏洞 常用的命令连接符: 2.代码执行漏洞 3.PHP中的危险函数: 二.靶场练习 命令执行: 1.Low级别 2.Medium级别 3.High级别 4. ...

  5. 破解索尼PS4系列:用户代码执行(二)

    本文讲的是破解索尼PS4系列:用户代码执行(二), 本文会重点讲解如何在WebKit进程中进行代码执行. 代码执行 正如上一篇文章讲过的那样,ROP只是以一种聪明的方式执行内存中加载的现有代码,而RO ...

  6. 浅谈PHP代码执行中出现过滤限制的绕过执行方法

    本篇文章总结于本人在CTF比赛中碰到的各种代码执行绕过方法 文章目录 代码执行函数 可回调函数 字符串拼接绕过 字符串转义绕过 多次传参绕过 内置函数访问绕过 异或绕过 URL编码取反绕过 代码执行函 ...

  7. android fastjson漏洞_【漏洞预警】Fastjson 远程代码执行漏洞(暂无PoC)

    Fastjson简介 Fastjson是一个Java语言编写的高性能功能完善的JSON库.它采用一种"假定有序快速匹配"的算法,把JSON Parse的性能提升到极致,是目前Jav ...

  8. python执行txt中代码_【技术分享】文件解压之过 Python中的代码执行

    预估稿费:200RMB 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 一.前言 Python中负责解压压缩文件的代码实现上并不安全,存在目录遍历漏洞,攻击者可以利用该漏洞覆盖_ ...

  9. pikachu靶场-5 远程命令,代码执行漏洞(RCE)

    远程命令,代码执行漏洞(RCE) RCE(remote command/code execute)概述 RCE漏洞,可以让攻击者直接向后台服务器远程注入操作系统命令或者代码,从而控制后台系统. 远程系 ...

最新文章

  1. enable_shared_from_this理解
  2. 【Android 安装包优化】移除无用资源 ( 自动移除无用资源 | 直接引用资源 | 动态获取资源 id | Lint 检查资源 )
  3. 九九乘法表c语言编程伪代码,py_11分支和循环
  4. yum安装出现No package vim available解决办法
  5. 如何判断SAP CDS view的association是inner join还是outer join实现的
  6. python 编程快速上手,Python编程快速上手
  7. 在FLEX中获得当前PLAYER版本等信息.
  8. pytorch学习笔记(6):GPU和如何保存加载模型
  9. 全库检索包含某个值的表名和所在的列.
  10. 剑指Offer 09 用两个栈实现队列
  11. linux内核分析及应用 -- Linux 网络层数据流分析(下)
  12. m3u8转换到mp4 python_Python 实现MP4视频转M3u8视频
  13. 2019天津市计算机等级考试报名时间,天津2020上半年计算机等级考试报名时间已公布...
  14. 【支线】基于Aidlux的Arduino小车
  15. Yii:zii.widgets.CMenu使用方法
  16. Linux伪文件系统proc
  17. C语言程序设计-p163例7-9
  18. 基于FPGA的频率计设计
  19. 基于人脸识别的智能服饰搭配小程序
  20. 广州华夏职业学院计算机,牛!华夏学子被清华大学聘用!

热门文章

  1. 为了给YiYi节省时间,写了个能自动拼图贴水印的机器人,很多bug,能用就行。...
  2. 你还在纠结器件丝印放错的烦恼么?
  3. 基于Android的本地电子书阅读器的设计与实现Ebook(1)
  4. 云服务器和虚拟主机有什么区别?哪个比较好呢?
  5. Win8安装mysq5.6没有MySQL服务
  6. win8 安装 iis 笔记
  7. centos8 安装docker
  8. FFMPEG 实现视频拼接,中间插入图片实现过渡
  9. 【考研数学】一文搞定不等式
  10. 程序员专属对联,句句扎心