Skip to content

Commit

Permalink
[Threat intel][part 3] Support for source type URL_Download and logic…
Browse files Browse the repository at this point in the history
… to activate/deactivate source (#1068) (#1074)

* added url_download type of threat intel source; activate/deactivate for sources



* added check for controls



---------


(cherry picked from commit 6b63eb2)

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 9172b05 commit e9e81a3
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ThreatIntelS3CustomSourcePayload,
ThreatIntelSourceItem,
ThreatIntelSourcePayload,
URLDownloadSource,
} from '../../../../../types';
import { defaultIntervalUnitOptions } from '../../../../utils/constants';
import { readIocsFromFile, threatIntelSourceItemToBasePayload } from '../../utils/helpers';
Expand Down Expand Up @@ -331,6 +332,14 @@ export const ThreatIntelSourceDetails: React.FC<ThreatIntelSourceDetailsProps> =
)}
</>
)}
{type === 'URL_DOWNLOAD' && (
<EuiFormRow label="Source URL">
<EuiFieldText
readOnly={isReadOnly}
value={(sourceItem.source as URLDownloadSource).url_download?.url}
/>
</EuiFormRow>
)}
<EuiFormRow label="Types of malicious indicators">
<>
<EuiSpacer size="s" />
Expand All @@ -344,14 +353,16 @@ export const ThreatIntelSourceDetails: React.FC<ThreatIntelSourceDetailsProps> =
</EuiFormRow>
<EuiSpacer />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
style={{ visibility: isReadOnly ? 'visible' : 'hidden' }}
onClick={() => setIsReadOnly(false)}
>
Edit
</EuiButton>
</EuiFlexItem>
{type !== 'URL_DOWNLOAD' && (
<EuiFlexItem grow={false}>
<EuiButton
style={{ visibility: isReadOnly ? 'visible' : 'hidden' }}
onClick={() => setIsReadOnly(false)}
>
Edit
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiPanel>
{!isReadOnly && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const ThreatIntelOverview: React.FC<ThreatIntelOverviewProps> = ({
initialIsOpen={threatIntelSources.length === 0 || logSources.length === 0}
>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexGroup wrap>
{threatIntelNextStepsProps.map(
({ id, title, description, footerButtonProps: { text, disabled } }) => (
<EuiFlexItem key={id}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import { useEffect } from 'react';
import { CoreServicesContext } from '../../../../components/core_services';
import {
EuiButton,
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiLoadingContent,
EuiPanel,
EuiSpacer,
EuiTabbedContent,
EuiTabbedContentTab,
EuiTitle,
EuiToolTip,
} from '@elastic/eui';
import { DescriptionGroup } from '../../../../components/Utility/DescriptionGroup';
import { IoCsTable } from '../../components/IoCsTable/IoCsTable';
Expand Down Expand Up @@ -138,8 +141,27 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
}
};

const { name, description, type, ioc_types, last_update_time, enabled } = source;
const toggleActiveState = async () => {
const updateRes = await threatIntelService.updateThreatIntelSource(source.id, {
...source,
enabled_for_scan: !source.enabled_for_scan,
});
if (updateRes.ok) {
onSourceUpdate();
}
};

const {
name,
description,
type,
ioc_types,
last_update_time,
enabled,
enabled_for_scan,
} = source;
const schedule = type === 'S3_CUSTOM' ? source.schedule : undefined;
const showActivateControls = 'enabled_for_scan' in source;

return (
<>
Expand All @@ -150,7 +172,36 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup alignItems="center">
<EuiFlexGroup alignItems="center" wrap>
{showActivateControls && (
<>
<EuiFlexItem grow={false}>
<EuiToolTip
content={
'When Active, the indicators of compromise from this source are used to scan the log data as part of the threat intel scan.'
}
>
<span>
<EuiIcon
type={'dot'}
color={enabled_for_scan ? 'success' : 'text'}
style={{ marginBottom: 4 }}
/>{' '}
{enabled_for_scan ? 'Active' : 'Inactive'}&nbsp;
<EuiIcon type={'iInCircle'} />
</span>
</EuiToolTip>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
color={enabled_for_scan ? 'danger' : 'primary'}
onClick={toggleActiveState}
>
{enabled_for_scan ? 'Deactivate' : 'Activate'}
</EuiButton>
</EuiFlexItem>
</>
)}
{type === 'S3_CUSTOM' && (
<EuiFlexItem grow={false}>
<EuiButton fill onClick={onRefresh}>
Expand All @@ -159,9 +210,9 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiButton color="danger" onClick={onDeleteButtonClick}>
Delete
</EuiButton>
<EuiToolTip content={'Delete'}>
<EuiButtonIcon iconType={'trash'} color="danger" onClick={onDeleteButtonClick} />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
22 changes: 21 additions & 1 deletion types/ThreatIntel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ export interface FileUploadSource {
};
}

export interface URLDownloadSource {
url_download: {
url: string;
};
}

export interface ThreatIntelSourcePayloadBase {
name: string;
description?: string;
format: 'STIX2';
store_type: 'OS';
enabled: boolean;
enabled_for_scan: boolean;
ioc_types: ThreatIntelIocType[];
}

Expand All @@ -78,9 +85,22 @@ export interface ThreatIntelIocUploadSourcePayload extends ThreatIntelSourcePayl
source: FileUploadSource;
}

export interface ThreatIntelURLDownloadSourceInfo extends ThreatIntelSourcePayloadBase {
type: 'URL_DOWNLOAD';
schedule: {
interval: {
start_time: number;
period: number;
unit: string;
};
};
source: URLDownloadSource;
}

export type ThreatIntelSourcePayload =
| ThreatIntelS3CustomSourcePayload
| ThreatIntelIocUploadSourcePayload;
| ThreatIntelIocUploadSourcePayload
| ThreatIntelURLDownloadSourceInfo;

export interface LogSourceIocConfig {
enabled: boolean;
Expand Down

0 comments on commit e9e81a3

Please sign in to comment.