當通過網絡訪問PHP頁面:確定通過web服務器在php中運行shell時的確切用戶?
<?php
print '<pre>'."\n";
print 'Current script owner: '."\n";
print get_current_user()."\n";
print "\n";
print '$USER: '."\n";
passthru('print $USER');
print "\n";
我得到的輸出:
Current script owner:
danny
$USER:
爲什麼shell用戶不等於當前的腳本所有者?如何通過Web服務器在php腳本中運行shell時確定用戶?
爲什麼_should_ shell用戶等於腳本的所有者?如果你想獲得進程的用戶名,在文檔頁面的註釋中有很多建議:http://us3.php.net/manual/en/function.get-current-user.php – Barmar
我發現' posix_getpwuid(posix_geteuid())'也是danny和'shell_exec('whoami')'是空的。如何通過web php執行系統命令時配置shell用戶? –
'$ USER'和'whoami'由'login'填充。由於PHP是作爲守護進程運行的,因此它不會獲得這些變量。 – Barmar