Description
Composer runs code from HTTP sources without validating the source of the download or the code downloaded. As such, trivial man-in-the-middle attacks through any number of vectors (dns, networking, local server exploit, etc) will result in execution of code of an attackers choosing at the userlevel of the user running composer. (Typically a developer account)
Example command to reproduce. (User)
php composer.phar self-update
src/Composer/Command/SelfUpdateCommand.php lines 45, 50 and 59 are key.
Exploitation:
Replace getcomposer.org for a given network perspective by replacing it with a malicious http instance (eg by changing the DNS locally, at the lan, at an isp or hosting provider dns resolver, or globally or equally easily by replacing a route to the legitimate server (eg arpspoof)) . The http server instance is configured to serve a malicious /composer.phar and a /version url that produces random data. When users run self-update, the malicious code will be downloaded and run as the user that is executing the self-update command.
The same technique can be used for any package configured over http.
Fix:
Disable HTTP scheme's in composer and implement TLS or redesign composer to support digital signatures. (See AptSecure)