剥离TZSP封装 - 实时流量

时间:2015-12-16 14:53:35

标签: python logging header scapy

我正在创建一个日志服务器,它将传入和传出连接(任何类型)写入TXT文件。一切正常,这是我的代码:

from scapy.all import *
import datetime
from threading import Thread
from Queue import Queue, Empty
from scapy.layers.dns import DNS, DNSQR
firstime = 0
times = time.time()+86400
def print_summary(pkt):
    global firstime
    global times
    if IP in pkt:
        ip_src=pkt[IP].src
        ip_dst=pkt[IP].dst
    else:
        ip_src="Null"
        ip_dst="Null"
        mac_src="Null"
        mac_dst="Null"    
    if TCP in pkt:
        tcp_sport=pkt[TCP].sport
        tcp_dport=pkt[TCP].dport
    else:
        tcp_sport="Null"
        tcp_dport="Null"
    if DNSQR in pkt:
        dns = pkt.qd.qname
    else:
        dns = "NULL"
    if Ether in pkt:
        mac_src = pkt[Ether].src
        mac_dst = pkt[Ether].dst
    else:
        mac_src = "Null"
        mac_dst = "Null"  
    Clog = " IP src: " + str(ip_src) +" ,MAC src: " + str(mac_src) + " , IP dst: " + str(ip_dst) +" ,MAC dst: "+str(mac_dst)+" ,TCP sport: " + str(tcp_sport) + ",TCP dport: " + str(tcp_dport) +", Time: " + str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(pkt.time))) + " Dns: "+dns
    if(times > pkt.time):
        if(firstime == 0):
            f = open("/root/Desktop/LOG-SERVER/"+time.strftime('%Y-%m-%d %H:%M:', time.localtime(time.time()))+".txt",'a')
            f.write(Clog+"\n")
            f.close()       
        else:
            f.write(Clog+"\n")
            f.close()   
    else:
        f = open("/root/Desktop/LOG-SERVER/"+time.strftime('%Y-%m-%d %H:%M:', time.localtime(time.time()))+".txt",'a')
        f.write(Clog+"\n")
        f.close()       
        times=times+86400
def startsnif():
    sniff(prn=print_summary, store=0)
    # you can filter with something like that
    #if ( ( pkt[IP].src == "192.168.0.1") or ( pkt[IP].dst == "192.168.0.1") ):
     #   print("!")
#def writing(log,indexp):
    #if(indexp == 0):
        #f = open("/root/Desktop/LOG-SERVER/"+time.strftime('%Y-%m-%d %H:%M:', time.localtime(time.time()))+".txt",'a')
        #f.write(log+"\n")
        #f.close()
    #else:
        #f.write(log+"\n")
        #f.close()

thread.start_new_thread(startsnif,());
while 1:
        pass
# or it possible to filter with filter parameter...!
#sniff(filter="ip and host 192.168.0.1",prn=print_summary)

输出是:

IP Src: 192.168.10.1 MAC Src: 54:55:12:FC:2D:CA IP Dst:192.168.10.15 MAC Src: 54:55:12:FC:1F:3A TCP sport: 80 TCP dport: 51233 Time:2015-12-16 13:25:11 DNS:Null(IF available DNS Name) 
问题是该公司获得了mikrotics,mikrotics通过一种称为TZSP Sniff的技术镜像流量,该技术使用路由器的IP和目标PC的目标PC MAC的路由器IP的MAC封装数据包,我正在搜索我找不到任何合适的解决方案,但我读到你需要删除数据包的前5个字节。

有没有办法剥离TZSP封装实时(不保存PCAP),请你解释一下这个过程,因为我对这个东西不熟悉了吗?

如果您有任何问题,请告诉我,我不太善于解释。

谢谢!

1 个答案:

答案 0 :(得分:0)

在检查了TZSP数据包标题的二进制文件之后,看来TZSP在添加它自己之后剥离了原始的mac地址,所以项目已经关闭了,谢谢你的帮助。