JnetPcap java。lang.NullPointerException
因此,我参加了一个CTF,我们需要向服务器发送一个命令,使其重新启动,扭曲的是,目标只接受来自特定ip地址的请求,所以我们要“欺骗”我们的地址,使其工作,现在我在Java中做这件事很复杂,我需要使用这个JnetPcap库,但我正在努力:
我得到的错误是:
Exception in thread "Thread-0" java.lang.NullPointerException
发生错误的地点:
@Override
public void run() {
Pcap pcap = new Pcap();
//first we create the packet
final JMemoryPacket packet = new JMemoryPacket(buff_size);
packet.scan(Ethernet.ID);
//this is where we are changing the ip address header
Ip4 ip_addr = packet.getHeader(new Ip4());
ip_addr.source(spoofed_ip); //here is where the null pointer is
ip_addr.destination(target_host);
Tcp tcp = packet.getHeader(new Tcp());
tcp.destination(target_port);
if (pcap.sendPacket(packet) != Pcap.OK){
System.err.println(pcap.getErr());
}
}
以下是我设置ip的方式: 1.创建对象时,需要输入一些参数,包括字节格式的ip地址,如下所示:
new byte[]{1, 2, 3, 4};
例:
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初始化:
public Attack(byte[] target_host, int target_port, int buff_size, byte[] spoofed_ip) {
this.target_host = target_host;
this.target_port = target_port;
this.buff_size = buff_size;
this.spoofed_ip = spoofed_ip;
}
共 (0) 个答案