misp-modules 2.4.196__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. misp_modules/__init__.py +379 -0
  2. misp_modules/helpers/__init__.py +1 -0
  3. misp_modules/helpers/cache.py +84 -0
  4. misp_modules/lib/__init__.py +4 -0
  5. misp_modules/lib/_vmray/__init__.py +0 -0
  6. misp_modules/lib/_vmray/parser.py +1417 -0
  7. misp_modules/lib/_vmray/rest_api.py +148 -0
  8. misp_modules/lib/cof2misp/LICENSE-2.0.txt +202 -0
  9. misp_modules/lib/cof2misp/__init__.py +0 -0
  10. misp_modules/lib/cof2misp/cof.py +165 -0
  11. misp_modules/lib/joe_mapping.py +114 -0
  12. misp_modules/lib/joe_parser.py +573 -0
  13. misp_modules/lib/lastline_api.py +841 -0
  14. misp_modules/lib/qintel_helper.py +263 -0
  15. misp_modules/lib/stix2misp.py +2080 -0
  16. misp_modules/lib/stix2misp_mapping.py +460 -0
  17. misp_modules/lib/synonymsToTagNames.json +1 -0
  18. misp_modules/lib/vt_graph_parser/__init__.py +8 -0
  19. misp_modules/lib/vt_graph_parser/errors.py +20 -0
  20. misp_modules/lib/vt_graph_parser/helpers/__init__.py +7 -0
  21. misp_modules/lib/vt_graph_parser/helpers/parsers.py +88 -0
  22. misp_modules/lib/vt_graph_parser/helpers/rules.py +304 -0
  23. misp_modules/lib/vt_graph_parser/helpers/wrappers.py +58 -0
  24. misp_modules/lib/vt_graph_parser/importers/__init__.py +7 -0
  25. misp_modules/lib/vt_graph_parser/importers/base.py +98 -0
  26. misp_modules/lib/vt_graph_parser/importers/pymisp_response.py +73 -0
  27. misp_modules/modules/__init__.py +4 -0
  28. misp_modules/modules/action_mod/__init__.py +1 -0
  29. misp_modules/modules/action_mod/_utils/__init__.py +1 -0
  30. misp_modules/modules/action_mod/_utils/utils.py +70 -0
  31. misp_modules/modules/action_mod/mattermost.py +113 -0
  32. misp_modules/modules/action_mod/slack.py +96 -0
  33. misp_modules/modules/action_mod/testaction.py +68 -0
  34. misp_modules/modules/expansion/__init__.py +36 -0
  35. misp_modules/modules/expansion/_dnsdb_query/COPYRIGHT +27 -0
  36. misp_modules/modules/expansion/_dnsdb_query/LICENSE +202 -0
  37. misp_modules/modules/expansion/_dnsdb_query/README.md +162 -0
  38. misp_modules/modules/expansion/_dnsdb_query/__init__.py +0 -0
  39. misp_modules/modules/expansion/_dnsdb_query/dnsdb_query.py +327 -0
  40. misp_modules/modules/expansion/_ransomcoindb/__init__.py +0 -0
  41. misp_modules/modules/expansion/_ransomcoindb/ransomcoindb.py +96 -0
  42. misp_modules/modules/expansion/_vulnerability_parser/__init__.py +0 -0
  43. misp_modules/modules/expansion/_vulnerability_parser/vulnerability_parser.py +118 -0
  44. misp_modules/modules/expansion/abuseipdb.py +146 -0
  45. misp_modules/modules/expansion/apiosintds.py +365 -0
  46. misp_modules/modules/expansion/apivoid.py +133 -0
  47. misp_modules/modules/expansion/assemblyline_query.py +179 -0
  48. misp_modules/modules/expansion/assemblyline_submit.py +100 -0
  49. misp_modules/modules/expansion/backscatter_io.py +84 -0
  50. misp_modules/modules/expansion/btc_scam_check.py +54 -0
  51. misp_modules/modules/expansion/btc_steroids.py +238 -0
  52. misp_modules/modules/expansion/censys_enrich.py +287 -0
  53. misp_modules/modules/expansion/circl_passivedns.py +85 -0
  54. misp_modules/modules/expansion/circl_passivessl.py +113 -0
  55. misp_modules/modules/expansion/clamav.py +129 -0
  56. misp_modules/modules/expansion/cluster25_expand.py +239 -0
  57. misp_modules/modules/expansion/countrycode.py +69 -0
  58. misp_modules/modules/expansion/cpe.py +140 -0
  59. misp_modules/modules/expansion/crowdsec.py +235 -0
  60. misp_modules/modules/expansion/crowdstrike_falcon.py +148 -0
  61. misp_modules/modules/expansion/cuckoo_submit.py +161 -0
  62. misp_modules/modules/expansion/cve.py +57 -0
  63. misp_modules/modules/expansion/cve_advanced.py +185 -0
  64. misp_modules/modules/expansion/cytomic_orion.py +196 -0
  65. misp_modules/modules/expansion/dbl_spamhaus.py +78 -0
  66. misp_modules/modules/expansion/dns.py +71 -0
  67. misp_modules/modules/expansion/docx_enrich.py +71 -0
  68. misp_modules/modules/expansion/domaintools.py +290 -0
  69. misp_modules/modules/expansion/eql.py +91 -0
  70. misp_modules/modules/expansion/eupi.py +86 -0
  71. misp_modules/modules/expansion/extract_url_components.py +83 -0
  72. misp_modules/modules/expansion/farsight_passivedns.py +243 -0
  73. misp_modules/modules/expansion/geoip_asn.py +75 -0
  74. misp_modules/modules/expansion/geoip_city.py +75 -0
  75. misp_modules/modules/expansion/geoip_country.py +73 -0
  76. misp_modules/modules/expansion/google_safe_browsing.py +86 -0
  77. misp_modules/modules/expansion/google_search.py +57 -0
  78. misp_modules/modules/expansion/google_threat_intelligence.py +453 -0
  79. misp_modules/modules/expansion/greynoise.py +346 -0
  80. misp_modules/modules/expansion/hashdd.py +53 -0
  81. misp_modules/modules/expansion/hashlookup.py +118 -0
  82. misp_modules/modules/expansion/hibp.py +62 -0
  83. misp_modules/modules/expansion/html_to_markdown.py +63 -0
  84. misp_modules/modules/expansion/hyasinsight.py +881 -0
  85. misp_modules/modules/expansion/intel471.py +73 -0
  86. misp_modules/modules/expansion/intelmq_eventdb.py.experimental +67 -0
  87. misp_modules/modules/expansion/ip2locationio.py +90 -0
  88. misp_modules/modules/expansion/ipasn.py +70 -0
  89. misp_modules/modules/expansion/ipinfo.py +112 -0
  90. misp_modules/modules/expansion/ipqs_fraud_and_risk_scoring.py +633 -0
  91. misp_modules/modules/expansion/iprep.py +98 -0
  92. misp_modules/modules/expansion/jinja_template_rendering.py +54 -0
  93. misp_modules/modules/expansion/joesandbox_query.py +91 -0
  94. misp_modules/modules/expansion/joesandbox_submit.py +147 -0
  95. misp_modules/modules/expansion/lastline_query.py +148 -0
  96. misp_modules/modules/expansion/lastline_submit.py +180 -0
  97. misp_modules/modules/expansion/macaddress_io.py +130 -0
  98. misp_modules/modules/expansion/macvendors.py +55 -0
  99. misp_modules/modules/expansion/malshare_upload.py +107 -0
  100. misp_modules/modules/expansion/malwarebazaar.py +67 -0
  101. misp_modules/modules/expansion/mcafee_insights_enrich.py +249 -0
  102. misp_modules/modules/expansion/mmdb_lookup.py +138 -0
  103. misp_modules/modules/expansion/module.py.skeleton +44 -0
  104. misp_modules/modules/expansion/mwdb.py +152 -0
  105. misp_modules/modules/expansion/ocr_enrich.py +74 -0
  106. misp_modules/modules/expansion/ods_enrich.py +71 -0
  107. misp_modules/modules/expansion/odt_enrich.py +61 -0
  108. misp_modules/modules/expansion/onyphe.py +243 -0
  109. misp_modules/modules/expansion/onyphe_full.py +387 -0
  110. misp_modules/modules/expansion/otx.py +167 -0
  111. misp_modules/modules/expansion/passive_ssh.py +150 -0
  112. misp_modules/modules/expansion/passivetotal.py +358 -0
  113. misp_modules/modules/expansion/pdf_enrich.py +58 -0
  114. misp_modules/modules/expansion/pptx_enrich.py +65 -0
  115. misp_modules/modules/expansion/qintel_qsentry.py +229 -0
  116. misp_modules/modules/expansion/qrcode.py +99 -0
  117. misp_modules/modules/expansion/ransomcoindb.py +82 -0
  118. misp_modules/modules/expansion/rbl.py +126 -0
  119. misp_modules/modules/expansion/recordedfuture.py +544 -0
  120. misp_modules/modules/expansion/reversedns.py +77 -0
  121. misp_modules/modules/expansion/securitytrails.py +571 -0
  122. misp_modules/modules/expansion/shodan.py +244 -0
  123. misp_modules/modules/expansion/sigma_queries.py +61 -0
  124. misp_modules/modules/expansion/sigma_syntax_validator.py +49 -0
  125. misp_modules/modules/expansion/sigmf_expand.py +303 -0
  126. misp_modules/modules/expansion/socialscan.py +108 -0
  127. misp_modules/modules/expansion/sophoslabs_intelix.py +146 -0
  128. misp_modules/modules/expansion/sourcecache.py +57 -0
  129. misp_modules/modules/expansion/stairwell.py +156 -0
  130. misp_modules/modules/expansion/stix2_pattern_syntax_validator.py +56 -0
  131. misp_modules/modules/expansion/threatcrowd.py +170 -0
  132. misp_modules/modules/expansion/threatfox.py +75 -0
  133. misp_modules/modules/expansion/threatminer.py +152 -0
  134. misp_modules/modules/expansion/triage_submit.py +119 -0
  135. misp_modules/modules/expansion/trustar_enrich.py +235 -0
  136. misp_modules/modules/expansion/urlhaus.py +164 -0
  137. misp_modules/modules/expansion/urlscan.py +269 -0
  138. misp_modules/modules/expansion/variotdbs.py +133 -0
  139. misp_modules/modules/expansion/virustotal.py +311 -0
  140. misp_modules/modules/expansion/virustotal_public.py +272 -0
  141. misp_modules/modules/expansion/virustotal_upload.py +91 -0
  142. misp_modules/modules/expansion/vmray_submit.py +161 -0
  143. misp_modules/modules/expansion/vmware_nsx.py +628 -0
  144. misp_modules/modules/expansion/vulndb.py +292 -0
  145. misp_modules/modules/expansion/vulnerability_lookup.py +324 -0
  146. misp_modules/modules/expansion/vulners.py +81 -0
  147. misp_modules/modules/expansion/vysion.py +221 -0
  148. misp_modules/modules/expansion/whois.py +72 -0
  149. misp_modules/modules/expansion/whoisfreaks.py +232 -0
  150. misp_modules/modules/expansion/wiki.py +58 -0
  151. misp_modules/modules/expansion/xforceexchange.py +189 -0
  152. misp_modules/modules/expansion/xlsx_enrich.py +63 -0
  153. misp_modules/modules/expansion/yara_query.py +70 -0
  154. misp_modules/modules/expansion/yara_syntax_validator.py +49 -0
  155. misp_modules/modules/expansion/yeti.py +196 -0
  156. misp_modules/modules/export_mod/__init__.py +3 -0
  157. misp_modules/modules/export_mod/cef_export.py +93 -0
  158. misp_modules/modules/export_mod/cisco_firesight_manager_ACL_rule_export.py +150 -0
  159. misp_modules/modules/export_mod/defender_endpoint_export.py +141 -0
  160. misp_modules/modules/export_mod/goamlexport.py +255 -0
  161. misp_modules/modules/export_mod/liteexport.py +97 -0
  162. misp_modules/modules/export_mod/mass_eql_export.py +106 -0
  163. misp_modules/modules/export_mod/nexthinkexport.py +131 -0
  164. misp_modules/modules/export_mod/osqueryexport.py +125 -0
  165. misp_modules/modules/export_mod/pdfexport.py +107 -0
  166. misp_modules/modules/export_mod/testexport.py +73 -0
  167. misp_modules/modules/export_mod/threatStream_misp_export.py +114 -0
  168. misp_modules/modules/export_mod/threat_connect_export.py +125 -0
  169. misp_modules/modules/export_mod/virustotal_collections.py +141 -0
  170. misp_modules/modules/export_mod/vt_graph.py +120 -0
  171. misp_modules/modules/export_mod/yara_export.py +290 -0
  172. misp_modules/modules/import_mod/__init__.py +22 -0
  173. misp_modules/modules/import_mod/cof2misp.py +264 -0
  174. misp_modules/modules/import_mod/csvimport.py +319 -0
  175. misp_modules/modules/import_mod/cuckooimport.py +749 -0
  176. misp_modules/modules/import_mod/email_import.py +294 -0
  177. misp_modules/modules/import_mod/goamlimport.py +188 -0
  178. misp_modules/modules/import_mod/import_blueprint.py +93 -0
  179. misp_modules/modules/import_mod/joe_import.py +74 -0
  180. misp_modules/modules/import_mod/lastline_import.py +160 -0
  181. misp_modules/modules/import_mod/mispjson.py +73 -0
  182. misp_modules/modules/import_mod/ocr.py +122 -0
  183. misp_modules/modules/import_mod/openiocimport.py +99 -0
  184. misp_modules/modules/import_mod/taxii21.py +383 -0
  185. misp_modules/modules/import_mod/testimport.py +73 -0
  186. misp_modules/modules/import_mod/threatanalyzer_import.py +552 -0
  187. misp_modules/modules/import_mod/url_import.py +97 -0
  188. misp_modules/modules/import_mod/vmray_import.py +96 -0
  189. misp_modules/modules/import_mod/vmray_summary_json_import.py +87 -0
  190. misp_modules-2.4.196.dist-info/LICENSE +661 -0
  191. misp_modules-2.4.196.dist-info/METADATA +281 -0
  192. misp_modules-2.4.196.dist-info/RECORD +194 -0
  193. misp_modules-2.4.196.dist-info/WHEEL +4 -0
  194. misp_modules-2.4.196.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/python3
2
+ """Python client library for VMRay REST API"""
3
+
4
+ import base64
5
+ import datetime
6
+ import os.path
7
+ import requests
8
+ import urllib.parse
9
+
10
+ # disable nasty certification warning
11
+ # pylint: disable=no-member
12
+ try:
13
+ requests.packages.urllib3.disable_warnings()
14
+ except AttributeError:
15
+ try:
16
+ import urllib3
17
+ try:
18
+ urllib3.disable_warnings()
19
+ except AttributeError:
20
+ pass
21
+ except ImportError:
22
+ pass
23
+
24
+ # pylint: disable=
25
+
26
+
27
+ class VMRayRESTAPIError(Exception):
28
+ """Exception class that is used when API returns an error"""
29
+
30
+ def __init__(self, *args, **kwargs):
31
+ self.status_code = kwargs.pop("status_code", None)
32
+ Exception.__init__(self, *args, **kwargs)
33
+
34
+
35
+ def handle_rest_api_result(result):
36
+ """Handle result of API request (check for errors)"""
37
+
38
+ if (result.status_code < 200) or (result.status_code > 299):
39
+ try:
40
+ json_result = result.json()
41
+ except ValueError:
42
+ raise VMRayRESTAPIError("API returned error %u: %s" % (result.status_code, result.text), status_code=result.status_code)
43
+
44
+ raise VMRayRESTAPIError(json_result.get("error_msg", "Unknown error"), status_code=result.status_code)
45
+
46
+
47
+ class VMRayRESTAPI(object):
48
+ """VMRay REST API class"""
49
+
50
+ def __init__(self, server, api_key, verify_cert=True):
51
+ # split server URL into components
52
+ url_desc = urllib.parse.urlsplit(server)
53
+
54
+ # assume HTTPS if no scheme is specified
55
+ if url_desc.scheme == "":
56
+ server = "https://" + server
57
+
58
+ # save variables
59
+ self.server = server
60
+ self.api_key = api_key
61
+ self.verify_cert = verify_cert
62
+
63
+ def call(self, http_method, api_path, params=None, raw_data=False):
64
+ """Call VMRay REST API"""
65
+
66
+ # get function of requests package
67
+ requests_func = getattr(requests, http_method.lower())
68
+
69
+ # parse parameters
70
+ req_params = {}
71
+ file_params = {}
72
+
73
+ if params is not None:
74
+ for key, value in params.items():
75
+ if isinstance(value, (datetime.date,
76
+ datetime.datetime,
77
+ float,
78
+ int)):
79
+ req_params[key] = str(value)
80
+ elif isinstance(value, str):
81
+ req_params[key] = str(value)
82
+ elif isinstance(value, dict):
83
+ filename = value["filename"]
84
+ sample = value["data"]
85
+ file_params[key] = (filename, sample, "application/octet-stream")
86
+ elif hasattr(value, "read"):
87
+ filename = os.path.split(value.name)[1]
88
+ # For the following block refer to DEV-1820
89
+ try:
90
+ filename.decode("ASCII")
91
+ except (UnicodeDecodeError, UnicodeEncodeError):
92
+ b64_key = key + "name_b64enc"
93
+ byte_value = filename.encode("utf-8")
94
+ b64_value = base64.b64encode(byte_value)
95
+
96
+ filename = "@param=%s" % b64_key
97
+ req_params[b64_key] = b64_value
98
+ file_params[key] = (filename, value, "application/octet-stream")
99
+ else:
100
+ raise VMRayRESTAPIError("Parameter \"%s\" has unknown type \"%s\"" % (key, type(value)))
101
+
102
+ # construct request
103
+ if file_params:
104
+ files = file_params
105
+ else:
106
+ files = None
107
+
108
+ # we need to adjust some stuff for POST requests
109
+ if http_method.lower() == "post":
110
+ req_data = req_params
111
+ req_params = None
112
+ else:
113
+ req_data = None
114
+
115
+ # do request
116
+ result = requests_func(self.server + api_path, data=req_data, params=req_params, headers={"Authorization": "api_key " + self.api_key}, files=files, verify=self.verify_cert, stream=raw_data)
117
+ handle_rest_api_result(result)
118
+
119
+ if raw_data:
120
+ return result.raw
121
+
122
+ # parse result
123
+ try:
124
+ json_result = result.json()
125
+ except ValueError:
126
+ raise ValueError("API returned invalid JSON: %s" % (result.text))
127
+
128
+ # if there are no cached elements then return the data
129
+ if "continuation_id" not in json_result:
130
+ return json_result.get("data", None)
131
+
132
+ data = json_result["data"]
133
+
134
+ # get cached results
135
+ while "continuation_id" in json_result:
136
+ # send request to server
137
+ result = requests.get("%s/rest/continuation/%u" % (self.server, json_result["continuation_id"]), headers={"Authorization": "api_key " + self.api_key}, verify=self.verify_cert)
138
+ handle_rest_api_result(result)
139
+
140
+ # parse result
141
+ try:
142
+ json_result = result.json()
143
+ except ValueError:
144
+ raise ValueError("API returned invalid JSON: %s" % (result.text))
145
+
146
+ data.extend(json_result["data"])
147
+
148
+ return data
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
File without changes
@@ -0,0 +1,165 @@
1
+ """
2
+ Common Output Format for passive DNS library.
3
+
4
+ Copyright 2021: Farsight Security (https://www.farsightsecurity.com/)
5
+
6
+ Author: Aaron Kaplan <aaron@lo-res.org>
7
+
8
+ Released under the Apache 2.0 license.
9
+ See: https://www.apache.org/licenses/LICENSE-2.0.txt
10
+
11
+ """
12
+
13
+ import ipaddress
14
+ import sys
15
+ import ndjson
16
+
17
+
18
+ def is_valid_ip(ip: str) -> bool:
19
+ """Check if an IP address given as string would be convertible to
20
+ an ipaddress object (and thus if it is a valid IP).
21
+
22
+ Returns
23
+ --------
24
+ True on success, False on validation failure.
25
+ """
26
+
27
+ try:
28
+ ipaddress.ip_address(ip)
29
+ except Exception as ex:
30
+ print("is_valid_ip(%s) returned False. Reason: %s" % (ip, str(ex)), file = sys.stderr)
31
+ return False
32
+ return True
33
+
34
+
35
+ def is_cof_valid_strict(d: dict) -> bool:
36
+ """Check the COF - do the full JSON schema validation.
37
+
38
+ Returns
39
+ --------
40
+ True on success, False on validation failure.
41
+ """
42
+ return True # FIXME
43
+
44
+
45
+ def is_cof_valid_simple(d: dict) -> bool:
46
+ """Check MANDATORY fields according to COF - simple check, do not do the full JSON schema validation.
47
+
48
+ Returns
49
+ --------
50
+ True on success, False on validation failure.
51
+ """
52
+
53
+ if "rrname" not in d:
54
+ print("Missing MANDATORY field 'rrname'", file = sys.stderr)
55
+ return False
56
+ if not isinstance(d['rrname'], str):
57
+ print("Type error: 'rrname' is not a JSON string", file = sys.stderr)
58
+ return False
59
+ if "rrtype" not in d:
60
+ print("Missing MANDATORY field 'rrtype'", file = sys.stderr)
61
+ return False
62
+ if not isinstance(d['rrtype'], str):
63
+ print("Type error: 'rrtype' is not a JSON string", file = sys.stderr)
64
+ return False
65
+ if "rdata" not in d:
66
+ print("Missing MANDATORY field 'rdata'", file = sys.stderr)
67
+ return False
68
+ if "rdata" not in d:
69
+ print("Missing MANDATORY field 'rdata'", file = sys.stderr)
70
+ return False
71
+ if not isinstance(d['rdata'], str) and not isinstance(d['rdata'], list):
72
+ print("'rdata' is not a list and not a string.", file = sys.stderr)
73
+ return False
74
+ if not ("time_first" in d and "time_last" in d) or ("zone_time_first" in d and "zone_time_last" in d):
75
+ print("We are missing EITHER ('first_seen' and 'last_seen') OR ('zone_time_first' and zone_time_last') fields",
76
+ file = sys.stderr)
77
+ return False
78
+ # currently we don't check the OPTIONAL fields. Sorry... to be done later.
79
+ return True
80
+
81
+
82
+ def validate_cof(d: dict, strict=True) -> bool:
83
+ """Validate an input passive DNS COF (given as dict).
84
+ strict might be set to False in order to loosen the checking.
85
+ With strict==True, a full JSON Schema validation will happen.
86
+
87
+
88
+ Returns
89
+ --------
90
+ True on success, False on validation failure.
91
+ """
92
+ if not strict:
93
+ return is_cof_valid_simple(d)
94
+ else:
95
+ return is_cof_valid_strict(d)
96
+
97
+
98
+ def validate_dnsdbflex(d: dict, strict=True) -> bool:
99
+ """
100
+ Validate if dict d is valid dnsdbflex. It should looks like this:
101
+ { "rrtype": <str>, "rrname": <str> }
102
+ """
103
+ if "rrname" not in d:
104
+ print("Missing MANDATORY field 'rrname'", file = sys.stderr)
105
+ return False
106
+ if not isinstance(d['rrname'], str):
107
+ print("Type error: 'rrname' is not a JSON string", file = sys.stderr)
108
+ return False
109
+ if "rrtype" not in d:
110
+ print("Missing MANDATORY field 'rrtype'", file = sys.stderr)
111
+ return False
112
+ if not isinstance(d['rrtype'], str):
113
+ print("Type error: 'rrtype' is not a JSON string", file = sys.stderr)
114
+ return False
115
+ return True
116
+
117
+
118
+ if __name__ == "__main__":
119
+ # simple, poor man's unit tests.
120
+
121
+ print(80 * "=", file = sys.stderr)
122
+ print("Unit Tests:", file = sys.stderr)
123
+ assert not is_valid_ip("a.2.3.4")
124
+ assert is_valid_ip("99.88.77.6")
125
+ assert is_valid_ip("2a0c:88:77:6::1")
126
+
127
+ # COF validation
128
+ print(80 * "=", file = sys.stderr)
129
+ print("COF unit tests....", file = sys.stderr)
130
+
131
+ mock_input = """{"count":1909,"rdata":["cpa.circl.lu"],"rrname":"www.circl.lu","rrtype":"CNAME","time_first":"1315586409","time_last":"1449566799"}
132
+ {"count":2560,"rdata":["cpab.circl.lu"],"rrname":"www.circl.lu","rrtype":"CNAME","time_first":"1449584660","time_last":"1617676151"}"""
133
+
134
+ i = 0
135
+ for entry in ndjson.loads(mock_input):
136
+ retval = validate_cof(entry, strict = False)
137
+ assert retval
138
+ print("line %d is valid: %s" % (i, retval))
139
+ i += 1
140
+
141
+ test2 = '{"count": 2, "time_first": 1619556027, "time_last": 1619556034, "rrname": "westernunion.com.ph.unblock-all.com.beta.opera-mini.net.", "rrtype": "A", "bailiwick": "beta.opera-mini.net.", "rdata": ["185.26.181.253"]}'
142
+ for entry in ndjson.loads(test2):
143
+ assert validate_cof(entry)
144
+
145
+ # dnsdbflex validation
146
+ print(80 * "=", file = sys.stderr)
147
+ print("dnsdbflex unit tests....", file = sys.stderr)
148
+
149
+ mock_input = """{"rrname":"labs.deep-insights.ai.","rrtype":"A"}
150
+ {"rrname":"www.deep-insights.ca.","rrtype":"CNAME"}
151
+ {"rrname":"mail.deep-insights.ca.","rrtype":"CNAME"}
152
+ {"rrname":"cpanel.deep-insights.ca.","rrtype":"A"}
153
+ {"rrname":"webdisk.deep-insights.ca.","rrtype":"A"}
154
+ {"rrname":"webmail.deep-insights.ca.","rrtype":"A"}"""
155
+
156
+ i = 0
157
+ for entry in ndjson.loads(mock_input):
158
+ retval = validate_dnsdbflex(entry, strict = False)
159
+ assert retval
160
+ print("dnsdbflex line %d is valid: %s" % (i, retval))
161
+ i += 1
162
+
163
+
164
+ print(80 * "=", file = sys.stderr)
165
+ print("Unit Tests DONE", file = sys.stderr)
@@ -0,0 +1,114 @@
1
+ arch_type_mapping = {
2
+ 'ANDROID': 'parse_apk',
3
+ 'LINUX': 'parse_elf',
4
+ 'WINDOWS': 'parse_pe'
5
+ }
6
+ domain_object_mapping = {
7
+ '@ip': {'type': 'ip-dst', 'object_relation': 'ip'},
8
+ '@name': {'type': 'domain', 'object_relation': 'domain'}
9
+ }
10
+ dropped_file_mapping = {
11
+ '@entropy': {'type': 'float', 'object_relation': 'entropy'},
12
+ '@file': {'type': 'filename', 'object_relation': 'filename'},
13
+ '@size': {'type': 'size-in-bytes', 'object_relation': 'size-in-bytes'},
14
+ '@type': {'type': 'mime-type', 'object_relation': 'mimetype'}
15
+ }
16
+ dropped_hash_mapping = {
17
+ 'MD5': 'md5',
18
+ 'SHA': 'sha1',
19
+ 'SHA-256': 'sha256',
20
+ 'SHA-512': 'sha512'
21
+ }
22
+ elf_object_mapping = {
23
+ 'epaddr': 'entrypoint-address',
24
+ 'machine': 'arch',
25
+ 'osabi': 'os_abi'
26
+ }
27
+ elf_section_flags_mapping = {
28
+ 'A': 'ALLOC',
29
+ 'I': 'INFO_LINK',
30
+ 'M': 'MERGE',
31
+ 'S': 'STRINGS',
32
+ 'T': 'TLS',
33
+ 'W': 'WRITE',
34
+ 'X': 'EXECINSTR'
35
+ }
36
+ file_object_fields = (
37
+ 'filename',
38
+ 'md5',
39
+ 'sha1',
40
+ 'sha256',
41
+ 'sha512',
42
+ 'ssdeep'
43
+ )
44
+ file_object_mapping = {
45
+ 'entropy': {'type': 'float', 'object_relation': 'entropy'},
46
+ 'filesize': {'type': 'size-in-bytes', 'object_relation': 'size-in-bytes'},
47
+ 'filetype': {'type': 'mime-type', 'object_relation': 'mimetype'}
48
+ }
49
+ file_references_mapping = {
50
+ 'fileCreated': 'creates',
51
+ 'fileDeleted': 'deletes',
52
+ 'fileMoved': 'moves',
53
+ 'fileRead': 'reads',
54
+ 'fileWritten': 'writes'
55
+ }
56
+ network_behavior_fields = ('srcip', 'dstip', 'srcport', 'dstport')
57
+ network_connection_object_mapping = {
58
+ 'srcip': {'type': 'ip-src', 'object_relation': 'ip-src'},
59
+ 'dstip': {'type': 'ip-dst', 'object_relation': 'ip-dst'},
60
+ 'srcport': {'type': 'port', 'object_relation': 'src-port'},
61
+ 'dstport': {'type': 'port', 'object_relation': 'dst-port'}
62
+ }
63
+ pe_object_fields = {
64
+ 'entrypoint': {'type': 'text', 'object_relation': 'entrypoint-address'},
65
+ 'imphash': {'type': 'imphash', 'object_relation': 'imphash'}
66
+ }
67
+ pe_object_mapping = {
68
+ 'CompanyName': 'company-name',
69
+ 'FileDescription': 'file-description',
70
+ 'FileVersion': 'file-version',
71
+ 'InternalName': 'internal-filename',
72
+ 'LegalCopyright': 'legal-copyright',
73
+ 'OriginalFilename': 'original-filename',
74
+ 'ProductName': 'product-filename',
75
+ 'ProductVersion': 'product-version',
76
+ 'Translation': 'lang-id'
77
+ }
78
+ pe_section_object_mapping = {
79
+ 'characteristics': {'type': 'text', 'object_relation': 'characteristic'},
80
+ 'entropy': {'type': 'float', 'object_relation': 'entropy'},
81
+ 'name': {'type': 'text', 'object_relation': 'name'},
82
+ 'rawaddr': {'type': 'hex', 'object_relation': 'offset'},
83
+ 'rawsize': {'type': 'size-in-bytes', 'object_relation': 'size-in-bytes'},
84
+ 'virtaddr': {'type': 'hex', 'object_relation': 'virtual_address'},
85
+ 'virtsize': {'type': 'size-in-bytes', 'object_relation': 'virtual_size'}
86
+ }
87
+ process_object_fields = {
88
+ 'cmdline': 'command-line',
89
+ 'name': 'name',
90
+ 'parentpid': 'parent-pid',
91
+ 'pid': 'pid',
92
+ 'path': 'current-directory'
93
+ }
94
+ protocols = {
95
+ 'tcp': 4,
96
+ 'udp': 4,
97
+ 'icmp': 3,
98
+ 'http': 7,
99
+ 'https': 7,
100
+ 'ftp': 7
101
+ }
102
+ registry_references_mapping = {
103
+ 'keyValueCreated': 'creates',
104
+ 'keyValueModified': 'modifies'
105
+ }
106
+ regkey_object_mapping = {
107
+ 'name': {'type': 'text', 'object_relation': 'name'},
108
+ 'newdata': {'type': 'text', 'object_relation': 'data'},
109
+ 'path': {'type': 'regkey', 'object_relation': 'key'}
110
+ }
111
+ signerinfo_object_mapping = {
112
+ 'sigissuer': {'type': 'text', 'object_relation': 'issuer'},
113
+ 'version': {'type': 'text', 'object_relation': 'version'}
114
+ }