| 10 | ) |
| 11 | |
| 12 | func GetSecurityDescriptor(input string, baseDN string, conn *ldap.Conn) (queryResult string) { |
| 13 | query := fmt.Sprintf("(samaccountname=%s)", input) |
| 14 | searchReq := Globals.LdapSearchSD(baseDN, query) |
| 15 | result, err := conn.Search(searchReq) |
| 16 | if err != nil { |
| 17 | fmt.Printf("Query error, %s", err) |
| 18 | |
| 19 | } |
| 20 | |
| 21 | // if LdapSearch returns information |
| 22 | if len(result.Entries) > 0 { |
| 23 | sd := result.Entries[0].GetRawAttributeValue("nTSecurityDescriptor") |
| 24 | hexSD := hex.EncodeToString(sd) |
| 25 | |
| 26 | abusableAces := SD.ParseSD(hexSD, baseDN, conn) |
| 27 | |
| 28 | queryResult += "\nGENERIC_ALL:\n" |
| 29 | for _, entry := range abusableAces { |
| 30 | if entry.GENERIC_ALL { |
| 31 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | queryResult += "\nGENERIC_WRITE:\n" |
| 36 | for _, entry := range abusableAces { |
| 37 | if entry.GENERIC_WRITE { |
| 38 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | queryResult += "\nWRITE_OWNER:\n" |
| 43 | for _, entry := range abusableAces { |
| 44 | if entry.WRITE_OWNER { |
| 45 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | queryResult += "\nWRITE_DACL:\n" |
| 50 | for _, entry := range abusableAces { |
| 51 | if entry.WRITE_DACL { |
| 52 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | queryResult += "\nFORCE_CHANGE_PASSWORD:\n" |
| 57 | for _, entry := range abusableAces { |
| 58 | if entry.FORCE_CHANGE_PASSWORD { |
| 59 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | queryResult += "\nADD_MEMBER:\n" |
| 64 | for _, entry := range abusableAces { |
| 65 | if entry.ADD_MEMBER { |
| 66 | queryResult += fmt.Sprintf("\t%s\n", entry.SamAccountName) |
| 67 | } |
| 68 | } |
| 69 | } else { |