Chinaunix

标题: 求教,刚接触perl 要做一个抓包分析 [打印本页]

作者: 懒狒狒    时间: 2012-11-27 09:20
标题: 求教,刚接触perl 要做一个抓包分析
本帖最后由 懒狒狒 于 2012-11-27 09:20 编辑

刚到一家公司,从php转perl吧,现在领导要将pkt文件根据指定时间进行抓包分析
已经根据之前的前辈将pkt文件合并成cap文件,然后不知道怎么分析实现让其生成
我想要的文本,我想的是只要能将cap文件解析成文本就好根据自己需要的规则把他
匹配出来,但是实在学浅,搞了两天停顿了,貌似cap问件是16进制之类的,还劳烦
大牛指点指点,给点思路,谢谢
不知道说的明白不

作者: sjdy521    时间: 2012-11-27 10:31
本帖最后由 sjdy521 于 2012-11-27 10:33 编辑

不明白 什么是pkt 什么是cap 看天书。。
作者: 懒狒狒    时间: 2012-11-27 10:41
我也不是很清楚,是用一款抓包分析工具wireshark打开的进行syn ack分析
回复 2# sjdy521


   
作者: laputa73    时间: 2012-11-27 10:52
wireshark和tcpdump的包格式是可以兼容的
可以先用tcpdump转成文本,再用perl分析吧
作者: 懒狒狒    时间: 2012-11-27 11:00
win7环境下可以么,我怎么搜都是linux环境哟回复 4# laputa73


   
作者: laputa73    时间: 2012-11-27 11:02
回复 5# 懒狒狒
win7环境下你可以直接用wireshark的命令行模式tshark


   
作者: q1208c    时间: 2012-11-27 11:05
perl应该不能直接分析tcpdump的二进制文件, 转成 文本 再分析吧.
作者: 懒狒狒    时间: 2012-11-27 11:12
我想的也是先将他转成文本,但是貌似到转成文本这一步我比较难实现哦,
这点不知道如何下手,有链接或者需要注意的事项没有呀,大虾
如果能转成文本的话,按照一定的规则应该分析起来比较得心应手一点回复 7# q1208c


   
作者: 懒狒狒    时间: 2012-11-27 11:15
在网上搜了一下有关的例子,貌似比较少哦
大牛么,不吝赐教
作者: sjdy521    时间: 2012-11-27 11:16
本帖最后由 sjdy521 于 2012-11-27 11:16 编辑

问公司的前辈,他们拿工资的,有责任指导你
作者: 懒狒狒    时间: 2012-11-27 11:18
{:3_186:} 公司就我一个perl哦回复 10# sjdy521


   
作者: sjdy521    时间: 2012-11-27 11:24
二进制转文本 这个和perl有啥关系
作者: q1208c    时间: 2012-11-27 11:31
回复 8# 懒狒狒

用 tcpdump的命令转呀. 那个需要 wincap的库的.
   
作者: 懒狒狒    时间: 2012-11-27 11:40
嗯呐,谢谢了,我在查查文档看看怎么用的哈回复 13# q1208c


   
作者: wsxedcer    时间: 2012-11-27 11:46
回复 1# 懒狒狒


    tshark -r input
  1. -r <infile>              set the filename to read from (no pipes or stdin!)
复制代码

作者: 懒狒狒    时间: 2012-11-27 12:18
嗯,也不算是吧,我们部门主要是分析当我们的服务器受到攻击的时候能快速的查询出自己想要的参数
回复 16# defendre


   
作者: dsadjkasd    时间: 2012-11-28 00:43
本帖最后由 dsadjkasd 于 2012-11-28 00:45 编辑

你可以下个010editor帮助你进行16进制或者2进制数据的分析,但数据位数字符型之类都需要自己不断猜测揣摩出规律来,才能进行有效的解码数据成可读的东西。。。比如02FAF080表示50000000,当然你看16进制的时候这个数应该是“80 F0 FA 02”, 抓的包应该分析下报文,报头,需要参考下TCP 和UDP如何封装的。。。
作者: laputa73    时间: 2012-11-28 08:23
本帖最后由 laputa73 于 2012-11-29 10:08 编辑

那些二进制包是有协议的,不是简单的16进制转转就能识别的
所以tshark是必须的
http://www.wireshark.org/docs/ws ... AppToolstshark.html
  1. TShark 1.7.0 (SVN Rev 39165 from /trunk)
  2. Dump and analyze network traffic.
  3. See http://www.wireshark.org for more information.

  4. Copyright 1998-2011 Gerald Combs <gerald@wireshark.org> and contributors.
  5. This is free software; see the source for copying conditions. There is NO
  6. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  7. Usage: tshark [options] ...

  8. Capture interface:
  9.   -i <interface>           name or idx of interface (def: first non-loopback)
  10.   -f <capture filter>      packet filter in libpcap filter syntax
  11.   -s <snaplen>             packet snapshot length (def: 65535)
  12.   -p                       don't capture in promiscuous mode
  13.   -B <buffer size>         size of kernel buffer (def: 1MB)
  14.   -y <link type>           link layer type (def: first appropriate)
  15.   -D                       print list of interfaces and exit
  16.   -L                       print list of link-layer types of iface and exit

  17. Capture stop conditions:
  18.   -c <packet count>        stop after n packets (def: infinite)
  19.   -a <autostop cond.> ...  duration:NUM - stop after NUM seconds
  20.                            filesize:NUM - stop this file after NUM KB
  21.                               files:NUM - stop after NUM files
  22. Capture output:
  23.   -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs
  24.                            filesize:NUM - switch to next file after NUM KB
  25.                               files:NUM - ringbuffer: replace after NUM files
  26. Input file:
  27.   -r <infile>              set the filename to read from (no pipes or stdin!)

  28. Processing:
  29.   -2                       perform a two-pass analysis
  30.   -R <read filter>         packet filter in Wireshark display filter syntax
  31.   -n                       disable all name resolutions (def: all enabled)
  32.   -N <name resolve flags>  enable specific name resolution(s): "mntC"
  33.   -d <layer_type>==<selector>,<decode_as_protocol> ...
  34.                            "Decode As", see the man page for details
  35.                            Example: tcp.port==8888,http
  36. Output:
  37.   -w <outfile|->           write packets to a pcap-format file named "outfile"
  38.                            (or to the standard output for "-")
  39.   -C <config profile>      start with specified configuration profile
  40.   -F <output file type>    set the output file type, default is libpcap
  41.                            an empty "-F" option will list the file types
  42.   -V                       add output of packet tree        (Packet Details)
  43.   -O <protocols>           Only show packet details of these protocols, comma
  44.                            separated
  45.   -P                       print packets even when writing to a file
  46.   -S <separator>           the line separator to print between packets
  47.   -x                       add output of hex and ASCII dump (Packet Bytes)
  48.   -T pdml|ps|psml|text|fields
  49.                            format of text output (def: text)
  50.   -e <field>               field to print if -Tfields selected (e.g. tcp.port);
  51.                            this option can be repeated to print multiple fields
  52.   -E<fieldsoption>=<value> set options for output when -Tfields selected:
  53.      header=y|n            switch headers on and off
  54.      separator=/t|/s|<char> select tab, space, printable character as separator
  55.      occurrence=f|l|a      print first, last or all occurrences of each field
  56.      aggregator=,|/s|<char> select comma, space, printable character as
  57.                            aggregator
  58.      quote=d|s|n           select double, single, no quotes for values
  59.   -t ad|a|r|d|dd|e         output format of time stamps (def: r: rel. to first)
  60.   -u s|hms                 output format of seconds (def: s: seconds)
  61.   -l                       flush standard output after each packet
  62.   -q                       be more quiet on stdout (e.g. when using statistics)
  63.   -X <key>:<value>         eXtension options, see the man page for details
  64.   -z <statistics>          various statistics, see the man page for details

  65. Miscellaneous:
  66.   -h                       display this help and exit
  67.   -v                       display version info and exit
  68.   -o <name>:<value> ...    override preference setting
  69.   -K <keytab>              keytab file to use for kerberos decryption
  70.   -G [report]              dump one of several available reports and exit
  71.                            default report="fields"
  72.                            use "-G ?" for more help
复制代码

作者: wuluoroad    时间: 2012-11-28 12:56
LZ这个工作做好了吗?我也想做类似的事情,一起交流哈
作者: 只爱睡觉    时间: 2012-11-29 15:24
这个工作鄙人早年做过分析cap的包话先用wireshark转成xls,在转成txt,然后在分析。
作者: feilong_36    时间: 2012-12-10 20:04
wireshark另存为 k12格式就方便perl解析了了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2