| 783 | |
| 784 | |
| 785 | class WINNT_SID(Packet): |
| 786 | fields_desc = [ |
| 787 | ByteField("Revision", 1), |
| 788 | FieldLenField("SubAuthorityCount", None, count_of="SubAuthority", fmt="B"), |
| 789 | PacketField( |
| 790 | "IdentifierAuthority", |
| 791 | WINNT_SID_IDENTIFIER_AUTHORITY(), |
| 792 | WINNT_SID_IDENTIFIER_AUTHORITY, |
| 793 | ), |
| 794 | FieldListField( |
| 795 | "SubAuthority", |
| 796 | [0], |
| 797 | LEIntField("", 0), |
| 798 | count_from=lambda pkt: pkt.SubAuthorityCount, |
| 799 | ), |
| 800 | ] |
| 801 | |
| 802 | def default_payload_class(self, payload): |
| 803 | return conf.padding_layer |
| 804 | |
| 805 | _SID_REG = re.compile(r"^S-(\d)-(\d+)((?:-\d+)*)$") |
| 806 | |
| 807 | @staticmethod |
| 808 | def fromstr(x): |
| 809 | m = WINNT_SID._SID_REG.match(x) |
| 810 | if not m: |
| 811 | raise ValueError("Invalid SID format !") |
| 812 | rev, authority, subauthority = m.groups() |
| 813 | return WINNT_SID( |
| 814 | Revision=int(rev), |
| 815 | IdentifierAuthority=WINNT_SID_IDENTIFIER_AUTHORITY( |
| 816 | Value=struct.pack(">Q", int(authority))[2:] |
| 817 | ), |
| 818 | SubAuthority=[int(x) for x in subauthority[1:].split("-")], |
| 819 | ) |
| 820 | |
| 821 | def summary(self): |
| 822 | return "S-%s-%s%s" % ( |
| 823 | self.Revision, |
| 824 | struct.unpack(">Q", b"\x00\x00" + self.IdentifierAuthority.Value)[0], |
| 825 | ( |
| 826 | ("-%s" % "-".join(str(x) for x in self.SubAuthority)) |
| 827 | if self.SubAuthority |
| 828 | else "" |
| 829 | ), |
| 830 | ) |
| 831 | |
| 832 | |
| 833 | # https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/manage/understand-security-identifiers |
no test coverage detected
searching dependent graphs…