|
| 1 | +import xlrd |
| 2 | +from collections import OrderedDict |
| 3 | +import simplejson as json |
| 4 | +import urllib.request |
| 5 | + |
| 6 | +SOURCESHEET = 'https://docs.google.com/spreadsheets/d/1TWS238xacAto-fLKh1n5uTsdijWdCEsGIM0Y0Hvmc5g/pub?output=xlsx' |
| 7 | +OUTPUTSHEET = 'RansomwareOverview.xlsx' |
| 8 | +JSONFILE = 'RansomwareOverview.json' |
| 9 | + |
| 10 | +# download and save ransomware overview file locally |
| 11 | +try: |
| 12 | + urllib.request.urlretrieve(SOURCESHEET, OUTPUTSHEET) |
| 13 | +except IOError: |
| 14 | + print('An error occured trying to write an updated spreadsheet. Do you already have it open?') |
| 15 | +except urllib.error.URLError: |
| 16 | + print('An error occured trying to download the file. Please check the source and try again.') |
| 17 | + |
| 18 | +wb = xlrd.open_workbook(OUTPUTSHEET) |
| 19 | +sh = wb.sheet_by_index(0) |
| 20 | +mw = wb.sheet_by_index(2) |
| 21 | +# List to hold dictionaries |
| 22 | +c_list = [] |
| 23 | + |
| 24 | +# Iterate through each row in worksheet and fetch values into dict |
| 25 | +for rownum in range(1, sh.nrows): |
| 26 | + cars = OrderedDict() |
| 27 | + row_values = sh.row_values(rownum) |
| 28 | + |
| 29 | + |
| 30 | + if row_values[6]=="": |
| 31 | + name = row_values[0] |
| 32 | + gre=[name] |
| 33 | + elif "," in row_values[6]: |
| 34 | + e=row_values[6].split(",") |
| 35 | + ge = [row_values[0]] |
| 36 | + gre=e+ge |
| 37 | + else: |
| 38 | + gre=[row_values[0],row_values[6]] |
| 39 | + print (gre) |
| 40 | + cars['Name'] = gre |
| 41 | + cars['Extensions'] = row_values[1] |
| 42 | + cars['Extension Pattern'] = row_values[2] |
| 43 | + cars['Ransom Note Filename(s)'] = row_values[3] |
| 44 | + cars['Comment'] = row_values[4] |
| 45 | + cars['Encryption Algorithm'] = row_values[5] |
| 46 | + cars['Decryptor'] = row_values[7] |
| 47 | + if row_values[8]=="": |
| 48 | + cars['Resources'] = [row_values[9]] |
| 49 | + elif row_values[9]=="": |
| 50 | + cars['Resources']=[row_values[8]] |
| 51 | + else: |
| 52 | + cars['Resources'] = [row_values[8], row_values[9]] |
| 53 | + cars['Screenshots'] = row_values[10] |
| 54 | + |
| 55 | + for r in range(1, mw.nrows): |
| 56 | + rowe = mw.row_values(r) |
| 57 | + |
| 58 | + if row_values[0] == rowe[0]: |
| 59 | + cars['Microsoft Detection Name']=rowe[1] |
| 60 | + cars['Microsoft Info'] = rowe[2] |
| 61 | + cars['Sandbox'] = rowe[3] |
| 62 | + cars['IOCs'] = rowe[4] |
| 63 | + cars['Snort'] = rowe[5] |
| 64 | + |
| 65 | + c_list.append(cars) |
| 66 | + |
| 67 | +# Serialize the list of dicts to JSON |
| 68 | +j = json.dumps(c_list) |
| 69 | + |
| 70 | +# Write to file |
| 71 | +with open(JSONFILE, 'w') as f: |
| 72 | + f.write(j) |
| 73 | + |
| 74 | +f.close() |
0 commit comments