PHP의 eval()
또는 MongoDB의 eval
명령 (또는 MongoDB::execute()
이라고도 함)을 사용한다고 언급하는지는 명확하지 않습니다. 후자의 경우 JavaScript 코드를 JavaScript에 연결하는 여러 가지 방법이 있습니다 (예 : 변수 할당).
eval
명령은 args
옵션을 사용합니다. 평가 된 함수에 인수를 제공합니다. MongoDB::execute()
명령 래퍼의 경우 두 번째 인수가됩니다. MongoCode 객체로 JS 함수를 정의하는 경우 scope
생성자 인수를 사용하여 PHP 컨텍스트를 JS 컨텍스트의 변수에 바인딩 할 수 있습니다. eval
에 대한 args
옵션과 마찬가지로 여기에있는 PHP 값은 BSON으로 직렬화 된 다음 JavaScript 함수에서 사용할 수 있습니다. 부울, 숫자 및 문자열 외에 배열, 객체 (실제 객체 또는 연관 배열) 및 함수 (MongoCode 객체의 문자열을 래핑하여)를 전달할 수도 있습니다.
다음 스크립트는 각 호출 메서드에 전달 될 수있는 방법을 다양한 PHP 값 설명한다 : AFAIK
$m = new MongoClient();
$values = [
true,
1.5,
'foo',
[1,2,3],
(object) ['a' => 1],
new MongoCode('function() {}'),
];
foreach ($values as $value) {
$type = is_object($value) ? get_class($value) : gettype($value);
printf("\nTesting PHP type: %s\n", $type);
$rs = $m->test->command([
'eval' => 'function(a){ return Array.isArray(a) ? "array" : typeof a; }',
'args' => [$value],
]);
printf("MongoDB::command() with code string and args: %s\n", $rs['retval']);
$rs = $m->test->execute(
new MongoCode('function(a){ return Array.isArray(a) ? "array" : typeof a; }'),
[$value]
);
printf("MongoDB::execute() with MongoCode and args: %s\n", $rs['retval']);
$rs = $m->test->execute(
'function(a){ return Array.isArray(a) ? "array" : typeof a; }',
[$value]
);
printf("MongoDB::execute() with code string and args: %s\n", $rs['retval']);
$rs = $m->test->execute(
new MongoCode('function(){ return Array.isArray(b) ? "array" : typeof b; }', ['b' => $value])
);
printf("MongoDB::execute() with MongoCode scope: %s\n", $rs['retval']);
}
, 당신은 그것을 시도하는 사람들을 막을 수 없습니다,하지만 당신은 쉽게 올바른 보호와 어떤 피해를 방지 할 수 있습니다 . 당신이 필터링되지 않은 입력에 eval()을 사용하지 않는 한 시도를 게시했습니다. innocuos가 –
입니다. 내 스크립트에는 평가 함수가 있습니다. mongodb를 사용하고 있습니다. 쿼리를 처리 할 수있는 사용자 지정 javascript 코드가 있습니다. 그래서 나는 그곳에 들어가는 것이 확실합니다. 당신이 말하는 '보호'는 무엇입니까? –
php'eval()'을 사용하고 계십니까? 이 코드를 추가하면 취약점을 발견하는 데 도움이됩니다. –