2011-09-12 5 views
0

고객 데이터가 관련되어 있으므로 실제로이 문제를보고 싶습니다.GNUPG shell_exec에서 에코 된 데이터를 이스케이프 처리합니다.

나는 공유 호스팅을 사용하고 있기 때문에 명령 줄을 통해 GNUPG를 사용하고 있으며 PHP 클래스를 사용할 수 없습니다.

putenv("GNUPGHOME=/home/me/.gnupg"); 

$gpg = '/usr/bin/gpg'; 
$gpgrecipient = 'email'; 
$mailrecp = 'email'; 
$plain = 'Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text'; 



$encrypted = shell_exec("echo {$plain} | {$gpg} --no-auto-check-trustdb --lock-never -e -a -r {$gpgrecipient} "); 

그래서, 어떻게 데이터 무결성을 유지하면서, $plain을 탈출 가야합니까 다음과 같이 그래서 내 코드는?

escapeshellcmd()을 사용하면 형식이 엉망입니다.

공유 호스팅의 중요한 데이터이기 때문에 파일에 아무것도 저장하지 않으려 고합니다.

답변

1

나는 PHP를 잘 모르겠지만, 당신은 proc_open보다는 shell_exec를 사용하여 고려 했는가? 쉘 명령을 호출하여 입력을 에코하고 파이프를 gpg에 파이프하는 것보다 깔끔한 것 같습니다.

proc_open을 사용하려면 echo -n 대신 printf을 사용하십시오. 더 나은 행동을 정의했습니다. (테스트되지 않은) 예를 들면 :

$encrypted = shell_exec("printf '%s' '{$plain}' | {$gpg} ...` 

echo으로, 당신은 (쉘 내장 또는 /bin/echo 명령이 될 수있다)을 echo 명령 문자열이 아닌 다른 무언가로 인수의 일부를 해석 할 수있는 위험을 실행 인쇄 할 수 있습니다.

+0

저는 proc_open을 사용하지 않았습니다. 파이핑하는 방법이 훨씬 복잡해 보이지만 잘하면 알 수 있습니다. 정보 주셔서 감사합니다! – Ben

0

escapeshellarg을 사용해 보셨습니까? 그리고 echo 출력에 문자열의 끝에 줄 바꿈을 추가, 그래서 당신은 -n을 사용할 수 있습니다 : Demo

<?php 

$gpg = '/usr/bin/gpg'; 
$gpgrecipient = 'email'; 
$mailrecp = 'email'; 
$plain = 'Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text Here is the encrypted Text Here is the encrypted Text Here is the 
    encrypted Text'; 


$plain = escapeshellarg($plain); 

$cmd = "echo -n {$plain} | {$gpg} --no-auto-check-trustdb --lock-never -e -a -r {$gpgrecipient} "; 

echo $cmd;