byt3bl33d3r / CrackMapExec

A swiss army knife for pentesting networks
BSD 2-Clause "Simplified" License
8.37k stars 1.64k forks source link

cmedb.py - export shares #604

Closed maaaaz closed 1 year ago

maaaaz commented 2 years ago

Hello there,

cmedb.py is currently missing a share export function, here's one I did, and to insert here https://github.com/Porchetta-Industries/CrackMapExec/blob/44ec821fff6516a43560290fb4256d2d91b7da84/cme/cmedb.py#L84

          import csv
          elif line[0].lower() == 'shares':
            if len(line) < 2:
                print("[-] invalid arguments, export shares <filename>")
                return

            shares = self.db.get_shares()

            with open(os.path.expanduser(line[1]), 'w') as export_file:
                spamwriter = csv.writer(export_file, delimiter=";", quoting=csv.QUOTE_ALL, lineterminator='\n')
                csv_header = ["host_ipaddress", "host_domain", "host_hostname", "share_name", "share_remark", "domain_username", "share_readaccess", "share_writeaccess"]
                spamwriter.writerow(csv_header)

                for share in shares:
                    share_id, share_hostid, share_userid, share_name, share_remark, share_readaccess, share_writeaccess = share

                    share_writeaccess = "True" if share_writeaccess == 1 else "False"
                    share_readaccess = "True" if share_readaccess == 1 else "False"

                    user_id, user_domain, user_username, user_password, user_credtype, user_pillaged = self.db.get_users(share_userid)[0]
                    user_domain_username = '%s\%s' % (user_domain, user_username)

                    hostid,host_ipaddress,host_hostname,host_domain,host_opsys,host_dc = self.db.get_computers(share_hostid)[0]

                    csv_row = [host_ipaddress, host_domain, host_hostname, share_name, share_remark, user_domain_username, share_readaccess, share_writeaccess]
                    spamwriter.writerow(csv_row)

So you can now do export shares <filename>

Cheers !

mpgn commented 2 years ago

Hello, can you make a PR ?

mpgn commented 2 years ago

638