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

[backend] handle multilines with cmd #2002

Open
wants to merge 19 commits into
base: release/1.10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
65fbb06
[tool] add missing arch/os agent & implant in circle build (#2093)
guillaumejparis Dec 18, 2024
3105c3c
[backend] add arm64 windows repository for agent & implant (#2093)
guillaumejparis Dec 18, 2024
e31e29d
[all] Release 1.10.0
Filigran-Automation Dec 18, 2024
d5e3aa0
[backend] Update dependency io.swagger.core.v3:swagger-annotations-ja…
renovate[bot] Dec 19, 2024
b415712
[backend] Update logback monorepo to v1.5.13
renovate[bot] Dec 19, 2024
5a98dec
[tool] Update Node.js to v22.12.0
renovate[bot] Dec 19, 2024
2d95d07
[frontend] Update typescript-eslint monorepo to v8.18.1
renovate[bot] Dec 19, 2024
42d0ab2
[frontend] Update fontsource monorepo to v5.1.0
renovate[bot] Dec 19, 2024
178f0b0
[frontend] Update dependency zod to v3.24.1
renovate[bot] Dec 19, 2024
0f83956
[frontend] Update dependency react-syntax-highlighter to v15.6.1
renovate[bot] Dec 19, 2024
3a1c813
[frontend] Update dependency globals to v15.14.0
renovate[bot] Dec 19, 2024
3fbafe0
[frontend] Update emotion monorepo to v11.14.0
renovate[bot] Dec 19, 2024
41cc761
[tool] Update feature github template
savacano28 Dec 19, 2024
fb0fab9
[all] updated the PR template
heditar Dec 19, 2024
c660d4d
[frontend] When I select injects and export them, the entire list is …
isselparra Dec 19, 2024
5a7c382
[frontend] Update dependency @ckeditor/ckeditor5-react to v9.4.0
renovate[bot] Dec 19, 2024
06654d2
[frontend] Update dependency @stylistic/eslint-plugin to v2.12.1
renovate[bot] Dec 19, 2024
275dc01
[frontend] Layout of inject lists is not correct in create injects #1842
heditar Dec 19, 2024
7a2a3e7
[backend] handle multilines with cmd
MarineLeM Dec 5, 2024
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
25 changes: 25 additions & 0 deletions .circleci/config.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ steps:
- mvn test -q

- name: frontend-tests
image: node:22.11.0-alpine
image: node:22.12.0-alpine
volumes:
- name: cache-node-frontend
path: /drone/src/openbas-front/node_modules
Expand Down Expand Up @@ -65,7 +65,7 @@ steps:
- frontend-tests

- name: frontend-e2e-tests
image: node:22.11.0
image: node:22.12.0
volumes:
- name: cache-node-frontend-e2e
path: /drone/src/openbas-front/node_modules
Expand Down
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ assignees: ''

---

## Context

<!--
- Why is this solution needed?
- What value or benefits will the end-users gain from this change?
- Is this change a technical improvement? just for internal use, or does it impact users as well?
-->

## Use case

<!-- Please describe the use case for which you need a solution -->
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ By doing this, you are actively helping us to improve the quality of the entire
- [ ] I wrote test cases for the relevant uses case
- [ ] I added/update the relevant documentation (either on github or on notion)
- [ ] Where necessary I refactored code to improve the overall quality
- [ ] For bug fix -> I implemented a test that covers the bug

<!-- _NOTE: these things are not required to open a PR and can be done afterwards / while the PR draft is open._ -->
<!-- For completed items, change [ ] to [x]. -->
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:22.11.0-alpine3.20 AS front-builder
FROM node:22.12.0-alpine3.20 AS front-builder

WORKDIR /opt/openbas-build/openbas-front
COPY openbas-front/packages ./packages
Expand Down
8 changes: 4 additions & 4 deletions openbas-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.openbas</groupId>
<artifactId>openbas-platform</artifactId>
<version>1.9.2</version>
<version>1.10.0</version>
</parent>

<artifactId>openbas-api</artifactId>
Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>io.openbas</groupId>
<artifactId>openbas-framework</artifactId>
<version>1.9.2</version>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
Expand Down Expand Up @@ -231,12 +231,12 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.12</version>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.12</version>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback.contrib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@
return result.toString();
}

private static String formatMultilineCommand(String command) {
String[] lines = command.split("\n");
StringBuilder formattedCommand = new StringBuilder();
boolean insideBlock = false;

Check warning on line 79 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L77-L79

Added lines #L77 - L79 were not covered by tests

for (int i = 0; i < lines.length; i++) {
String line = lines[i];
String trimmedLine = line.trim();

Check warning on line 83 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L82-L83

Added lines #L82 - L83 were not covered by tests
if (trimmedLine.isEmpty()) {
continue;

Check warning on line 85 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L85

Added line #L85 was not covered by tests
}
formattedCommand.append(trimmedLine);

Check warning on line 87 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L87

Added line #L87 was not covered by tests

if (trimmedLine.endsWith("(")) {
insideBlock = true;

Check warning on line 90 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L90

Added line #L90 was not covered by tests
}

if (trimmedLine.endsWith(")")) {
insideBlock = false;

Check warning on line 94 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L94

Added line #L94 was not covered by tests
}

boolean isLastLine = (i == lines.length - 1);
if (!insideBlock && !isLastLine) {
formattedCommand.append(" & ");

Check warning on line 99 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L99

Added line #L99 was not covered by tests
} else {
formattedCommand.append(" ");

Check warning on line 101 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L101

Added line #L101 was not covered by tests
}
}

return formattedCommand.toString();

Check warning on line 105 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L105

Added line #L105 was not covered by tests
}

private String processAndEncodeCommand(
String command,
String executor,
Expand All @@ -83,7 +115,7 @@

if (executor.equals("cmd")) {
computedCommand = replaceCmdVariables(computedCommand);
computedCommand = computedCommand.trim().replace("\n", " & ");
computedCommand = formatMultilineCommand(computedCommand);

Check warning on line 118 in openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/inject/service/ExecutableInjectService.java#L118

Added line #L118 was not covered by tests
}

if (obfuscator.equals("base64")) {
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions openbas-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.openbas</groupId>
<artifactId>openbas-platform</artifactId>
<version>1.9.2</version>
<version>1.10.0</version>
</parent>

<artifactId>openbas-framework</artifactId>
Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>io.openbas</groupId>
<artifactId>openbas-model</artifactId>
<version>1.9.2</version>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
Expand Down
26 changes: 13 additions & 13 deletions openbas-front/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "openbas-front",
"version": "1.9.2",
"version": "1.10.0",
"private": true,
"main": "src/index.tsx",
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@ckeditor/ckeditor5-react": "9.3.1",
"@ckeditor/ckeditor5-react": "9.4.0",
"@dagrejs/dagre": "1.1.4",
"@emotion/react": "11.13.3",
"@emotion/styled": "11.13.0",
"@fontsource/geologica": "5.0.6",
"@fontsource/ibm-plex-sans": "5.0.21",
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.0",
"@fontsource/geologica": "5.1.0",
"@fontsource/ibm-plex-sans": "5.1.0",
"@hookform/resolvers": "3.9.1",
"@microsoft/fetch-event-source": "2.0.1",
"@mui/icons-material": "6.2.0",
Expand Down Expand Up @@ -63,7 +63,7 @@
"react-markdown": "9.0.1",
"react-redux": "9.2.0",
"react-router": "7.0.1",
"react-syntax-highlighter": "15.5.0",
"react-syntax-highlighter": "15.6.1",
"redux": "5.0.1",
"redux-thunk": "3.1.0",
"remark-flexible-markers": "1.2.1",
Expand All @@ -74,18 +74,18 @@
"usehooks-ts": "3.1.0",
"uuid": "11.0.3",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
"zod": "3.23.8",
"zod": "3.24.1",
"zustand": "5.0.1"
},
"devDependencies": {
"@eslint/js": "9.15.0",
"@playwright/test": "1.49.0",
"@stylistic/eslint-plugin": "2.11.0",
"@stylistic/eslint-plugin": "2.12.1",
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.1.0",
"@types/d3-hierarchy": "3.1.7",
"@types/eslint__js": "8.42.3",
"@types/node": "22.9.3",
"@types/node": "22.10.2",
"@types/pdfmake": "0.2.9",
"@types/qs": "6",
"@types/react": "18.3.14",
Expand All @@ -94,7 +94,7 @@
"@types/react-syntax-highlighter": "15",
"@types/seamless-immutable": "7.1.19",
"@types/uuid": "10.0.0",
"@typescript-eslint/parser": "8.16.0",
"@typescript-eslint/parser": "8.18.1",
"@vitejs/plugin-react": "4.3.4",
"chokidar": "4.0.1",
"cross-env": "7.0.3",
Expand All @@ -111,13 +111,13 @@
"eslint-plugin-simple-import-sort": "12.1.1",
"express": "4.21.1",
"fs-extra": "11.2.0",
"globals": "15.13.0",
"globals": "15.14.0",
"jsdom": "25.0.1",
"monocart-coverage-reports": "2.11.3",
"monocart-reporter": "2.9.11",
"swagger-typescript-api": "13.0.22",
"typescript": "5.7.2",
"typescript-eslint": "8.16.0",
"typescript-eslint": "8.18.1",
"vite": "6.0.3",
"vitest": "2.1.1"
},
Expand Down
16 changes: 8 additions & 8 deletions openbas-front/src/admin/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ const Dashboard = () => {
name: t('Number of simulations'),
data: exercisesCountByWeekHasValues
? Object.entries<number>(statistics.exercises_count_by_week!).map(([date, value]) => ({
x: date,
y: value,
}))
x: date,
y: value,
}))
: exercisesTimeSeriesFakeData,
},
], [exercisesCountByWeekHasValues, statistics?.exercises_count_by_week]);
Expand Down Expand Up @@ -140,11 +140,11 @@ const Dashboard = () => {
name: t('Number of injects'),
data: injectsCountByAttackPatternHasValues && Object.keys(attackPatternsMap).length
? Object.entries<number>(statistics.injects_count_by_attack_pattern!).map(([attackPatternId, value]) => {
return ({
x: [`[${attackPatternsMap[attackPatternId].attack_pattern_external_id}]`, attackPatternsMap[attackPatternId].attack_pattern_name],
y: value,
});
})
return ({
x: [`[${attackPatternsMap[attackPatternId].attack_pattern_external_id}]`, attackPatternsMap[attackPatternId].attack_pattern_name],
y: value,
});
})
: attackPatternsFakeData,
}],
[statistics?.injects_count_by_attack_pattern, injectsCountByAttackPatternHasValues, attackPatternsMap],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,56 +201,56 @@ const InjectResultList: FunctionComponent<Props> = ({
loading
? <PaginatedListLoader Icon={HelpOutlineOutlined} headers={headers} headerStyles={inlineStyles} />
: injects.map((injectResultOutput, index) => {
return (
<ListItem
key={injectResultOutput.inject_id}
classes={{ root: classes.item }}
divider={injects.length !== index + 1}
secondaryAction={showActions ? (
<AtomicTestingPopover
atomic={injectResultOutput}
actions={['Duplicate', 'Delete']}
onDelete={result => setInjects(injects.filter(e => e.inject_id !== result))}
inList
/>
) : null}
disablePadding
>
<ListItemButton
component={Link}
to={goTo(injectResultOutput.inject_id)}
return (
<ListItem
key={injectResultOutput.inject_id}
classes={{ root: classes.item }}
divider={injects.length !== index + 1}
secondaryAction={showActions ? (
<AtomicTestingPopover
atomic={injectResultOutput}
actions={['Duplicate', 'Delete']}
onDelete={result => setInjects(injects.filter(e => e.inject_id !== result))}
inList
/>
) : null}
disablePadding
>
<ListItemIcon>
<InjectIcon
isPayload={isNotEmptyField(injectResultOutput.inject_injector_contract?.injector_contract_payload?.payload_id)}
type={
injectResultOutput.inject_injector_contract?.injector_contract_payload?.payload_id
? injectResultOutput.inject_injector_contract.injector_contract_payload?.payload_collector_type
|| injectResultOutput.inject_injector_contract.injector_contract_payload?.payload_type
: injectResultOutput.inject_type
}
variant="list"
<ListItemButton
component={Link}
to={goTo(injectResultOutput.inject_id)}
>
<ListItemIcon>
<InjectIcon
isPayload={isNotEmptyField(injectResultOutput.inject_injector_contract?.injector_contract_payload?.payload_id)}
type={
injectResultOutput.inject_injector_contract?.injector_contract_payload?.payload_id
? injectResultOutput.inject_injector_contract.injector_contract_payload?.payload_collector_type
|| injectResultOutput.inject_injector_contract.injector_contract_payload?.payload_type
: injectResultOutput.inject_type
}
variant="list"
/>
</ListItemIcon>
<ListItemText
primary={(
<div className={classes.bodyItems}>
{headers.map(header => (
<div
key={header.field}
className={classes.bodyItem}
style={inlineStyles[header.field]}
>
{header.value?.(injectResultOutput)}
</div>
))}
</div>
)}
/>
</ListItemIcon>
<ListItemText
primary={(
<div className={classes.bodyItems}>
{headers.map(header => (
<div
key={header.field}
className={classes.bodyItem}
style={inlineStyles[header.field]}
>
{header.value?.(injectResultOutput)}
</div>
))}
</div>
)}
/>
</ListItemButton>
</ListItem>
);
})
</ListItemButton>
</ListItem>
);
})
}
{!injects ? (<Empty message={t('No data available')} />) : null}
</List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ const AtomicTesting = () => {
{
injectResultOverviewOutput.injects_documents !== undefined && injectResultOverviewOutput.injects_documents.length > 0
? injectResultOverviewOutput.injects_documents.map((documentId) => {
const document = documentMap[documentId];
return (
<Typography key={documentId} variant="body1">
{document?.document_name ?? '-'}
const document = documentMap[documentId];
return (
<Typography key={documentId} variant="body1">
{document?.document_name ?? '-'}
</Typography>
);
}) : (
<Typography variant="body1" gutterBottom>
-
</Typography>
);
}) : (
<Typography variant="body1" gutterBottom>
-
</Typography>
)
)
}
</Grid>
<Grid item xs={4} style={{ paddingTop: 10 }}>
Expand Down
Loading
Loading