Skip to content

Commit

Permalink
[frontend] Display more payload informations (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 authored Nov 14, 2024
1 parent b0bea51 commit c6f9eda
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 90 deletions.
3 changes: 2 additions & 1 deletion openbas-front/src/actions/payloads/Payload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { Payload } from '../../utils/api-types';

export type PayloadStore = Omit<Payload, 'payload_collector'> & {
payload_collector?: string;

command_executor?: string;
command_content?: string;
dns_resolution_hostname?: string;
file_drop_file?: string;
executable_file?: string;
executable_arch?: string;
payload_attack_patterns?: string[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const AtomicTestingDetail: FunctionComponent<Props> = () => {
<Typography variant="h4">{t('Command Lines')}</Typography>
<Paper variant="outlined" classes={{ root: classes.paper }}>
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Content')}
{t('Attack command')}
</Typography>
{(injectResultDto.inject_commands_lines?.content?.length ?? 0) > 0 ? (
<pre>
Expand Down
263 changes: 263 additions & 0 deletions openbas-front/src/admin/components/payloads/Payload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
import { Chip, Grid, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, Typography } from '@mui/material';
import { makeStyles } from '@mui/styles';
import { FunctionComponent } from 'react';

import { AttackPatternHelper } from '../../../actions/attack_patterns/attackpattern-helper';
import { PayloadStore } from '../../../actions/payloads/Payload';
import { useFormatter } from '../../../components/i18n';
import ItemCopy from '../../../components/ItemCopy';
import ItemTags from '../../../components/ItemTags';
import PlatformIcon from '../../../components/PlatformIcon';
import { useHelper } from '../../../store';
import { AttackPattern, PayloadArgument, PayloadPrerequisite } from '../../../utils/api-types';
import { emptyFilled } from '../../../utils/String';

const useStyles = makeStyles(() => ({
chip: {
fontSize: 12,
height: 25,
margin: '0 7px 7px 0',
textTransform: 'uppercase',
borderRadius: 4,
width: 180,
},
}));

interface Props {
selectedPayload: PayloadStore | null;
}

const Payload: FunctionComponent<Props> = ({
selectedPayload,
}) => {
// Standard hooks
const classes = useStyles();
const { t } = useFormatter();

const { attackPatternsMap } = useHelper((helper: AttackPatternHelper) => ({
attackPatternsMap: helper.getAttackPatternsMap(),
}));

return (
<Grid container spacing={3}>
<Grid item xs={12} style={{ paddingTop: 10 }}>
<Typography
variant="h2"
gutterBottom
style={{ marginTop: 20 }}
>
{selectedPayload?.payload_name}
</Typography>

<Typography
variant="body2"
gutterBottom
style={{ marginTop: 20 }}
>
{emptyFilled(selectedPayload?.payload_description)}
</Typography>
</Grid>

<Grid item xs={6} style={{ paddingTop: 10 }}>
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Platforms')}
</Typography>
{(selectedPayload?.payload_platforms ?? []).length === 0 ? (
<PlatformIcon platform={t('No inject in this scenario')} tooltip width={25} />
) : selectedPayload?.payload_platforms?.map(
platform => <PlatformIcon key={platform} platform={platform} tooltip width={25} marginRight={10} />,
)}
{(selectedPayload?.executable_arch) && (
<>
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Architecture')}
</Typography>
{selectedPayload?.executable_arch}
</>
)}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Tags')}
</Typography>
<ItemTags
variant="reduced-view"
tags={selectedPayload?.payload_tags}
/>
</Grid>
<Grid item xs={6} style={{ paddingTop: 10 }}>
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Attack patterns')}
</Typography>
{selectedPayload?.payload_attack_patterns && selectedPayload?.payload_attack_patterns.length === 0 ? '-' : selectedPayload?.payload_attack_patterns?.map((attackPatternId: string) => attackPatternsMap[attackPatternId]).map((attackPattern: AttackPattern) => (
<Tooltip key={attackPattern.attack_pattern_id} title={`[${attackPattern.attack_pattern_external_id}] ${attackPattern.attack_pattern_name}`}>
<Chip
variant="outlined"
classes={{ root: classes.chip }}
color="primary"
label={`[${attackPattern.attack_pattern_external_id}] ${attackPattern.attack_pattern_name}`}
/>
</Tooltip>
))}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('External ID')}
</Typography>
{selectedPayload?.payload_external_id && selectedPayload?.payload_external_id.length > 0 ? (
<pre>
<ItemCopy content={selectedPayload?.payload_external_id} />
</pre>
) : '-'}
</Grid>
<Grid item xs={12} style={{ paddingTop: 10 }}>
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Command executor')}
</Typography>
{selectedPayload?.command_executor}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Attack commands')}
</Typography>
<pre>
<ItemCopy content={
selectedPayload?.command_content ?? selectedPayload?.dns_resolution_hostname ?? selectedPayload?.file_drop_file ?? selectedPayload?.executable_file ?? ''
}
/>
</pre>
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Arguments')}
</Typography>
{
!selectedPayload?.payload_arguments?.length ? '-'
: (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }}>
<TableHead>
<TableRow sx={{ textTransform: 'uppercase', fontWeight: 'bold' }}>
<TableCell width="30%">{t('Type')}</TableCell>
<TableCell width="30%">{t('Key')}</TableCell>
<TableCell width="30%">{t('Default value')}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{selectedPayload?.payload_arguments?.map((argument: PayloadArgument) => {
return (
<>
<TableRow
key={argument.key}
>
<TableCell>
{argument.type}
</TableCell>
<TableCell>
{argument.key}
</TableCell>
<TableCell>
{argument.default_value}
</TableCell>
</TableRow>
</>
);
})}
</TableBody>
</Table>
</TableContainer>
)
}

<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Prerequisites')}
</Typography>
{
selectedPayload?.payload_prerequisites && selectedPayload?.payload_prerequisites.length === 0 ? '-'
: (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }}>
<TableHead>
<TableRow sx={{ textTransform: 'uppercase', fontWeight: 'bold' }}>
<TableCell width="30%">{t('Command executor')}</TableCell>
<TableCell width="30%">{t('Get command')}</TableCell>
<TableCell width="30%">{t('Check command')}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{selectedPayload?.payload_prerequisites?.map((prerequisite: PayloadPrerequisite) => {
return (
<>
<TableRow
key={prerequisite.executor}
>
<TableCell>
{prerequisite.executor}
</TableCell>
<TableCell>
{prerequisite.get_command}
</TableCell>
<TableCell>
{prerequisite.check_command}
</TableCell>
</TableRow>
</>
);
})}
</TableBody>
</Table>
</TableContainer>
)
}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Cleanup executor')}
</Typography>
{selectedPayload?.payload_cleanup_executor}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Cleanup commands')}
</Typography>
{selectedPayload?.payload_cleanup_command && selectedPayload?.payload_cleanup_command.length > 0
? <pre><ItemCopy content={selectedPayload?.payload_cleanup_command} /></pre> : '-'}

</Grid>
</Grid>
);
};

export default Payload;
Loading

0 comments on commit c6f9eda

Please sign in to comment.