Exception in 'get_malicious_ldap_packet' when message_id greater than 255 #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This error can manifest in a few different ways. Sometimes the
b'\x02\x01'
string is found in the ldap message from the target, but in the wrong place. That will get you a traceback from "dcerpc" because the ldap message we send back lacks the required information to trigger the exploit (or more accurately is parsed wrong):And sometimes (though I can't figure out how to trigger this specifically)
b'\x02\x01'
is not found at all. Which looks similar to #1 and might actually be the same issue.get_malicious_ldap_packet was assuming a single byte message_id_field length when calculating 'lm_referral_length_index'; this is correct for message_ids below 256 (as in a freshly rebooted server). The 4th byte in the message (index 3) is the length of the message_id field, so that value added to the static start (index 4) gets us a consistent message_id_bytes value (slice [4: 4+length]). This effects the number of padding bytes needed, which also changes the calculation of the new message length.
I also moved the 'message_length' calculation closer to the start of the method for clairity.