예제 #1
0
 def oiocCreate(self, iocname, ioc, username):
     with self._lock:
         return self._db.table("openioc").insert(
             {
                 "ioc_id": str(secure_uuid4()),
                 "iocname": str(iocname),
                 "username": str(username),
                 "ioc": str(ioc),
                 "create_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         )
예제 #2
0
 def taskProfileAdd(self, name, actor, params):
     with self._lock:
         return self._db.table("taskprofiles").insert(
             {
                 "taskprofile_id": str(secure_uuid4()),
                 "name": str(name),
                 "actor": str(actor),
                 "params": params,
                 "create_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         )
예제 #3
0
 def scriptCreate(self, scriptname, script, username):
     with self._lock:
         return self._db.table("scripts").insert(
             {
                 "script_id": str(secure_uuid4()),
                 "scriptname": str(scriptname),
                 "username": str(username),
                 "script": str(script),
                 "create_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         )
예제 #4
0
 def oiocCreate(self, iocname, ioc, username):
     return self._db_openioc.insert_one({
         "ioc_id":
         str(secure_uuid4()),
         "iocname":
         str(iocname),
         "username":
         str(username),
         "ioc":
         str(ioc),
         "create_timestamp":
         HXAPI.dt_to_str(datetime.datetime.utcnow()),
         "update_timestamp":
         HXAPI.dt_to_str(datetime.datetime.utcnow()),
     })
예제 #5
0
 def scriptCreate(self, scriptname, script, username):
     return self._db_scripts.insert_one({
         "script_id":
         str(secure_uuid4()),
         "scriptname":
         str(scriptname),
         "username":
         str(username),
         "script":
         str(script),
         "create_timestamp":
         HXAPI.dt_to_str(datetime.datetime.utcnow()),
         "update_timestamp":
         HXAPI.dt_to_str(datetime.datetime.utcnow()),
     })
예제 #6
0
 def transform(element):
     if dict_key in element[dict_name]:
         del element[dict_name][dict_key]
     if update_timestamp and "update_timestamp" in element:
         element["update_timestamp"] = HXAPI.dt_to_str(
             datetime.datetime.utcnow()
         )
예제 #7
0
 def multiFileCreate(
         self,
         username,
         profile_id,
         display_name=None,
         file_listing_id=None,
         api_mode=False,
 ):
     with self._lock:
         ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
         r = None
         try:
             return self._db.table("multi_file").insert(
                 {
                     "display_name": display_name or "Unnamed File Request",
                     "username": username,
                     "profile_id": profile_id,
                     "files": [],
                     "stopped": False,
                     "api_mode": api_mode,
                     "create_timestamp": ts,
                     "update_timestamp": ts,
                     "file_listing_id": file_listing_id,
                 }
             )
         except:
             # TODO: Not sure if the value returns that we'd ever see an exception
             if r:
                 self._db.table("multi_file").remove(doc_ids=[r])
             raise
     return None
예제 #8
0
 def sessionCreate(self, session_id):
     return self._db_session.insert_one({
         "session_id":
         session_id,
         "session_data": {},
         "update_timestamp":
         HXAPI.dt_to_str(datetime.datetime.utcnow()),
     })
예제 #9
0
 def transform(element):
     for i in element[list_name]:
         if i[query_key] == query_value:
             i[k] = v
             break
     if update_timestamp and "update_timestamp" in element:
         element["update_timestamp"] = HXAPI.dt_to_str(
             datetime.datetime.utcnow()
         )
예제 #10
0
 def sessionUpdate(self, session_id, session_data):
     with self._lock:
         return self._db.table("session").update(
             {
                 "session_data": session_data,
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             },
             (tinydb.Query()["session_id"] == session_id),
         )
예제 #11
0
 def sessionCreate(self, session_id):
     with self._lock:
         return self._db.table("session").insert(
             {
                 "session_id": session_id,
                 "session_data": {},
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         )
예제 #12
0
 def stackJobStop(self, stack_job_eid):
     with self._lock:
         return self._db.table("stacking").update(
             {
                 "stopped": True,
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             },
             doc_ids=[int(stack_job_eid)],
         )
예제 #13
0
 def multiFileStop(self, multi_file_id):
     with self._lock:
         return self._db.table("multi_file").update(
             {
                 "stopped": True,
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             },
             doc_ids=[int(multi_file_id)],
         )
예제 #14
0
 def fileListingStop(self, file_listing_id):
     with self._lock:
         return self._db.table("file_listing").update(
             {
                 "stopped": True,
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             },
             doc_ids=[int(file_listing_id)],
         )
예제 #15
0
 def transform(element):
     if type(value) is list:
         element[list_name].extend(value)
     else:
         element[list_name].append(value)
     if update_timestamp and "update_timestamp" in element:
         element["update_timestamp"] = HXAPI.dt_to_str(
             datetime.datetime.utcnow()
         )
예제 #16
0
 def stackJobUpdateGroupBy(self, profile_id, bulk_download_eid, last_groupby):
     with self._lock:
         return self._db.table("stacking").update(
             {
                 "last_groupby": last_groupby,
                 "update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
             },
             (tinydb.Query()["profile_id"] == profile_id)
             & (tinydb.Query()["bulk_download_eid"] == int(bulk_download_eid)),
         )
예제 #17
0
 def sessionUpdate(self, session_id, session_data):
     return self._db_session.replace_one(
         {"session_id": session_id},
         {
             "session_id": session_id,
             "session_data": dict(session_data),
             "update_timestamp": HXAPI.dt_to_str(
                 datetime.datetime.utcnow()),
         },
     )
예제 #18
0
 def transform(element):
     if not dict_key in element[dict_name]:
         element[dict_name][dict_key] = dict_values
     else:
         if type(dict_values) is dict:
             element[dict_name][dict_key].update(dict_values)
         else:
             element[dict_name][dict_key] = dict_values
     if update_timestamp and "update_timestamp" in element:
         element["update_timestamp"] = HXAPI.dt_to_str(
             datetime.datetime.utcnow()
         )
예제 #19
0
 def stackJobStop(self, stack_job_eid):
     return self._db_stacking.update_one(
         {"_id": ObjectId(stack_job_eid)},
         {
             "$set": {
                 "stopped":
                 True,
                 "update_timestamp":
                 HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         },
     )
예제 #20
0
 def fileListingStop(self, file_listing_id):
     return self._db_file_listing.update_one(
         {"_id": ObjectId(file_listing_id)},
         {
             "$set": {
                 "stopped":
                 True,
                 "update_timestamp":
                 HXAPI.dt_to_str(datetime.datetime.utcnow()),
             }
         },
     )
예제 #21
0
 def multiFileStop(self, multi_file_id):
     return self.mongoStripKeys(
         self._db_multi_file.update_one(
             {"_id": ObjectId(multi_file_id)},
             {
                 "$set": {
                     "stopped":
                     True,
                     "update_timestamp":
                     HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 }
             },
         ))
예제 #22
0
 def stackJobCreate(self, profile_id, bulk_download_eid, stack_type):
     ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
     r = self._db_stacking.insert_one({
         "profile_id": profile_id,
         "bulk_download_eid": bulk_download_eid,
         "stopped": False,
         "stack_type": stack_type,
         "hosts": [],
         "results": [],
         "last_index": None,
         "last_groupby": [],
         "create_timestamp": ts,
         "update_timestamp": ts,
     })
     return r.inserted_id
예제 #23
0
 def alertAddAnnotation(
         self, profile_id, hx_alert_id, annotation, state, create_user
 ):
     with self._lock:
         return self._db.table("alert").update(
             self._db_append_to_list(
                 "annotations",
                 {
                     "annotation": annotation,
                     "state": int(state),
                     "create_user": create_user,
                     "create_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 },
             ),
             (tinydb.Query()["profile_id"] == profile_id)
             & (tinydb.Query()["hx_alert_id"] == int(hx_alert_id)),
         )
예제 #24
0
 def bulkDownloadCreate(self,
                        profile_id,
                        hostset_name=None,
                        hostset_id=None,
                        task_profile=None):
     r = None
     ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
     r = self._db_bulk_download.insert_one({
         "profile_id": profile_id,
         "hostset_id": int(hostset_id),
         "hostset_name": hostset_name,
         "hosts": {},
         "task_profile": task_profile,
         "stopped": False,
         "complete": False,
         "create_timestamp": ts,
         "update_timestamp": ts,
     })
     return r.inserted_id
예제 #25
0
 def multiFileCreate(
     self,
     username,
     profile_id,
     display_name=None,
     file_listing_id=None,
     api_mode=False,
 ):
     ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
     r = self._db_multi_file.insert_one({
         "display_name": display_name or "Unnamed File Request",
         "username": username,
         "profile_id": profile_id,
         "files": [],
         "stopped": False,
         "api_mode": api_mode,
         "create_timestamp": ts,
         "update_timestamp": ts,
         "file_listing_id": file_listing_id,
     })
     return r.inserted_id
예제 #26
0
    def bulkDownloadUpdate(
        self,
        bulk_download_eid,
        bulk_acquisition_id=None,
        hosts=None,
        stopped=None,
        complete=None,
    ):
        d = {"update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow())}

        if bulk_acquisition_id is not None:
            d["bulk_acquisition_id"] = bulk_acquisition_id
        if hosts is not None:
            d["hosts"] = hosts
        if stopped is not None:
            d["stopped"] = stopped
        if complete is not None:
            d["complete"] = complete

        return self._db_bulk_download.update_one(
            {"_id": ObjectId(bulk_download_eid)}, {"$set": d})
예제 #27
0
 def alertAddAnnotation(self, profile_id, hx_alert_id, annotation, state,
                        create_user):
     return self._db_alerts.update_one(
         {
             "profile_id": profile_id,
             "hx_alert_id": int(hx_alert_id)
         },
         {
             "$push": {
                 "annotations": {
                     "annotation":
                     annotation,
                     "state":
                     int(state),
                     "create_user":
                     create_user,
                     "create_timestamp":
                     HXAPI.dt_to_str(datetime.datetime.utcnow()),
                 }
             }
         },
     )
예제 #28
0
 def stackJobCreate(self, profile_id, bulk_download_eid, stack_type):
     r = None
     with self._lock:
         ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
         try:
             r = self._db.table("stacking").insert(
                 {
                     "profile_id": profile_id,
                     "bulk_download_eid": int(bulk_download_eid),
                     "stopped": False,
                     "stack_type": stack_type,
                     "hosts": [],
                     "results": [],
                     "last_index": None,
                     "last_groupby": [],
                     "create_timestamp": ts,
                     "update_timestamp": ts,
                 }
             )
         except:
             self._db.table("stacking").remove(doc_ids=[r])
             raise
     return r
예제 #29
0
    def bulkDownloadUpdate(
            self,
            bulk_download_eid,
            bulk_acquisition_id=None,
            hosts=None,
            stopped=None,
            complete=None,
    ):
        d = {"update_timestamp": HXAPI.dt_to_str(datetime.datetime.utcnow())}

        if bulk_acquisition_id is not None:
            d["bulk_acquisition_id"] = bulk_acquisition_id
        if hosts is not None:
            d["hosts"] = hosts
        if stopped is not None:
            d["stopped"] = stopped
        if complete is not None:
            d["complete"] = complete

        with self._lock:
            return self._db.table("bulk_download").update(
                d, doc_ids=[int(bulk_download_eid)]
            )
예제 #30
0
 def fileListingCreate(
         self,
         profile_id,
         username,
         bulk_download_eid,
         path,
         regex,
         depth,
         display_name,
         api_mode=False,
 ):
     r = None
     with self._lock:
         ts = HXAPI.dt_to_str(datetime.datetime.utcnow())
         try:
             r = self._db.table("file_listing").insert(
                 {
                     "profile_id": profile_id,
                     "display_name": display_name,
                     "bulk_download_eid": int(bulk_download_eid),
                     "username": username,
                     "stopped": False,
                     "files": [],
                     "cfg": {
                         "path": path,
                         "regex": regex,
                         "depth": depth,
                         "api_mode": api_mode,
                     },
                     "create_timestamp": ts,
                     "update_timestamp": ts,
                 }
             )
         except:
             self._db.table("file_listing").remove(doc_ids=[r])
             raise
     return r