Merge pull request #638 from ILightThings/cmedb_export_shares

Cmedb export shares
main
mpgn 2022-09-22 12:25:21 +02:00 committed by GitHub
commit 2cf755d215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 2 deletions

View File

@ -11,6 +11,7 @@ from terminaltables import AsciiTable
import configparser import configparser
from cme.loaders.protocol_loader import protocol_loader from cme.loaders.protocol_loader import protocol_loader
from requests import ConnectionError from requests import ConnectionError
import csv
# The following disables the InsecureRequests warning and the 'Starting new HTTPS connection' log message # The following disables the InsecureRequests warning and the 'Starting new HTTPS connection' log message
from requests.packages.urllib3.exceptions import InsecureRequestWarning from requests.packages.urllib3.exceptions import InsecureRequestWarning
@ -84,9 +85,49 @@ class DatabaseNavigator(cmd.Cmd):
export_file.write('{},{},{},{},{},{}\n'.format(hostid,ipaddress,hostname,domain,opsys,dc)) export_file.write('{},{},{},{},{},{}\n'.format(hostid,ipaddress,hostname,domain,opsys,dc))
print('[+] hosts exported') print('[+] hosts exported')
else: elif line[0].lower() == 'shares':
print('[-] invalid argument, specify creds or hosts') if len(line) < 3:
print("[-] invalid arguments, export shares <simple|detailed> <filename>")
return
if line[1].lower() == 'simple':
shares = self.db.get_shares()
with open(os.path.expanduser(line[2]), 'w') as export_file:
shareCSV = csv.writer(export_file, delimiter=";", quoting=csv.QUOTE_ALL, lineterminator='\n')
csv_header = ["id","computerid","userid","name","remark","read","write"]
shareCSV.writerow(csv_header)
#id|computerid|userid|name|remark|read|write
for share in shares:
shareid,hostid,userid,sharename,shareremark,read,write = share
shareCSV.writerow([shareid,hostid,userid,sharename,shareremark,read,write])
print('[+] shares exported')
elif line[1].lower() == 'detailed': #Detailed view gets hostsname, and usernames, and true false statement
shares = self.db.get_shares()
#id|computerid|userid|name|remark|read|write
with open(os.path.expanduser(line[2]), 'w') as export_file:
shareCSV = csv.writer(export_file, delimiter=";", quoting=csv.QUOTE_ALL, lineterminator='\n')
csv_header = ["id","computerid","userid","name","remark","read","write"]
shareCSV.writerow(csv_header)
for share in shares:
shareid,hostid,userid,sharename,shareremark,read,write = share
#Format is domain\user
prettyuser = f"{self.db.get_users(userid)[0][1]}\{self.db.get_users(userid)[0][2]}"
#Format is hostname
prettyhost = f"{self.db.get_computers(hostid)[0][2]}"
shareCSV.writerow([shareid,prettyhost,prettyuser,sharename,shareremark,bool(read),bool(write)])
print('[+] shares exported')
else:
print("[-] invalid arguments, export shares <simple|detailed> <filename>")
return
else:
print('[-] invalid argument, specify creds, hosts or shares')
def do_import(self, line): def do_import(self, line):
if not line: if not line: