Skip to content

Detect parser feature #4

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

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -2,6 +2,7 @@ import { useDispatch } from 'react-redux';
import { Dispatch } from '@reduxjs/toolkit';
import { setText } from '../../../reduxData/inputEditor';
import { useInfoProvider } from '../../Info';
import { useDetectParserByText } from '../../../hooks';

export const FILE_TYPES_ALLOWED_FOR_UPLOAD = [
'text/csv',
Expand All @@ -14,6 +15,7 @@ export const MAX_FILE_SIZE_FOR_UPLOAD = 3 * 1024 * 1024;
export const useInputEditorFileUploadButton = () => {
const dispatch = useDispatch<Dispatch<any>>();
const { showErrorMessage, showSuccessMessage } = useInfoProvider();
const { detectParser } = useDetectParserByText();
const uploadHandler = async (file: File) => {
if (!file) {
return;
Expand All @@ -34,6 +36,7 @@ export const useInputEditorFileUploadButton = () => {

const fileContent = await file.text();
dispatch(setText(fileContent));
detectParser(fileContent);
showSuccessMessage('File uploaded successfully');
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import './InputTextEditor.sass';

export const InputTextEditor: FC = () => {
const {
inputText, mode, onChangeInputText, onFocusInputText,
inputText,
mode,
onChangeInputText,
onFocusInputText,
onPasteInputText,
} = useInputEditor();

return (
Expand All @@ -18,6 +22,7 @@ export const InputTextEditor: FC = () => {
name="ua-text-editor-input"
onChange={onChangeInputText}
onFocus={onFocusInputText}
onPaste={onPasteInputText}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ace from 'ace-builds';
import 'ace-builds/src-noconflict/ext-language_tools';
import { loadSuggesterData, suggesterSelector } from '../../../reduxData/suggester';
import { useEditorSuggestion } from '../useEditorSuggestion';
import { useDetectParserByText } from '../../../hooks';

const defineMode = (parser: string) => {
if (['sigma', 'roota'].includes(parser)) {
Expand All @@ -27,6 +28,7 @@ export const useInputEditor = () => {
const { text: inputText, platformCode: parser, changed } = useSelector(inputEditorSelector);
const suggestionData = useSelector(suggesterSelector);
const { languageCompleter } = useEditorSuggestion(suggestionData);
const { detectParser } = useDetectParserByText();

useEffect(() => {
const langTools = ace.require('ace/ext/language_tools');
Expand Down Expand Up @@ -54,11 +56,16 @@ export const useInputEditor = () => {
dispatch(setText(''));
};

const onPasteInputText = (value: string) => {
detectParser(value);
};

return {
isIoc: parser === 'ioc',
inputText,
mode: defineMode(parser),
onChangeInputText,
onFocusInputText,
onPasteInputText,
};
};
3 changes: 2 additions & 1 deletion uncoder-os/src/components/TextEditor/TextEditor.sass
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
background-color: $darkHighlight
.ace_scrollbar
z-index: 0
&.ace_scrollbar-v
&.ace_scrollbar-v,
&.ace_scrollbar-h
+scrollbars
.ace_folding-enabled
.ace_gutter-cell
Expand Down
5 changes: 4 additions & 1 deletion uncoder-os/src/constants/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ uuid:`,
{
name: TemplatesKeys.MinimalSigma,
value: `title: sigma title
description:
references:
-
logsource:
#service:
category:
category:
product: windows
detection:
selection:
Expand Down
1 change: 1 addition & 0 deletions uncoder-os/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { useHandleClickOutside } from './useHandleClickOutside';
export * from './useDetectParserByText';
1 change: 1 addition & 0 deletions uncoder-os/src/hooks/useDetectParserByText/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useDetectParserByText';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useDispatch } from 'react-redux';
import { Dispatch } from '@reduxjs/toolkit';
import { setPlatformCode } from '../../reduxData/inputEditor';

const isSigma = (text: string): boolean => {
return text.includes('title:') && text.includes('logsource:') && text.includes('detection:');
};

const isRoota = (text: string): boolean => {
return text.includes('name:') && text.includes('mitre-attack:') && text.includes('detection:');
};
export const useDetectParserByText = () => {
const dispatch = useDispatch<Dispatch<any>>();
const detectParser = (text: string) => {
if (isRoota(text)) {
dispatch(setPlatformCode('roota'));
return;
}

if (isSigma(text)) {
dispatch(setPlatformCode('sigma'));
return;
}

dispatch(setPlatformCode('ioc'));
};

return {
detectParser,
};
};
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy