async def store_domain(self, info): info.ldap_enumeration_state = 'STARTED' self.domain_name = str(info.distinguishedName).replace(',', '.').replace( 'DC=', '') self.session.add(info) self.session.commit() self.session.refresh(info) self.ad_id = info.id graph = GraphInfo() graph.ad_id = self.ad_id self.session.add(graph) self.session.commit() self.session.refresh(graph) self.graph_id = graph.id t = EdgeLookup(self.ad_id, info.objectSid, 'domain') self.session.add(t) data = { 'dn': info.distinguishedName, 'sid': info.objectSid, 'guid': info.objectGUID, 'object_type': 'domain' } if self.sd_file_handle is not None: self.sd_file_handle.write(json.dumps(data).encode() + b'\r\n')
def main(): import argparse import os parser = argparse.ArgumentParser(description='Calculate edges and flattem them in a file') parser.add_argument('-v', '--verbose', action='count', default=0, help='Increase verbosity, can be stacked') subparsers = parser.add_subparsers(help = 'dunno') subparsers.required = True subparsers.dest = 'command' full_group = subparsers.add_parser('run', help='Full migration') full_group.add_argument('sql', help='SQL connection string.') full_group.add_argument('ad', type=int, help='AD id to calc the edges on') full_group.add_argument('-g','--graph-id', type=int, default = -1, help='AD id to calc the edges on') full_group.add_argument('-w', '--worker-count', type=int, default = 4, help='output file path') args = parser.parse_args() if args.verbose == 0: logging.basicConfig(level=logging.INFO) logger.setLevel(logging.INFO) elif args.verbose == 1: logging.basicConfig(level=logging.DEBUG) logger.setLevel(logging.DEBUG) elif args.verbose > 1: logging.basicConfig(level=1) logger.setLevel(1) os.environ['JACKDAW_SQLITE'] = '0' if args.sql.lower().startswith('sqlite'): os.environ['JACKDAW_SQLITE'] = '1' session = get_session(args.sql) graph_id = args.graph_id if graph_id == -1: gi = GraphInfo() session.add(gi) session.commit() session.refresh(gi) graph_id = gi.id if args.command == 'run': calc = EdgeCalc(session, args.ad, graph_id, buffer_size = 100, worker_count = args.worker_count) calc.run() else: print('?????')