Refactored scan status to use numeric value and other PR fixes

This commit is contained in:
VakarisZ 2019-07-08 13:44:15 +03:00
parent bc1be8e452
commit 967fec8487
14 changed files with 33 additions and 27 deletions

View File

@ -243,10 +243,8 @@ class InfectionMonkey(object):
@staticmethod @staticmethod
def self_delete(): def self_delete():
if utils.remove_monkey_dir(): status = ScanStatus.USED if utils.remove_monkey_dir() else ScanStatus.SCANNED
T1107Telem(ScanStatus.USED, utils.get_monkey_dir_path()).send() T1107Telem(status, utils.get_monkey_dir_path()).send()
else:
T1107Telem(ScanStatus.SCANNED, utils.get_monkey_dir_path()).send()
if WormConfiguration.self_delete_in_cleanup \ if WormConfiguration.self_delete_in_cleanup \
and -1 == sys.executable.find('python'): and -1 == sys.executable.find('python'):

View File

@ -58,12 +58,12 @@ class AttackReportService:
Gets latest report (by retrieving it from db or generating a new one). Gets latest report (by retrieving it from db or generating a new one).
:return: report dict. :return: report dict.
""" """
return AttackReportService.generate_new_report()
if AttackReportService.is_report_generated(): if AttackReportService.is_report_generated():
telem_time = AttackReportService.get_latest_attack_telem_time() telem_time = AttackReportService.get_latest_attack_telem_time()
latest_report = mongo.db.attack_report.find_one({'name': REPORT_NAME}) latest_report = mongo.db.attack_report.find_one({'name': REPORT_NAME})
if telem_time and latest_report['latest_telem_time'] and telem_time == latest_report['latest_telem_time']: if telem_time and latest_report['latest_telem_time'] and telem_time == latest_report['latest_telem_time']:
return latest_report return latest_report
return AttackReportService.generate_new_report()
@staticmethod @staticmethod
def is_report_generated(): def is_report_generated():

View File

@ -7,7 +7,7 @@ __author__ = "VakarisZ"
class T1107(AttackTechnique): class T1107(AttackTechnique):
tech_id = "T1107" tech_id = "T1107"
unscanned_msg = "" unscanned_msg = ""
scanned_msg = "Monkey tried to delete files on a system in the network but failed." scanned_msg = "Monkey tried to delete files on systems in the network, but failed."
used_msg = "Monkey successfully deleted files on systems in the network." used_msg = "Monkey successfully deleted files on systems in the network."
query = [{'$match': {'telem_category': 'attack', query = [{'$match': {'telem_category': 'attack',

View File

@ -55,13 +55,13 @@ class AttackTechnique(object):
if mongo.db.telemetry.find_one({'telem_category': 'attack', if mongo.db.telemetry.find_one({'telem_category': 'attack',
'data.status': ScanStatus.USED.value, 'data.status': ScanStatus.USED.value,
'data.technique': cls.tech_id}): 'data.technique': cls.tech_id}):
return ScanStatus.USED return ScanStatus.USED.value
elif mongo.db.telemetry.find_one({'telem_category': 'attack', elif mongo.db.telemetry.find_one({'telem_category': 'attack',
'data.status': ScanStatus.SCANNED.value, 'data.status': ScanStatus.SCANNED.value,
'data.technique': cls.tech_id}): 'data.technique': cls.tech_id}):
return ScanStatus.SCANNED return ScanStatus.SCANNED.value
else: else:
return ScanStatus.UNSCANNED return ScanStatus.UNSCANNED.value
@classmethod @classmethod
def get_message_and_status(cls, status): def get_message_and_status(cls, status):
@ -70,7 +70,7 @@ class AttackTechnique(object):
:param status: Enum type value from common/attack_utils.py :param status: Enum type value from common/attack_utils.py
:return: Dict with message and status :return: Dict with message and status
""" """
return {'message': cls.get_message_by_status(status), 'status': status.name} return {'message': cls.get_message_by_status(status), 'status': status.value}
@classmethod @classmethod
def get_message_by_status(cls, status): def get_message_by_status(cls, status):
@ -102,7 +102,7 @@ class AttackTechnique(object):
data = {} data = {}
status = cls.technique_status() status = cls.technique_status()
title = cls.technique_title() title = cls.technique_title()
data.update({'status': status.name, data.update({'status': status,
'title': title, 'title': title,
'message': cls.get_message_by_status(status)}) 'message': cls.get_message_by_status(status)})
return data return data

View File

@ -19,3 +19,9 @@ export function renderMachineFromSystemData(data) {
}); });
return machineStr + ")" return machineStr + ")"
} }
export const scanStatus = {
UNSCANNED: 0,
SCANNED: 1,
USED: 2
};

View File

@ -2,6 +2,7 @@ import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import '../../report-components/StolenPasswords' import '../../report-components/StolenPasswords'
import StolenPasswordsComponent from "../../report-components/StolenPasswords"; import StolenPasswordsComponent from "../../report-components/StolenPasswords";
import {scanStatus} from "./Helpers"
class T1003 extends React.Component { class T1003 extends React.Component {
@ -15,7 +16,7 @@ class T1003 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status === scanStatus.USED ?
<StolenPasswordsComponent data={this.props.reportData.glance.stolen_creds.concat(this.props.reportData.glance.ssh_keys)}/> <StolenPasswordsComponent data={this.props.reportData.glance.stolen_creds.concat(this.props.reportData.glance.ssh_keys)}/>
: ""} : ""}
</div> </div>

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachine } from "./Helpers" import { renderMachine, scanStatus } from "./Helpers"
class T1059 extends React.Component { class T1059 extends React.Component {
@ -25,7 +25,7 @@ class T1059 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status === scanStatus.USED ?
<ReactTable <ReactTable
columns={T1059.getCommandColumns()} columns={T1059.getCommandColumns()}
data={this.props.data.cmds} data={this.props.data.cmds}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachine } from "./Helpers" import { renderMachine, scanStatus } from "./Helpers"
class T1075 extends React.Component { class T1075 extends React.Component {
@ -34,7 +34,7 @@ class T1075 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status !== scanStatus.UNSCANNED ?
<ReactTable <ReactTable
columns={T1075.getHashColumns()} columns={T1075.getHashColumns()}
data={this.props.data.successful_logins} data={this.props.data.successful_logins}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachineFromSystemData } from "./Helpers" import { renderMachineFromSystemData, scanStatus } from "./Helpers"
class T1082 extends React.Component { class T1082 extends React.Component {
@ -33,7 +33,7 @@ class T1082 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status === scanStatus.USED ?
<ReactTable <ReactTable
columns={T1082.getSystemInfoColumns()} columns={T1082.getSystemInfoColumns()}
data={this.props.data.system_info} data={this.props.data.system_info}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachine } from "./Helpers" import { renderMachine, scanStatus } from "./Helpers"
class T1086 extends React.Component { class T1086 extends React.Component {
@ -25,7 +25,7 @@ class T1086 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status === scanStatus.USED ?
<ReactTable <ReactTable
columns={T1086.getPowershellColumns()} columns={T1086.getPowershellColumns()}
data={this.props.data.cmds} data={this.props.data.cmds}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachineFromSystemData } from "./Helpers" import { renderMachineFromSystemData, scanStatus } from "./Helpers"
class T1107 extends React.Component { class T1107 extends React.Component {

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachine } from "./Helpers" import { renderMachine, scanStatus } from "./Helpers"
class T1110 extends React.Component { class T1110 extends React.Component {
@ -32,7 +32,7 @@ class T1110 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{(this.props.data.status === 'SCANNED' || this.props.data.status === 'USED') ? {this.props.data.status !== scanStatus.UNSCANNED ?
<ReactTable <ReactTable
columns={T1110.getServiceColumns()} columns={T1110.getServiceColumns()}
data={this.props.data.services} data={this.props.data.services}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import '../../../styles/Collapse.scss' import '../../../styles/Collapse.scss'
import ReactTable from "react-table"; import ReactTable from "react-table";
import { renderMachineFromSystemData } from "./Helpers" import { renderMachineFromSystemData, scanStatus } from "./Helpers"
class T1145 extends React.Component { class T1145 extends React.Component {
@ -38,7 +38,7 @@ class T1145 extends React.Component {
<div> <div>
<div>{this.props.data.message}</div> <div>{this.props.data.message}</div>
<br/> <br/>
{this.props.data.status === 'USED' ? {this.props.data.status === scanStatus.USED ?
<ReactTable <ReactTable
columns={T1145.getKeysInfoColumns()} columns={T1145.getKeysInfoColumns()}
data={this.props.data.ssh_info} data={this.props.data.ssh_info}

View File

@ -4,6 +4,7 @@ import {ReactiveGraph} from 'components/reactive-graph/ReactiveGraph';
import {edgeGroupToColor, options} from 'components/map/MapOptions'; import {edgeGroupToColor, options} from 'components/map/MapOptions';
import '../../styles/Collapse.scss'; import '../../styles/Collapse.scss';
import AuthComponent from '../AuthComponent'; import AuthComponent from '../AuthComponent';
import {scanStatus} from "../attack/techniques/Helpers";
import Collapse from '@kunukn/react-collapse'; import Collapse from '@kunukn/react-collapse';
import T1210 from '../attack/techniques/T1210'; import T1210 from '../attack/techniques/T1210';
import T1197 from '../attack/techniques/T1197'; import T1197 from '../attack/techniques/T1197';
@ -77,9 +78,9 @@ class AttackReportPageComponent extends AuthComponent {
getComponentClass(tech_id){ getComponentClass(tech_id){
switch (this.state.report[tech_id].status) { switch (this.state.report[tech_id].status) {
case 'SCANNED': case scanStatus.SCANNED:
return 'collapse-info'; return 'collapse-info';
case 'USED': case scanStatus.USED:
return 'collapse-danger'; return 'collapse-danger';
default: default:
return 'collapse-default'; return 'collapse-default';