Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. package ns.tcphack;
  2.  
  3. class MyTcpHandler extends TcpHandler {
  4. public static void main(String[] args) {
  5. new MyTcpHandler();
  6. }
  7.  
  8. public MyTcpHandler() {
  9. super();
  10.  
  11. boolean done = false;
  12.  
  13. // array of bytes in which we're going to build our packet:
  14. int[] txpkt = new int[68]; // 40 bytes long for now, may need to expand this later
  15.  
  16. txpkt[0] = 0x60; // first byte of the IPv6 header contains version number in upper nibble
  17. // add our traffic class to the same byte
  18. // txpkt[0] = txpkt[0] | 0x00;
  19. // the rest of traffic class
  20. txpkt[1] = 0x00;
  21. // flow label
  22. txpkt[2] = 0x00;
  23. txpkt[3] = 0x00;
  24.  
  25. // payload length
  26. txpkt[4] = 0x00;
  27. txpkt[5] = 0x1c;
  28.  
  29. // next header (type TCP is 6)
  30. txpkt[6] = 0x06;
  31. // hop limit 64
  32. txpkt[7] = 0x40;
  33.  
  34. // Our source IP:
  35. // 2001:67c:2564:a309:f91c:f77c:9c2f:24ed
  36. // Split this up into 16 array elements:
  37. txpkt[8] = 0x20;
  38. txpkt[9] = 0x01;
  39. txpkt[10] = 0x06;
  40. txpkt[11] = 0x7c;
  41. txpkt[12] = 0x25;
  42. txpkt[13] = 0x64;
  43. txpkt[14] = 0xa3;
  44. txpkt[15] = 0x09;
  45. txpkt[16] = 0xf9;
  46. txpkt[17] = 0x1c;
  47. txpkt[18] = 0xf7;
  48. txpkt[19] = 0x7c;
  49. txpkt[20] = 0x9c;
  50. txpkt[21] = 0x2f;
  51. txpkt[22] = 0x24;
  52. txpkt[23] = 0xed;
  53.  
  54. // Our destination IP:
  55. // 2001:67c:2564:a170:204:23ff:fede:4b2c
  56. txpkt[24] = 0x20;
  57. txpkt[25] = 0x01;
  58. txpkt[26] = 0x06;
  59. txpkt[27] = 0x7c;
  60. txpkt[28] = 0x25;
  61. txpkt[29] = 0x64;
  62. txpkt[30] = 0xa1;
  63. txpkt[31] = 0x70;
  64. txpkt[32] = 0x02;
  65. txpkt[33] = 0x04;
  66. txpkt[34] = 0x23;
  67. txpkt[35] = 0xff;
  68. txpkt[36] = 0xfe;
  69. txpkt[37] = 0xde;
  70. txpkt[38] = 0x4b;
  71. txpkt[39] = 0x2c;
  72.  
  73. // TCP header
  74. // source port (we chose 6543)
  75. txpkt[40] = 0x19;
  76. txpkt[41] = 0x8f;
  77.  
  78. // destination port (this depends on which one we're doing)
  79. txpkt[42] = 0x1e;
  80. txpkt[43] = 0x1e;
  81.  
  82. // sequence number! initially choose 1
  83. txpkt[44] = 0x01;
  84. txpkt[45] = 0x00;
  85. txpkt[46] = 0x00;
  86. txpkt[47] = 0x00;
  87.  
  88. // ack number! initially choose 0
  89. txpkt[48] = 0x00;
  90. txpkt[49] = 0x00;
  91. txpkt[50] = 0x00;
  92. txpkt[51] = 0x00;
  93.  
  94. // data offset initially choose 0
  95. txpkt[52] = 0x50;
  96. // reserved (must be 0)
  97. // | FLAGS: |
  98. // Reserved: (2 bits) | urg | ack | psh | rst | syn | fin |
  99. txpkt[53] = 0b00000010;
  100.  
  101. // window
  102. txpkt[54] = 0xff;
  103. txpkt[55] = 0x00;
  104.  
  105. // checksum
  106. txpkt[56] = 0x00;
  107. txpkt[57] = 0x00;
  108.  
  109. // Urgent pointer
  110. txpkt[58] = 0x00;
  111. txpkt[59] = 0x00;
  112.  
  113. // options
  114. txpkt[60] = 0x00;
  115. txpkt[61] = 0x00;
  116. txpkt[62] = 0x00;
  117.  
  118. // Padding
  119. txpkt[63] = 0x00;
  120.  
  121. // Data
  122. txpkt[64] = 0x00;
  123. txpkt[65] = 0x00;
  124. txpkt[66] = 0x00;
  125. txpkt[67] = 0x00;
  126.  
  127. this.sendData(txpkt); // send the packet
  128.  
  129. while (!done) {
  130. // check for reception of a packet, but wait at most 500 ms:
  131. int[] rxpkt = this.receiveData(500);
  132. if (rxpkt.length==0) {
  133. // nothing has been received yet
  134. System.out.println("Nothing...");
  135. continue;
  136. }
  137.  
  138. // something has been received
  139. int len=rxpkt.length;
  140.  
  141. // print the received bytes:
  142. int i;
  143. System.out.print("Received "+len+" bytes: ");
  144. for (i=0;i<len;i++) System.out.print(rxpkt[i]+" ");
  145. System.out.println("");
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement