duanfenhui5511 2017-03-15 06:56
浏览 177

使用golang进行NTP检测,有效负载为空

I'm working on detecting NTP using golang and the gopacket package. I'm using a pcap I downloaded from wireshark. I've got the following code for opening PCAPs and handling them :

func (d *DPI) readPCAP(pcapFile string) (*pcap.Handle, error) {
    // Open file instead of device
    handle, err := pcap.OpenOffline(pcapFile)
    if err != nil {
        return nil, err
    }
    return handle, nil
}

And this is the code I'm writing to perform the actual detection

func TestNTP(t *testing.T) {



    dpi := newDPI()
    handle, _ := dpi.readPCAP("data/pcap/NTP_sync.pcap")

    var filter = "udp and port 123"
    dpi.setFilter(handle,filter)
    ntpPackets := 0

    for packet := range dpi.getPacketChan(handle) {
        fmt.Println("stuff: ",packet.ApplicationLayer().Payload())
        if dpi.detectNTP(packet) == 1 {
            ntpPackets++
        } else {
            fmt.Println(" Output : ", dpi.detectNTP(packet))
        }
    }
    fmt.Println(" Total ntp packets ", ntpPackets)


}

The Payload content in the ApplicationLayer is coming up empty and I'm unable to figure out why this is happening.

Example screenshot when I print out the ApplicationLayer itself :

https://i.gyazo.com/6257f298a09e7403bbc0be5b8ac84ccc.png

Example screenshot when I print out the Payload : https://i.gyazo.com/7f4abd449025f5d65160fdbecffa8181.png

Could use some help figuring out what I'm doing wrong. Thanks!

  • 写回答

1条回答 默认 最新

  • dsrjs86444 2017-03-15 15:29
    关注

    Reading through the golang soure code, I came across this :

    // NTP packets do not carry any data payload, so the empty byte slice is retured.
    // In Go, a nil slice is functionally identical to an empty slice, so we
    // return nil to avoid a heap allocation.
    func (d *NTP) Payload() []byte {
        return nil
    }
    

    So, apparently it's not supposed to carry a Payload. I've managed to perform the detection using layers.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器