3333Fermer3335
GodzilLe 12/12/2017 à 16:29
Relis alors parce que le papier ne dit pas "OMG Shell Exec permet de lancer un executable"

mais le fait que PHP fait trop de reintrepretations a sa facon, et le code

shell_exec(bash." something")

actuellement lance "bash" si le define "bash" n'est pas definie

When the PHP function shell_exec() receives theundefined constant bash, it usesthe string representation of the constant.
This means that the string bash will be concatenated with the user - supplied input, allowing command injection.


En gros sur une ligne de commande:

php -r 'echo shell_exec(escapeshellcmd(bash." -c id"));'

Plutot que de tenter d'executer " -c id" va executer "bash -c id" parceque PHP va trouver "bash" et comme ce n'est pas un define, va le traiter comme du texte

Ou peut etre plus explicite:

php -r 'echo shell_exec(escapeshellcmd(ls." /"));'
PHP Notice:  Use of undefined constant ls - assumed 'ls' in Command line code on line 1

Notice: Use of undefined constant ls - assumed 'ls' in Command line code on line 1
backup
bin
boot
dev
etc
gcc4ti
git
home
lib
lib32
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
svn
sys
tigccpp
tmp
usr
var

(testé localement)

Le notice Notice: Use of undefined constant ls - assumed 'ls' in Command line code on line 1 est un comportement indesirable