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 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题