Security researchers from Sucuri observed threat actors using swap files in compromised Magento websites to conceal a persistent software skimmer and harvest payment information.
The attackers used this tactic to maintain persistence and allowing the malware to survive multiple cleanup attempts.
The researchers discovered a suspicious script in the compromised website’s checkout page that had all the usual indicators of malware. The script included base64 encoded variables and hex encoded strings. The experts decoded the script and determined that it was used to capture credit card details.
When the checkout button is clicked, a script captures credit card data using the querySelectorAll function. This script also harvest sensitive information like name, address, and card number. The stolen details are sent to the domain amazon-analytic[.]com, registered in February 2024, which has been used in other credit card theft cases. Attackers often use well-known brand names in domain names in an attempt to evade detection.
Upon analyzing the malicious script, the experts noticed an interesting “swapme” file reference. Although initially invisible, using the vi
command revealed a swap file containing the same malware as the infected bootstrap.php
. Attackers used this swap file to keep malware on the server and evade detection. After removing the swap file and clearing caches, the checkout page was clean.
“The swapme part of the file name clued us in that there might be some swap lingering around. When files are edited directly via ssh the server will create a temporary ‘swap’ version in case the editor crashes, which prevents the entire contents from being lost.” reads the published by Sucuri.
“While we could not see any ~swapme file with the ls command, running a vi command on bootstrap.php-swapme to directly edit the swap file revealed that the file was indeed there, and it contained the exact same contents as the infected version of bootstrap.php. It became evident that the attackers were leveraging a swap file to keep the malware present on the server and evade normal methods of detection.”
The abuse of the swap file system by attackers underscores the necessity of deeper security measures beyond basic scans. The presence of a swap file suggests that the attackers initially accessed to the compromised wesites via SSH or a terminal session. To prevent such persistent malware infections, restrict sFTP, SSH, FTP, and CPanel access to trusted IPs, configure FTP and SSH restrictions on the hosting server, and use website firewalls for additional protection. Experts also recommends of regularly updating your CMS and plugins to avoid vulnerabilities exploited by automated attack tools.
Follow me on Twitter: and and Mastodon
(SecurityAffairs – hacking, swap files)