package de.tudarmstadt.informatik.hostage.protocol.smbutils; import java.nio.ByteBuffer; import de.tudarmstadt.informatik.hostage.commons.HelperUtils; public class NBDS { private byte[] type; private byte[] flags; private byte[] id; private byte[] srcIP; private byte[] srcPort; private byte[] length; private byte[] offset; private byte[] srcName; private byte[] dstName; private SMBPacket smb; public NBDS(byte[] transactID, byte[] addr, String src, String dst, int nbdstype) { this.type = new byte[]{0x11}; flags = new byte[]{0x0a}; id = transactID; srcIP = addr; srcPort = new byte[]{0x00, (byte) 0x8a}; offset = new byte[]{0x00, 0x00}; length = new byte[2]; srcName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(src.getBytes()), NBNSService.WORKSTATION); if (nbdstype == NBDSType.REQUEST_ANNOUNCEMENT || nbdstype == NBDSType.LOCAL_MASTER_ANNOUNCEMENT_ALL) { dstName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(dst.getBytes()), NBNSService.BROWSER_ELECTION); } else if (nbdstype == NBDSType.DOMAIN_ANNOUNCEMENT) { dstName = HelperUtils.concat(new byte[]{0x20, 0x41, 0x42, 0x41, 0x43}, NMBStringCoder.encodeNBNSName("__MSBROWSE__".getBytes()), new byte[]{0x41, 0x43, 0x41, 0x42, 0x00}); } else { dstName = NMBStringCoder.wrapNBNSName(NMBStringCoder.encodeNBNSName(dst.getBytes()), NBNSService.LOCAL_MASTER_BROWSER); } smb = new SMBPacket(null); smb.prepareNextResponse(nbdstype, src, dst); byte[] buffer = HelperUtils.concat(srcName, dstName, smb.getTrans()); byte[] lengthBuffer = ByteBuffer.allocate(4).putInt(buffer.length).array(); length[0] = lengthBuffer[2]; length[1] = lengthBuffer[3]; } public byte[] getBytes() { return HelperUtils.concat(type, flags, id, srcIP, srcPort, length, offset, srcName, dstName, smb.getTrans()); } }