0

So I am taking part in a CTF and we are required to send a command to a server to make it reboot itself, the twist is the target only accepts requests from a specific ip addr so we are meant to be "spoofing" our addr to make this work, now as I am doing this in Java is complicated af, I need to use this JnetPcap library but I am struggling:

The error I am getting:

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

The spot the error is occurring in:

    @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());
            }


    }

This is how I am setting the ip: 1. When you create the object you need to input some params including the ip address in byte format like so:

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

Ex:

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

Upon debugging I outputted this as the ip address - [45, 80, -108, -102] when the ip address I am trying to spoof as is 45.80.148.154

Any assistance would be loved!

EDIT 1: init of spoof_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;
    }
Aasil
  • 103
  • 5

0 Answers0