Shell - 通过hook文件后门实现应用的自动启停

文章目录

Shell - 通过hook文件后门实现应用的自动启停

启动脚本
 #!/bin/bash

set_network_param()
{
	sysctl -w fs.file-max=999999
	sysctl -w net.ipv4.tcp_tw_reuse=1
	sysctl -w net.ipv4.tcp_fin_timeout=15
	sysctl -w net.core.netdev_max_backlog=4096
	sysctl -w net.core.somaxconn=40960
	sysctl -w net.ipv4.tcp_max_syn_backlog=40960
	sysctl -w net.ipv4.tcp_syncookies=1
	sysctl -w net.ipv4.tcp_syn_retries=2
	sysctl -w net.ipv4.tcp_synack_retries=2
	return
}

#service start
start()
{
	number=`ps -ef | grep "/home/nginx/bin/nginx" | grep -v grep | head -n 1 | wc -l`
	if [ $number -ge 1 ];then
		 
	fi
	set_network_param
	ulimit -n  65535
	if [ -f "/home/nginx/bin/nginx" ]
	then
		/home/nginx/bin/nginx -p /home/nginx -c /home/nginx/conf/nginx.conf
	fi
	
	number=`ps -ef | grep "/home/nginx/daemon/nginx_daemon" | grep -v grep | head -n 1 | wc -l`
	if [ $number -lt 1 ];then
		# Do Something
	fi
	if [ -f "/home/nginx/daemon/nginx_daemon" ]
	then
		nohup /home/nginx/daemon/nginx_daemon >/dev/null 2>&1 & 
	fi 
}

#service stop
stop()
{
	/home/nginx/bin/nginx -p /home/nginx -s stop 
}


#parse cmd
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit 0

姑且称之为a.sh 在 /home/nginx 目录下


daemon

通过放入hook文件, 在对应的目录下touch start \ stop \restart 文件 , 实现应用的启停

#!/bin/sh

number=`ps -ef | grep "/home/nginx/daemon/nginx_daemon" | grep -v grep | head -n 1 | wc -l`
if [ $number -lt 1 ];then
	#do something
fi

while [ 1 -eq 1 ]
do
	if [ -f "/home/nginx/daemon/start" ]; then
		rm -rf /home/nginx/daemon/start
		 /home/nginx/a.sh start
	fi
	
	if [ -f "/home/nginx/daemon/stop" ]; then
		rm -rf /home/nginx/daemon/stop
		 /home/nginx/a.sh stop
	fi
	
	if [ -f "/home/nginx/daemon/restart" ]; then
		rm -rf /home/nginx/daemon/restart
		 /home/nginx/a.sh restart
	fi
	
	sleep 5
done
	
上一篇:带你轻松理解Android-Hook机制,移动架构师成长路线


下一篇:hook入门篇