douchangmian0305 2018-05-27 09:17
浏览 55

如何获取IP数据包并注入到不同的VM和接口上

I have been trying to solve these 2 problems, but without success.

  1. I wonder if it's possible to remove specific packets from an interface with Gopacket or is it just for listening on the wire? For example when I send a UDP packet to a wrong port and then with Gopacket I correct it, it will send 2 packets, 1 to the wrong port and 1 to the correct one. Is there a way to discard/drop the wrong packet with Gopacket?

  2. What I am trying to do, is to pick up all packets that are sent by a client over IP and then encapsulate each packet as a payload in another protocol X and send to the remote host which will receive on protocol X, get the payload and send it on its interface to reach the server over IP again. (IP (Client) -> Protocol X (Sniffer 1) -> Protocol X (Sniffer 2) -> IP (Server))

I have verified that the packet which Sniffer 1 picks up from the Client's interface is the same which arrives at Sniffer 2, but the problem is when Sniffer 2 injects it on the Server's interface. I can't see that packet with tcpdump or any other tool. The packet is injected with this command:

if handle, err := pcap.OpenLive("enp0s8", 1600, true, 100); err != nil {
    panic(err)
} else {
   err = handle.WritePacketData(packet.Data())
}

If the Protocol X part is avoided, then the server will receive messages from client, but with Protocol X it is not possible.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • doudouchan5830 2018-05-28 08:59
    关注

    According to the Documentation

    Package pcap allows users of gopacket to read packets off the wire or from pcap files.

    To discard packages, you will need to be able to intercept them. Depending on how generic you want to solve this problem, you probably need to hook into the kernel. I recommend looking into iptables and netfilters.

    I found some VPN that are written in go, maybe look into how they are built, as you want to do something similar (tunnelling of packets).

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?