Created
October 8, 2013 20:19
-
-
Save kf0jvt/6890939 to your computer and use it in GitHub Desktop.
Takes a CSV file and creates json output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import uuid | |
| import copy | |
| import csv | |
| from datetime import datetime | |
| # putIncident(i, 'blackfist') | |
| def putIncident(i, analyst="blackfist"): | |
| i['plus']['analyst'] = analyst | |
| i['plus']['created'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') | |
| identity = str(uuid.uuid4()).upper() | |
| i['incident_id'] = identity | |
| i['plus']['master_id'] = identity | |
| i['source_id'] = 'vcdb' | |
| outfile = open(identity + '.json','w') | |
| try: | |
| outfile.write(json.dumps(i,sort_keys=True, indent=2,separators=(',', ': '))) | |
| except: | |
| print i | |
| outfile.close() | |
| infile = csv.DictReader(open('misuse.csv','rU')) | |
| template = {'schema_version' : '1.2','discovery_method' : 'Unknown', 'security_incident':'Confirmed'} | |
| template['actor'] = { 'internal' : {'motive':['Financial']} } | |
| template['action'] = {'misuse' : {} } | |
| template['asset'] = {'assets' : [{}] } | |
| template['attribute'] = {'confidentiality':{'data_disclosure':'Yes'} } | |
| template['impact'] = {'overall_rating':'Unknown'} | |
| template['plus'] = {'timeline' : {'notification' : {} },'f500':'N' } | |
| template['timeline'] = {'incident' : {} } | |
| template['victim'] = [{'employee_count':'Unknown'}] | |
| for row in infile: | |
| i = copy.copy(template) | |
| i['reference'] = row['reference'] | |
| i['plus']['github'] = row['github'] | |
| if row['vic.name'] != '': | |
| i['victim'][0]['victim_id'] = row['vic.name'] | |
| i['victim'][0]['industry'] = row['vic.naics'] | |
| i['victim'][0]['country'] = row['vic.country'] | |
| i['summary'] = row['summary'] | |
| notification_date = datetime.strptime(row['notification'],'%m/%d/%y') | |
| i['plus']['timeline']['notification']['month'] = notification_date.month | |
| i['plus']['timeline']['notification']['day'] = notification_date.day | |
| i['plus']['timeline']['notification']['year'] = notification_date.year | |
| incident_date = datetime.strptime(row['incident'],'%m/%d/%y') | |
| i['timeline']['incident']['month'] = incident_date.month | |
| i['timeline']['incident']['day'] = incident_date.day | |
| i['timeline']['incident']['year'] = incident_date.year | |
| i['actor']['internal']['variety'] = [row['actor.variety']] | |
| if row['actor.notes'] != '': | |
| i['actor']['internal']['notes'] = row['actor.notes'] | |
| i['action']['misuse']['vector'] = [row['action.vector']] | |
| i['action']['misuse']['variety'] = [row['action.variety']] | |
| i['asset']['assets'][0]['variety'] = row['asset.variety'] | |
| if row['data.total'] != '': | |
| i['attribute']['confidentiality']['data_total'] = int(row['data.total']) | |
| putIncident(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment