Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Cmedb export shares #638

Merged
merged 5 commits into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions cme/cmedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import configparser
from cme.loaders.protocol_loader import protocol_loader
from requests import ConnectionError
import csv

# The following disables the InsecureRequests warning and the 'Starting new HTTPS connection' log message
from requests.packages.urllib3.exceptions import InsecureRequestWarning
Expand Down Expand Up @@ -84,9 +85,49 @@ def do_export(self, line):
export_file.write('{},{},{},{},{},{}\n'.format(hostid,ipaddress,hostname,domain,opsys,dc))
print('[+] hosts exported')

else:
print('[-] invalid argument, specify creds or hosts')
elif line[0].lower() == 'shares':
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):
if not line:
Expand Down