Class NTLMUtilities

    • Method Detail

      • writeSecurityBuffer

        public static final byte[] writeSecurityBuffer​(short length,
                                                       int bufferOffset)
        Parameters:
        length - The length of the security buffer
        bufferOffset - The offset in the security buffer
        Returns:
        Th created buffer
        See Also:
        writeSecurityBuffer(short, short, int, byte[], int)
      • writeSecurityBuffer

        public static final void writeSecurityBuffer​(short length,
                                                     short allocated,
                                                     int bufferOffset,
                                                     byte[] b,
                                                     int offset)
        Writes a security buffer to the given array b at offset offset. A security buffer defines a pointer to an area in the data that defines some data with a variable length. This allows to have a semi-fixed length header thus making a little bit easier the decoding process in the NTLM protocol.
        Parameters:
        length - the length of the security buffer
        allocated - the allocated space for the security buffer (should be greater or equal to length
        bufferOffset - the offset from the main array where the currently defined security buffer will be written
        b - the buffer in which we write the security buffer
        offset - the offset at which to write to the b buffer
      • writeOSVersion

        public static final void writeOSVersion​(byte majorVersion,
                                                byte minorVersion,
                                                short buildNumber,
                                                byte[] b,
                                                int offset)
        Writes the Windows OS version passed in as three byte values (majorVersion.minorVersion.buildNumber) to the given byte array at offset.
        Parameters:
        majorVersion - the major version number
        minorVersion - the minor version number
        buildNumber - the build number
        b - the target byte array
        offset - the offset at which to write in the array
      • getOsVersion

        public static final byte[] getOsVersion()
        Tries to return a valid OS version on Windows systems. If it fails to do so or if we're running on another OS then a fake Windows XP OS version is returned because the protocol uses it.
        Returns:
        a NTLM OS version byte buffer
      • createType1Message

        public static final byte[] createType1Message​(String workStation,
                                                      String domain,
                                                      Integer customFlags,
                                                      byte[] osVersion)
        see http://davenport.sourceforge.net/ntlm.html#theType1Message
        Parameters:
        workStation - the workstation name
        domain - the domain name
        customFlags - custom flags, if null then NTLMConstants.DEFAULT_CONSTANTS is used
        osVersion - the os version of the client, if null then NTLMConstants.DEFAULT_OS_VERSION is used
        Returns:
        the type 1 message
      • writeSecurityBufferAndUpdatePointer

        public static final int writeSecurityBufferAndUpdatePointer​(ByteArrayOutputStream baos,
                                                                    short len,
                                                                    int pointer)
                                                             throws IOException
        Writes a security buffer and returns the pointer of the position where to write the next security buffer.
        Parameters:
        baos - the stream where the security buffer is written
        len - the length of the security buffer
        pointer - the position where the security buffer can be written
        Returns:
        the position where the next security buffer will be written
        Throws:
        IOException - if writing to the ByteArrayOutputStream fails
      • extractChallengeFromType2Message

        public static final byte[] extractChallengeFromType2Message​(byte[] msg)
        Extracts the NTLM challenge from the type 2 message as an 8 byte array.
        Parameters:
        msg - the type 2 message byte array
        Returns:
        the challenge
      • extractFlagsFromType2Message

        public static final int extractFlagsFromType2Message​(byte[] msg)
        Extracts the NTLM flags from the type 2 message.
        Parameters:
        msg - the type 2 message byte array
        Returns:
        the proxy flags as an int
      • readSecurityBufferTarget

        public static final byte[] readSecurityBufferTarget​(byte[] msg,
                                                            int securityBufferOffset)
        Reads the byte array described by the security buffer stored at the securityBufferOffset offset.
        Parameters:
        msg - the message where to read the security buffer and it's value
        securityBufferOffset - the offset at which to read the security buffer
        Returns:
        a new byte array holding the data pointed by the security buffer
      • extractTargetNameFromType2Message

        public static final String extractTargetNameFromType2Message​(byte[] msg,
                                                                     Integer msgFlags)
                                                              throws UnsupportedEncodingException
        Extracts the target name from the type 2 message.
        Parameters:
        msg - the type 2 message byte array
        msgFlags - the flags if null then flags are extracted from the type 2 message
        Returns:
        the target name
        Throws:
        UnsupportedEncodingException - if unable to use the needed UTF-16LE or ASCII charsets
      • extractTargetInfoFromType2Message

        public static final byte[] extractTargetInfoFromType2Message​(byte[] msg,
                                                                     Integer msgFlags)
        Extracts the target information block from the type 2 message.
        Parameters:
        msg - the type 2 message byte array
        msgFlags - the flags if null then flags are extracted from the type 2 message
        Returns:
        the target info
      • printTargetInformationBlockFromType2Message

        public static final void printTargetInformationBlockFromType2Message​(byte[] msg,
                                                                             Integer msgFlags,
                                                                             PrintWriter out)
                                                                      throws UnsupportedEncodingException
        Prints to the PrintWriter the target information block extracted from the type 2 message.
        Parameters:
        msg - the type 2 message
        msgFlags - the flags if null then flags are extracted from the type 2 message
        out - the output target for the information
        Throws:
        UnsupportedEncodingException - if unable to use the needed UTF-16LE or ASCII charsets
      • createType3Message

        public static final byte[] createType3Message​(String user,
                                                      String password,
                                                      byte[] challenge,
                                                      String target,
                                                      String workstation,
                                                      Integer serverFlags,
                                                      byte[] osVersion)
        Parameters:
        user - the user name
        password - the user password
        challenge - the challenge response
        target - the target name
        workstation - the client workstation's name
        serverFlags - the flags set by the client
        osVersion - the os version of the client
        Returns:
        the type 3 message
        See Also:
        NTLM message type