简体   繁体   English

捕获通过Netcat发送的Tun接口上的数据包

[英]Capturing packets on a tun interface sent via netcat

I'm trying to work through some of the simple tun/tap examples on the web and am having a bit of trouble. 我正在尝试浏览网络上的一些简单的tun / tap示例,并且遇到了一些麻烦。 Briefly, I'm trying to: 简要地说,我正在尝试:

  1. Create a tun interface and give it an address 创建一个tun接口并给它一个地址
  2. Open the tun interface with some code that will print out received packets 使用一些代码打开tun界面,这些代码将打印出接收到的数据包
  3. Send some packets with netcat 用netcat发送一些数据包
  4. Observe the packets with both wireshark and the code that prints them out 观察带有Wireshark的数据包以及将其打印出来的代码

I'm having trouble with (3) and (4). 我在(3)和(4)上遇到麻烦。 This tutorial says that in older linux versions you could use ping, but apparently that is not the case anymore, so I'm attempting to use netcat. 本教程说,在较早的linux版本中,您可以使用ping,但是显然情况不再如此,因此,我尝试使用netcat。 My assumption is that I am not sending the data correctly- specifically, with netcat I have to aim at a specific port, so I give it an arbitrary port along with address of the tun interface. 我的假设是我没有正确发送数据-特别是对于netcat,我必须瞄准特定端口,因此我给它一个任意端口以及tun接口的地址。

Since wireshark and both programs don't see anything, I assume it's the sending of the packets that is incorrect. 由于wireshark和两个程序都看不到任何内容,因此我认为发送数据包不正确。 Is there a better approach then using netcat? 有没有比使用netcat更好的方法?

The tun inferface: tun接口:

$ ifconfig tun2
tun2      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:192.168.7.1  P-t-P:192.168.7.2  Mask:255.255.255.255
          UP POINTOPOINT NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Writing some packets, no error observed 写入一些数据包,未观察到错误

$ echo -n 'fooooo' | nc 192.168.7.1 5555
$
$ echo -n `cat index.html` | nc 192.168.7.1 5555
$

Wireshark (and program console) show nothing: Wireshark(和程序控制台)什么也不显示:

$sudo tshark -i tun2
....

I've tried two different pieces of code for (2), both of which should print out received packets: 我为(2)尝试了两段不同的代码,这两段代码都应该打印出接收到的数据包:

UPDATE: 更新:

Running the simpletun program in the second link above as both client and server, on the same machine, for the server I get: 在同一台机器上,在上面的第二个链接中,在客户端和服务器上同时运行simpletun程序,我得到的服务器是:

$ ./simpletun -i tun2 -s -d
Successfully connected to interface tun2

And for the client (which would be run on a different machine I think): 对于客户端(我认为它将在其他计算机上运行):

$./simpletun -i tun2 -c 192.168.7.1 -d
ioctl(TUNSETIFF): Device or resource busy
Error connecting to tun/tap interface tun2!

So I'm pretty sure I'm opening tun2. 所以我很确定我要打开tun2。

EDIT2: 编辑2:

I'm doing this on virtualbox VM with ubuntu server on it. 我正在带有ubuntu服务器的virtualbox VM上执行此操作。 Once I get it working on one machine I would like to try writing a simple UDP bridge with a second machine, both on tun interfaces. 一旦我在一台机器上运行它,我想尝试在第二个机器上都在tun接口上编写一个简单的UDP桥。

EDIT3: 编辑3:

Loopback it is 环回它是

$ sudo tshark -i lo
[sudo] password for nflacco: 
tshark: Lua: Error during loading:
 [string "/usr/share/wireshark/init.lua"]:45: dofile has been disabled
Running as user "root" and group "root". This could be dangerous.
Capturing on lo
  0.000000  192.168.7.1 -> 192.168.7.1  TCP 74 59584 > personal-agent [SYN] Seq=0 Win=32792 Len=0 MSS=16396 SACK_PERM=1 TSval=26444728 TSecr=0 WS=4
  0.000019  192.168.7.1 -> 192.168.7.1  TCP 54 personal-agent > 59584 [RST, ACK] Seq=1 Ack=1 Win=0 Len=0

Is there another system which is connected at the other end of the tunnel tun2? 隧道tun2的另一端是否连接了另一个系统?

Notice RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) in the ifconfig output. 注意ifconfig输出中的RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) There is indeed no packet transferred over that interface. 实际上,没有任何数据包通过该接口传输。 Make sure that there is some receiver on that interface. 确保该接口上有一些接收器。

eg If you are using this for virtualization, make sure that the virtual machine is up & ready to receive the packets. 例如,如果将其用于虚拟化,请确保虚拟机已启动并准备好接收数据包。 If you are using this for VPN or something, make sure that the remote system is responding. 如果您将此用于VPN或其他用途,请确保远程系统正在响应。

I have used tunnel interface for virtulization. 我已经使用隧道接口进行虚拟化。 & it works, when VM is up & running. 它可以在VM启动并运行时正常工作。

Try 尝试

echo -n 'fooooo' | nc 192.168.7.2 5555

You need to send traffic to an IP that is in the subnet of the tun interface but not the interface IP itself. 您需要将流量发送到tun接口子网中的IP,而不是接口IP本身。 If you send it to the interface IP, the kernel will not send it on the wire, since the packet has reached its destination. 如果将其发送到接口IP,则内核将不会通过网络将其发送,因为数据包已到达其目的地。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM