Merge branch 'master' into cme_db_detailed

main
iLightThings 2022-09-23 12:02:40 -04:00 committed by GitHub
commit c005d844e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 9 deletions

4
cme/cmedb.py Executable file → Normal file
View File

@ -120,6 +120,7 @@ class DatabaseNavigator(cmd.Cmd):
filename = line[2] filename = line[2]
if line[1].lower() == 'simple': if line[1].lower() == 'simple':
self.write_csv(filename,csv_header,shares) self.write_csv(filename,csv_header,shares)
@ -155,9 +156,11 @@ class DatabaseNavigator(cmd.Cmd):
self.write_csv(filename,csv_header,formattedShares) self.write_csv(filename,csv_header,formattedShares)
#Format is domain\user #Format is domain\user
#prettyuser = f"{self.db.get_users(userid)[0][1]}\{self.db.get_users(userid)[0][2]}" #prettyuser = f"{self.db.get_users(userid)[0][1]}\{self.db.get_users(userid)[0][2]}"
#Format is hostname #Format is hostname
#prettyhost = f"{}" #prettyhost = f"{}"
@ -168,6 +171,7 @@ class DatabaseNavigator(cmd.Cmd):
elif line[0].lower() == 'local_admins': elif line[0].lower() == 'local_admins':
if len(line) < 3: if len(line) < 3:
print("[-] invalid arguments, export local_admins <simple|detailed> <filename>") print("[-] invalid arguments, export local_admins <simple|detailed> <filename>")
return return
# These Values don't change between simple and detailed # These Values don't change between simple and detailed

View File

@ -148,12 +148,15 @@ class CMEModule:
if RECORD_TYPE_MAPPING[dr['Type']] == "A": if RECORD_TYPE_MAPPING[dr['Type']] == "A":
if dr['Type'] == 1: if dr['Type'] == 1:
address = DNS_RPC_RECORD_A(dr['Data']) address = DNS_RPC_RECORD_A(dr['Data'])
if str(recordname) != 'DomainDnsZones' and str(recordname) != 'ForestDnsZones':
outdata.append({'name':recordname, 'type': RECORD_TYPE_MAPPING[dr['Type']], 'value': address.formatCanonical()}) outdata.append({'name':recordname, 'type': RECORD_TYPE_MAPPING[dr['Type']], 'value': address.formatCanonical()})
if dr['Type'] in [a for a in RECORD_TYPE_MAPPING if RECORD_TYPE_MAPPING[a] in ['CNAME', 'NS', 'PTR']]: if dr['Type'] in [a for a in RECORD_TYPE_MAPPING if RECORD_TYPE_MAPPING[a] in ['CNAME', 'NS', 'PTR']]:
address = DNS_RPC_RECORD_NODE_NAME(dr['Data']) address = DNS_RPC_RECORD_NODE_NAME(dr['Data'])
if str(recordname) != 'DomainDnsZones' and str(recordname) != 'ForestDnsZones':
outdata.append({'name':recordname, 'type':RECORD_TYPE_MAPPING[dr['Type']], 'value': address[list(address.fields)[0]].toFqdn()}) outdata.append({'name':recordname, 'type':RECORD_TYPE_MAPPING[dr['Type']], 'value': address[list(address.fields)[0]].toFqdn()})
elif dr['Type'] == 28: elif dr['Type'] == 28:
address = DNS_RPC_RECORD_AAAA(dr['Data']) address = DNS_RPC_RECORD_AAAA(dr['Data'])
if str(recordname) != 'DomainDnsZones' and str(recordname) != 'ForestDnsZones':
outdata.append({'name':recordname, 'type':RECORD_TYPE_MAPPING[dr['Type']], 'value': address.formatCanonical()}) outdata.append({'name':recordname, 'type':RECORD_TYPE_MAPPING[dr['Type']], 'value': address.formatCanonical()})
context.log.highlight('Found %d records' % len(outdata)) context.log.highlight('Found %d records' % len(outdata))

View File

@ -504,6 +504,8 @@ class smb(connection):
self.conn = SMBConnection(self.host, self.host, None, self.args.port, timeout=self.args.smb_timeout) self.conn = SMBConnection(self.host, self.host, None, self.args.port, timeout=self.args.smb_timeout)
self.smbv1 = False self.smbv1 = False
except socket.error: except socket.error:
if str(e).find('Too many open files') != -1:
self.logger.error('SMBv3 connection error on {}: {}'.format(self.host, e))
return False return False
except (Exception, NetBIOSTimeout) as e: except (Exception, NetBIOSTimeout) as e:
logging.debug('Error creating SMBv3 connection to {}: {}'.format(self.host, e)) logging.debug('Error creating SMBv3 connection to {}: {}'.format(self.host, e))
@ -628,7 +630,7 @@ class smb(connection):
def shares(self): def shares(self):
temp_dir = ntpath.normpath("\\" + gen_random_string()) temp_dir = ntpath.normpath("\\" + gen_random_string())
computer_id = self.db.get_computers(filterTerm=self.host)[0][0] #computer_id = self.db.get_computers(filterTerm=self.host)[0][0]
try: try:
user_id = self.db.get_user( user_id = self.db.get_user(
self.domain.split('.')[0].upper(), self.domain.split('.')[0].upper(),
@ -664,7 +666,7 @@ class smb(connection):
if share_name != "IPC$": if share_name != "IPC$":
try: try:
self.db.add_share(computer_id, user_id, share_name, share_remark, read, write) self.db.add_share(self.hostname, user_id, share_name, share_remark, read, write)
except: except:
pass pass

View File

@ -66,13 +66,12 @@ class database:
db_conn.execute('''CREATE TABLE "shares" ( db_conn.execute('''CREATE TABLE "shares" (
"id" integer PRIMARY KEY, "id" integer PRIMARY KEY,
"computerid" integer, "computerid" text,
"userid" integer, "userid" integer,
"name" text, "name" text,
"remark" text, "remark" text,
"read" boolean, "read" boolean,
"write" boolean, "write" boolean,
FOREIGN KEY(computerid) REFERENCES computers(id),
FOREIGN KEY(userid) REFERENCES users(id) FOREIGN KEY(userid) REFERENCES users(id)
UNIQUE(computerid, userid, name) UNIQUE(computerid, userid, name)
)''') )''')

View File

@ -67,7 +67,7 @@ class navigator(DatabaseNavigator):
def display_shares(self, shares): def display_shares(self, shares):
data = [["ShareID", "Name", "Remark", "Read Access", "Write Access"]] data = [["ShareID", "computer", "Name", "Remark", "Read Access", "Write Access"]]
for share in shares: for share in shares:
@ -88,7 +88,7 @@ class navigator(DatabaseNavigator):
permissions='w' permissions='w'
) )
data.append([shareID, name, remark, f"{len(users_r_access)} User(s)", f"{len(users_w_access)} Users"]) data.append([shareID, computerid, name, remark, f"{len(users_r_access)} User(s)", f"{len(users_w_access)} Users"])
self.print_table(data) self.print_table(data)