Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ns.tcphack;
- class MyTcpHandler extends TcpHandler {
- public static void main(String[] args) {
- new MyTcpHandler();
- }
- public MyTcpHandler() {
- super();
- boolean done = false;
- // array of bytes in which we're going to build our packet:
- int[] txpkt = new int[68]; // 40 bytes long for now, may need to expand this later
- txpkt[0] = 0x60; // first byte of the IPv6 header contains version number in upper nibble
- // add our traffic class to the same byte
- // txpkt[0] = txpkt[0] | 0x00;
- // the rest of traffic class
- txpkt[1] = 0x00;
- // flow label
- txpkt[2] = 0x00;
- txpkt[3] = 0x00;
- // payload length
- txpkt[4] = 0x00;
- txpkt[5] = 0x1c;
- // next header (type TCP is 6)
- txpkt[6] = 0x06;
- // hop limit 64
- txpkt[7] = 0x40;
- // Our source IP:
- // 2001:67c:2564:a309:f91c:f77c:9c2f:24ed
- // Split this up into 16 array elements:
- txpkt[8] = 0x20;
- txpkt[9] = 0x01;
- txpkt[10] = 0x06;
- txpkt[11] = 0x7c;
- txpkt[12] = 0x25;
- txpkt[13] = 0x64;
- txpkt[14] = 0xa3;
- txpkt[15] = 0x09;
- txpkt[16] = 0xf9;
- txpkt[17] = 0x1c;
- txpkt[18] = 0xf7;
- txpkt[19] = 0x7c;
- txpkt[20] = 0x9c;
- txpkt[21] = 0x2f;
- txpkt[22] = 0x24;
- txpkt[23] = 0xed;
- // Our destination IP:
- // 2001:67c:2564:a170:204:23ff:fede:4b2c
- txpkt[24] = 0x20;
- txpkt[25] = 0x01;
- txpkt[26] = 0x06;
- txpkt[27] = 0x7c;
- txpkt[28] = 0x25;
- txpkt[29] = 0x64;
- txpkt[30] = 0xa1;
- txpkt[31] = 0x70;
- txpkt[32] = 0x02;
- txpkt[33] = 0x04;
- txpkt[34] = 0x23;
- txpkt[35] = 0xff;
- txpkt[36] = 0xfe;
- txpkt[37] = 0xde;
- txpkt[38] = 0x4b;
- txpkt[39] = 0x2c;
- // TCP header
- // source port (we chose 6543)
- txpkt[40] = 0x19;
- txpkt[41] = 0x8f;
- // destination port (this depends on which one we're doing)
- txpkt[42] = 0x1e;
- txpkt[43] = 0x1e;
- // sequence number! initially choose 1
- txpkt[44] = 0x01;
- txpkt[45] = 0x00;
- txpkt[46] = 0x00;
- txpkt[47] = 0x00;
- // ack number! initially choose 0
- txpkt[48] = 0x00;
- txpkt[49] = 0x00;
- txpkt[50] = 0x00;
- txpkt[51] = 0x00;
- // data offset initially choose 0
- txpkt[52] = 0x50;
- // reserved (must be 0)
- // | FLAGS: |
- // Reserved: (2 bits) | urg | ack | psh | rst | syn | fin |
- txpkt[53] = 0b00000010;
- // window
- txpkt[54] = 0xff;
- txpkt[55] = 0x00;
- // checksum
- txpkt[56] = 0x00;
- txpkt[57] = 0x00;
- // Urgent pointer
- txpkt[58] = 0x00;
- txpkt[59] = 0x00;
- // options
- txpkt[60] = 0x00;
- txpkt[61] = 0x00;
- txpkt[62] = 0x00;
- // Padding
- txpkt[63] = 0x00;
- // Data
- txpkt[64] = 0x00;
- txpkt[65] = 0x00;
- txpkt[66] = 0x00;
- txpkt[67] = 0x00;
- this.sendData(txpkt); // send the packet
- while (!done) {
- // check for reception of a packet, but wait at most 500 ms:
- int[] rxpkt = this.receiveData(500);
- if (rxpkt.length==0) {
- // nothing has been received yet
- System.out.println("Nothing...");
- continue;
- }
- // something has been received
- int len=rxpkt.length;
- // print the received bytes:
- int i;
- System.out.print("Received "+len+" bytes: ");
- for (i=0;i<len;i++) System.out.print(rxpkt[i]+" ");
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement