Skip to content

Commit

Permalink
#1738 Add integrity checks on alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jan 11, 2021
1 parent 0b2c524 commit cc9fc52
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions thehive/app/org/thp/thehive/TheHiveModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class TheHiveModule(environment: Environment, configuration: Configuration) exte
integrityCheckOpsBindings.addBinding.to[CaseTemplateIntegrityCheckOps]
integrityCheckOpsBindings.addBinding.to[DataIntegrityCheckOps]
integrityCheckOpsBindings.addBinding.to[CaseIntegrityCheckOps]
integrityCheckOpsBindings.addBinding.to[AlertIntegrityCheckOps]
bind[ActorRef].annotatedWithName("integrity-check-actor").toProvider[IntegrityCheckActorProvider]

bind[ActorRef].annotatedWithName("flow-actor").toProvider[FlowActorProvider]
Expand Down
21 changes: 20 additions & 1 deletion thehive/app/org/thp/thehive/services/AlertSrv.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.thp.thehive.services

import akka.actor.ActorRef
import org.apache.tinkerpop.gremlin.structure.Graph
import org.thp.scalligraph.auth.{AuthContext, Permission}
import org.thp.scalligraph.models._
Expand Down Expand Up @@ -32,7 +33,8 @@ class AlertSrv @Inject() (
customFieldSrv: CustomFieldSrv,
caseTemplateSrv: CaseTemplateSrv,
observableSrv: ObservableSrv,
auditSrv: AuditSrv
auditSrv: AuditSrv,
@Named("integrity-check-actor") integrityCheckActor: ActorRef
)(implicit
@Named("with-thehive-schema") db: Database
) extends VertexSrv[Alert] {
Expand Down Expand Up @@ -268,6 +270,7 @@ class AlertSrv @Inject() (
_ <- importObservables(alert.alert, createdCase.`case`)
_ <- alertCaseSrv.create(AlertCase(), alert.alert, createdCase.`case`)
_ <- markAsRead(alert._id)
_ = integrityCheckActor ! EntityAdded("Alert")
} yield createdCase
}
}(richCase => auditSrv.`case`.create(richCase.`case`, richCase.toJson))
Expand Down Expand Up @@ -304,6 +307,7 @@ class AlertSrv @Inject() (
)
} yield details
}(details => auditSrv.alertToCase.merge(alert, `case`, Some(details)))
.map(_ => integrityCheckActor ! EntityAdded("Alert"))
.flatMap(_ => caseSrv.getOrFail(`case`._id))

def importObservables(alert: Alert with Entity, `case`: Case with Entity)(implicit
Expand Down Expand Up @@ -591,3 +595,18 @@ object AlertOps {

implicit class AlertCustomFieldsOpsDefs(traversal: Traversal.E[AlertCustomField]) extends CustomFieldValueOpsDefs(traversal)
}

class AlertIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: AlertSrv) extends IntegrityCheckOps[Alert] {
override def check(): Unit = {
db.tryTransaction { implicit graph =>
service
.startTraversal
.flatMap(_.outE[AlertCase].range(1, 100))
.remove()
Success(())
}
()
}

override def resolve(entities: Seq[Alert with Entity])(implicit graph: Graph): Try[Unit] = Success(())
}
4 changes: 4 additions & 0 deletions thehive/conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ integrityCheck {
initialDelay: 1 minute
interval: 10 minutes
}
alert {
initialDelay: 5 minute
interval: 30 minutes
}
}


Expand Down

0 comments on commit cc9fc52

Please sign in to comment.