-
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 'develop-th4' into feature/indexBackend
- Loading branch information
Showing
100 changed files
with
3,864 additions
and
407 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.thp.thehive.dto.v1 | ||
|
||
import org.thp.thehive.dto.v1.ObservablesFilter.ObservablesFilter | ||
import org.thp.thehive.dto.v1.TasksFilter.TasksFilter | ||
import play.api.libs.json.{Format, Json, Writes} | ||
|
||
import java.util.Date | ||
|
||
case class InputShare(organisationName: String, profile: String, tasks: TasksFilter, observables: ObservablesFilter) | ||
|
||
object TasksFilter extends Enumeration { | ||
type TasksFilter = Value | ||
|
||
val all: TasksFilter = Value("all") | ||
val none: TasksFilter = Value("none") | ||
|
||
implicit val format: Format[TasksFilter] = Json.formatEnum(TasksFilter) | ||
} | ||
|
||
object ObservablesFilter extends Enumeration { | ||
type ObservablesFilter = Value | ||
|
||
val all: ObservablesFilter = Value("all") | ||
val none: ObservablesFilter = Value("none") | ||
|
||
implicit val format: Format[ObservablesFilter] = Json.formatEnum(ObservablesFilter) | ||
} | ||
|
||
object InputShare { | ||
implicit val writes: Writes[InputShare] = Json.writes[InputShare] | ||
} | ||
|
||
case class OutputShare( | ||
_id: String, | ||
_type: String, | ||
_createdBy: String, | ||
_updatedBy: Option[String] = None, | ||
_createdAt: Date, | ||
_updatedAt: Option[Date] = None, | ||
caseId: String, | ||
profileName: String, | ||
organisationName: String, | ||
owner: Boolean | ||
) | ||
|
||
object OutputShare { | ||
implicit val format: Format[OutputShare] = Json.format[OutputShare] | ||
} |
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,15 @@ | ||
package org.thp.thehive.dto.v1 | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
case class OutputTag( | ||
namespace: String, | ||
predicate: String, | ||
value: Option[String], | ||
description: Option[String], | ||
colour: String | ||
) | ||
|
||
object OutputTag { | ||
implicit val format: OFormat[OutputTag] = Json.format[OutputTag] | ||
} |
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,74 @@ | ||
package org.thp.thehive.dto.v1 | ||
|
||
import play.api.libs.json.{JsObject, Json, OFormat} | ||
|
||
import java.util.Date | ||
|
||
/* | ||
Format based on : | ||
https://tools.ietf.org/id/draft-dulaunoy-misp-taxonomy-format-04.html | ||
*/ | ||
|
||
case class InputTaxonomy( | ||
namespace: String, | ||
description: String, | ||
version: Int, | ||
`type`: Option[Seq[String]], | ||
exclusive: Option[Boolean], | ||
predicates: Seq[InputPredicate], | ||
values: Option[Seq[InputValue]] | ||
) | ||
|
||
case class InputPredicate( | ||
value: String, | ||
expanded: Option[String], | ||
exclusive: Option[Boolean], | ||
description: Option[String] | ||
) | ||
|
||
case class InputValue( | ||
predicate: String, | ||
entry: Seq[InputEntry] | ||
) | ||
|
||
case class InputEntry( | ||
value: String, | ||
expanded: Option[String], | ||
colour: Option[String], | ||
description: Option[String], | ||
numerical_value: Option[Int] | ||
) | ||
|
||
object InputTaxonomy { | ||
implicit val format: OFormat[InputTaxonomy] = Json.format[InputTaxonomy] | ||
} | ||
|
||
object InputPredicate { | ||
implicit val format: OFormat[InputPredicate] = Json.format[InputPredicate] | ||
} | ||
|
||
object InputValue { | ||
implicit val format: OFormat[InputValue] = Json.format[InputValue] | ||
} | ||
|
||
object InputEntry { | ||
implicit val format: OFormat[InputEntry] = Json.format[InputEntry] | ||
} | ||
|
||
case class OutputTaxonomy( | ||
_id: String, | ||
_type: String, | ||
_createdBy: String, | ||
_updatedBy: Option[String] = None, | ||
_createdAt: Date, | ||
_updatedAt: Option[Date] = None, | ||
namespace: String, | ||
description: String, | ||
version: Int, | ||
tags: Seq[OutputTag], | ||
extraData: JsObject | ||
) | ||
|
||
object OutputTaxonomy { | ||
implicit val format: OFormat[OutputTaxonomy] = Json.format[OutputTaxonomy] | ||
} |
Oops, something went wrong.