ubuntu 编写shell脚本自动抓包

国庆节之后,好多课结课了,其中一门是实验课,我们小组的任务是使用wireshark和 编写ubuntu shell 脚本抓包

我负责的是编写shell脚本抓包

大神们可能觉得超级简单,可是我是小白,觉得还挺麻烦的。

首先参考的是 https://jingyan.baidu.com/article/e75057f21c10d0ebc91a898f.html  我的网卡是eno1

#!/bin/bash
filename='view_history_'`date +%F-%H:%M:%S.pcap`
touch $filename
#没有后面的taid则无法退出tcpdump进程
tcpdump -i eno1 -s 0 -A 'tcp[((tcp[12:1] & 0xf0)>>2):4]=0x47455420' -w $filename & tdid='pgrep tcpdump'


while [ "1" = "1" ]
do
    file_size=`du $filename|awk '{print $1}'`
    echo 'file_size'$file_size
    #文件达到100M时,重启tcpdump
    if [ $file_size -ge 102400 ]
    then
        echo 'data is enough,stop tcpdump,create new file'
        killall tcpdump
        #备份名称,用于后面压缩
        filenameBak=$filename
        filename='view_history_'`date +%F-%H:%M:%S`
        touch $filename
        tcpdump -i br0 -s 0 -A 'tcp[((tcp[12:1] & 0xf0)>>2):4] = 0x47455420' -w filename & tdid='pgrep tcpdump'
        gzip $filenameBak
    else
        echo 'data not enough.'
    fi
    sleep 5s
done

然后按照要求修改权限,进行抓包。在抓得过程中打开火狐浏览器,抓到了包。

http://pwdme.cc/2016/10/20/tcpdump/ 这个博客可以指定抓取的包,进行一定的过滤。

https://www.cnblogs.com/chyingp/p/linux-command-tcpdump.html linux基础,用tcpdump抓包

总结几个:

sudo tcpdump -i eno1 通过特定的网卡抓包,网卡在终端中输入ifconfig -a可以看到,我的网卡是eno1

sudo tcpdump host 182.254.38.55  监听本机跟主机182.254.38.55之间往来的通信包

比如:119.75.213.61是百度的ip地址 我们可以sudo tcpdump host 119.75.213.61 然后在另一个终端输入ping 119.75.213.61 或者用火狐打开百度的首页,就可以抓到相应的包

未完待续。。。(不懂shell脚本,待补充) 

 

猜你喜欢

转载自blog.csdn.net/weixin_37485708/article/details/83039682
今日推荐