Codebase list poshc2 / bfc583e0-9aeb-4db4-9079-d10f7ad22fdd/main poshc2 / client / reporting / CSV.py
bfc583e0-9aeb-4db4-9079-d10f7ad22fdd/main

Tree @bfc583e0-9aeb-4db4-9079-d10f7ad22fdd/main (Download .tar.gz)

CSV.py @bfc583e0-9aeb-4db4-9079-d10f7ad22fdd/mainraw · history · blame

#!/usr/bin/env python3
from poshc2.server.Config import ReportsDirectory
from poshc2.server.database.DB import get_implantbyrandomuri, get_alldata

def generate_csv(table):
    frame = get_alldata(table)

    # convert the randomuri to Domain\User @ Hostname
    if table.lower() == "tasks":
        for index, row in frame.iterrows():
            implant = get_implantbyrandomuri(row[1])
            try:
                if frame.loc[index, "randomuri"]:
                    frame.loc[index, "randomuri"] = implant.Domain + "\\" + implant.User + " @ " + implant.Hostname
            except:
                try:
                    if frame.loc[index, "RandomURI"]:
                        frame.loc[index, "RandomURI"] = implant.Domain + "\\" + implant.User + " @ " + implant.Hostname 
                except:
                    print("Cannot translate RandomURI")

    csvreportname = "%s%s.csv" % (ReportsDirectory, table)
    output_csv = open(csvreportname, 'w')
    CSV = (frame.to_csv(index=False, encoding='utf-8'))
    output_csv.write(CSV)
    output_csv.close()
    print(csvreportname)