Exemplo n.º 1
0
    def __init__(self):

        UpdateReactMapping()

        response_actions = []
        for ra_id, ra_name in ra_mapping.items():
            ra_color = ""
            category_score = int(ra_id[3:6])
            ra_category = REACTutils.get_ra_category(ra_id)

            for category_name, category_color in category_colors.items():
                if ra_category == category_name:
                    ra_color = category_color
                    break

            response_actions.append({
                "techniqueID": ra_id,
                "color": ra_color,
                "score": category_score,        # for sorting
            })

        NAVIGATOR_TEMPLATE['techniques'] = response_actions

        with open(directory + '/' + filename, 'w') as fp:
            json.dump(NAVIGATOR_TEMPLATE, fp)
        print(f'[+] Created {filename}')
Exemplo n.º 2
0
    def render_template(self, template_type):
        """Description
        template_type:
            - "markdown"
            - "confluence"
        """

        if template_type not in ["markdown", "confluence"]:
            raise Exception(
                "Bad template_type. Available values:" +
                " [\"markdown\", \"confluence\"]")

        #
        # PRE: Common for both Markdown and Confluence templates
        #

        self.ra_parsed_file.update(
            {'category': REACTutils.get_ra_category(self.ra_parsed_file
                .get('id'))}
        )

        self.ra_parsed_file.update(
            {'description': self.ra_parsed_file.get('description').strip()}
        )

        # Get proper template
        if template_type == "markdown":

            template = env.get_template(
                'markdown_responseaction_template.md.j2'
            )
    
            self.ra_parsed_file.update(
                {'title': REACTutils.normalize_react_title(self.ra_parsed_file
                    .get('title'),REACTConfig.get('titlefmtrules'))}
            )
    
            stage_list = []
            stage = self.ra_parsed_file.get('stage')
    
            for rs_id, rs_name in rs_mapping.items():
                if REACTutils.normalize_rs_name(stage) == rs_name:
                    stage_list.append((rs_id, rs_name))
    
            self.ra_parsed_file.update(
                {'stage': stage_list}
            )

        elif template_type == "confluence":

            template = env.get_template(
                'confluence_responseaction_template.html.j2')

            new_title = self.ra_parsed_file.get('id')\
                + ": "\
                + REACTutils.normalize_react_title(self.ra_parsed_file.get('title'),REACTConfig.get('titlefmtrules'))

            self.ra_parsed_file.update(
                {'title': new_title}
            )

            self.ra_parsed_file.update(
                {'confluence_viewpage_url': REACTConfig.get('confluence_viewpage_url')})

            ##
            ## Add link to a stage
            ##
            stage = self.ra_parsed_file.get('stage')
            rs_list = []
            for rs_id, rs_name in rs_mapping.items():
                if REACTutils.normalize_rs_name(stage) == rs_name:
                    if self.apipath and self.auth and self.space:
                        rs_confluence_page_name = rs_id + ": " + rs_name
                        rs_confluence_page_id = str(REACTutils.confluence_get_page_id(
                            self.apipath, self.auth, self.space, rs_confluence_page_name)
                        )
                        rs_list.append((rs_id, rs_name, rs_confluence_page_id))
                    else:
                        rs_confluence_page_id = ""
                        rs_list.append((rs_id, rs_name, rs_confluence_page_id))
                    break

            self.ra_parsed_file.update(
                    {'stage': rs_list}
            )

        #
        # POST: Common for both Markdown and Confluence templates
        #
        self.content = template.render(self.ra_parsed_file)