jnetpcap java.lang.nullpointerexception异常

tjjdgumg  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(444)

因此,我参加了一个ctf,我们需要向服务器发送一个命令,使其重新启动本身,扭曲的是,目标只接受来自特定ip地址的请求,所以我们打算“欺骗”我们的地址,使这项工作,现在我在java中做这是复杂的af,我需要使用这个jnetpcap库,但我正在努力:
我得到的错误是:

  1. Exception in thread "Thread-0" java.lang.NullPointerException

发生错误的地点:

  1. @Override
  2. public void run() {
  3. Pcap pcap = new Pcap();
  4. //first we create the packet
  5. final JMemoryPacket packet = new JMemoryPacket(buff_size);
  6. packet.scan(Ethernet.ID);
  7. //this is where we are changing the ip address header
  8. Ip4 ip_addr = packet.getHeader(new Ip4());
  9. ip_addr.source(spoofed_ip); //here is where the null pointer is
  10. ip_addr.destination(target_host);
  11. Tcp tcp = packet.getHeader(new Tcp());
  12. tcp.destination(target_port);
  13. if (pcap.sendPacket(packet) != Pcap.OK){
  14. System.err.println(pcap.getErr());
  15. }
  16. }

这就是我设置ip:1的方式。创建对象时,需要输入一些参数,包括字节格式的ip地址,如下所示:

  1. new byte[]{1, 2, 3, 4};

前任:

  1. new byte[]{(byte)Integer.parseInt(p[0]), (byte)Integer.parseInt(p[1]), (byte)Integer.parseInt(p[2]), (byte)Integer.parseInt(p[3])}

在调试时,我将其输出为ip地址- [45, 80, -108, -102] 当ip地址是我试图欺骗 45.80.148.154 任何援助都会被爱!
编辑1:初始化欺骗ip:

  1. public Attack(byte[] target_host, int target_port, int buff_size, byte[] spoofed_ip) {
  2. this.target_host = target_host;
  3. this.target_port = target_port;
  4. this.buff_size = buff_size;
  5. this.spoofed_ip = spoofed_ip;
  6. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题