Skip to content

Commit 3c12f6e

Browse files
Merge pull request #452 from wazuh/dev-mitre-framework-4036
New endpoint for Mitre
2 parents 8739852 + 8002848 commit 3c12f6e

File tree

6 files changed

+861
-4
lines changed

6 files changed

+861
-4
lines changed

CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ All notable changes to this project will be documented in this file.
33

44
## [v3.13.0]
55

6-
- New API request to add SOC complicance support: [commit](https://github.com/wazuh/wazuh-api/commit/719563a6e18581a2c062ba0f6a950730ac74222d).
7-
* `GET/rules/tsc`
6+
### Added
7+
8+
- New API requests:
9+
* `GET/mitre` ([#452](https://github.com/wazuh/wazuh-api/pull/452))
10+
* `GET/rules/tsc` (Add SOC complicance support: [commit](https://github.com/wazuh/wazuh-api/commit/719563a6e18581a2c062ba0f6a950730ac74222d).)
11+
812
- New filters in request `GET/rules`:
13+
- `mitre`: Filters the rules by mitre requirement
914
- `tsc`: Filters the rules by tsc requirement
1015

1116
## [v3.12.3]

controllers/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ router.use('/ciscat', require('./ciscat'));
8787
router.use('/active-response', require('./active_response'));
8888
router.use('/lists', require('./lists'));
8989
router.use('/summary', require('./summary'));
90+
router.use('/mitre', require('./mitre'));
9091

9192
if (config.experimental_features){
9293
router.use('/experimental', require('./experimental'));

controllers/mitre.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Wazuh RESTful API
3+
* Copyright (C) 2015-2019 Wazuh, Inc. All rights reserved.
4+
* Wazuh.com
5+
*
6+
* This program is a free software; you can redistribute it
7+
* and/or modify it under the terms of the GNU General Public
8+
* License (version 2) as published by the FSF - Free Software
9+
* Foundation.
10+
*/
11+
12+
13+
var router = require('express').Router();
14+
15+
/**
16+
* @api {get} /mitre Get information from Mitre database
17+
* @apiName GetMitre
18+
* @apiGroup Info
19+
*
20+
* @apiParam {Number} [offset] First element to return in the collection.
21+
* @apiParam {Number} [limit=10] Maximum number of elements to return.
22+
* @apiParam {String} [sort] Sorts the collection by a field or fields (separated by comma). Use +/- at the beginning to list in ascending or descending order.
23+
* @apiParam {String} [select] List of selected fields separated by commas.
24+
* @apiParam {String} [q] Query to filter results by. For example q="id=T1010"
25+
* @apiParam {String} [id] Filter by attack ID.
26+
* @apiParam {String} [phase_name] Filter by phase name.
27+
* @apiParam {String} [platform_name] Filter by platform name.
28+
* @apiParam {String} [search] Looks for elements with the specified string.
29+
*
30+
* @apiDescription Returns information from Mitre database
31+
*
32+
* @apiExample {curl} Example usage*:
33+
* curl -u foo:bar -k -X GET "https://127.0.0.1:55000/mitre?limit=2&offset=4&pretty"
34+
*
35+
*/
36+
router.get('/', cache(), function(req, res) {
37+
logger.debug(req.connection.remoteAddress + " GET /mitre");
38+
39+
req.apicacheGroup = "mitre";
40+
41+
var data_request = {'function': '/mitre', 'arguments': {}};
42+
var filters = {'offset': 'numbers', 'limit': 'numbers', 'q': 'query_param',
43+
'id': 'search_param', 'phase_name': 'search_param',
44+
'platform_name': 'names', 'search': 'search_param', 'sort':'sort_param', 'select': 'select_param'};
45+
46+
if (!filter.check(req.query, filters, req, res)) // Filter with error
47+
return;
48+
49+
if ('offset' in req.query)
50+
data_request['arguments']['offset'] = Number(req.query.offset);
51+
if ('limit' in req.query)
52+
data_request['arguments']['limit'] = Number(req.query.limit);
53+
if ('id' in req.query)
54+
data_request['arguments']['id'] = req.query.id;
55+
if ('phase_name' in req.query)
56+
data_request['arguments']['phase_name'] = req.query.phase_name;
57+
if ('platform_name' in req.query)
58+
data_request['arguments']['platform_name'] = req.query.platform_name;
59+
if ('search' in req.query)
60+
data_request['arguments']['search'] = filter.search_param_to_json(req.query.search);
61+
if ('sort' in req.query)
62+
data_request['arguments']['sort'] = filter.sort_param_to_json(req.query.sort);
63+
if ('select' in req.query)
64+
data_request['arguments']['select'] = filter.select_param_to_json(req.query.select);
65+
if ('q' in req.query)
66+
data_request['arguments']['q'] = req.query.q;
67+
68+
execute.exec(python_bin, [wazuh_control], data_request, function (data) { res_h.send(req, res, data); });
69+
})
70+
71+
module.exports = router;

controllers/rules.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var router = require('express').Router();
3131
* @apiParam {String} [hipaa] Filters the rules by hipaa requirement.
3232
* @apiParam {String} [nist-800-53] Filters the rules by nist-800-53 requirement.
3333
* @apiParam {String} [gpg13] Filters the rules by gpg13 requirement.
34+
* @apiParam {String} [mitre] Filters the rules by mitre requirement.
3435
* @apiParam {String} [tsc] Filters the rules by tsc requirement.
3536
* @apiParam {String} [q] Query to filter results by. For example q=id=89055
3637
*
@@ -45,7 +46,8 @@ router.get('/', cache(), function(req, res) {
4546
query_checks = {'status':'alphanumeric_param', 'group':'alphanumeric_param',
4647
'level':'ranges', 'path':'paths', 'file':'alphanumeric_param', 'pci':'alphanumeric_param',
4748
'gdpr': 'alphanumeric_param', 'hipaa': 'alphanumeric_param',
48-
'nist-800-53': 'alphanumeric_param', 'gpg13': 'alphanumeric_param', 'tsc': 'alphanumeric_param'};
49+
'nist-800-53': 'alphanumeric_param', 'gpg13': 'alphanumeric_param', 'tsc': 'alphanumeric_param',
50+
'mitre': 'alphanumeric_param'};
4951

5052
templates.array_request('/rules', req, res, "rules", param_checks, query_checks);
5153
})
@@ -327,6 +329,46 @@ router.get('/tsc', cache(), function(req, res) {
327329
execute.exec(python_bin, [wazuh_control], data_request, function (data) { res_h.send(req, res, data); });
328330
})
329331

332+
/**
333+
* @api {get} /rules/mitre Get rule mitre requirements
334+
* @apiName GetRulesMitre
335+
* @apiGroup Info
336+
*
337+
* @apiParam {Number} [offset] First element to return in the collection.
338+
* @apiParam {Number} [limit=500] Maximum number of elements to return.
339+
* @apiParam {String} [sort] Sorts the collection by a field or fields (separated by comma). Use +/- at the beginning to list in ascending or descending order.
340+
* @apiParam {String} [search] Looks for elements with the specified string.
341+
*
342+
* @apiDescription Returns the Mitre requirements of all rules.
343+
*
344+
* @apiExample {curl} Example usage:
345+
* curl -u foo:bar -k -X GET "https://127.0.0.1:55000/rules/Mitre?offset=0&limit=2&pretty"
346+
*
347+
*/
348+
router.get('/mitre', cache(), function(req, res) {
349+
logger.debug(req.connection.remoteAddress + " GET /rules/mitre");
350+
351+
req.apicacheGroup = "rules";
352+
353+
var data_request = {'function': '/rules/mitre', 'arguments': {}};
354+
var filters = {'offset': 'numbers', 'limit': 'numbers', 'sort':'sort_param', 'search':'search_param'};
355+
356+
if (!filter.check(req.query, filters, req, res)) // Filter with error
357+
return;
358+
359+
if ('offset' in req.query)
360+
data_request['arguments']['offset'] = Number(req.query.offset);
361+
if ('limit' in req.query)
362+
data_request['arguments']['limit'] = Number(req.query.limit);
363+
if ('sort' in req.query)
364+
data_request['arguments']['sort'] = filter.sort_param_to_json(req.query.sort);
365+
if ('search' in req.query)
366+
data_request['arguments']['search'] = filter.search_param_to_json(req.query.search);
367+
368+
execute.exec(python_bin, [wazuh_control], data_request, function (data) { res_h.send(req, res, data); });
369+
})
370+
371+
330372
/**
331373
* @api {get} /rules/files Get files of rules
332374
* @apiName GetRulesFiles

0 commit comments

Comments
 (0)