SHELL笔记之管家
2016-04-14 09:34
253 查看
1.通过监控用户登录找出入侵者
入侵者定义: 屡次试图登入系统达两分钟以上,并且期间的登录过程全部失败。 凡这类用户都应该被检测出并生成以下细节报告:试图登录的账号;试图登录的次数;攻击者的IP地址;IP地址对应的主机;进行登录的时间。
用户认证会话日志会被记录在日志文件/var/log/auth.log中。
=========================
#!/bin/bash
#filename: intruder_detect.sh
#use to check out the invilad login
AUTHLOG=/var/log/auth.log
if [[ -n $1 ]];
then
AUTHLOG=$1
echo Using Log file: $AUTHLOG
fi
LOG=/tmp/valid.$$.log
grep -v "invalid" $AUTHLOG > $LOG
users=$(grep "Failed password" $LOG | awk '{print $(NF-5) }' | sort | uniq )
printf "%-5s|%-10s|%-10s|%-13s|%-33s|%s\n" "Sr#" "User" "Attempts" "IP address" "Host_Mapping" "Time range"
ucount=0;
ip_list="$(egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" $LOG | sort | uniq)"
for ip in $ip_list;
do
grep $ip $LOG > /tmp/tmp.$$.log
for user in $users;
do
grep $user /tmp/tmp.$$.log > /tmp/$$.log
cut -c-16 /tmp/$$.log >$$.time
tstart=$(head -1 $$.time);
start=$(date -d "$tstart" "+%s");
tend=$(tail -1 $$.time);
end=$(date -d "$tend" "+%s")
limit=$(( $end - $start ))
if [ $limit -gt 120 ];
then
let ucount++;
IP=$(egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" /tmp/$$.log | head -1 );
TIME_RANGE="$tstart-->$tend"
ATTEMPTS=$(cat /tmp/$$.log|wc -l);
HOST=$(host $IP | awk '{print $NF }' )
printf "%-5s|%-10s|%-10s|%-10s|%-33s|%-s\n" "$ucount" "$user" "$ATTEMPTS" "$IP" "$HOST" "$TIME_RANGE";
fi
done
done
rm /tmp/valid.$$.log /tmp/$$.log $$.time /tmp/tmp.$$.log 2>/dev/null
入侵者定义: 屡次试图登入系统达两分钟以上,并且期间的登录过程全部失败。 凡这类用户都应该被检测出并生成以下细节报告:试图登录的账号;试图登录的次数;攻击者的IP地址;IP地址对应的主机;进行登录的时间。
用户认证会话日志会被记录在日志文件/var/log/auth.log中。
=========================
#!/bin/bash
#filename: intruder_detect.sh
#use to check out the invilad login
AUTHLOG=/var/log/auth.log
if [[ -n $1 ]];
then
AUTHLOG=$1
echo Using Log file: $AUTHLOG
fi
LOG=/tmp/valid.$$.log
grep -v "invalid" $AUTHLOG > $LOG
users=$(grep "Failed password" $LOG | awk '{print $(NF-5) }' | sort | uniq )
printf "%-5s|%-10s|%-10s|%-13s|%-33s|%s\n" "Sr#" "User" "Attempts" "IP address" "Host_Mapping" "Time range"
ucount=0;
ip_list="$(egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" $LOG | sort | uniq)"
for ip in $ip_list;
do
grep $ip $LOG > /tmp/tmp.$$.log
for user in $users;
do
grep $user /tmp/tmp.$$.log > /tmp/$$.log
cut -c-16 /tmp/$$.log >$$.time
tstart=$(head -1 $$.time);
start=$(date -d "$tstart" "+%s");
tend=$(tail -1 $$.time);
end=$(date -d "$tend" "+%s")
limit=$(( $end - $start ))
if [ $limit -gt 120 ];
then
let ucount++;
IP=$(egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" /tmp/$$.log | head -1 );
TIME_RANGE="$tstart-->$tend"
ATTEMPTS=$(cat /tmp/$$.log|wc -l);
HOST=$(host $IP | awk '{print $NF }' )
printf "%-5s|%-10s|%-10s|%-10s|%-33s|%-s\n" "$ucount" "$user" "$ATTEMPTS" "$IP" "$HOST" "$TIME_RANGE";
fi
done
done
rm /tmp/valid.$$.log /tmp/$$.log $$.time /tmp/tmp.$$.log 2>/dev/null
相关文章推荐
- Linux下文件 ~/.bashrc 和 ~/.bash_profile 和 /etc/bashrc 和 /etc/profile 的区别 | 用户登录后加载配置文件的顺序
- learning bash-chap 01
- Windows客户端 SSH 远程连接Windows服务器(PowerShell Server)
- shell 删除奇数偶数行
- .bashrc 大数据版个人配置
- shell脚本学习笔记 (流编辑器sed)
- hbase shell基础和常用命令详解
- 数据库七天自动备份(shell)
- shell 中的特殊符号的含义
- 王高利:shell下使用find xargs grep查找文件及文件内容
- Linux Shell脚本教程
- shell script中的 if判断,及test命令
- Java提取两个文件夹中的有差异的文件并生成相应的shell脚本
- shell各类脚本
- 开机小脚本自动打开sublime text 和git-bash
- 在CentOS7.2安装Jdk1.8和resin4.0.45的步骤及shell脚本
- Linux下Bash编程之條件判斷详解(二)
- Linux下Shell编程实现基于Hadoop的ETL(流程篇)
- Linux下Shell编程实现基于Hadoop的ETL(导出篇)
- Linux下Shell编程实现基于Hadoop的ETL(分析篇)