NBDS.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package de.tudarmstadt.informatik.hostage.protocol.SMBUtils;
  2. import java.nio.ByteBuffer;
  3. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  4. public class NBDS {
  5. private byte[] type;
  6. private byte[] flags;
  7. private byte[] id;
  8. private byte[] srcIP;
  9. private byte[] srcPort;
  10. private byte[] length;
  11. private byte[] offset;
  12. private byte[] srcName;
  13. private byte[] dstName;
  14. private SMBPacket smb;
  15. private SMBMailSlot smbMailSlot;
  16. private MicrosoftWindowsBrowser microsoftWindowsBrowser;
  17. public NBDS(byte[] transactID, byte[] ip, byte[] addr, String src, String dst) {
  18. type = new byte[]{0x11};
  19. flags = new byte[]{0x0a};
  20. id = transactID;
  21. srcIP = addr;
  22. srcPort = new byte[]{0x00, (byte) 0x8a};
  23. offset = new byte[]{0x00, 0x00};
  24. length = new byte[2];
  25. srcName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(src.getBytes()), Service.WORKSTATION);
  26. dstName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(dst.getBytes()), Service.LOCAL_MASTER_BROWSER);
  27. smb = new SMBPacket(null);
  28. smb.prepareNextResponse();
  29. smbMailSlot = new SMBMailSlot();
  30. microsoftWindowsBrowser = new MicrosoftWindowsBrowser(src);
  31. byte[] buffer = HelperUtils.concat(srcName, dstName, smb.getTrans(), smbMailSlot.getBytes(), microsoftWindowsBrowser.getBytes());
  32. byte[] lengthBuffer = ByteBuffer.allocate(4).putInt(buffer.length).array();
  33. length[0] = lengthBuffer[2];
  34. length[1] = lengthBuffer[3];
  35. }
  36. public byte[] getBytes() {
  37. return HelperUtils.concat(type, flags, id, srcIP, srcPort, length,
  38. offset, srcName, dstName, smb.getTrans(), smbMailSlot.getBytes(), microsoftWindowsBrowser.getBytes());
  39. }
  40. private class SMBMailSlot {
  41. private byte[] opcode;
  42. private byte[] priority;
  43. private byte[] smbclass;
  44. private byte[] size;
  45. private byte[] name;
  46. public SMBMailSlot() {
  47. opcode = new byte[]{0x01, 0x00};
  48. priority = new byte[]{0x01, 0x00};
  49. smbclass = new byte[]{0x02, 0x00};
  50. size = new byte[]{0x3e, 0x00};
  51. name = HelperUtils.concat("\\MAILSLOT\\BROWSE".getBytes(), new byte[]{0x00});
  52. }
  53. public byte[] getBytes() {
  54. return HelperUtils.concat(opcode, priority, smbclass, size, name);
  55. }
  56. }
  57. private class MicrosoftWindowsBrowser {
  58. private byte[] command;
  59. private byte[] updateCount;
  60. private byte[] updatePeriodicity;
  61. private byte[] hostName;
  62. private byte[] osMajorVersion;
  63. private byte[] osMinorVersion;
  64. private byte[] serverType;
  65. private byte[] browserProtocolMajorVer;
  66. private byte[] browserProtocolMinorVer;
  67. private byte[] signature;
  68. private byte[] hostComment;
  69. public MicrosoftWindowsBrowser(String name) {
  70. command = new byte[]{0x01};
  71. updateCount = new byte[]{0x00};
  72. updatePeriodicity = new byte[]{0x60, (byte) 0xea, 0x00, 0x00};
  73. hostName = HelperUtils.concat(name.getBytes(),
  74. new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
  75. osMajorVersion = new byte[]{0x04};
  76. osMinorVersion = new byte[]{0x09};
  77. serverType = new byte[]{0x03, (byte) 0x9a, (byte) 0x81, 0x00};
  78. browserProtocolMajorVer = new byte[]{0x0f};
  79. browserProtocolMinorVer = new byte[]{0x01};
  80. signature = new byte[]{0x55, (byte) 0xaa};
  81. hostComment = HelperUtils.concat("Samba Server".getBytes(), new byte[]{0x00});
  82. }
  83. public byte[] getBytes() {
  84. return HelperUtils.concat(command, updateCount, updatePeriodicity,
  85. hostName, osMajorVersion, osMinorVersion, serverType,
  86. browserProtocolMajorVer, browserProtocolMinorVer,
  87. signature, hostComment);
  88. }
  89. }
  90. }