Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splunk2HDF Updates #2675

Merged
merged 61 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
948e984
Don't assume descriptions is defined
camdenmoors Feb 28, 2022
92047c4
Add Splunk Logging
camdenmoors Feb 28, 2022
6a6b689
Add insecure mode
camdenmoors Feb 28, 2022
1029179
Merge branch 'master' into splunkUpdates
camdenmoors Feb 28, 2022
b2d9632
Upload multiple items to collector at once
camdenmoors Feb 28, 2022
bed0792
Remove set index value, add hint for hostname field, fix profile subt…
camdenmoors Feb 28, 2022
ea4f2a0
Revert "Upload multiple items to collector at once"
camdenmoors Feb 28, 2022
6a05eba
Add hint for admin
camdenmoors Feb 28, 2022
0994aec
Remove spath.meta
camdenmoors Feb 28, 2022
985e647
Use index="*"
camdenmoors Feb 28, 2022
5efb07e
Set empty array for Profile.controls
camdenmoors Feb 28, 2022
f469d10
Log getExecution result
camdenmoors Feb 28, 2022
1e9cd54
Use replaceKeyValue descriptions
camdenmoors Feb 28, 2022
840b69f
Allow undefined return values, remove FileList log, increase timeout
camdenmoors Mar 1, 2022
a5f98bf
Add better error handling to SplunkReader, remove admin hint
camdenmoors Mar 1, 2022
8da1f4c
Post test data to webhook
camdenmoors Mar 1, 2022
bcb7ae5
Update test data, remove webhook
camdenmoors Mar 1, 2022
1d42282
Ignore LGTM issue and comment on insecure mode
camdenmoors Mar 1, 2022
40c61ae
Allow passing custom search to SplunkReader
camdenmoors Mar 1, 2022
782146c
Use notify for success message
camdenmoors Mar 1, 2022
3506a13
Revert "Allow passing custom search to SplunkReader"
camdenmoors Mar 1, 2022
c743de6
Add title
camdenmoors Mar 2, 2022
ae94be8
Merge branch 'splunkUpdates' of https://github.com/mitre/heimdall2 in…
camdenmoors Mar 2, 2022
09a6422
Clean up SplunkReader usability, add splunk-sdk to hdf-converters, de…
camdenmoors Mar 2, 2022
a304623
Switch to splunk-sdk for hdf2splunk, upload multiple events at once
camdenmoors Mar 3, 2022
d183b12
Switch to @mitre/splunk-sdk-no-env
camdenmoors Mar 3, 2022
f667092
Follow Sonarqube suggestions, update mapper tests
camdenmoors Mar 4, 2022
a16edd9
Update splunk_reverse_mapper.spec.ts
camdenmoors Mar 4, 2022
d101626
Don't redefine err, change debug to verbose
camdenmoors Mar 4, 2022
fb29915
[WIP] Move SplunkReader to splunk-sdk
camdenmoors Mar 4, 2022
f54c53d
Merge branch 'master' into splunkUpdates
camdenmoors Mar 11, 2022
a1492b7
Move Splunk2HDF into hdf-converters
camdenmoors Mar 11, 2022
1b390d3
Lint, wait for all files to load before closing SplunkReader
camdenmoors Mar 11, 2022
c73752d
Remove duplicate splunk-sdk
camdenmoors Mar 11, 2022
c7c0525
Address code smells
camdenmoors Mar 11, 2022
a5f0311
Use JQuery provided by HTML Export
camdenmoors Mar 11, 2022
1144dc1
Add Upload to Splunk from Heimdall
camdenmoors Mar 11, 2022
e3ac147
Merge branch 'splunkUpdates' of github.com:mitre/heimdall2 into splun…
camdenmoors Mar 11, 2022
31e5b80
Use full path to jQuery
camdenmoors Mar 11, 2022
c41964f
Merge branch 'master' into splunkUpdates
camdenmoors Mar 14, 2022
d4696fc
Fix Matching for http(s), add Refresh to Splunk FileList
camdenmoors Mar 14, 2022
b7000f8
Merge branch 'master' into splunkUpdates
camdenmoors Mar 14, 2022
18a6be8
Merge branch 'master' into splunkUpdates
camdenmoors Mar 14, 2022
1c55ae9
Fix E2E Tests, Chunk Control Uploads (100/upload), Remove Insecure Fl…
camdenmoors Mar 14, 2022
a985bb4
Merge branch 'splunkUpdates' of github.com:mitre/heimdall2 into splun…
camdenmoors Mar 14, 2022
4f43af2
Return onUpdateSearch consistently, clean execution query
camdenmoors Mar 14, 2022
8a30618
Add login timeout error
camdenmoors Mar 14, 2022
4be7f85
Add logging to splunk2hdf, remove export for local hdf2splunk variables
camdenmoors Mar 14, 2022
e180bca
Move parseSplunkResponse to a seperate function
camdenmoors Mar 14, 2022
14a093a
Mark Overlaid Controls as "Overlaid Controls" in Splunk
camdenmoors Mar 15, 2022
63846be
Update type for targetIndex
camdenmoors Mar 15, 2022
e51f6b1
!= !== !==
camdenmoors Mar 15, 2022
a5d5a1e
Allow any for Splunk types
camdenmoors Mar 15, 2022
7a2d21f
Merge branch 'master' into splunkUpdates
camdenmoors Mar 15, 2022
dfc40b4
Add Non-AJAX Mode for Splunk Mapper
camdenmoors Mar 17, 2022
4c6a2d2
Restore profile.status
camdenmoors Mar 17, 2022
3c51f65
Merge branch 'splunkUpdates' of github.com:mitre/heimdall2 into splun…
camdenmoors Mar 17, 2022
f4c0b94
Reduce complexity of checkSplunkCredentials
camdenmoors Mar 18, 2022
02d5dae
Merge branch 'master' into splunkUpdates
camdenmoors Mar 18, 2022
910b6aa
Update help message
camdenmoors Mar 18, 2022
4f5c91d
Merge branch 'splunkUpdates' of github.com:mitre/heimdall2 into splun…
camdenmoors Mar 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
v-model="username"
label="Username"
for="username_field"
hint="admin"
data-cy="splunkusername"
/>
<v-text-field
Expand All @@ -18,13 +19,14 @@
v-model="hostname"
label="Hostname"
for="hostname_field"
hint="https://yourdomain.com:8089"
data-cy="splunkhostname"
/>
</v-form>
<v-row class="mx-1">
<v-btn
color="primary"
class="my-4 mt-0"
class="my-4 mt-4"
data-cy="splunkLoginButton"
@click="login"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ export default class FileList extends Vue {

loadResults() {
const files = this.selectedExecutions.map((execution) => {
return getExecution(this.splunkClient, execution.guid).then((result) =>
return getExecution(this.splunkClient, execution.guid).then((result) => {
console.log(result);
InspecIntakeModule.loadText({
text: JSON.stringify(result),
filename: _.get(result, 'meta.filename')
}).catch((err) => {
SnackbarModule.failure(String(err));
})
);
});
});
});
this.$emit('got-files', files);
}
Expand Down
14 changes: 12 additions & 2 deletions apps/frontend/src/utilities/splunk_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,20 @@ function consolidateFilePayloads(
(ctrl) => ctrl.meta.profile_sha256
);
for (const profile of profileEvents) {
profile.controls = [];
// Get the corresponding controls, and put them into the profile
const sha = profile.meta.profile_sha256;
const corrControls = shaGroupedControls[sha] || [];
profile.controls.push(...corrControls);
profile.controls.push(
...replaceKeyValueDescriptions(
corrControls as unknown as (ExecJSON.Control &
GenericPayloadWithMetaData & {
descriptions?:
| {[key: string]: string}
| ExecJSON.ControlDescription[];
})[]
)
);
}

return exec as unknown as ExecJSON.Execution;
Expand Down Expand Up @@ -179,7 +189,7 @@ export async function createSearch(
// We basically can't, and really shouldn't, do typescript here. Output is changes depending on the job called
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<JobID> {
const fullQuery = `search=search index="hdf" | ${searchString || ''}`;
const fullQuery = `search=search index="*" | ${searchString || ''}`;
return apiClient({
method: 'POST',
url: `${splunkClient.host}/services/search/jobs?output_mode=json`,
Expand Down
1 change: 1 addition & 0 deletions libs/hdf-converters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"inspecjs": "^2.6.10",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"winston": "^3.6.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ index="<<YOUR INDEX>>" | stats list(meta.filename) list(meta.filetype) list(tags
"compliance": "?"
}
],
controls: [], // An empty array, for backwards compatibility with versions of Heimdall that assume this is already defined
// "Inputs" in modern Inspec parlance, Attributes are the parameters specified at runtime for the profile.
"attributes": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import axios, {AxiosResponse} from 'axios';
import https from 'https';
import {
ContextualizedControl,
ContextualizedEvaluation,
ContextualizedProfile,
contextualizeEvaluation,
ExecJSON
} from 'inspecjs';
import winston from 'winston';
import {MappedTransform} from '../../base-converter';
import {createWinstonLogger} from '../../utils/global';
import {FromAnyBaseConverter} from '../reverse-any-base-converter';
import {ILookupPathFH} from '../reverse-base-converter';
import {SplunkControl} from './splunk-control-types';
import {SplunkProfile} from './splunk-profile-types';
import {SplunkReport} from './splunk-report-types';

export const HDF_SPLUNK_SCHEMA = '1.0';
export const MAPPER_NAME = 'HDF2Splunk';

export type SplunkConfig = {
host: string;
port: number;
insecure?: boolean;
token: string;
protocol: string;
index?: string;
Expand All @@ -28,6 +34,9 @@ export type SplunkData = {
reports: SplunkReport[];
};

let logger: winston.Logger | undefined = undefined;
let httpsAgent = new https.Agent();

export function createGUID(length: number) {
let result = '';
const characters =
Expand Down Expand Up @@ -62,6 +71,7 @@ export function postDataToSplunkHEC(
index: config.index
},
{
httpsAgent: httpsAgent,
headers: {
Authorization: `Splunk ${config.token}`
}
Expand All @@ -76,6 +86,7 @@ export function postDataToSplunkHEC(
event: data
},
{
httpsAgent: httpsAgent,
headers: {
Authorization: `Splunk ${config.token}`
}
Expand All @@ -98,6 +109,7 @@ export function createReportMapping(
hdf_splunk_schema: HDF_SPLUNK_SCHEMA,
filetype: 'evaluation'
},
profiles: [],
platform: execution.data.platform,
statistics: execution.data.statistics,
version: execution.data.version
Expand Down Expand Up @@ -155,7 +167,7 @@ export function createProfileMapping(
profile_sha256: {
path: 'data.sha256'
},
subtype: 'header'
subtype: 'profile'
},
summary: {
path: 'data.summary'
Expand Down Expand Up @@ -187,6 +199,7 @@ export function createProfileMapping(
title: {
path: 'data.title'
},
controls: [],
parent_profile: {
path: 'data.depends[0].name'
},
Expand Down Expand Up @@ -231,9 +244,11 @@ export function createControlMapping(
path: 'data.descriptions',
transformer: (data: {label: string; data: string}[]) => {
const descObjects: Record<string, string> = {};
data.forEach((item) => {
descObjects[item['label']] = item['data'];
});
if (Array.isArray(data)) {
camdenmoors marked this conversation as resolved.
Show resolved Hide resolved
data.forEach((item) => {
descObjects[item['label']] = item['data'];
});
}
return descObjects;
}
},
Expand All @@ -250,9 +265,18 @@ export class FromHDFExecutionToSplunkExecutionMapper extends FromAnyBaseConverte
constructor(
evaluation: ContextualizedEvaluation,
filename: string,
guid: string
guid: string,
logService?: winston.Logger,
loggingLevel?: string
) {
super(evaluation);
if (logService) {
logger = logService;
} else {
logger = createWinstonLogger(MAPPER_NAME, loggingLevel || 'debug');
}
logger.debug('Got Execution: ' + filename);
logger.debug('Using GUID: ' + guid);
this.setMappings(createReportMapping(evaluation, filename, guid));
}

Expand Down Expand Up @@ -305,6 +329,11 @@ export class FromHDFToSplunkMapper extends FromAnyBaseConverter {
profiles: [],
reports: []
};
if (config.insecure) {
httpsAgent = new https.Agent({
rejectUnauthorized: false
});
}
const guid = createGUID(30);
splunkData.reports.push(
new FromHDFExecutionToSplunkExecutionMapper(
Expand All @@ -313,6 +342,7 @@ export class FromHDFToSplunkMapper extends FromAnyBaseConverter {
guid
).toSplunkExecution() as SplunkReport
);
logger?.debug(`Converted execution: ${JSON.stringify(splunkData.reports)}`);
this.data.contains.forEach((profile: ContextualizedProfile) => {
splunkData.profiles.push(
new FromHDFProfileToSplunkProfileMapper(
Expand All @@ -335,10 +365,19 @@ export class FromHDFToSplunkMapper extends FromAnyBaseConverter {
});

const uploads: Promise<AxiosResponse>[] = [];
logger?.info(
'Data converted, uploading to Splunk with config: ' +
JSON.stringify(config)
);
uploads.push(...postDataToSplunkHEC(splunkData.reports, config));
uploads.push(...postDataToSplunkHEC(splunkData.profiles, config));
uploads.push(...postDataToSplunkHEC(splunkData.controls, config));

return Promise.all(uploads).then(() => guid);
return Promise.all(uploads).then(() => {
logger?.info(
camdenmoors marked this conversation as resolved.
Show resolved Hide resolved
`Uploaded into splunk successfully, to find this data search for: meta.guid="${guid}"`
);
return guid;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type SplunkProfile = {
meta: Meta;
summary: string;
sha256: string;
controls: any[];
supports: any[] | ILookupPathFH;
name: string;
copyright: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ExecJSON} from 'inspecjs';
export type SplunkReport = {
meta: Meta;
statistics?: ExecJSON.Statistics;
profiles: any[];
platform: Platform;
version: string;
};
Expand Down
19 changes: 19 additions & 0 deletions libs/hdf-converters/src/utils/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import winston from 'winston';

export function createWinstonLogger(
mapperName: string,
level = 'debug'
): winston.Logger {
return winston.createLogger({
transports: [new winston.transports.Console()],
level: level,
format: winston.format.combine(
winston.format.timestamp({
format: 'MMM-DD-YYYY HH:mm:ss Z'
}),
winston.format.printf(
(info) => `[${[info.timestamp]}] ${mapperName} ${info.message}`
)
)
});
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20558,7 +20558,7 @@ winston-transport@^4.5.0:
readable-stream "^3.6.0"
triple-beam "^1.3.0"

winston@^3.3.3:
winston@^3.3.3, winston@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/winston/-/winston-3.6.0.tgz#be32587a099a292b88c49fac6fa529d478d93fb6"
integrity sha512-9j8T75p+bcN6D00sF/zjFVmPp+t8KMPB1MzbbzYjeN9VWxdsYnTB40TkbNUEXAmILEfChMvAMgidlX64OG3p6w==
Expand Down