Beispiel #1
0
    def import_ous(self):
        print('Importing ous!')
        for ou in self.get_file('ous')['ous']:
            #pprint.pprint(groups)
            #input()
            try:
                ad_name = ou['Name'].rsplit('@', 1)[1]
                m = ADOU()
                m.ad_id = self.adn[ad_name]
                m.name = ou['Name'].split('@', 1)[0]
                m.objectSid = ou['Properties']['objectsid']
                m.description = ou['Properties'].get('description', None)

                self.db_session.add(m)
            except Exception as e:
                print(e)
                pprint.pprint(ou)
                input()
                continue
        self.db_session.commit()
Beispiel #2
0
    def import_ous(self):
        logger.debug('[BHIMPORT] Importing OUs')

        meta = self.get_file('ous')['meta']
        total = meta['count']
        for ou in tqdm(self.get_file('ous')['ous'],
                       desc='OUs     ',
                       total=total,
                       disable=self.disable_print_progress):
            if self.debug is True:
                pprint.pprint(ou)
                input()
            try:
                if self.bloodhound_version == '2':
                    ad_name = ou['Properties']['name'].rsplit('@', 1)[1]
                    m = ADOU()
                    m.ad_id = self.adn[ad_name]
                    m.name = ou['Properties']['name'].split('@', 1)[0]
                    m.objectGUID = ou['Guid']
                    m.description = ou['Properties'].get('description', None)

                    if ou['Properties'].get('highvalue') is True:
                        hvt = ADObjProps(self.graphid, m.objectGUID, 'HVT')
                        self.db_session.add(hvt)

                    #not importing [ChildOus] [Properties][blocksinheritance][Computers]

                else:
                    ad_name = ou['Properties']['name'].rsplit('@', 1)[1]
                    m = ADOU()
                    m.ad_id = self.adn[ad_name]
                    m.name = ou['Properties']['name'].split('@', 1)[0]
                    m.objectGUID = ou['ObjectIdentifier']
                    m.description = ou['Properties'].get('description', None)
                    m.dn = ou['Properties'].get('distinguishedname', None)

                    if ou['Properties'].get('highvalue') is True:
                        hvt = ADObjProps(self.graphid, m.objectGUID, 'HVT')
                        self.db_session.add(hvt)

                    #not importing [ChildOus] [Properties][blocksinheritance] [Users] [RemoteDesktopUsers] [PSRemoteUsers] [LocalAdmins] [Computers] [DcomUsers] [ACLProtected]

                if 'Links' in ou and ou['Links'] is not None:
                    for link in ou['Links']:
                        #input(link)
                        l = Gplink()
                        l.ad_id = m.ad_id
                        l.ou_guid = m.objectGUID
                        if self.bloodhound_version == '2':
                            gponame = link['Name'].split('@', 1)[0]
                            res = self.db_session.query(GPO).filter_by(
                                name=gponame).filter(
                                    GPO.ad_id == m.ad_id).first()
                            if res is None:
                                logger.debug(
                                    'Could not insert OU link %s. Reason: could not find GPO %s'
                                    % (link, link['Name']))
                                continue
                            l.gpo_dn = res.objectGUID
                        else:
                            l.gpo_dn = '{%s}' % link['Guid']
                        self.db_session.add(l)

                    #not importing [IsEnforced]

                self.db_session.add(m)
                edgeinfo = EdgeLookup(m.ad_id, m.objectGUID, 'ou')
                self.db_session.add(edgeinfo)
                self.db_session.commit()

                if ou['Aces'] is not None:
                    self.insert_acl(m.objectGUID, 'ou', ou['Aces'], m.ad_id)

            except Exception as e:
                logger.debug(
                    '[BHIMPORT] Error while processing OU %s Reason: %s' %
                    (ou, e))
                continue
        self.db_session.commit()