Alert: Laravel Packagist packages bring backdoor and remote access

Published 5 min de lectura 117 reading

In recent weeks, security researchers have detected a campaign that uses the PHP ecosystem's own infrastructure to build malware in Laravel projects: several packages published in Packagist were used as legitimate utilities and actually activated persistent remote access to the affected machines. The team that reported the finding published a detailed analysis that you can consult on their blog ( Socket), and the pages of the packages are still accessible in the public register ( author profile in Packagist and individual packages like nhattuanbl / lara-helper, nhattuanbl / simple-queue and nhattuanbl / lara-swagger).

The tactic was not trivial: some of the packages did not contain malicious code directly, but introduced a dependence that did. In particular, one of the packages acts as a bridge and causes another bookstore to be installed as a unit of Composer - the standard unit manager in PHP - with all that it entails ( Composer documentation). This second bookstore includes an affuscated PHP file that, once loaded by the application, establishes communication with a control and control server (C2) and opens a back door.

Alert: Laravel Packagist packages bring backdoor and remote access
Image generated with IA.

Analysts describe that the malicious code is designed to make the analysis difficult: the author used control flow outflow techniques, function names and random variables, as well as coding routes and domains. When the payload is run, it collects information from the system and maintains a connection to the C2 using TCP sockets using PHP's own functions (e.g., stream _ socket _ client ()), waiting for orders that may include command execution, file transfer, screenshots and PowerShell running on Windows systems.

The risk goes beyond a simple script that runs: by how the code is activated - when you start the Laravel application through a service provider or by autoloading - malware runs within the same process as the web application. This means that it inherits the permissions and environment variables of the application, and therefore can access credentials stored in .env, database keys, APIs and other secrets that the project has available.

The sample examined tried to reconnect continuously if it did not find a response from the C2 server, which makes it persistent and able to reestablish communication as soon as the attacker reactivated its infrastructure. Although at the time of the report the command server was out of line, the presence of the code in production systems represents a real and lasting threat if it is not acted on.

If your project uses third-party packages, and in particular if you depend on little-known author packages, you have to take a defensive stance. First, you need to quickly identify if any of the mentioned packages are present in the dependency tree by reviewing composer.json and composer.lock and scanning the selling folder for suspicious files such as opussed helpers. If compromised code appears, the wise thing is to eliminate the affected dependence, but that's just the beginning.

Assume there was commitment: any system that has loaded the malicious code should be considered potentially controlled. It is necessary to rotate all credentials that may have been accessible from the application (databases, service keys, third party tokens), to audit network outputs in search of connections to unusual domains or PIs and to review logs to detect remote activity. It is also appropriate to verify integrity and permissions of sensitive files and, if there is any doubt, restore from reliable backup and clean the environment before reproducing it.

This incident fits into the broader pattern of attacks on the software supply chain: malicious actors publish packages with legitimate appearance for developers to install without suspicion. Organizations and developers can reduce the risk by taking practices such as carefully reviewing the origin of the dependencies, setting composer.lock versions, audiating new packages before inclusion and using automated scanning tools that detect suspicious behaviors. Expert projects and security guides on the supply chain offer practical recommendations to be followed, for example, the OWASP community maintains security resources in the software supply chain ( OWASP Supply Chain).

Alert: Laravel Packagist packages bring backdoor and remote access
Image generated with IA.

For PHP administrators and developers, it is also useful to know PHP settings that limit attack vectors, such as the directivedisable _ functionsin php.ini, although the malware detected tries to circumvent these protections by testing multiple methods to run commands. The official PHP page documents these and other relevant functions ( disable _ functions in PHP documentation).

The lesson is clear: the comfort of installing a utility from the record cannot replace a minimum diligence. To review the author's reputation, to check the contents of the package before installing it in productive environments and to maintain secret rotation policies are measures that are no longer optional. If you think you have used any of the packages involved, act quickly, document the actions and, if necessary, seek professional help in responding to incidents.

If you want to deepen the technical report, the campaign break-up and specific recommendations are available in the analysis of researchers ( Socket), and package entries can be publicly reviewed in Packagist ( author's profile and the pages of each package). In order to better understand the implications of the supply chain and defence practices, please also consult Community resources and guides such as OWASP and the official documentation of Composer ( Composer).

Coverage

Related

More news on the same subject.