如何将原始L2数据包作为传入数据包注入Linux上的接口? [英] How to inject a raw L2 packet as an incoming packet to an interface on Linux?

查看:158
本文介绍了如何将原始L2数据包作为传入数据包注入Linux上的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向特定接口注入一些L2数据包(自定义),作为Linux中的传入数据包,以测试在其上运行的某些应用程序.

I need to inject some L2 packets(customized) to an specific interface as incoming packets in Linux to test some applications running on it.

是否有可以帮助的库(首选python)/示例?我浏览了Scrapy库,但是看起来它只能将数据包作为传出数据包注入网络?

Is there any libraries(python preferred)/examples that can help? I was skimming through the Scrapy library, but then it looks like it can only inject packets to the network as outgoing packets?

推荐答案

如果您有可用的本地linux bridge模块,则可以这种方式使用它.创建一座桥

If you have the native linux bridge module available then you can use it in this way. Create a bridge

brctl addbr <brname>

现在创建一个虚拟的eth对(默认名称veth0veth1).所有已连接的L2设备

Now create a virtual eth pair (default names veth0, veth1). veths are connected L2 devices

ip link add type veth
ifconfig veth0 up
ifconfig veth1 <some_ip> up

现在添加您的特定接口,例如eth0,并将veth对的一侧添加到该网桥.

Now add your specific interface, lets say eth0, and one side of the veth pair to this bridge.

brctl addif <brname> eth0
brctl addif <brname> veth0

这会将这两个接口添加到网桥.现在,当您在veth0上发送流量时,您也应该也可以在eth0上获取流量(基于正常的L2交换机功能).要在veth0上发送流量,您只需要将流量泵入veth1,因为它们都是内部连接的.因此,假设您要使用tcpreplay,只需

This adds both these interfaces to the bridge. Now when you send traffic on veth0, you should be able to get it on eth0 also(based on normal L2 switch functionality). To send traffic on veth0 you simply need to pump traffic into veth1 since both of them are connected internally. So lets say you want to use tcpreplay, just do

tcpreply -i veth1 yourpcap.pcap

让我们知道进展如何

这篇关于如何将原始L2数据包作为传入数据包注入Linux上的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆