types.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package cticlient
  2. import (
  3. "time"
  4. )
  5. type CTIScores struct {
  6. Overall CTIScore `json:"overall"`
  7. LastDay CTIScore `json:"last_day"`
  8. LastWeek CTIScore `json:"last_week"`
  9. LastMonth CTIScore `json:"last_month"`
  10. }
  11. type CTIScore struct {
  12. Aggressiveness int `json:"aggressiveness"`
  13. Threat int `json:"threat"`
  14. Trust int `json:"trust"`
  15. Anomaly int `json:"anomaly"`
  16. Total int `json:"total"`
  17. }
  18. type CTIAttackDetails struct {
  19. Name string `json:"name"`
  20. Label string `json:"label"`
  21. Description string `json:"description"`
  22. References []string `json:"references"`
  23. }
  24. type CTIClassifications struct {
  25. FalsePositives []CTIClassification `json:"false_positives"`
  26. Classifications []CTIClassification `json:"classifications"`
  27. }
  28. type CTIClassification struct {
  29. Name string `json:"name"`
  30. Label string `json:"label"`
  31. Description string `json:"description"`
  32. }
  33. type CTIHistory struct {
  34. FirstSeen *string `json:"first_seen"`
  35. LastSeen *string `json:"last_seen"`
  36. FullAge int `json:"full_age"`
  37. DaysAge int `json:"days_age"`
  38. }
  39. type CTIBehavior struct {
  40. Name string `json:"name"`
  41. Label string `json:"label"`
  42. Description string `json:"description"`
  43. }
  44. type CTILocationInfo struct {
  45. Country *string `json:"country"`
  46. City *string `json:"city"`
  47. Latitude *float64 `json:"latitude"`
  48. Longitude *float64 `json:"longitude"`
  49. }
  50. type CTIReferences struct {
  51. Name string `json:"name"`
  52. Label string `json:"label"`
  53. Description string `json:"description"`
  54. }
  55. type SmokeItem struct {
  56. IpRangeScore int `json:"ip_range_score"`
  57. Ip string `json:"ip"`
  58. IpRange *string `json:"ip_range"`
  59. AsName *string `json:"as_name"`
  60. AsNum *int `json:"as_num"`
  61. Location CTILocationInfo `json:"location"`
  62. ReverseDNS *string `json:"reverse_dns"`
  63. Behaviors []*CTIBehavior `json:"behaviors"`
  64. History CTIHistory `json:"history"`
  65. Classifications CTIClassifications `json:"classifications"`
  66. AttackDetails []*CTIAttackDetails `json:"attack_details"`
  67. TargetCountries map[string]int `json:"target_countries"`
  68. BackgroundNoiseScore *int `json:"background_noise_score"`
  69. Scores CTIScores `json:"scores"`
  70. References []CTIReferences `json:"references"`
  71. IsOk bool `json:"-"`
  72. }
  73. type SearchIPResponse struct {
  74. Total int `json:"total"`
  75. NotFound int `json:"not_found"`
  76. Items []SmokeItem `json:"items"`
  77. }
  78. type CustomTime struct {
  79. time.Time
  80. }
  81. func (ct *CustomTime) UnmarshalJSON(b []byte) error {
  82. if string(b) == "null" {
  83. return nil
  84. }
  85. t, err := time.Parse(`"2006-01-02T15:04:05.999999999"`, string(b))
  86. if err != nil {
  87. return err
  88. }
  89. ct.Time = t
  90. return nil
  91. }
  92. type FireItem struct {
  93. IpRangeScore int `json:"ip_range_score"`
  94. Ip string `json:"ip"`
  95. IpRange *string `json:"ip_range"`
  96. AsName *string `json:"as_name"`
  97. AsNum *int `json:"as_num"`
  98. Location CTILocationInfo `json:"location"`
  99. ReverseDNS *string `json:"reverse_dns"`
  100. Behaviors []*CTIBehavior `json:"behaviors"`
  101. History CTIHistory `json:"history"`
  102. Classifications CTIClassifications `json:"classifications"`
  103. AttackDetails []*CTIAttackDetails `json:"attack_details"`
  104. TargetCountries map[string]int `json:"target_countries"`
  105. BackgroundNoiseScore *int `json:"background_noise_score"`
  106. Scores CTIScores `json:"scores"`
  107. References []CTIReferences `json:"references"`
  108. Status string `json:"status"`
  109. Expiration CustomTime `json:"expiration"`
  110. }
  111. type FireParams struct {
  112. Since *string `json:"since"`
  113. Page *int `json:"page"`
  114. Limit *int `json:"limit"`
  115. }
  116. type Href struct {
  117. Href string `json:"href"`
  118. }
  119. type Links struct {
  120. First *Href `json:"first"`
  121. Self *Href `json:"self"`
  122. Prev *Href `json:"prev"`
  123. Next *Href `json:"next"`
  124. }
  125. type FireResponse struct {
  126. Links Links `json:"_links"`
  127. Items []FireItem `json:"items"`
  128. }
  129. func (c *SmokeItem) GetAttackDetails() []string {
  130. var ret []string = make([]string, 0)
  131. if c.AttackDetails != nil {
  132. for _, b := range c.AttackDetails {
  133. ret = append(ret, b.Name)
  134. }
  135. }
  136. return ret
  137. }
  138. func (c *SmokeItem) GetBehaviors() []string {
  139. var ret []string = make([]string, 0)
  140. if c.Behaviors != nil {
  141. for _, b := range c.Behaviors {
  142. ret = append(ret, b.Name)
  143. }
  144. }
  145. return ret
  146. }
  147. // Provide the likelihood of the IP being bad
  148. func (c *SmokeItem) GetMaliciousnessScore() float32 {
  149. if c.IsPartOfCommunityBlocklist() {
  150. return 1.0
  151. }
  152. if c.Scores.LastDay.Total > 0 {
  153. return float32(c.Scores.LastDay.Total) / 10.0
  154. }
  155. return 0.0
  156. }
  157. func (c *SmokeItem) IsPartOfCommunityBlocklist() bool {
  158. if c.Classifications.Classifications != nil {
  159. for _, v := range c.Classifications.Classifications {
  160. if v.Name == "community-blocklist" {
  161. return true
  162. }
  163. }
  164. }
  165. return false
  166. }
  167. func (c *SmokeItem) GetBackgroundNoiseScore() int {
  168. if c.BackgroundNoiseScore != nil {
  169. return *c.BackgroundNoiseScore
  170. }
  171. return 0
  172. }
  173. func (c *SmokeItem) GetFalsePositives() []string {
  174. var ret []string = make([]string, 0)
  175. if c.Classifications.FalsePositives != nil {
  176. for _, b := range c.Classifications.FalsePositives {
  177. ret = append(ret, b.Name)
  178. }
  179. }
  180. return ret
  181. }
  182. func (c *SmokeItem) IsFalsePositive() bool {
  183. if c.Classifications.FalsePositives != nil {
  184. if len(c.Classifications.FalsePositives) > 0 {
  185. return true
  186. }
  187. }
  188. return false
  189. }
  190. func (c *FireItem) GetAttackDetails() []string {
  191. var ret []string = make([]string, 0)
  192. if c.AttackDetails != nil {
  193. for _, b := range c.AttackDetails {
  194. ret = append(ret, b.Name)
  195. }
  196. }
  197. return ret
  198. }
  199. func (c *FireItem) GetBehaviors() []string {
  200. var ret []string = make([]string, 0)
  201. if c.Behaviors != nil {
  202. for _, b := range c.Behaviors {
  203. ret = append(ret, b.Name)
  204. }
  205. }
  206. return ret
  207. }
  208. // Provide the likelihood of the IP being bad
  209. func (c *FireItem) GetMaliciousnessScore() float32 {
  210. if c.IsPartOfCommunityBlocklist() {
  211. return 1.0
  212. }
  213. if c.Scores.LastDay.Total > 0 {
  214. return float32(c.Scores.LastDay.Total) / 10.0
  215. }
  216. return 0.0
  217. }
  218. func (c *FireItem) IsPartOfCommunityBlocklist() bool {
  219. if c.Classifications.Classifications != nil {
  220. for _, v := range c.Classifications.Classifications {
  221. if v.Name == "community-blocklist" {
  222. return true
  223. }
  224. }
  225. }
  226. return false
  227. }
  228. func (c *FireItem) GetBackgroundNoiseScore() int {
  229. if c.BackgroundNoiseScore != nil {
  230. return *c.BackgroundNoiseScore
  231. }
  232. return 0
  233. }
  234. func (c *FireItem) GetFalsePositives() []string {
  235. var ret []string = make([]string, 0)
  236. if c.Classifications.FalsePositives != nil {
  237. for _, b := range c.Classifications.FalsePositives {
  238. ret = append(ret, b.Name)
  239. }
  240. }
  241. return ret
  242. }
  243. func (c *FireItem) IsFalsePositive() bool {
  244. if c.Classifications.FalsePositives != nil {
  245. if len(c.Classifications.FalsePositives) > 0 {
  246. return true
  247. }
  248. }
  249. return false
  250. }