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

Modification: Modified index and engine files to fix azure remediation invalid token issue #623

Merged
merged 121 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
e1708af
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 12, 2020
2122ade
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
306d721
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
7c8616c
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
de52e8a
Merge branch 'master' into feature/ec2-plugin-mark-launch-wizard-secu…
AkhtarAmir Aug 14, 2020
f3b72f6
Merge pull request #1 from AkhtarAmir/feature/ec2-plugin-mark-launch-…
AkhtarAmir Aug 14, 2020
d32cbac
Merge branch 'master' of https://github.com/AkhtarAmir/scans into fea…
AkhtarAmir Aug 14, 2020
3da6672
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
928c712
Merge pull request #2 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
ce65325
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
f3e3ab5
Merge pull request #3 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
e70b96a
Made PR requested changes
AkhtarAmir Aug 14, 2020
f62a1d5
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
865e0b6
Merge pull request #4 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
9745614
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Aug 15, 2020
1b80ac4
Accommodated PR changes
AkhtarAmir Aug 17, 2020
c0dc834
Fixed eslint issues
AkhtarAmir Aug 18, 2020
7d457bd
Update exports.js
AkhtarAmir Aug 18, 2020
8c2466c
Fixed eslint issues
AkhtarAmir Aug 18, 2020
ccb92ee
Update index.js
AkhtarAmir Aug 18, 2020
93c553d
Update index.js
AkhtarAmir Aug 18, 2020
cf21d1d
Added cloudformation in china and gov regions
AkhtarAmir Aug 18, 2020
aac8ece
Accomodated PR changes
AkhtarAmir Aug 18, 2020
7707dbd
Updated status in result of failure
AkhtarAmir Aug 18, 2020
a4ea92f
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
8e5b6be
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
a9afe44
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
0323a98
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
aab9f79
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
12d88c1
Made PR requested changes
AkhtarAmir Aug 14, 2020
7dd1a5b
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
c8a23c3
Accommodated PR changes
AkhtarAmir Aug 17, 2020
92821dd
Fixed eslint issues
AkhtarAmir Aug 18, 2020
e32accc
Update index.js
AkhtarAmir Aug 18, 2020
90094a2
Update index.js
AkhtarAmir Aug 18, 2020
c29ab07
Accomodated PR changes
AkhtarAmir Aug 18, 2020
49f1202
Updated status in result of failure
AkhtarAmir Aug 18, 2020
fa70d92
Updated master from upstream/master
AkhtarAmir Aug 21, 2020
357cd0b
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
77ca002
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
73172b8
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
7b448ff
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
50d9d70
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
46ff92c
Made PR requested changes
AkhtarAmir Aug 14, 2020
ec1e5ef
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
e89dd5e
Accommodated PR changes
AkhtarAmir Aug 17, 2020
4d7ee30
Fixed eslint issues
AkhtarAmir Aug 18, 2020
f5c9bf0
Update index.js
AkhtarAmir Aug 18, 2020
53e18b8
Update index.js
AkhtarAmir Aug 18, 2020
6ec73bc
Accomodated PR changes
AkhtarAmir Aug 18, 2020
2f55a11
Updated status in result of failure
AkhtarAmir Aug 18, 2020
0ba2fbf
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 12, 2020
e9415b9
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
8820775
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
8e6b23b
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
82d8406
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
b022a52
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
d3ee380
Made PR requested changes
AkhtarAmir Aug 14, 2020
560d273
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
9195d32
Accommodated PR changes
AkhtarAmir Aug 17, 2020
0287cc5
Fixed eslint issues
AkhtarAmir Aug 18, 2020
1315ccd
Update exports.js
AkhtarAmir Aug 18, 2020
229461c
Update index.js
AkhtarAmir Aug 18, 2020
f5a3b8b
Update index.js
AkhtarAmir Aug 18, 2020
c574f76
Accomodated PR changes
AkhtarAmir Aug 18, 2020
1a4b495
Updated status in result of failure
AkhtarAmir Aug 18, 2020
a45a9f7
Merge branch 'master' of https://github.com/AkhtarAmir/scans into master
AkhtarAmir Aug 28, 2020
156d027
Removed unnecesary rebase changes
AkhtarAmir Aug 28, 2020
32ee6d9
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 12, 2020
c687820
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 22, 2020
29075e7
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit …
AkhtarAmir Sep 24, 2020
c51edd1
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 25, 2020
0768693
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Oct 16, 2020
2d04307
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Oct 20, 2020
c6b7eb1
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 5, 2020
159f5dd
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 21, 2020
d713e12
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 26, 2020
b63a6d3
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
472380f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
a95a46b
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
f83f331
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
55b0319
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit
AkhtarAmir Dec 20, 2020
f627c6a
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Dec 22, 2020
6fe875d
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 21, 2021
d129f4b
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 21, 2021
c132394
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 22, 2021
68e9bfe
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit
AkhtarAmir Jan 23, 2021
0cbc28f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 23, 2021
2fa5e63
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 25, 2021
7319bca
Merge branch 'master' of https://github.com/AkhtarAmir/scans
AkhtarAmir Jan 25, 2021
4c73161
Added superlinter
AkhtarAmir Jan 26, 2021
6cda1ef
Added scans ci
AkhtarAmir Jan 27, 2021
072a98a
Updated Ci file
AkhtarAmir Jan 27, 2021
cb40648
Updated Node version in CI file
AkhtarAmir Jan 27, 2021
b0138cb
removed spech check command
AkhtarAmir Jan 27, 2021
239b8a6
Delete scan_ci.yml
AkhtarAmir Jan 27, 2021
63cd684
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
ab41137
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
f04d8d8
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
9c56577
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 28, 2021
8c3e0ef
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
32f8e04
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
2db8162
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
46cfe9d
Added spellcheck
AkhtarAmir Feb 1, 2021
5f0adec
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Feb 3, 2021
ea01ba2
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 2, 2021
9f518b6
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 5, 2021
0bf276d
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 12, 2021
5271345
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 14, 2021
2852187
Azure MySQL Enforce SSL Connection remediated
AkhtarAmir Mar 18, 2021
da2417f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 23, 2021
ffe9864
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 24, 2021
48d11fd
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 26, 2021
2d04881
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 29, 2021
c8edb8a
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 29, 2021
566a513
Modified index and engine files to fix azure remediation invalid toke…
AkhtarAmir Mar 30, 2021
7670ef0
Merge branch 'master' of https://github.com/AkhtarAmir/scans into rem…
AkhtarAmir Mar 30, 2021
2409824
Update engine.js
AkhtarAmir Mar 30, 2021
fdaf02e
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 1, 2021
c1373ac
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 16, 2021
5d3704c
Merge branch 'master' of https://github.com/AkhtarAmir/scans into mod…
AkhtarAmir Apr 16, 2021
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
17 changes: 17 additions & 0 deletions config_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ module.exports = {
// session_token: process.env.AWS_SESSION_TOKEN || '',
// plugins_remediate: ['bucketEncryptionInTransit']
},
aws_remediate: {
// OPTION 1: If using a credential JSON file, enter the path below
// credential_file: '/path/to/file.json',
// OPTION 2: If using hard-coded credentials, enter them below
// access_key: process.env.AWS_ACCESS_KEY_ID || '',
// secret_access_key: process.env.AWS_SECRET_ACCESS_KEY || '',
// session_token: process.env.AWS_SESSION_TOKEN || '',
},
azure: {
// OPTION 1: If using a credential JSON file, enter the path below
// credential_file: '/path/to/file.json',
Expand All @@ -20,6 +28,15 @@ module.exports = {
// directory_id: process.env.AZURE_DIRECTORY_ID || '',
// subscription_id: process.env.AZURE_SUBSCRIPTION_ID || ''
},
azure_remediate: {
// OPTION 1: If using a credential JSON file, enter the path below
// credential_file: '/path/to/file.json',
// OPTION 2: If using hard-coded credentials, enter them below
// application_id: process.env.AZURE_APPLICATION_ID || '',
// key_value: process.env.AZURE_KEY_VALUE || '',
// directory_id: process.env.AZURE_DIRECTORY_ID || '',
// subscription_id: process.env.AZURE_SUBSCRIPTION_ID || ''
},
google: {
// OPTION 1: If using a credential JSON file, enter the path below
// credential_file: process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/file.json',
Expand Down
181 changes: 101 additions & 80 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ var async = require('async');
var exports = require('./exports.js');
var suppress = require('./postprocess/suppress.js');
var output = require('./postprocess/output.js');

var azureHelper = require('./helpers/azure/auth.js');

function runAuth(settings, remediateConfig, callback) {
if (settings.cloud && settings.cloud == 'azure') {
azureHelper.login(remediateConfig, function(err, loginData) {
if (err) return (callback(err));
remediateConfig.token = loginData.token;
return callback();
});
} else callback();
}
/**
* The main function to execute CloudSploit scans.
* @param cloudConfig The configuration for the cloud provider.
Expand Down Expand Up @@ -138,91 +148,102 @@ var engine = function(cloudConfig, settings) {
console.log('INFO: Analysis complete. Scan report to follow...');

var maximumStatus = 0;

async.mapValuesLimit(plugins, 10, function(plugin, key, pluginDone) {
if (skippedPlugins.indexOf(key) > -1) return pluginDone(null, 0);

var postRun = function(err, results) {
if (err) return console.log(`ERROR: ${err}`);
if (!results || !results.length) {
console.log(`Plugin ${plugin.title} returned no results. There may be a problem with this plugin.`);
} else {
for (var r in results) {
// If we have suppressed this result, then don't process it
// so that it doesn't affect the return code.
if (suppressionFilter([key, results[r].region || 'any', results[r].resource || 'any'].join(':'))) {
continue;
}

var complianceMsg = [];
if (settings.compliance && settings.compliance.length) {
settings.compliance.forEach(function(c) {
if (plugin.compliance && plugin.compliance[c]) {
complianceMsg.push(`${c.toUpperCase()}: ${plugin.compliance[c]}`);
}
});
}
complianceMsg = complianceMsg.join('; ');
if (!complianceMsg.length) complianceMsg = null;

// Write out the result (to console or elsewhere)
outputHandler.writeResult(results[r], plugin, key, complianceMsg);

// Add this to our tracking for the worst status to calculate
// the exit code
maximumStatus = Math.max(maximumStatus, results[r].status);
// Remediation
if (settings.remediate && settings.remediate.length) {
if (settings.remediate.indexOf(key) > -1) {
if (results[r].status === 2) {
var resource = results[r].resource;
var event = {};
event.region = results[r].region;
event['remediation_file'] = {};
event['remediation_file'] = initializeFile(event['remediation_file'], 'execute', key, resource);
plugin.remediate(cloudConfig, collection, event, resource, (err, result) => {
if (err) return console.log(err);
return console.log(result);
});

function executePlugins(cloudRemediateConfig) {
async.mapValuesLimit(plugins, 10, function(plugin, key, pluginDone) {
if (skippedPlugins.indexOf(key) > -1) return pluginDone(null, 0);

var postRun = function(err, results) {
if (err) return console.log(`ERROR: ${err}`);
if (!results || !results.length) {
console.log(`Plugin ${plugin.title} returned no results. There may be a problem with this plugin.`);
} else {
for (var r in results) {
// If we have suppressed this result, then don't process it
// so that it doesn't affect the return code.
if (suppressionFilter([key, results[r].region || 'any', results[r].resource || 'any'].join(':'))) {
continue;
}

var complianceMsg = [];
if (settings.compliance && settings.compliance.length) {
settings.compliance.forEach(function(c) {
if (plugin.compliance && plugin.compliance[c]) {
complianceMsg.push(`${c.toUpperCase()}: ${plugin.compliance[c]}`);
}
});
}
complianceMsg = complianceMsg.join('; ');
if (!complianceMsg.length) complianceMsg = null;

// Write out the result (to console or elsewhere)
outputHandler.writeResult(results[r], plugin, key, complianceMsg);

// Add this to our tracking for the worst status to calculate
// the exit code
maximumStatus = Math.max(maximumStatus, results[r].status);
// Remediation
if (settings.remediate && settings.remediate.length) {
if (settings.remediate.indexOf(key) > -1) {
if (results[r].status === 2) {
var resource = results[r].resource;
var event = {};
event.region = results[r].region;
event['remediation_file'] = {};
event['remediation_file'] = initializeFile(event['remediation_file'], 'execute', key, resource);
plugin.remediate(cloudRemediateConfig, collection, event, resource, (err, result) => {
if (err) return console.log(err);
return console.log(result);
});
}
}
}
}

}

setTimeout(function() { pluginDone(err, maximumStatus); }, 0);
};

if (plugin.asl) {
console.log(`INFO: Using custom ASL for plugin: ${plugin.title}`);
// Inject APIs and resource maps
plugin.asl.apis = plugin.apis;
var aslConfig = require('./helpers/asl/config.json');
var aslVersion = plugin.asl.version ? plugin.asl.version : aslConfig.current_version;
let aslRunner;
try {
aslRunner = require(`./helpers/asl/asl-${aslVersion}.js`);

} catch (e) {
postRun('Error: ASL: Wrong ASL Version: ', e);
}

aslRunner(collection, plugin.asl, resourceMap, postRun);
} else {
plugin.run(collection, settings, postRun);
}
setTimeout(function() { pluginDone(err, maximumStatus); }, 0);
};

if (plugin.asl) {
console.log(`INFO: Using custom ASL for plugin: ${plugin.title}`);
// Inject APIs and resource maps
plugin.asl.apis = plugin.apis;
var aslConfig = require('./helpers/asl/config.json');
var aslVersion = plugin.asl.version ? plugin.asl.version : aslConfig.current_version;
let aslRunner;
try {
aslRunner = require(`./helpers/asl/asl-${aslVersion}.js`);

} catch (e) {
postRun('Error: ASL: Wrong ASL Version: ', e);
}, function(err) {
if (err) return console.log(err);
// console.log(JSON.stringify(collection, null, 2));
outputHandler.close();
if (settings.exit_code) {
// The original cloudsploit always has a 0 exit code. With this option, we can have
// the exit code depend on the results (useful for integration with CI systems)
console.log(`INFO: Exiting with exit code: ${maximumStatus}`);
process.exitCode = maximumStatus;
}

aslRunner(collection, plugin.asl, resourceMap, postRun);
} else {
plugin.run(collection, settings, postRun);
}
}, function(err) {
if (err) return console.log(err);
// console.log(JSON.stringify(collection, null, 2));
outputHandler.close();
if (settings.exit_code) {
// The original cloudsploit always has a 0 exit code. With this option, we can have
// the exit code depend on the results (useful for integration with CI systems)
console.log(`INFO: Exiting with exit code: ${maximumStatus}`);
process.exitCode = maximumStatus;
}
console.log('INFO: Scan complete');
});
console.log('INFO: Scan complete');
});
}

if (settings.remediate && settings.remediate.length && cloudConfig.remediate) {
runAuth(settings, cloudConfig.remediate, function(err) {
if (err) return console.log(err);
executePlugins(cloudConfig.remediate);
});
} else {
executePlugins(cloudConfig);
}
});
};

Expand Down
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,42 @@ if (config.credentials.aws.credential_file) {
process.exit(1);
}

if (settings.remediate && settings.remediate.length) {
if (!config.credentials[`${settings.cloud}_remediate`]) {
console.error('ERROR: No credentials provided for remediation.');
process.exit(1);
}
if (config.credentials.aws_remediate && config.credentials.aws_remediate.credential_file) {
cloudConfig.remediate = loadHelperFile(config.credentials.aws_remediate.credential_file);
if (!cloudConfig.remediate || !cloudConfig.remediate.accessKeyId || !cloudConfig.remediate.secretAccessKey) {
console.error('ERROR: AWS credential file for remediation does not have accessKeyId or secretAccessKey properties');
process.exit(1);
}
} else if (config.credentials.aws_remediate && config.credentials.aws_remediate.access_key) {
checkRequiredKeys(config.credentials.aws_remediate, ['secret_access_key']);
cloudConfig.remediate = {
accessKeyId: config.credentials.aws_remediate.access_key,
secretAccessKey: config.credentials.aws_remediate.secret_access_key,
sessionToken: config.credentials.aws_remediate.session_token
};
} else if (config.credentials.azure_remediate && config.credentials.azure_remediate.credential_file) {
cloudConfig.remediate = loadHelperFile(config.credentials.azure_remediate.credential_file);
if (!cloudConfig.remediate || !cloudConfig.remediate.ApplicationID || !cloudConfig.remediate.KeyValue || !cloudConfig.remediate.DirectoryID || !cloudConfig.remediate.SubscriptionID) {
console.error('ERROR: Azure credential file for remediation does not have ApplicationID, KeyValue, DirectoryID, or SubscriptionID');
process.exit(1);
}
} else if (config.credentials.azure_remediate && config.credentials.azure_remediate.application_id) {
checkRequiredKeys(config.credentials.azure_remediate, ['key_value', 'directory_id', 'subscription_id']);
cloudConfig.remediate = {
ApplicationID: config.credentials.azure_remediate.application_id,
KeyValue: config.credentials.azure_remediate.key_value,
DirectoryID: config.credentials.azure_remediate.directory_id,
SubscriptionID: config.credentials.azure_remediate.subscription_id
};
} else {
console.error('ERROR: Config file does not contain any valid credential configs for remediation.');
process.exit(1);
}
}
// Now execute the scans using the defined configuration information.
engine(cloudConfig, settings);