NBDS.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public NBDS(byte[] transactID, byte[] addr, String src, String dst, int nbdstype) {
  16. this.type = new byte[]{0x11};
  17. flags = new byte[]{0x0a};
  18. id = transactID;
  19. srcIP = addr;
  20. srcPort = new byte[]{0x00, (byte) 0x8a};
  21. offset = new byte[]{0x00, 0x00};
  22. length = new byte[2];
  23. srcName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(src.getBytes()), NBNSService.WORKSTATION);
  24. if (nbdstype == NBDSType.REQUEST_ANNOUNCEMENT || nbdstype == NBDSType.LOCAL_MASTER_ANNOUNCEMENT_ALL) {
  25. dstName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(dst.getBytes()), NBNSService.BROWSER_ELECTION);
  26. } else if (nbdstype == NBDSType.DOMAIN_ANNOUNCEMENT) {
  27. dstName = HelperUtils.concat(new byte[]{0x20, 0x41, 0x42, 0x41, 0x43}, NMBStringCoder.encodeNBNSName("__MSBROWSE__".getBytes()),
  28. new byte[]{0x41, 0x43, 0x41, 0x42, 0x00});
  29. } else {
  30. dstName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(dst.getBytes()), NBNSService.LOCAL_MASTER_BROWSER);
  31. }
  32. smb = new SMBPacket(null);
  33. smb.prepareNextResponse(nbdstype, src, dst);
  34. byte[] buffer = HelperUtils.concat(srcName, dstName, smb.getTrans());
  35. byte[] lengthBuffer = ByteBuffer.allocate(4).putInt(buffer.length).array();
  36. length[0] = lengthBuffer[2];
  37. length[1] = lengthBuffer[3];
  38. }
  39. public byte[] getBytes() {
  40. return HelperUtils.concat(type, flags, id, srcIP, srcPort, length,
  41. offset, srcName, dstName, smb.getTrans());
  42. }
  43. }