Skip to content
This repository was archived by the owner on Mar 20, 2020. It is now read-only.
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
8 changes: 8 additions & 0 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ module.exports = {
inputs: ['query'],
sinks: sinks.cmdInjectionSemanticChainedCommands
},
cmdInjectionSemanticDangerousPaths: {
base: '/cmdInjectionSemanticDangerousPaths',
name: 'Command Injection Semantic Dangerous Paths',
link: 'https://www.owasp.org/index.php/Command_Injection',
products: ['Protect'],
inputs: ['query'],
sinks: sinks.cmdInjectionSemanticDangerousPaths
},
nosqlInjection: {
base: '/nosqlInjection',
name: 'NoSQL Injection',
Expand Down
29 changes: 29 additions & 0 deletions lib/sinks/cmdInjectionSemanticDangerousPaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const cp = require('child_process');

const pre = (str) => `<pre>${str}</pre>`;

/**
* @param {string} input user input string
* @param {Object} opts
* @param {boolean=} opts.safe are we calling the sink safely?
* @param {boolean=} opts.noop are we calling the sink as a noop?
*/
module.exports['child_process.exec'] = async function exec(
input,
{ safe = false, noop = false } = {}
) {
if (safe) return 'SAFE';
if (noop) return 'NOOP';

return new Promise((resolve) => {
cp.exec("/bin/sh -c 'cat /tmp/foo.txt /etc/passwd'", (err, data) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't take any data from request which is ok but what do we do in darpa-testing-config to test these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Would it be better to just take in data from the request so that we could have darpa-testing-config sending different commands that'll trigger this rule?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine just curious

if (err) {
console.log(
`exec failed on /bin/sh -c 'cat /tmp/foo.txt /etc/passwd', err: ${err.message}`
);
}
resolve(pre(data.toString()));
});
});
};
1 change: 1 addition & 0 deletions lib/sinks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
sqlInjection: require('./sqlInjection'),
cmdInjection: require('./cmdInjection'),
cmdInjectionSemanticChainedCommands: require('./cmdInjectionSemanticChainedCommands'),
cmdInjectionSemanticDangerousPaths: require('./cmdInjectionSemanticDangerousPaths'),
pathTraversal: require('./pathTraversal'),
ssjs: require('./ssjs'),
ssrf: require('./ssrf'),
Expand Down