Skip to content
This repository was archived by the owner on Mar 20, 2020. It is now read-only.

Commit a3d74b2

Browse files
Merge pull request #13 from Contrast-Security-OSS/NODE-637-chained-commands-sink
add semantic chained commands protect rule sink
2 parents 62fe745 + d323d21 commit a3d74b2

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/routes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module.exports = {
99
inputs: ['query', 'cookies'],
1010
sinks: sinks.cmdInjection
1111
},
12+
cmdInjectionSemanticChainedCommands: {
13+
base: '/cmdInjectionSemanticChainedCommands',
14+
name: 'Command Injection Semantic Chained Commands',
15+
link: 'https://www.owasp.org/index.php/Command_Injection',
16+
products: ['Protect'],
17+
inputs: ['query'],
18+
sinks: sinks.cmdInjectionSemanticChainedCommands
19+
},
1220
nosqlInjection: {
1321
base: '/nosqlInjection',
1422
name: 'NoSQL Injection',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const cp = require('child_process');
3+
4+
const pre = (str) => `<pre>${str}</pre>`;
5+
6+
/**
7+
* @param {string} input user input string
8+
* @param {Object} opts
9+
* @param {boolean=} opts.safe are we calling the sink safely?
10+
* @param {boolean=} opts.noop are we calling the sink as a noop?
11+
*/
12+
module.exports['child_process.exec'] = async function exec(
13+
input,
14+
{ safe = false, noop = false } = {}
15+
) {
16+
if (safe) return 'SAFE';
17+
if (noop) return 'NOOP';
18+
19+
return new Promise((resolve) => {
20+
cp.exec('ls ; ps', (err, data) => {
21+
if (err) {
22+
console.log(`exec failed on 'ls ; ps', err: ${err.message}`);
23+
}
24+
resolve(pre(data.toString()));
25+
});
26+
});
27+
};

lib/sinks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
nosqlInjection: require('./nosqlInjection'),
55
sqlInjection: require('./sqlInjection'),
66
cmdInjection: require('./cmdInjection'),
7+
cmdInjectionSemanticChainedCommands: require('./cmdInjectionSemanticChainedCommands'),
78
pathTraversal: require('./pathTraversal'),
89
ssjs: require('./ssjs'),
910
ssrf: require('./ssrf'),

0 commit comments

Comments
 (0)