def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) with open('/tmp/plugin-dump.csv', 'wb') as csvfile: writer = csv.writer(csvfile, dialect='excel') writer.writerow(['id','name','description','family','type','version','riskFactor', \ 'solution','synopsis','checkType','exploitAvailable','baseScore', \ 'temporalSCore','stigSeverity','pluginPubDate','pluginModDate', \ 'vulnPubDate','modifiedTime']) for p in conn.list_plugins(): # default 90 days pp.pprint(p) try: writer.writerow([str(p.id),p.name,p.type,p.version,p.riskFactor, \ p.solution,p.synopsis,p.checkType,p.exploitAvailable,str(p.baseScore), \ str(p.temporalScore),p.stigSeverity, \ str(time.strftime("%x %X", time.localtime(p.pluginPubDate))), \ str(time.strftime("%x %X", time.localtime(p.pluginModDate))), \ str(time.strftime("%x %X", time.localtime(p.vulnPubDate))), \ str(time.strftime("%x %X", time.localtime(p.modifiedTime)))]) except: cprint("There was an error", "red")
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'admin_cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) sys = conn.getSystem() #pp.pprint(sys) print(""" Version: %s Build ID: %s Banner: %s Release ID: %s UUID: %s Logo: %s ServerAuth: %s ServerClassification: %s SessionTimeout: %s LicenseStatus: %s Mode: %s ACAS: %s FreshInstall: %s HeaderText: %s PasswordComplexity: %s TimeZone Count: %s ReportTypes: %s """ % (sys.version, sys.buildID, sys.banner, sys.releaseID, \ sys.uuid, sys.logo, sys.serverAuth, sys.serverClassification, \ sys.sessionTimeout, sys.licenseStatus, sys.mode, sys.ACAS, \ sys.freshInstall, sys.headerText, sys.PasswordComplexity, \ len(sys.timezones), sys.reportTypes)) pp.pprint(sys.diagnostics)
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for repo in conn.list_repositories(): #pp.pprint(repo) print """ id: %s name: %s description: %s type: %s dataFormat: %s vulnCount: %s remoteID: %s remoteIP: %s running: %s downloadFormat: %s lastSyncTime: %s lastVulnUpdate: %s createdTime: %s modifiedTime: %s typeFields: %s""" % (repo.id, repo.name, repo.description, \ repo.type, repo.dataFormat, repo.vulnCount, \ repo.remoteID, repo.remoteIP, repo.running, \ repo.downloadFormat, repo.lastSyncTime, \ repo.lastVulnUpdate, repo.createdTime, \ repo.modifiedTime, repo.typeFields)
def main(): pp = pprint.PrettyPrinter(indent=4) cark = '../cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], \ cark_conf['username'], passwd) pname_by_date = {} pobj_by_date = {} for plg in conn.get_plugins_since(2592000): pname_by_date[plg.pluginPubDate] = plg.name pobj_by_date[plg.pluginPubDate] = plg #print("{0} {1}".format(time.strftime("%x %X", \ # time.localtime(float(plg.pluginPubDate))), plg.name)) with open('/tmp/plugin-timeline.csv', 'wb') as csvfile: writer = csv.writer(csvfile, dialect='excel') # header writer.writerow(['vulnPubDate', 'pluginPubDate', \ 'pluginModDate', 'pluginName']) for p in sorted(pname_by_date): print("{0} {1} {2} {3}".format(time.strftime("%x %X", \ time.localtime(float(pobj_by_date[p].vulnPubDate))),\ time.strftime("%x %X", time.localtime(float(p))), \ time.strftime("%x %X", \ time.localtime(float(pobj_by_date[p].pluginModDate))), \ pname_by_date[p])) writer.writerow([time.strftime("%x %X", \ time.localtime(float(pobj_by_date[p].vulnPubDate))), \ time.strftime("%x %X", time.localtime(float(p))), \ time.strftime("%x %X", \ time.localtime(float(pobj_by_date[p].pluginModDate))), \ pname_by_date[p]])
def main(): pp = pprint.PrettyPrinter(indent=4) cark = '../cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], \ cark_conf['username'], passwd) for p in conn.plugins(): #pp.pprint(p) print """ id: %s name: %s description: %s family: %s type: %s copyright: %s version: %s sourceFile: %s source: %s dependencies: %s requiredPorts: %s requiredUDPPorts: %s cpe: %s srcPort: %s dstPort: %s protocol: %s riskFactor: %s solution: %s seeAlso: %s synopsis: %s checkType: %s exploitEase: %s exploitAvailable: %s cvssVector: %s cvssVectorBF: %s baseScore: %s temporalScore: %s stgSeverity: %s pluginPubDate: %s pluginModDate: %s patchPubDate: %s patchModDate: %s vulnPubDate: %s modifiedTime: %s md5: %s xrefs: %s """ % (p.id, p.name, p.description, p.family.to_string(), \ p.type, p.copyright, p.version, p.sourceFile, \ p.source, p.dependencies, p.requiredPorts, \ p.requiredUDPPorts, p.cpe, p.srcPort, p.dstPort, \ p.protocol, p.riskFactor, p.solution, p.seeAlso, \ p.synopsis, p.checkType, p.exploitEase, \ p.exploitAvailable, p.cvssVector, p.cvssVectorBF, \ p.baseScore, p.temporalScore, p.stigSeverity, \ p.pluginPubDate, p.pluginModDate, p.patchPubDate, \ p.patchModDate, p.vulnPubDate, p.modifiedTime, \ p.md5, p.xrefs)
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for s in conn.list_scanners(): pp.pprint(s)
def main(): pp = pprint.PrettyPrinter(indent=4) conn = pyscclient.Connection("nessussc.sempra.com", "sv-apiuser", "##Sempra01") total_plugins = 0 for pf in conn.list_plugin_families(): total_plugins += pf.count pp.pprint(pf) print("Total plugins: {0}".format(total_plugins))
def main(): cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) cprint("Basic status output:", "green", attrs=["bold"]) conn.getStatus() cprint("Verbose status output:", "green", attrs=["bold"]) conn.getStatus(True)
def main(): pp = pprint.PrettyPrinter(indent=4) cark = '/home/charlie/pyscclient-gh/pyscclient/admin_cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) pp.pprint(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for org in conn.list_orgs(): pp.pprint(org) print("DEBUG: restrictedIPs is a {0}".format(type(org.restrictedIPs))) print("restrictedIPs: {0}".format(org.restrictedIPs))
def main(): pp = pprint.PrettyPrinter(indent=4) cark = '../cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], \ cark_conf['username'], passwd) for s in conn.list_scans(): #print(str(dir(s))) print("""Name: %s Schedule: %s""" % (s.name, s.schedule['nextRun']))
def main(): pp = pprint.PrettyPrinter(indent=4) conn = pyscclient.Connection("nessussc.sempra.com", "sv-apiuser", "##Sempra01") for p in conn.plugins(): #pp.pprint(p) print """ id: %s name: %s description: %s family: %s type: %s copyright: %s version: %s sourceFile: %s source: %s dependencies: %s requiredPorts: %s requiredUDPPorts: %s cpe: %s srcPort: %s dstPort: %s protocol: %s riskFactor: %s solution: %s seeAlso: %s synopsis: %s checkType: %s exploitEase: %s exploitAvailable: %s cvssVector: %s cvssVectorBF: %s baseScore: %s temporalScore: %s stgSeverity: %s pluginPubDate: %s pluginModDate: %s patchPubDate: %s patchModDate: %s vulnPubDate: %s modifiedTime: %s md5: %s xrefs: %s """ % (p.id, p.name, p.description, p.family.to_string(), \ p.type, p.copyright, p.version, p.sourceFile, \ p.source, p.dependencies, p.requiredPorts, \ p.requiredUDPPorts, p.cpe, p.srcPort, p.dstPort, \ p.protocol, p.riskFactor, p.solution, p.seeAlso, \ p.synopsis, p.checkType, p.exploitEase, \ p.exploitAvailable, p.cvssVector, p.cvssVectorBF, \ p.baseScore, p.temporalScore, p.stigSeverity, \ p.pluginPubDate, p.pluginModDate, p.patchPubDate, \ p.patchModDate, p.vulnPubDate, p.modifiedTime, \ p.md5, p.xrefs)
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) #pp.pprint(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for ass in conn.list_assets(): #pp.pprint(ass) # Asset is really asset group print("%s, %s, %s" % (ass.id, ass.name, ass.ipCount))
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) #pp.pprint(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for user in conn.list_users(): #pp.pprint(user) print("id: {0}, {1}, {2} ({3}) {4}".format(user.id, user.lastname, \ user.firstname, user.username, user.orgID))
def main(): pp = pprint.PrettyPrinter(indent=4) cark = '../cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) scan = conn.get_scan(sys.argv[1]) #pp.pprint(scan) print(""" id: %s name: %s description: %s status: %s ipList: %s type: %s policy: %s plugin: %s repository: %s zone: %s dhcpTracking: %s classifyMitigatedAge: %s emailOnLaunch: %s emailOnFinish: %s timeoutAction: %s scanningVirtualHosts: %s rolloverType: %s createdTime: %s modifiedTime: %s ownerGroup: %s creator: %s owner: %s reports: %s assets: %s credentials: %s numDependents: %s schedule: %s policyPrefs: %s maxScanTime: %s""" % (scan.id, scan.name, scan.description, scan.status, scan.ipList, scan.type, scan.policy, scan.plugin, scan.repository, scan.zone, scan.dhcpTracking, scan.classifyMitigatedAge, scan.emailOnLaunch, scan.emailOnFinish, scan.timeoutAction, scan.scanningVirtualHosts, scan.rolloverType, scan.createdTime, scan.modifiedTime, scan.ownerGroup, scan.creator, scan.owner, scan.reports, scan.assets, scan.credentials, scan.numDependents, scan.schedule, scan.policyPrefs, scan.maxScanTime))
def main(): pp = pprint.PrettyPrinter(indent=4) cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) try: conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) except pyscclient.APIError as apierr: if 'Invalid login credentials' in str(apierr): print("Invalid login credentials.") exit(1) for s in conn.list_zones(): pp.pprint(s)
def main(): assets_to_dump = list() with open(sys.argv[1], 'r') as f: for line in f: assets_to_dump.append(line.strip("\n").strip(" ")) pp = pprint.PrettyPrinter(indent=4) cark = '../cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for a in conn.list_assets(): if a.name in assets_to_dump: with open("{0}.txt".format(a.name), 'w') as out: print("{0}".format(a.viewableIPs)) out.write(str(a.viewableIPs)) else: print("{0} not in list: {1}".format(a.name, assets_to_dump))
def main(): pp = pprint.PrettyPrinter(indent=4) conn = pyscclient.Connection("nessussc.sempra.com", "sv-apiuser", "##Sempra01") pname_by_date = {} pobj_by_date = {} for plg in conn.get_plugins_since(2592000): pname_by_date[plg.pluginPubDate] = plg.name pobj_by_date[plg.pluginPubDate] = plg #print("{0} {1}".format(time.strftime("%x %X", time.localtime(float(plg.pluginPubDate))), plg.name)) with open('/tmp/plugin-timeline.csv', 'wb') as csvfile: writer = csv.writer(csvfile, dialect='excel') # header writer.writerow(['vulnPubDate','pluginPubDate','pluginModDate','pluginName']) for p in sorted(pname_by_date): print("{0} {1} {2} {3}".format(time.strftime("%x %X", time.localtime(float(pobj_by_date[p].vulnPubDate))),\ time.strftime("%x %X", time.localtime(float(p))), \ time.strftime("%x %X", time.localtime(float(pobj_by_date[p].pluginModDate))), \ pname_by_date[p])) writer.writerow([time.strftime("%x %X", time.localtime(float(pobj_by_date[p].vulnPubDate))), \ time.strftime("%x %X", time.localtime(float(p))), \ time.strftime("%x %X", time.localtime(float(pobj_by_date[p].pluginModDate))), \ pname_by_date[p]])
def main(): pp = pprint.PrettyPrinter(indent=4) args = handle_arguments() cark = args.carkconf with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) # check the number of organizations print("Checking {0} organization(s) on this SC console.".format(len(conn.organizations()))) # loop through the list of organizations and check the restrictedIPs for org in conn.list_orgs(): #pp.pprint(org.restrictedIPs) # if the restrictedIPs looks like an array, loop through it if 'list' in str(type(org.restrictedIPs)): print("restrictedIPs is a list()") else: print("restrictedIPs is a {0}".format(type(org.restrictedIPs))) #pp.pprint(org.restrictedIPs) if "," in org.restrictedIPs: iplist = org.restrictedIPs.split(",") #pp.pprint(iplist) is_global_exclude = False for cidr in iplist: match = re.search(r'[0-9.]+\/\d+', cidr) if match: # ip looks like a CIDR block if netaddr.IPAddress(args.ipaddr) in netaddr.IPNetwork(cidr): print("{0} is in {1}".format(args.ipaddr, cidr)) is_global_exclude = True if is_global_exclude: print("IP is globally excluded within the Organization and will not be scanned.") exit(0) else: # list any active scans # check the ipList to see if the ip in question is a member pass
def get_tenable_version(): pp = pprint.PrettyPrinter(indent=4) url_address = "https://docs.tenable.com/releasenotes/nessus/" page = urllib3.urlopen(url_address) soup = BeautifulSoup(page.read(), 'lxml') listitems = soup.find_all('li', {'value': 1}) #pp.pprint(listitems) match = re.search( r'<a href=".*">Nessus\s+([0-9.]+)\s+Release Notes - ([0-9/]+)</a>', str(listitems[0])) if match: print("Version: {0}, Date Released: {1}".format( match.group(1), match.group(2))) else: print("Didn't match.") cark = 'cark_conf.json' with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) for s in conn.list_scanners(): print("Name: {0}, Version: {1}".format(s.name, s.version))
def main(): pp = pprint.PrettyPrinter(indent=4) args = handle_arguments() cark = args.carkconf with open(cark, 'r') as f: cark_conf = json.load(f) passwd = pyscclient.Utils.get_cark_creds(cark_conf) conn = pyscclient.Connection(cark_conf['schost'], cark_conf['username'], passwd) # check the number of organizations print("Checking {0} organization(s) on this SC console.".format(len(conn.organizations()))) # loop through the list of organizations and check the restrictedIPs for org in conn.list_orgs(): #pp.pprint(org.restrictedIPs) # if the restrictedIPs looks like an array, loop through it if 'list' in str(type(org.restrictedIPs)): print("restrictedIPs is a list()") else: print("restrictedIPs in a {0}".format(org.restrictedIPs)) # list any active scans # check the ipList to see if the ip in question is a member pass if __name__=='__main__': main()