System compromised by crypto-miner, Am I alone?

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
lost
Posts: 729
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

System compromised by crypto-miner, Am I alone?

Post by lost »

Hello,

For the 1st time my PI hosting Domoticz was compromised: 1st noticed this from the widgets showing CPU/RAM usage. CPU was near to 100% and DDR to ~80% with no visible issue from user POV (webUI still responsive etc). So this looked quite well calibrated to use as many ressources as possible without a user likely to notice.

=> As (see hereunder) the starter code of this was in my ~/domoticz, even if I could not trace were this exactly came from, I advise everyone to check its system load (widgets, if setup, or using top utility for instance).

Another consequence was core temp at 70°C instead of usual 45/50°C (with only passive cooling glued on SoC/memory in my system).

This lasted about 24h before I notice.

Usual process monitoring tools (ps, top...) dit not show anything but process usage added from top output being far from 100% (this was at most 8/10%, so a big and suspect gap). The load was userspace (labelled us in top), so not kernel related (interrupt storm due to faulty HW...).

If you see high loads, go ahead:

Checking socket stat quickly shows a process with a tcp connection active (remote port being https/443), but no name shown. So a process using network was somehow hidden.

To check this:

Code: Select all

ss -tup
This will show active tcp/udp connections with associated process... If you see a line with no process name shown, you may be in same situation as me.

The easy way (not modifying system tools/LD_PRELOADing a library affecting their behavior or kernel patch) to hide a process is to remounts it's /proc/PID tree somewhere else (to a tmpfs in my case).

Code: Select all

mount | grep proc
On a Debian system if you have anything added after /proc and both lines showing binfmt_misc this is a sign of something bad. This will also show the remount point for the process PID.

I 1st tried to kill it but came back almost immediately but load started to decrease before being back to ~100%. So the culprit was this hidden process.

So I did last step again to get the new PID and this time did an unmount of the shadow mount point from hereupper command.

This revealed a ~/domoticz/.sysinit hidden executable (another [process] named between squares, to have a "kernel process look"/avoid suspicion, was in cgroups: This is the one that was restarting the process responsible for the load). Searching for this in the whole SD card did show 2 callers: An added root cron line for reboot (that could be also seen using "crontab -l" as root) and in /root/.bashrc file executed when connection is done as root user: Exactly what I did when this started on saturday at ~16h45, as I did not restarted my since a few days.

=> So I presume compromise happened between this last reboot on tuesday after some apt update needing it (otherwise load would probably have risen immediately) and my connection as root for administrative tasks on last saturday.

Unfortunately, I don't keep logs for long (SD card storage...) so I could not get more clues. Only this .sysinit file in domoticz tree makes me think this could have something to do with Dz but as root anyone can setup anything where it decides to.

I also did a mistake by doing a move (mv ~/domoticz/.sysinit ~) of the file to keep it out of it's known start path, in case there is unseen starters: This kept the inode and the file was destroyed at both found processes kill. Should have done a cp instead... So no more investigation possible from there. Google search shows load and dissimulation techniques may point to some crypto-miner (on a PI, that's a bit surprising as this need some horsepower).

There was also 2 directories (.global), empty at time of check, lying in domoticz and plugin roots. They may be some remaining traces of the install path.

This looks now quiet since yesterday, but I'll probably have to wipe a just installed system (less than a month)...

Just wanted to know if I'm alone or not?
User avatar
gizmocuz
Posts: 3082
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: System compromised by crypto-miner, Am I alone?

Post by gizmocuz »

Sorry to see this, a compromised box is never fun, and you are certainly not alone in being hit by a crypto-miner on an internet facing Raspberry Pi.

That said, from what you describe this is not a Domoticz bug. The .sysinit binary and the .global directories are not Domoticz files, Domoticz creates neither. Once an attacker has root (the crontab in /root and the line in /root/.bashrc show they had it) they can drop and hide files anywhere, and ~/domoticz is just a writable directory that was used to blend in. With the original evidence gone (the mv instead of cp) the entry vector cannot be established, so there is nothing here we can act on in Domoticz itself. If you ever find concrete evidence that Domoticz itself was the entry point, please report it privately through a GitHub security advisory or [email protected] (see SECURITY.md), not in a public thread.

A few things that matter here, and as a long time user you most likely know them already:
  • Run the latest beta. Security and hardening fixes land there first.
  • Never expose Domoticz or SSH directly to the internet. Put it behind a VPN such as WireGuard or OpenVPN and reach your network through that. A port forward to Domoticz or SSH is the usual way these boxes get taken over.
  • Do not run Domoticz as root, and use a strong admin password.
  • Keep the OS patched.
Thanks for the write up anyway, warnings like this are useful for others.
Quality outlives Quantity!
lost
Posts: 729
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: System compromised by crypto-miner, Am I alone?

Post by lost »

Hi,

Yes, note I was a bit careful on this and location could be chosen to anything that does not attract attention too much. I wrote a MP yesterday with more details on this but this was not on dedicated security mail and without any evidence on Domoticz, probably not the right place anyway.

I forgot to write it, but only Domoticz https is exposed (my ssh can be opened for 30s, time to setup a connection, by a script triggered by a virtual switch from domoticz webUI ; this is the alternative to my former knockd setup but this tool unfortunately does not manage IPv6 and I'm dual stack).
There is fail2ban rules to ban those that must be banned. There is truecrypt for cert management.

For now, this was enough. I must confess I do not like VPN so much for 2 reasons:
-Needs a host with the VPN setup... So your brain contents is not enough.
-Any flaw on the VPN is like anyone being able to plug a RJ45 in one of your home socket without any further escalation needs.

Domoticz is ran as root to be able to bind default https 443 port... An alternative to avoid this would be using an alternate port out of 0-1024 range dedicated to root, but with the risk to be blocked by some external networks while connecting remotely (I can NAT IPv4 side, but from IPv6 only networks that's not an option). Would be better to avoid this as any flaw on webUI server ran as root would be open bar, but I don't know if this is possible with the need to bind 443 (some mechanism to drop privilege after bind?).

The OS was patched: Wednesday restart reason was last apt updated packages needing this. I'm aware this goes a bit more quickly than a few years ago on security due to IA. I don't think I'll reach several weeks or even months of uptime as in the past.

What worries me is I don't have a clue on how this came in... this was recent installation on debian13 with, in between, just an upgrade from stable 2026.4 to a beta with some fixes we talked about on another thread.

So a reinstall may lead to same situation. I'll for now monitor my system more closely and try to find other evidences I may still have missed when I have some time. And if this is back, avoid my mv mistake!
jannl
Posts: 877
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.1.x
Location: Geleen
Contact:

Re: System compromised by crypto-miner, Am I alone?

Post by jannl »

As far as I know Domoticz runs on nginx, which had a major vulnerability, mainly on the http/2.

Correct me if I am wrong on this.

I had mine more or less exposed via a reverse proxy on Synology, for which I did some precautions based on http/2. Besides that, I disabled the obscure port forwarding in my router, since I basically always enable wireguard on my phone. Only time not is when I need Android auto, but in that case I do not use my phone ;-)
Post Reply