50 const std::string &phase_2_response,
51 const std::string &dom_username,
52 const std::string &password,
56 if (dom_username.empty())
61 if (phase_2_response.size() < 32)
62 throw Exception(
"phase2 base64 response from server too short (" + std::to_string(phase_2_response.size()) +
")");
72 md4_ctx->
update(password_u->c_data(), password_u->size());
73 unsigned char md4_hash[21];
74 md4_ctx->
final(md4_hash);
75 std::memset(md4_hash + 16, 0, 5);
81 if (response.
size() < 32)
82 throw Exception(
"phase2 decoded response from server too short (" + std::to_string(response.
size()) +
")");
85 unsigned char challenge[8];
86 for (
size_t i = 0; i < 8; ++i)
87 challenge[i] = response[i + 24];
95 hmac_ctx1->update(ud_u->c_data(), ud_u->size());
96 unsigned char ntlmv2_hash[16];
97 hmac_ctx1->final(ntlmv2_hash);
100 unsigned char ntlmv2_response[144];
101 unsigned char *ntlmv2_blob = ntlmv2_response + 16;
102 memset(ntlmv2_blob, 0, 128);
103 ntlmv2_blob[0x00] = 1;
104 ntlmv2_blob[0x01] = 1;
105 ntlmv2_blob[0x04] = 0;
108 ntlmv2_blob[0x18] = 0;
112 if (response[0x16] & 0x80u)
114 tib_len = response[0x28];
117 const size_t tib_offset = response[0x2c];
118 if (tib_offset + tib_len < response.
size())
120 const unsigned char *tib_ptr = response.
c_data() + tib_offset;
121 std::memcpy(&ntlmv2_blob[0x1c], tib_ptr, tib_len);
126 ntlmv2_blob[0x1c + tib_len] = 0;
129 const size_t ntlmv2_blob_size = 0x20 + tib_len;
132 std::memcpy(&ntlmv2_response[8], challenge, 8);
136 hmac_ctx2->update(&ntlmv2_response[8], ntlmv2_blob_size + 8);
137 unsigned char ntlmv2_hmacmd5[16];
138 hmac_ctx2->final(ntlmv2_hmacmd5);
142 std::memcpy(ntlmv2_response, ntlmv2_hmacmd5, 16);
146 std::strcpy((
char *)phase3.
data(),
"NTLMSSP");
150 add_security_buffer(0x14, ntlmv2_response, numeric_cast<unsigned char>(ntlmv2_blob_size + 16), phase3);
153 add_security_buffer(0x24, username.c_str(), numeric_cast<unsigned char>(username.length()), phase3);
156 add_security_buffer(0x1c, domain.c_str(), numeric_cast<unsigned char>(domain.size()), phase3);
159 const unsigned char phase3_size =
static_cast<unsigned char>(phase3.
size());
160 phase3[0x10] = phase3_size;
161 phase3[0x30] = phase3_size;
162 phase3[0x38] = phase3_size;
201 typedef std::vector<std::string> StringList;
204 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, combined,
'\\', 1);
210 else if (sl.size() == 2)
216 throw Exception(
"split_domain_username failed");