public class NTLMUtilities extends java.lang.Object implements NTLMConstants
DEFAULT_FLAGS, DEFAULT_OS_VERSION, FLAG_NEGOTIATE_128_BIT_ENCRYPTION, FLAG_NEGOTIATE_56_BIT_ENCRYPTION, FLAG_NEGOTIATE_ALWAYS_SIGN, FLAG_NEGOTIATE_ANONYMOUS, FLAG_NEGOTIATE_DATAGRAM_STYLE, FLAG_NEGOTIATE_DOMAIN_SUPPLIED, FLAG_NEGOTIATE_KEY_EXCHANGE, FLAG_NEGOTIATE_LAN_MANAGER_KEY, FLAG_NEGOTIATE_LOCAL_CALL, FLAG_NEGOTIATE_NTLM, FLAG_NEGOTIATE_NTLM2, FLAG_NEGOTIATE_OEM, FLAG_NEGOTIATE_SEAL, FLAG_NEGOTIATE_SIGN, FLAG_NEGOTIATE_TARGET_INFO, FLAG_NEGOTIATE_UNICODE, FLAG_NEGOTIATE_WORKSTATION_SUPPLIED, FLAG_REQUEST_SERVER_AUTH_REALM, FLAG_TARGET_TYPE_DOMAIN, FLAG_TARGET_TYPE_SERVER, FLAG_TARGET_TYPE_SHARE, FLAG_UNIDENTIFIED_1, FLAG_UNIDENTIFIED_10, FLAG_UNIDENTIFIED_11, FLAG_UNIDENTIFIED_2, FLAG_UNIDENTIFIED_3, FLAG_UNIDENTIFIED_4, FLAG_UNIDENTIFIED_5, FLAG_UNIDENTIFIED_6, FLAG_UNIDENTIFIED_7, FLAG_UNIDENTIFIED_8, FLAG_UNIDENTIFIED_9, MESSAGE_TYPE_1, MESSAGE_TYPE_2, MESSAGE_TYPE_3, NTLM_SIGNATURE, TARGET_INFORMATION_SUBBLOCK_DNS_DOMAIN_NAME_TYPE, TARGET_INFORMATION_SUBBLOCK_DOMAIN_TYPE, TARGET_INFORMATION_SUBBLOCK_FQDNS_HOSTNAME_TYPE, TARGET_INFORMATION_SUBBLOCK_PARENT_DNS_DOMAIN_NAME_TYPE, TARGET_INFORMATION_SUBBLOCK_SERVER_TYPE, TARGET_INFORMATION_SUBBLOCK_TERMINATOR_TYPE
构造器和说明 |
---|
NTLMUtilities() |
限定符和类型 | 方法和说明 |
---|---|
static byte[] |
createType1Message(java.lang.String workStation,
java.lang.String domain,
java.lang.Integer customFlags,
byte[] osVersion)
see http://davenport.sourceforge.net/ntlm.html#theType1Message
|
static byte[] |
createType3Message(java.lang.String user,
java.lang.String password,
byte[] challenge,
java.lang.String target,
java.lang.String workstation,
java.lang.Integer serverFlags,
byte[] osVersion) |
static byte[] |
extractChallengeFromType2Message(byte[] msg)
Extracts the NTLM challenge from the type 2 message as an 8 byte array.
|
static int |
extractFlagsFromType2Message(byte[] msg)
Extracts the NTLM flags from the type 2 message.
|
static byte[] |
extractTargetInfoFromType2Message(byte[] msg,
java.lang.Integer msgFlags)
Extracts the target information block from the type 2 message.
|
static java.lang.String |
extractTargetNameFromType2Message(byte[] msg,
java.lang.Integer msgFlags)
Extracts the target name from the type 2 message.
|
static byte[] |
getOsVersion()
Tries to return a valid OS version on Windows systems.
|
static void |
printTargetInformationBlockFromType2Message(byte[] msg,
java.lang.Integer msgFlags,
java.io.PrintWriter out)
Prints to the
PrintWriter the target information block extracted
from the type 2 message. |
static byte[] |
readSecurityBufferTarget(byte[] msg,
int securityBufferOffset)
Reads the byte array described by the security buffer stored at the
securityBufferOffset offset. |
static 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 . |
static byte[] |
writeSecurityBuffer(short length,
int bufferOffset) |
static void |
writeSecurityBuffer(short length,
short allocated,
int bufferOffset,
byte[] b,
int offset)
Writes a security buffer to the given array
b at offset
offset . |
static int |
writeSecurityBufferAndUpdatePointer(java.io.ByteArrayOutputStream baos,
short len,
int pointer)
Writes a security buffer and returns the pointer of the position
where to write the next security buffer.
|
public static final byte[] writeSecurityBuffer(short length, int bufferOffset)
length
- The length of the security bufferbufferOffset
- The offset in the security bufferwriteSecurityBuffer(short, short, int, byte[], int)
public static final void writeSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset)
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.length
- the length of the security bufferallocated
- 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 writtenb
- the buffer in which we write the security bufferoffset
- the offset at which to write to the b bufferpublic static final void writeOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, int offset)
offset
.majorVersion
- the major version numberminorVersion
- the minor version numberbuildNumber
- the build numberb
- the target byte arrayoffset
- the offset at which to write in the arraypublic static final byte[] getOsVersion()
public static final byte[] createType1Message(java.lang.String workStation, java.lang.String domain, java.lang.Integer customFlags, byte[] osVersion)
workStation
- the workstation namedomain
- the domain namecustomFlags
- custom flags, if null then
NTLMConstants.DEFAULT_CONSTANTS
is usedosVersion
- the os version of the client, if null then
NTLMConstants.DEFAULT_OS_VERSION
is usedpublic static final int writeSecurityBufferAndUpdatePointer(java.io.ByteArrayOutputStream baos, short len, int pointer) throws java.io.IOException
baos
- the stream where the security buffer is writtenlen
- the length of the security bufferpointer
- the position where the security buffer can be writtenjava.io.IOException
- if writing to the ByteArrayOutputStream failspublic static final byte[] extractChallengeFromType2Message(byte[] msg)
msg
- the type 2 message byte arraypublic static final int extractFlagsFromType2Message(byte[] msg)
msg
- the type 2 message byte arraypublic static final byte[] readSecurityBufferTarget(byte[] msg, int securityBufferOffset)
securityBufferOffset
offset.msg
- the message where to read the security buffer and it's valuesecurityBufferOffset
- the offset at which to read the security bufferpublic static final java.lang.String extractTargetNameFromType2Message(byte[] msg, java.lang.Integer msgFlags) throws java.io.UnsupportedEncodingException
msg
- the type 2 message byte arraymsgFlags
- the flags if null then flags are extracted from the
type 2 messagejava.io.UnsupportedEncodingException
- if unable to use the
needed UTF-16LE or ASCII charsetspublic static final byte[] extractTargetInfoFromType2Message(byte[] msg, java.lang.Integer msgFlags)
msg
- the type 2 message byte arraymsgFlags
- the flags if null then flags are extracted from the
type 2 messagepublic static final void printTargetInformationBlockFromType2Message(byte[] msg, java.lang.Integer msgFlags, java.io.PrintWriter out) throws java.io.UnsupportedEncodingException
PrintWriter
the target information block extracted
from the type 2 message.msg
- the type 2 messagemsgFlags
- the flags if null then flags are extracted from the
type 2 messageout
- the output target for the informationjava.io.UnsupportedEncodingException
- if unable to use the
needed UTF-16LE or ASCII charsetspublic static final byte[] createType3Message(java.lang.String user, java.lang.String password, byte[] challenge, java.lang.String target, java.lang.String workstation, java.lang.Integer serverFlags, byte[] osVersion)
user
- the user namepassword
- the user passwordchallenge
- the challenge responsetarget
- the target nameworkstation
- the client workstation's nameserverFlags
- the flags set by the clientosVersion
- the os version of the client