Skip to content

Commit d5b98de

Browse files
authored
feat(probe/unsafe-command): detect uname command (#376)
* feat(probes): handle uname command in unsafe-command probe Signed-off-by: Tony Gorez <[email protected]> * test(probes): add truncated aog-checker payload Signed-off-by: Tony Gorez <[email protected]> * chore: add change set Signed-off-by: Tony Gorez <[email protected]> --------- Signed-off-by: Tony Gorez <[email protected]>
1 parent 53b25a4 commit d5b98de

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.changeset/dark-garlics-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/js-x-ray": patch
3+
---
4+
5+
Handle uname as unsafe-command

workspaces/js-x-ray/src/probes/isUnsafeCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ProbeSignals } from "../ProbeRunner.js";
88
import { isLiteral } from "../types/estree.js";
99

1010
// CONSTANTS
11-
const kUnsafeCommands = ["csrutil"];
11+
const kUnsafeCommands = ["csrutil", "uname"];
1212

1313
function isUnsafeCommand(
1414
command: string

workspaces/js-x-ray/test/probes/isUnsafeCommand.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,28 @@ test("should not detect non suspicious command", () => {
8989
assert.equal(sastAnalysis.warnings().length, 0);
9090
});
9191
});
92+
93+
// Note: Until we can safely test with actual malware samples,
94+
// these tests uses a truncated snippet from a known malicious package.
95+
96+
test("aog-checker detection", () => {
97+
// Ref: https://socket.dev/npm/package/aog-checker/files/99.99.99/index.js
98+
const maliciousCode = `
99+
const { execSync } = require("child_process");
100+
// truncated ...
101+
let uname = "";
102+
try {
103+
uname = execSync("uname -a").toString().trim();
104+
} catch (e) {
105+
uname = "N/A";
106+
}
107+
`;
108+
109+
const ast = parseScript(maliciousCode);
110+
const sastAnalysis = getSastAnalysis(maliciousCode, isUnsafeCommand)
111+
.execute(ast.body);
112+
113+
const result = sastAnalysis.getWarning(kWarningUnsafeCommand);
114+
assert.equal(result.kind, kWarningUnsafeCommand);
115+
assert.equal(result.value, "uname -a");
116+
});

0 commit comments

Comments
 (0)