-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-mitre-attack' into develop-th4
- Loading branch information
Showing
30 changed files
with
1,464 additions
and
108 deletions.
There are no files selected for viewing
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
dto/src/main/scala/org/thp/thehive/dto/v1/Pattern.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.thp.thehive.dto.v1 | ||
|
||
import play.api.libs.json.{Format, Json, Reads, Writes} | ||
|
||
import java.util.Date | ||
|
||
case class InputPattern( | ||
external_id: String, | ||
name: String, | ||
description: Option[String], | ||
kill_chain_phases: Seq[InputKillChainPhase], | ||
url: String, | ||
`type`: String, | ||
x_mitre_platforms: Seq[String], | ||
x_mitre_data_sources: Seq[String], | ||
x_mitre_is_subtechnique: Option[Boolean], | ||
x_mitre_version: Option[String] | ||
) | ||
|
||
case class InputReference( | ||
source_name: String, | ||
external_id: Option[String], | ||
url: String | ||
) | ||
|
||
case class InputKillChainPhase( | ||
kill_chain_name: String, | ||
phase_name: String | ||
) | ||
|
||
object InputReference { | ||
implicit val reads: Reads[InputReference] = Reads[InputReference] { json => | ||
for { | ||
source_name <- (json \ "source_name").validate[String] | ||
external_id <- (json \ "external_id").validateOpt[String] | ||
url <- (json \ "url").validate[String] | ||
} yield InputReference( | ||
source_name, | ||
external_id, | ||
url | ||
) | ||
} | ||
|
||
implicit val writes: Writes[InputReference] = Json.writes[InputReference] | ||
} | ||
|
||
object InputKillChainPhase { | ||
implicit val reads: Reads[InputKillChainPhase] = Json.reads[InputKillChainPhase] | ||
|
||
implicit val writes: Writes[InputKillChainPhase] = Json.writes[InputKillChainPhase] | ||
} | ||
|
||
object InputPattern { | ||
implicit val reads: Reads[InputPattern] = Reads[InputPattern] { json => | ||
for { | ||
references <- (json \ "external_references").validate[Seq[InputReference]] | ||
mitreReference = references.find(ref => isSourceNameValid(ref.source_name)) | ||
name <- (json \ "name").validate[String] | ||
description <- (json \ "description").validateOpt[String] | ||
kill_chain_phases <- (json \ "kill_chain_phases").validateOpt[Seq[InputKillChainPhase]] | ||
techniqueType <- (json \ "type").validate[String] | ||
x_mitre_platforms <- (json \ "x_mitre_platforms").validateOpt[Seq[String]] | ||
x_mitre_data_sources <- (json \ "x_mitre_data_sources").validateOpt[Seq[String]] | ||
x_mitre_is_subtechnique <- (json \ "x_mitre_is_subtechnique").validateOpt[Boolean] | ||
x_mitre_version <- (json \ "x_mitre_version").validateOpt[String] | ||
} yield InputPattern( | ||
mitreReference.flatMap(_.external_id).getOrElse(""), | ||
name, | ||
description, | ||
kill_chain_phases.getOrElse(Seq()), | ||
mitreReference.map(_.url).getOrElse(""), | ||
techniqueType, | ||
x_mitre_platforms.getOrElse(Seq()), | ||
x_mitre_data_sources.getOrElse(Seq()), | ||
x_mitre_is_subtechnique, | ||
x_mitre_version | ||
) | ||
} | ||
|
||
private def isSourceNameValid(reference: String): Boolean = | ||
reference == "mitre-attack" | ||
|
||
implicit val writes: Writes[InputPattern] = Json.writes[InputPattern] | ||
} | ||
|
||
case class OutputPattern( | ||
_id: String, | ||
_type: String, | ||
_createdBy: String, | ||
_updatedBy: Option[String], | ||
_createdAt: Date, | ||
_updatedAt: Option[Date], | ||
patternId: String, | ||
name: String, | ||
description: Option[String], | ||
tactics: Set[String], | ||
url: String, | ||
patternType: String, | ||
platforms: Seq[String], | ||
dataSources: Seq[String], | ||
version: Option[String], | ||
parent: Option[String] | ||
) | ||
|
||
object OutputPattern { | ||
implicit val format: Format[OutputPattern] = Json.format[OutputPattern] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.thp.thehive.dto.v1 | ||
|
||
import play.api.libs.json.{Format, Json, Reads, Writes} | ||
|
||
import java.util.Date | ||
|
||
case class InputProcedure( | ||
description: String, | ||
occurence: Date, | ||
caseId: String, | ||
patternId: String | ||
) | ||
|
||
object InputProcedure { | ||
implicit val reads: Reads[InputProcedure] = Reads[InputProcedure] { json => | ||
for { | ||
description <- (json \ "description").validate[String] | ||
occurence <- (json \ "occurence").validate[Date] | ||
caseId <- (json \ "caseId").validate[String] | ||
patternId <- (json \ "patternId").validate[String] | ||
} yield InputProcedure( | ||
description, | ||
occurence, | ||
caseId, | ||
patternId | ||
) | ||
} | ||
|
||
implicit val writes: Writes[InputProcedure] = Json.writes[InputProcedure] | ||
} | ||
|
||
case class OutputProcedure( | ||
_id: String, | ||
_createdAt: Date, | ||
_createdBy: String, | ||
_updatedAt: Option[Date], | ||
_updatedBy: Option[String], | ||
description: String, | ||
occurence: Date, | ||
patternId: String | ||
) | ||
|
||
object OutputProcedure { | ||
implicit val format: Format[OutputProcedure] = Json.format[OutputProcedure] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.