Skip to content

Commit

Permalink
Update to msldap 0.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
CravateRouge committed Sep 24, 2024
1 parent 8638d5d commit 1913e10
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 154 deletions.
152 changes: 0 additions & 152 deletions bloodyAD/msldap_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,155 +717,3 @@ def from_url(connection_url):


UniCredential.from_url = from_url

# MODIFICATIONS:
### ldap search encoding ###
from msldap.protocol import query
from msldap.protocol.messages import (
Filter,
Filters,
AttributeDescription,
SubstringFilter,
MatchingRuleAssertion,
Substrings,
Substring,
)


def equality(attr, value):
if attr[-1] == ":":
name, oid_raw = attr[:-1].split(":")
return Filter(
{
"extensibleMatch": MatchingRuleAssertion(
{
"matchingRule": oid_raw.encode(),
"type": name.encode(),
"matchValue": rfc4515_encode(value),
"dnAttributes": False,
}
)
}
)

elif value == "*":
return Filter({"present": AttributeDescription(attr.encode())})

elif value.startswith("*") and value.endswith("*"):
return Filter(
{
"substrings": SubstringFilter(
{
"type": attr.encode(),
"substrings": Substrings(
[Substring({"any": rfc4515_encode(value[1:-1])})]
),
}
)
}
)

elif value.startswith("*") is True:
return Filter(
{
"substrings": SubstringFilter(
{
"type": attr.encode(),
"substrings": Substrings(
[Substring({"final": rfc4515_encode(value[1:])})]
),
}
)
}
)

elif value.endswith("*") is True:
return Filter(
{
"substrings": SubstringFilter(
{
"type": attr.encode(),
"substrings": Substrings(
[Substring({"initial": rfc4515_encode(value[:-1])})]
),
}
)
}
)

else:
return Filter(
{
"equalityMatch": {
"attributeDesc": attr.encode(),
"assertionValue": rfc4515_encode(value),
}
}
)


query.equality = equality


def rfc4515_encode(value):
i = 0
byte_str = b""
while i < len(value):
if (value[i] == "\\") and i < len(value) - 2:
try:
byte_str += int(value[i + 1 : i + 3], 16).to_bytes()
i += 2
except ValueError: # not an ldap escaped value, sends as is
byte_str += b"\\"
else:
byte_str += value[i].encode()
i += 1
return byte_str


from msldap.protocol.ldap_filter import parser


def _read_EscapedCharacter(self):
address0, index0 = FAILURE, self._offset
cached = self._cache["EscapedCharacter"].get(index0)
if cached:
self._offset = cached[1]
return cached[0]
index1, elements0 = self._offset, []
chunk0 = None
if self._offset < self._input_size:
chunk0 = self._input[self._offset : self._offset + 1]
# if chunk0 == '\\':
# address1 = TreeNode(self._input[self._offset:self._offset + 1], self._offset)
# self._offset = self._offset + 1
# else:
address1 = FAILURE
if self._offset > self._failure:
self._failure = self._offset
self._expected = []
if self._offset == self._failure:
self._expected.append("'\\\\'")
if address1 is not FAILURE:
elements0.append(address1)
address2 = self._read_ASCII_VALUE()
if address2 is not FAILURE:
elements0.append(address2)
else:
elements0 = None
self._offset = index1
else:
elements0 = None
self._offset = index1
if elements0 is None:
address0 = FAILURE
else:
address0 = self._actions.return_escaped_char(
self._input, index1, self._offset, elements0
)
self._offset = self._offset
self._cache["EscapedCharacter"][index0] = (address0, self._offset)
return address0


parser._read_EscapeCharacter = _read_EscapedCharacter
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "bloodyAD"
authors = [
{ name="CravateRouge", email="[email protected]" },
]
version = "2.0.6"
version = "2.0.7"
description = "AD Privesc Swiss Army Knife"
readme = "README.md"
requires-python = ">=3.8"
Expand All @@ -18,7 +18,7 @@ classifiers = [
]
dependencies = [
"cryptography>=37.0.2",
"msldap>=0.5.9",
"msldap>=0.5.12",
"winacl>=0.1.7",
"asn1crypto>=1.3.0",
"dnspython>=2.3.0"
Expand Down

0 comments on commit 1913e10

Please sign in to comment.