text
stringlengths 0
93.6k
|
|---|
eid = checkAge()
|
hashValue = hashValue.strip()
|
md5 = re.compile(r'[0-9a-f]{32}$', flags = re.IGNORECASE)
|
sha1= re.compile(r'[0-9a-f]{40}$', flags = re.IGNORECASE)
|
sha256 = re.compile(r'[0-9a-f]{64}$', flags = re.IGNORECASE)
|
if re.match(sha256, hashValue):
|
hashType = "sha256"
|
mispAttribute = MISPAttribute()
|
mispAttribute.type = 'sha256'
|
mispAttribute.value = hashValue
|
misp.add_attribute(eid, mispAttribute)
|
elif re.match(sha1, hashValue):
|
hashType = "sha1"
|
mispAttribute = MISPAttribute()
|
mispAttribute.type = 'sha1'
|
mispAttribute.value = hashValue
|
misp.add_attribute(eid, mispAttribute)
|
elif re.match(md5, hashValue):
|
hashType = "md5"
|
mispAttribute = MISPAttribute()
|
mispAttribute.type = 'md5'
|
mispAttribute.value = hashValue
|
misp.add_attribute(eid, mispAttribute)
|
else:
|
returnFailure("hash", hashValue, "length of %s" % len(hashValue))
|
returnSuccess("%s hash" % hashType,hashValue,eid)
|
def createEvent(eventName):
|
mt = MaltegoTransform()
|
mt.addUIMessage("[Info] Creating event with the name %s" % eventName)
|
mispevent = MISPEvent()
|
mispevent.analysis = MISP_ANALYSIS
|
mispevent.date = datetime.now()
|
mispevent.distribution = MISP_DISTRIBUTION
|
mispevent.info = eventName
|
mispevent.threat_level_id = MISP_THREAT
|
mispevent.published = MISP_EVENT_PUBLISH
|
event = misp.add_event(mispevent)
|
eid = event['Event']['id']
|
einfo = event['Event']['info']
|
eorgc = event['Event']['orgc_id']
|
me = MaltegoEntity('maltego.MISPEvent',eid);
|
me.addAdditionalFields('EventLink', 'EventLink', False, BASE_URL + '/events/view/' + eid )
|
me.addAdditionalFields('Org', 'Org', False, eorgc)
|
me.addAdditionalFields('notes', 'notes', False, eorgc + ": " + einfo)
|
mt.addEntityToMessage(me);
|
returnSuccess("event", eid, None, mt)
|
def selectEvent(eventID):
|
s = shelve.open(eventDB)
|
s['id'] = eventID
|
s['age'] = datetime.today()
|
s.close()
|
mt = MaltegoTransform()
|
mt.addUIMessage("[Info] Event with ID %s selected for insert" % eventID)
|
mt.returnOutput()
|
def dataError(request):
|
mt = MaltegoTransform()
|
mt.addException("[Error] Failure to load function with name %s" % request)
|
mt.throwExceptions()
|
def checkAge():
|
s = shelve.open(eventDB)
|
try:
|
age = s['age']
|
eid = s['id']
|
except:
|
age = datetime.today()-timedelta(seconds=6000)
|
eid = "none"
|
s.close()
|
curDate = datetime.today()
|
if age < curDate - timedelta(seconds=3600):
|
mt = MaltegoTransform()
|
mt.addException("[Warning] Selection of Event is over 1 hour old. Please reselect. Current selection: %s" % eid);
|
mt.throwExceptions()
|
else:
|
return eid
|
def returnSuccess(etype,value,event=None, mt=None):
|
if not mt:
|
mt = MaltegoTransform()
|
if event:
|
mt.addUIMessage("[Info] Successful entry of %s with value %s into event %s" % (etype, value, event))
|
else:
|
mt.addUIMessage("[Info] Successful entry of %s with ID %s" % (etype, value))
|
mt.returnOutput()
|
def returnFailure(etype, value, reason):
|
mt = MaltegoTransform()
|
mt.addException("[Error] Failed to add %s with value %s due to %s" % (etype, value, reason));
|
mt.throwExceptions()
|
def main():
|
request = sys.argv[1]
|
value = sys.argv[2]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.