linux - Duplicate packets when crafted from a VM with host OSX -
i'm getting strange results when crafting packets linux vm osx host (using virtualbox 4.3.20).
basically using script below reply icmp packets. when use wireshark both in vm , in osx different amount of packets , i'm interested in reason this. in vm expect, icmp request , associated reply, when capture same 'session' in osx see icmp request , 2 icmp replies...!
i'm filtering legitimate replies vm using following iptable rule:
iptables -a input -p ip -i eth0 -j drop in terms of vm setup i'm using virtualbox v4.3.20, using host adapter.
sorry code quality i'm been hammering @ while , didn't cleanup!
#!/usr/bin/python import socket, sys, commands multiprocessing import process, queue scapy.all import sniff, send, ether, ip, conf, raw, icmp conf.verbose = 0 def start_procs(iface, bpf): pkt_pipe = queue() pkt_cap_th = process(target=pkt_cap, args=(iface, bpf, pkt_pipe,)) pkt_cap_th.start() pkt_play_th = process(target=pkt_play, args=(iface, pkt_pipe,)) pkt_play_th.start() def pkt_cap(iface, bpf, pkt_pipe): while true: try: sniff(iface=iface, filter=bpf, prn=lambda pkt:pkt_pipe.put(str(pkt[ip])), count=0, store=0, timeout=none) except exception, error: print 'error in pkt_cap: ' + str(error.message) def pkt_play(iface, pkt_pipe): try: s = socket.socket(socket.af_inet, socket.sock_raw, socket.ipproto_raw) except socket.error , msg: print 'socket not created. error code : ' + str(msg[0]) + ' message ' + msg[1] count = 1 while true: pkt = pkt_pipe.get() pkt = ip(pkt) pkt = modpkt(pkt) dest_ip = pkt[ip].dst print 'pkt_play ****** s: ' + str(count) print 'pkt_play - ' + pkt.summary() print pkt.show2() pkt_hex = str(pkt) try: #send(pkt, iface=iface, verbose=0) s.sendto(pkt_hex, (dest_ip , 0)) except exception, e: print 'error sending packet: ' + str(e.message) print 'pkt_play ****** e :' + str(count) count += 1 def modpkt(pkt): ipdst = pkt[ip].dst ipsrc = pkt[ip].src pkt[ip].src = ipdst pkt[ip].dst = ipsrc pkt[icmp].type = 0 del pkt[ip].chksum del pkt[ip].len del pkt[icmp].chksum return pkt def main(): iface = 'eth0' srcmac = commands.getoutput('ifconfig ' + iface + ' | grep hwaddr | awk \'{print $5}\'') bpf = '(ether dst ' + srcmac + ') , ip' print bpf start_procs_th = process(target=start_procs, args=(iface, bpf)) start_procs_th.start() if __name__ == '__main__': main() tia!
Comments
Post a Comment