安全类和远程类shell脚本
批量杀php小马脚本
find /home/hatdot/ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc">>/tmp/test.txt grep -r -include=*.php '[^a-z]eval($_POST' . >> /tmp/test.txt grep -r -include=*.php 'file_put_contents(.*$_POST\[ .*\ ]);' . >> /tmp/test.txt find /home/hatdot/ -name "*.php" -type f -print 0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq >> /tmp/test.txt
python批量杀php小马
#!/usr/bin/python
# -*- coding: utf-8 -*-
#blog:www.sinesafe.com import os
import sys
import re rulelist = [
'(\$_(GET|POST|REQUEST)\[.{0,15}\]\(\$_(GET|POST|REQUEST)\[.{0,15}\]\))',
'(base64_decode\([\'"][\w\+/=]{200,}[\'"]\))',
'eval\(base64_decode\(',
'(eval\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))',
'(assert\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))',
'(\$[\w_]{0,15}\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))',
'(wscript\.shell)',
'(gethostbyname\()',
'(cmd\.exe)',
'(shell\.application)',
'(documents\s+and\s+settings)',
'(system32)',
'(serv-u)',
'(提权)',
'(phpspy)',
'(后门)',
'(webshell)',
'(Program\s+Files)'
] def Scan(path):
for root,dirs,files in os.walk(path):
for filespath in files:
isover = False
if '.' in filespath:
ext = filespath[(filespath.rindex('.')+1):]
if ext=='php':
file= open(os.path.join(root,filespath))
filestr = file.read()
file.close()
for rule in rulelist:
result = re.compile(rule).findall(filestr)
if result:
print '文件:'+os.path.join(root,filespath)
print '恶意代码:'+str(result[0])
print '\n\n'
break if os.path.lexists(sys.argv[1]):
print('\n\n开始扫描:'+sys.argv[1])
print(' 可疑文件 ')
print('########################################')
Scan(sys.argv[1])
print('提示:扫描完成-- O(∩_∩)O哈哈~')
else:
print '提示:指定的扫描目录不存在--- 我靠( \'o′)!!凸'
#!/bin/bash
echo "check ssh...."
while true
do
who | awk -F"(" '{print $2}' | sed 's/.$//' | while read ip
do
if [ `echo $ip | awk -F"." 'END{print NF}'` -eq 4 ]
then
echo "$ip ssh close"
iptables -A INPUT -p tcp --dport 22 -s $ip -j REJECT
ipssh=`who | awk '{print $2}' | head -$i | tail -1`
ipsshid=`ps -ef | grep "@$ipssh" | awk '{print $2}'`
kill -9 $ipsshid 2> /dev/null
echo iptables -D INPUT -p tcp --dport 22 -s $ip -j REJECT | at now + 30 minutes
fi
done
sleep 2
done
版本2:
#!/bin/bash
while true
do
line=`who |grep -v "(:" |wc -l` for i in `seq $line`
do
pts=`who |grep -v "(:" |awk '{print $2}' |head -$i |tail -1`
ip=`who |grep -v "(:" |awk -F"(" '{print $2}'|awk -F")" '{print $1}' |head -$i |tail -1`
pid=`ps -ef |grep $pts |grep sshd |grep -v grep |awk '{print $2}'`
kill -9 $pid
iptables -A INPUT -p tcp --dport 22 -s $ip -j REJECT
at now + 30 minutes << EOF > /dev/null 2>&1
iptables -D INPUT -p tcp --dport 22 -s $ip -j REJECT
EOF
done sleep 2
done
rsync+ssh批量自动化部署:
#!/bin/bash
#-------------------------------------#
# author by bossco #
# auto change server files #
# 2015.12.24 #
#-------------------------------------#
#前提:先要做SSH等效性,让SSH远程登陆不需要输入密码
#ssh-keygen 回车回车回车
#ssh-copy-id -i /root/.ssh/id_rsa.pub 远程服务器IP flush()
{
if [ ! f rsync.list ];then
echo -e "\033[34mPlease Create rsync.list files,
The rsync.list contents as follows! \033[0m"
cat <<EOF
192.168.10.128 src_dir des_dir
192.168.10.129 src_dir des_dir
EOF
exit
fi
rm -rf rsync.list.swp;cat rsync.list | grep -v "#" >rsync.list.swp
COUNT=`cat rsync.list.swp | wc -l`
NUM=0
while (($(NUM) < $COUNT))
do
NUM=`expr $NUM + 1`
LINE=`sed -n "$(NUM)p" rsync.list.swp`
SRC=`echo $LINE | awk '{print $2}'`
DES=`echo $LINE | awk '{print $3}'`
IP=`echo $LINE | awk '{print $1}'`
rsync -av $(SRC)/ root@$(IP):$(DES)/
done
} restart ()
{
if [ ! f restart.list ];then
echo -e "\033[34mPlease Create restart.list files,
The restart.list contents as follows! \033[0m"
cat <<EOF
192.168.10.128 COMMAND
192.168.10.129 COMMAND
EOF
exit
fi
rm -rf restart.list.swp;cat restart.list | grep -v "#" >> restart.list.swap
COUNT=`cat restart.list.swp | wc -l`
NUM=0
while (($(NUM) < $COUNT))
do
NUM=`expr $NUM + 1`
LINE=`sed -n "$(NUM)p" restart.list.swp`
COMMAND=`echo $LINE | awk '{print $2}'`
IP=`echo $LINE | awk '{print $1}'`
ssh -l root $IP
"sh $COMMAND;echo -e '------------\nThe $IP Exec commands:sh $COMMAND success!'"
done
} case $1 in
flush )
flush ;;
restart )
restart ;;
*)
echo -e "\033[31mUsage: $0 command,example{flush | restart} \033[0m"
esac
批量远程执行命令:
#!/bin/bash
#-------------------------------------#
# author by bossco #
# remote exec command #
# 2015.12.24 #
#-------------------------------------#
#前提:先要做SSH等效性,让SSH远程登陆不需要输入密码
#ssh-keygen 回车回车回车
#ssh-copy-id -i /root/.ssh/id_rsa.pub 远程服务器IP
#把远程服务器的IP地址ip.txt文件里 if [ ! -f ip.txt ];then
echo -e "\033[31m please create ip.txt\033[0m"
exit
fi if [ -z "$*" ];then
echo -e "\033[32mUsage: $0 command,example{rm /tmp/test.txt | mkdir /tmp/20150505}\033[0m"
exit
fi count=`cat ip.txt | wc -l`
rm -rf ip.txt.swap
i=0
while ((i< $count))
do
i=`expr $i + 1`
sed "$(i)s/^/&$(i) /g" ip.txt >> ip.txt.swp
IP=`awk -v I="$i" '{if(I==$1)print $2}' ip.txt.swp`
ssh -q -l root $IP "$*;echo -e '\033[35m-------------------\nThe $IP Exec Commands: $* success !';sleep 2"
done
批量拷贝文件或目录至远程服务器:
#!/bin/bash
#-------------------------------------#
# author by bossco #
# cp file/dir to remote server #
# 2015.12.24 #
#-------------------------------------#
#前提:先要做SSH等效性,让SSH远程登陆不需要输入密码
#ssh-keygen 回车回车回车
#ssh-copy-id -i /root/.ssh/id_rsa.pub 远程服务器IP
#把远程服务器的IP地址ip.txt文件里 if [ ! -f ip.txt ];then
echo -e "\033[31m please create ip.txt\033[0m"
exit
fi if [ -z "$1" ];then
echo -e "\033[32mUsage: $0 command,example{src_files|src_dir des_dir}\033[0m"
exit
fi count=`cat ip.txt | wc -l`
rm -rf ip.txt.swap
i=0
while ((i< $count))
do
i=`expr $i + 1`
sed "$(i)s/^/&$(i) /g" ip.txt >> ip.txt.swp
IP=`awk -v I="$i" '{if(I==$1)print $2}' ip.txt.swp`
scp -r $1 root@${ip}:$2
#rsync -aP --delete $1 root${ip}:$2
done
自动阻止3次SSH远程登陆输入密码错误的恶意IP
#!/bin/bash
#auto drop ssh failed IP address
#-------------------------------------#
# author by bossco #
# auto drop ssh failed IP address #
# 2015.12.23 #
#-------------------------------------#
#定义变量
SEC_FILE=/var/log/secure
IP_ADDR=`tail -n 1000 /var/log/secure | grep "failed password" | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" | sort -nr | uniq -c | awk ' $1>=3 {print $2}'`
IPTABLE_CONF=/etc/sysconfig/iptables
echo
cat <<EOF
+++++++++++++++welcome to use ssh login drop failed ip +++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
for i in `echo IP_ADDR`
do
cat $IPTABLE_CONF | grep $i >/dev/null
if
[ $? -ne 0 ];then
sed -i "/lo/a -A INPUT -s $i -m state --state NEW -p tcp --dport 22 -j DROP" $IPTABLE_CONF
else
echo "$i is exists in iptalbes"
fi
done
安全类和远程类shell脚本的更多相关文章
- JAVA远程执行Shell脚本类
1.java远程执行shell脚本类 package com.test.common.utility; import java.io.IOException; import java.io.Input ...
- Java SSH远程执行Shell脚本实现(转)
前言 此程序需要ganymed-ssh2-build210.jar包(下载地址:http://www.ganymed.ethz.ch/ssh2/) 为了调试方便,可以将\ganymed-ssh2-bu ...
- Java实践 — SSH远程执行Shell脚本(转)
原文地址:http://www.open-open.com/lib/view/open1384351384024.html 1. SSH简介 SSH是Secure Shell的缩写,一 ...
- Java实践 — SSH远程执行Shell脚本
1. SSH简介 SSH是Secure Shell的缩写,一种建立在应用层和传输层基础上的安全协议.SSH在连接和传送过程中会加密所有数据,可以用来在不同系统或者服务器之间进行安全连接 ...
- Java实践-远程调用Shell脚本并获取输出信息
1.添加依赖 <dependency> <groupId>ch.ethz.ganymed</groupId> <artifactId>ganymed-s ...
- 远程调用shell脚本文件和远程复制文件
1.安装sshpass yum install sshpass 2.本地调用远程服务器的shell脚本文件: sshpass -p sa ssh root@192.168.56.105 -C &quo ...
- Shell 脚本 —— java 代码远程调用shell脚本重启 tomcat
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 1.创建maven 工程 maven 依赖: <dependency> <grou ...
- 远程执行shell脚本
ssh -p2016 apache@10.10.18.130 '/bin/sh /data/www/vhosts/WOStest3_ENV/update_env.sh' 需要设置shell远程免密码登 ...
- SaltStack远程执行shell脚本
编辑文件fansik.sh 脚本内容: #!/bin/bash # Author: fansik # data: 2017年 09月 26日 星期二 :: CST touch /tmp/fansik. ...
随机推荐
- Thymeleaf对象的使用:字符串对象
Thymeleaf主要使用 org.thymeleaf.expression.Strings 类处理字符串,在模板中使用 #strings 对象来处理字符串. 开发环境:IntelliJ IDEA 2 ...
- sqlserver查看表空间
sqlserver 用于查看当前数据库所有表占用空间大小的存储过程 create procedure dbo.proc_getsize as begin create table #temp ( t_ ...
- Flask框架后端开发常见错误处理
1.ValueError: urls must start with a leading slash 这个错误原因可能发生在所有路由相关地方,少加了一个'/'造成的. 2.ImportError: c ...
- 3-SQL过滤
# 筛选最大生命值大于6000,最大法力值大1700的英雄,然后按照二者之和从高到低进行排序 SELECT NAME , hp_max, mp_max FROM he ...
- 题解:swj社会摇成佛第六课
题目链接 solution: dp f[i]表示lhy小伙身长为i,能砍得的最优解 f[i]=f[j]*f[i-j]; public class CuttingRope01 { public stat ...
- nginx学习(三):nginx的进程模型
概述 nginx 进程分为 master进程和work进程 1.打开配置文件查看,这里我修改为2 [root@xxx conf]# vim nginx.conf #user nobody; worke ...
- HDUNumber Sequence(KMP)
传送门 题目大意:b在a第一次出现的位置 题解:KMP 代码: #include<iostream> #include<cstdio> #include<cstring& ...
- 【CodeForces】CodeForcesRound594 Div1 解题报告
点此进入比赛 \(A\):Ivan the Fool and the Probability Theory(点此看题面) 大致题意: 给一个\(n\times m\)的矩阵\(01\)染色,使得不存在 ...
- Eclipse maven创建web项目报错Could not resolve archetype
1.下载http://repo1.maven.org/maven2/archetype-catalog.xml 通过eclipse下载和网页下载我这里都比较慢,最后用的迅雷下载 2.将本地xml文件配 ...
- Azure Sphere Development Environment Setup
1. Visual Studio 目前,Visual Studio 2017/2019支持Azure Sphere开发,后续,微软会加入Visual Studio Code的支持.以Visual St ...