CR improvements: /report/ redirect to /report/security, component renaming and other small fixes

This commit is contained in:
VakarisZ 2019-12-03 10:53:25 +02:00
parent 605c993618
commit a3cae51a6b
8 changed files with 32 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import {BrowserRouter as Router, NavLink, Redirect, Route, Switch} from 'react-router-dom'; import {BrowserRouter as Router, NavLink, Redirect, Route, Switch, withRouter} from 'react-router-dom';
import {Col, Grid, Row} from 'react-bootstrap'; import {Col, Grid, Row} from 'react-bootstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCheck, faUndo } from '@fortawesome/free-solid-svg-icons' import { faCheck, faUndo } from '@fortawesome/free-solid-svg-icons'
@ -83,6 +83,13 @@ class AppComponent extends AuthComponent {
} }
}; };
redirectTo = (userPath, targetPath) => {
let pathQuery = new RegExp(userPath+"[\/]?$", "g");
if(window.location.pathname.match(pathQuery)){
return <Redirect to={{pathname: targetPath}}/>
}
};
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
@ -198,12 +205,12 @@ class AppComponent extends AuthComponent {
{this.renderRoute('/infection/map', <MapPage onStatusChange={this.updateStatus}/>)} {this.renderRoute('/infection/map', <MapPage onStatusChange={this.updateStatus}/>)}
{this.renderRoute('/infection/telemetry', <TelemetryPage onStatusChange={this.updateStatus}/>)} {this.renderRoute('/infection/telemetry', <TelemetryPage onStatusChange={this.updateStatus}/>)}
{this.renderRoute('/start-over', <StartOverPage onStatusChange={this.updateStatus}/>)} {this.renderRoute('/start-over', <StartOverPage onStatusChange={this.updateStatus}/>)}
{this.redirectTo('/report', '/report/security')}
<Switch> <Switch>
{this.renderRoute('/report/security', <ReportPage/>)} {this.renderRoute('/report/security', <ReportPage/>)}
{this.renderRoute('/report/attack', <ReportPage/>)} {this.renderRoute('/report/attack', <ReportPage/>)}
{this.renderRoute('/report/zeroTrust', <ReportPage/>)} {this.renderRoute('/report/zeroTrust', <ReportPage/>)}
</Switch> </Switch>
{this.renderRoute(reportZeroTrustRoute, <ZeroTrustReportPage onStatusChange={this.updateStatus}/>)}
{this.renderRoute('/license', <LicensePage onStatusChange={this.updateStatus}/>)} {this.renderRoute('/license', <LicensePage onStatusChange={this.updateStatus}/>)}
</Col> </Col>
</Row> </Row>

View File

@ -11,7 +11,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCircle as faCircle } from '@fortawesome/free-solid-svg-icons'; import { faCircle as faCircle } from '@fortawesome/free-solid-svg-icons';
import { faCircle as faCircleThin } from '@fortawesome/free-regular-svg-icons'; import { faCircle as faCircleThin } from '@fortawesome/free-regular-svg-icons';
class MatrixComponent extends AuthComponent { class ConfigMatrixComponent extends AuthComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {lastAction: 'none'} this.state = {lastAction: 'none'}
@ -81,8 +81,8 @@ class MatrixComponent extends AuthComponent {
getTableData = (config) => { getTableData = (config) => {
let configCopy = JSON.parse(JSON.stringify(config)); let configCopy = JSON.parse(JSON.stringify(config));
let maxTechniques = MatrixComponent.findMaxTechniques(Object.values(configCopy)); let maxTechniques = ConfigMatrixComponent.findMaxTechniques(Object.values(configCopy));
let matrixTableData = MatrixComponent.parseTechniques(Object.values(configCopy), maxTechniques); let matrixTableData = ConfigMatrixComponent.parseTechniques(Object.values(configCopy), maxTechniques);
let columns = this.getColumns(matrixTableData); let columns = this.getColumns(matrixTableData);
return {'columns': columns, 'matrixTableData': matrixTableData, 'maxTechniques': maxTechniques} return {'columns': columns, 'matrixTableData': matrixTableData, 'maxTechniques': maxTechniques}
}; };
@ -120,4 +120,4 @@ class MatrixComponent extends AuthComponent {
} }
} }
export default MatrixComponent; export default ConfigMatrixComponent;

View File

@ -5,7 +5,7 @@ import FileSaver from 'file-saver';
import AuthComponent from '../AuthComponent'; import AuthComponent from '../AuthComponent';
import {FilePond} from 'react-filepond'; import {FilePond} from 'react-filepond';
import 'filepond/dist/filepond.min.css'; import 'filepond/dist/filepond.min.css';
import MatrixComponent from '../attack/MatrixComponent'; import ConfigMatrixComponent from '../attack/ConfigMatrixComponent';
const ATTACK_URL = '/api/attack'; const ATTACK_URL = '/api/attack';
const CONFIG_URL = '/api/configuration/island'; const CONFIG_URL = '/api/configuration/island';
@ -450,10 +450,10 @@ class ConfigurePageComponent extends AuthComponent {
} }
renderMatrix = () => { renderMatrix = () => {
return (<MatrixComponent configuration={this.state.attackConfig} return (<ConfigMatrixComponent configuration={this.state.attackConfig}
submit={this.componentDidMount} submit={this.componentDidMount}
reset={this.resetConfig} reset={this.resetConfig}
change={this.attackTechniqueChange}/>) change={this.attackTechniqueChange}/>)
}; };

View File

@ -7,7 +7,7 @@ import { faCircle } from '@fortawesome/free-solid-svg-icons';
import ReportHeader, {ReportTypes} from './common/ReportHeader'; import ReportHeader, {ReportTypes} from './common/ReportHeader';
import {ScanStatus} from '../attack/techniques/Helpers'; import {ScanStatus} from '../attack/techniques/Helpers';
import Matrix from './attack/ReportMatrix'; import Matrix from './attack/ReportMatrixComponent';
import SelectedTechnique from './attack/SelectedTechnique'; import SelectedTechnique from './attack/SelectedTechnique';
import TechniqueDropdowns from './attack/TechniqueDropdowns'; import TechniqueDropdowns from './attack/TechniqueDropdowns';
import ReportLoader from './common/ReportLoader'; import ReportLoader from './common/ReportLoader';
@ -46,7 +46,7 @@ class AttackReport extends React.Component {
} }
} }
onTechniqueSelect = (technique, value, mapped = false) => { onTechniqueSelect = (technique, value) => {
let selectedTechnique = this.getTechniqueByTitle(technique); let selectedTechnique = this.getTechniqueByTitle(technique);
if (selectedTechnique === false){ if (selectedTechnique === false){
return; return;
@ -89,7 +89,7 @@ class AttackReport extends React.Component {
<hr/> <hr/>
<p> <p>
This report shows information about This report shows information about
<Button bsStyle={'link'} href={'https://attack.mitre.org/'} bsSize={'lg'} className={'attack-link'}>ATT&CK </Button> <Button bsStyle={'link'} href={'https://attack.mitre.org/'} bsSize={'lg'} className={'attack-link'}>Mitre ATT&CK</Button>
techniques used by Infection Monkey. techniques used by Infection Monkey.
</p> </p>
{this.renderLegend()} {this.renderLegend()}
@ -105,7 +105,7 @@ class AttackReport extends React.Component {
} }
getTechniqueByTitle(title){ getTechniqueByTitle(title){
for (let tech_id in this.state.techniques){ for (const tech_id in this.state.techniques){
if (! this.state.techniques.hasOwnProperty(tech_id)) {return false;} if (! this.state.techniques.hasOwnProperty(tech_id)) {return false;}
let technique = this.state.techniques[tech_id]; let technique = this.state.techniques[tech_id];
if (technique.title === title){ if (technique.title === title){
@ -118,10 +118,10 @@ class AttackReport extends React.Component {
static addLinksToTechniques(schema, techniques){ static addLinksToTechniques(schema, techniques){
schema = schema.properties; schema = schema.properties;
for(let type in schema){ for(const type in schema){
if (! schema.hasOwnProperty(type)) {return false;} if (! schema.hasOwnProperty(type)) {return false;}
let typeTechniques = schema[type].properties; let typeTechniques = schema[type].properties;
for(let tech_id in typeTechniques){ for(const tech_id in typeTechniques){
if (! typeTechniques.hasOwnProperty(tech_id)) {return false;} if (! typeTechniques.hasOwnProperty(tech_id)) {return false;}
if (typeTechniques[tech_id] !== undefined){ if (typeTechniques[tech_id] !== undefined){
techniques[tech_id]['link'] = typeTechniques[tech_id].link techniques[tech_id]['link'] = typeTechniques[tech_id].link

View File

@ -5,7 +5,7 @@ import ReactTable from 'react-table';
import 'filepond/dist/filepond.min.css'; import 'filepond/dist/filepond.min.css';
import '../../../styles/report/ReportAttackMatrix.scss'; import '../../../styles/report/ReportAttackMatrix.scss';
class MatrixComponent extends React.Component { class ReportMatrixComponent extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {techniques: this.props.techniques, this.state = {techniques: this.props.techniques,
@ -14,7 +14,7 @@ class MatrixComponent extends React.Component {
getColumns() { getColumns() {
let columns = []; let columns = [];
for(let type_key in this.state.schema.properties){ for(const type_key in this.state.schema.properties){
if (! this.state.schema.properties.hasOwnProperty(type_key)){ if (! this.state.schema.properties.hasOwnProperty(type_key)){
continue; continue;
} }
@ -31,11 +31,11 @@ class MatrixComponent extends React.Component {
getTableRows() { getTableRows() {
let rows = []; let rows = [];
for (let tech_id in this.state.techniques) { for (const tech_id in this.state.techniques) {
if (this.state.techniques.hasOwnProperty(tech_id)){ if (this.state.techniques.hasOwnProperty(tech_id)){
let technique_added = false; let technique_added = false;
let technique = this.state.techniques[tech_id]; let technique = this.state.techniques[tech_id];
for(let row of rows){ for(const row of rows){
if (! row.hasOwnProperty(technique.type)){ if (! row.hasOwnProperty(technique.type)){
row[technique.type] = technique; row[technique.type] = technique;
technique_added = true; technique_added = true;
@ -81,4 +81,4 @@ class MatrixComponent extends React.Component {
} }
} }
export default MatrixComponent; export default ReportMatrixComponent;

View File

@ -62,7 +62,7 @@ class SelectedTechnique extends React.Component {
return ( return (
<div> <div>
<h3 className='selected-technique-title'>Selected technique:</h3> <h3 className='selected-technique-title'>Selected technique</h3>
<section className='attack-report selected-technique'> <section className='attack-report selected-technique'>
{content} {content}
</section> </section>

View File

@ -7,7 +7,7 @@ let monkeyLogoImage = require('../../../images/monkey-icon.svg');
export const ReportTypes = { export const ReportTypes = {
zeroTrust: 'Zero Trust', zeroTrust: 'Zero Trust',
security: 'Security', security: 'Security',
attack: 'Attack', attack: 'ATT&CK',
null: '' null: ''
}; };

View File

@ -42,5 +42,5 @@
} }
.attack-link{ .attack-link{
padding: 6px 10px !important; padding: 0 7px 3px 7px !important;
} }