很多网络爱好者都比较痴迷程序的编写,那ddos攻击器如何编写呢?了解网络安全常识,首先就要了解常见电脑黑客攻击类型与预防方法,下面小编就带您认识一下吧。

一、读取文件

这里我用了判断语句,起初我是想写出类似于access=more /usr/access*.*,将这个路径全部加到变量里,方便判断,因为在shell里,只能将固定文件、文件夹作为变量,变量中不能加*号(我是没找到别的方法,有知道大牛请提点下小弟),所以就想了个笨办法,用匹配关键词的方式来判断特定目录下,是apache日志,还是weblogic日志,还是IIS日志,具体判断方法如下:

if ls -l /usr/ | egrep “access”;then

more /usr/access*.* | egrep “多个关键词”

else

more /usr/ex*.log | egrep“多个关键词”

fi

这样的方式来进行判断,但是这样判断有个缺点,就是中间件日志在/usr/目录下,只能存在一种,比如同时存在apache和IIS的日志,就会优先判断apache的,进而不会执行IIS日志分析的语句。而且,为了不跟之前的历史数据混乱,在脚本执行开始,清空了下数据。

file=/usr/nmgxy/

if [ -e “$file” ];then

echo “日志目录存在,跳过创建过程,该操作会清空/usr/nmgxy/目录下所有数据”

echo “按回车键开始清空数据,结束请点击Ctrl+c”

read key

rm -r /usr/nmgxy/*

mkdir -p /usr/nmgxy/LFI/ /usr/nmgxy/exp/ /usr/nmgxy/sql/ /usr/nmgxy/scan/ /usr/nmgxy/xss/ /usr/nmgxy/getshell/ /usr/nmgxy/dir/

else

mkdir -p /usr/nmgxy/ /usr/nmgxy/LFI/ /usr/nmgxy/exp/ /usr/nmgxy/sql/ /usr/nmgxy/scan/ /usr/nmgxy/xss/ /usr/nmgxy/getshell/ /usr/nmgxy/dir/

fi

echo “分析结果日志保存在/usr/nmgxy/目录下”

echo ———————日志目标文件—————————

if ls -l /usr/ | egrep “access”;then

echo ——————–统计出现次数最多的前20个IP地址—————–

cat /usr/access*.* |awk ‘{print $1}’ |sort |uniq -c |sort -rn |head -20 >/usr/nmgxy/top20.log

echo “统计完成”

二、定义攻击特征

日志读取的问题解决了,接下来就是定义攻击特征的事儿了,攻击特征比较好定义。例如,SQL注入攻击的判断:

echo ————————SQL注入攻击sql.log—————-

echo “开始分析存在SQL注入的攻击行为,并将结果保存在/usr/nmgxy/sql/目录下”

more /usr/access*.* |egrep “%20select%20|%20and%201=1|%20and%201=2|%20exec|%27exec| information_schema.tables|%20information_schema.tables|%20where%20|%20union%20|%20SELECT%20|%2ctable_name%20|cmdshell|%20table_schema” >/usr/nmgxy/sql/sql.log

echo “分析结束”

awk ‘{print “共检测到SQL注入攻击” NR”次”}’ /usr/nmgxy/sql/sql.log|tail -n1

echo “开始统计SQL注入攻击事件中,出现频率最多的前20个IP地址”

cat /usr/nmgxy/sql/sql.log |awk -F “[” ‘{print $1}’ |sort |uniq -c |sort -rn |head -20 >/usr/nmgxy/sql/top20.log

echo ———————————————————-

more /usr/nmgxy/sql/top20.log

echo “统计结束”

我把一些常见的SQL注入攻击的特征写到了里面,去掉了MSSQL数据库存储过程以及MSSQL数据库才会出现的一些注入语句。

三、输出匹配到的含有攻击特征的记录

将匹配到的攻击特征内容,重新输出到了另外一个log里面,相当于做了一次筛选/usr/nmgxy/sql/sql.log

more/usr/access*.*|egrep”%20select%20|%20and%201=1|%20and%201=2|%20exec|%27exec|information_schema.tables|%20information_schema.tables|%20where%20|%20union%20|%20SELECT%20|%2ctable_name%20|cmdshell|%20table_schema” >/usr/nmgxy/sql/sql.log

然后二次分析这个筛选过的文件,统计SQL注入攻击出现的次数

awk ‘{print “共检测到SQL注入攻击” NR”次”}’ /usr/nmgxy/sql/sql.log|tail -n1

输出完毕后,将攻击出现最多的前20个IP地址进行统计并显示到屏幕上

echo “开始统计SQL注入攻击事件中,出现频率最多的前20个IP地址”

cat /usr/nmgxy/sql/sql.log |awk -F “[” ‘{print $1}’ |sort |uniq -c |sort -rn |head -20 >/usr/nmgxy/sql/top20.log

echo

more /usr/nmgxy/sql/top20.log

echo “统计结束”

四、输出结果

这个在代码开头,创建了一些文件夹,用来存放筛选过的记录

mkdir -p /usr/nmgxy/LFI/ /usr/nmgxy/exp/ /usr/nmgxy/sql/ /usr/nmgxy/scan/ /usr/nmgxy/xss/ /usr/nmgxy/getshell/ /usr/nmgxy/dir/

中间删删改改折腾了好几次。后来针对特定的攻击,我们比较关注(重点是比较好写的= =)的内容做了HTTP响应请求200/500的判断,并输出结果。

关于网络安全小知识小编为您介绍和普及这么多了,看完上面的介绍,您对“ddos攻击器如何编写”这个问题了解多少了呢?掌握和了解ddos攻击器的编写方法对于我们防范它来说有着至关重要的意义和影响。