~alienagain/Stix_stuff

4b2d68958cc64d8b6b10c8d36d949f192bcd038e — terceranexus6 1 year, 11 months ago 3959dbd
added malware uuid check in domains, too
1 files changed, 27 insertions(+), 5 deletions(-)

M from_csv/domains.py
M from_csv/domains.py => from_csv/domains.py +27 -5
@@ 4,14 4,15 @@ import datetime
import sys
import random
import string

import uuid

#by default, the time for creation and modification is the time of the execution
now = datetime.datetime.now()
mytime=now.strftime('%Y-%m-%dT%H:%M:%S.%fZ')

#funtion to create unique IDs based on random strings starting with the given type (indicator, malware, etc)
def create_id(itype):
# DEPRECATED
def create_id_old(itype):
    # lenghts for generating random strings for the id
    l1 = 8
    l2 = 4


@@ 26,12 27,18 @@ def create_id(itype):

    print(itype+"--"+random_string_1+"-"+random_string_2+"-"+random_string_3+"-"+random_string_4+"-"+random_string_5)

def create_id(itype):
    myuuid = uuid.uuid4()
    print(itype+"--"+str(myuuid))

#it takes the csv from argument
filename = str(sys.argv[1])
count=0

with open(filename, 'r') as csvfile:
with open(filename, 'r') as csvfile, open('malware_IDs.csv','r') as malware_ids:
    datareader = csv.reader(csvfile)
    datareader2 = csv.reader(malware_ids)

    for row in datareader:
        count=count+1



@@ 71,7 78,22 @@ with open(filename, 'r') as csvfile:
            valid_from=mytime
        )       
        
        myid2 = create_id("malware")
        #myid2 = create_id("malware")

        # condition to assure that if the 
        # malware already has an ID registered, don use
        skedaddle = False

        while not (skedaddle):
            for row2 in datareader2:
                if str(row2[0]) == str(mname):
                    myid2 = row2[1]
                    skedaddle = True
                else:
                    myid2 = create_id("malware")
            skedaddle = True


        #malware which is related to it
        malware = Malware(
            id=myid2,


@@ 94,5 116,5 @@ with open(filename, 'r') as csvfile:
        # this way it makes it easier to understand the data before opening it

        print(str(bundle))
        with open(tname+"_domain_indicates_"+mname+"_"+str(count)+".stix", 'a') as f:
        with open("domain_indicates_"+mname+"_"+str(count)+".stix", 'a') as f:
            f.write(str(bundle))