Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ali-imran7/cloudsploit in…
Browse files Browse the repository at this point in the history
…to feature/AKD-191
  • Loading branch information
AkhtarAmir committed Jun 1, 2021
2 parents 62acb24 + e61b78e commit 2cf101c
Show file tree
Hide file tree
Showing 50 changed files with 4,204 additions and 51 deletions.
7 changes: 7 additions & 0 deletions collectors/alibaba/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ var postcalls = [
filterValue: ['UserName'],
apiVersion: '2015-05-01'
},
ListAccessKeys: {
reliesOnService: 'ram',
reliesOnCall: 'ListUsers',
filterKey: ['UserName'],
filterValue: ['UserName'],
apiVersion: '2015-05-01'
},
ListPoliciesForUser: {
reliesOnService: 'ram',
reliesOnCall: 'ListUsers',
Expand Down
16 changes: 15 additions & 1 deletion exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ module.exports = {
'http20Enabled' : require(__dirname + '/plugins/azure/appservice/http20Enabled.js'),
'httpsOnlyEnabled' : require(__dirname + '/plugins/azure/appservice/httpsOnlyEnabled.js'),
'tlsVersionCheck' : require(__dirname + '/plugins/azure/appservice/tlsVersionCheck.js'),
'automatedBackupsConfigured' : require(__dirname + '/plugins/azure/appservice/automatedBackupsConfigured.js'),
'appserviceAutomatedBackups' : require(__dirname + '/plugins/azure/appservice/appserviceAutomatedBackups.js'),

'rbacEnabled' : require(__dirname + '/plugins/azure/kubernetesservice/rbacEnabled.js'),
'aksLatestVersion' : require(__dirname + '/plugins/azure/kubernetesservice/aksLatestVersion.js'),
Expand Down Expand Up @@ -561,6 +561,7 @@ module.exports = {
'excessivePolicies' : require(__dirname + '/plugins/oracle/identity/excessivePolicies.js'),
'excessivePolicyStatements' : require(__dirname + '/plugins/oracle/identity/excessivePolicyStatements.js'),
'policyLeastPrivilege' : require(__dirname + '/plugins/oracle/identity/policyLeastPrivilege.js'),
'usersEmailVerified' : require(__dirname + '/plugins/oracle/identity/usersEmailVerified.js'),

'openSSH' : require(__dirname + '/plugins/oracle/networking/openSSH.js'),
'openOracleAutoDataWarehouse' : require(__dirname + '/plugins/oracle/networking/openOracleAutoDataWarehouse.js'),
Expand Down Expand Up @@ -669,6 +670,9 @@ module.exports = {
'dbPubliclyAccessible' : require(__dirname + '/plugins/google/sql/dbPubliclyAccessible.js'),
'dbSSLEnabled' : require(__dirname + '/plugins/google/sql/dbSSLEnabled.js'),
'anyHostRootAccess' : require(__dirname + '/plugins/google/sql/anyHostRootAccess.js'),
'postgresqlLogMinError' : require(__dirname + '/plugins/google/sql/postgresqlLogMinError.js'),
'postgresqlLogTempFiles' : require(__dirname + '/plugins/google/sql/postgresqlLogTempFiles.js'),
'postgresqlLogMinDuration' : require(__dirname + '/plugins/google/sql/postgresqlLogMinDuration.js'),
'postgresqlLogLockWaits' : require(__dirname + '/plugins/google/sql/postgresqlLogLockWaits.js'),
'mysqlLocalInfile' : require(__dirname + '/plugins/google/sql/mysqlLocalInfile.js'),
'postgresqlLogConnections' : require(__dirname + '/plugins/google/sql/postgresqlLogConnections.js'),
Expand Down Expand Up @@ -735,6 +739,7 @@ module.exports = {
'inactiveUserDisabled' : require(__dirname + '/plugins/alibaba/ram/inactiveUserDisabled.js'),
'passwordRequiresUppercase' : require(__dirname + '/plugins/alibaba/ram/passwordRequiresUppercase.js'),
'usersMfaEnabled' : require(__dirname + '/plugins/alibaba/ram/usersMfaEnabled.js'),
'accessKeysRotation' : require(__dirname + '/plugins/alibaba/ram/accessKeysRotation.js'),
'passwordNoReuse' : require(__dirname + '/plugins/alibaba/ram/passwordNoReuse.js'),
'passwordExpiry' : require(__dirname + '/plugins/alibaba/ram/passwordExpiry.js'),
'passwordBlockLogon' : require(__dirname + '/plugins/alibaba/ram/passwordBlockLogon.js'),
Expand All @@ -755,6 +760,15 @@ module.exports = {
'openNetBIOS' : require(__dirname + '/plugins/alibaba/ecs/openNetBIOS.js'),
'openOracle' : require(__dirname + '/plugins/alibaba/ecs/openOracle.js'),
'dataDisksEncrypted' : require(__dirname + '/plugins/alibaba/ecs/dataDisksEncrypted.js'),
'openCustomPorts' : require(__dirname + '/plugins/alibaba/ecs/openCustomPorts.js'),
'openOracleAutoDataWarehouse' : require(__dirname + '/plugins/alibaba/ecs/openOracleAutoDataWarehouse.js'),
'openSalt' : require(__dirname + '/plugins/alibaba/ecs/openSalt.js'),
'openSMTP' : require(__dirname + '/plugins/alibaba/ecs/openSMTP.js'),
'openSMBoTCP' : require(__dirname + '/plugins/alibaba/ecs/openSMBoTCP.js'),
'openSQLServer' : require(__dirname + '/plugins/alibaba/ecs/openSQLServer.js'),
'openTelnet' : require(__dirname + '/plugins/alibaba/ecs/openTelnet.js'),
'openVNCClient' : require(__dirname + '/plugins/alibaba/ecs/openVNCClient.js'),
'openVNCServer' : require(__dirname + '/plugins/alibaba/ecs/openVNCServer.js'),

'bucketLoggingEnabled' : require(__dirname + '/plugins/alibaba/oss/bucketLoggingEnabled.js'),
'ossBucketPrivate' : require(__dirname + '/plugins/alibaba/oss/ossBucketPrivate.js'),
Expand Down
3 changes: 1 addition & 2 deletions helpers/alibaba/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function createArn(service, account, resourceType, resourceId, region) {
}

function findOpenPorts(cache, groups, ports, service, region, results) {
// console.log(JSON.stringify(cache, null, 2));
var found = false;

for (var group of groups) {
Expand Down Expand Up @@ -51,7 +50,7 @@ function findOpenPorts(cache, groups, ports, service, region, results) {
for (let i = rangeFrom; i <= rangeTo; i++) {
if (fromPort<= i && toPort >= i) {
string = `some of ${permission.IpProtocol}:${port}`;
openV4Ports.push(string);
if (openV4Ports.indexOf(string) === -1) openV4Ports.push(string);
found = true;
break;
}
Expand Down
66 changes: 66 additions & 0 deletions plugins/alibaba/ecs/openCustomPorts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var async = require('async');
var helpers = require('../../../helpers/alibaba');

module.exports = {
title: 'Open Custom Ports',
category: 'ECS',
description: 'Ensure that defined custom ports are not open to public.',
more_info: 'Security groups should restrict access to ports from known networks.',
link: 'https://www.alibabacloud.com/help/doc-detail/25471.htm',
recommended_action: 'Modify the security group to ensure the defined custom ports are not exposed publicly',
apis: ['ECS:DescribeSecurityGroups', 'ECS:DescribeSecurityGroupAttribute', 'STS:GetCallerIdentity'],
settings: {
restricted_open_ports: {
name: 'Restricted Open Ports',
description: 'Comma separated list of ports/port-ranges that should be restricted and not publicly open. Example: tcp:80,tcp:443,tcp:80-443',
regex: '[a-zA-Z0-9,:]',
default: ''
},
},

run: function(cache, settings, callback) {
var results = [];
var source = {};
var regions = helpers.regions(settings);

var restricted_open_ports = settings.restricted_open_ports || this.settings.restricted_open_ports.default;

if (!restricted_open_ports.length) return callback();

restricted_open_ports = restricted_open_ports.split(',');

var ports = {};
restricted_open_ports.forEach(port => {
var [protocol, portNo] = port.split(':');
if (ports[protocol]) {
ports[protocol].push(portNo);
} else {
ports[protocol] = [portNo];
}
});

async.each(regions.ecs, function(region, rcb){
var describeSecurityGroups = helpers.addSource(cache, source,
['ecs', 'DescribeSecurityGroups', region]);

if (!describeSecurityGroups) return rcb();

if (describeSecurityGroups.err || !describeSecurityGroups.data) {
helpers.addResult(results, 3,
`Unable to describe security groups: ${helpers.addError(describeSecurityGroups)}`, region);
return rcb();
}

if (!describeSecurityGroups.data.length) {
helpers.addResult(results, 0, 'No security groups found', region);
return rcb();
}

helpers.findOpenPorts(cache, describeSecurityGroups.data, ports, 'custom', region, results);

rcb();
}, function(){
callback(null, results, source);
});
}
};
145 changes: 145 additions & 0 deletions plugins/alibaba/ecs/openCustomPorts.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
var expect = require('chai').expect;
const openCustomPorts = require('./openCustomPorts');

const describeSecurityGroups = [
{
"Description": "System created security group.",
"SecurityGroupName": "sg-rj998kwpxbxh3muao6nx",
"VpcId": "vpc-rj9vu86hdve3qr173ew17",
"ServiceManaged": false,
"ResourceGroupId": "",
"SecurityGroupId": "sg-rj998kwpxbxh3muao6nx",
"CreationTime": "2021-04-30T09:57:23Z",
"SecurityGroupType": "normal",
"Tags": {
"Tag": []
}
}
];

const describeSecurityGroupAttribute = [
{
"Description": "System created security group.",
"RequestId": "B417712F-F2D9-4D84-9E14-53642866EC41",
"SecurityGroupName": "sg-rj998kwpxbxh3muao6nx",
"VpcId": "vpc-rj9vu86hdve3qr173ew17",
"SecurityGroupId": "sg-rj998kwpxbxh3muao6nx",
"Permissions": {
"Permission": [
{
"Direction": "ingress",
"SourceGroupName": "",
"PortRange": "443/443",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "TCP"
}
]
}
},
{
"Description": "System created security group.",
"RequestId": "BCC3A7D9-93A5-44AA-85C1-A0C94A53DDBD",
"SecurityGroupName": "sg-0xijcm5n3s67cgnlklmi",
"VpcId": "vpc-0xitjib9awrnrv6i3sk9y",
"SecurityGroupId": "sg-0xijcm5n3s67cgnlklmi",
"Permissions": {
"Permission": [
{
"SourceGroupId": "",
"Policy": "Accept",
"Description": "System created rule.",
"SourcePortRange": "",
"Priority": 100,
"CreateTime": "2021-04-29T22:40:41Z",
"DestPrefixListName": "",
"Ipv6SourceCidrIp": "",
"NicType": "intranet",
"DestGroupId": "",
"Direction": "ingress",
"SourceGroupName": "",
"PortRange": "53/80",
"DestGroupOwnerAccount": "",
"DestPrefixListId": "",
"SourceCidrIp": "0.0.0.0/0",
"SourcePrefixListName": "",
"IpProtocol": "TCP",
"DestCidrIp": "",
"DestGroupName": "",
"SourceGroupOwnerAccount": "",
"Ipv6DestCidrIp": "",
"SourcePrefixListId": ""
},
]
}
}
];

const createCache = (securityGroups, describeSecurityGroupAttribute, securityGroupsErr, describeSecurityGroupAttributeErr) => {
const securityGroupId = (securityGroups && securityGroups.length) ? securityGroups[0].SecurityGroupId : null;
return {
ecs:{
DescribeSecurityGroups: {
'cn-hangzhou': {
err: securityGroupsErr,
data: securityGroups
}
},
DescribeSecurityGroupAttribute: {
'cn-hangzhou': {
[securityGroupId]: {
err: describeSecurityGroupAttributeErr,
data: describeSecurityGroupAttribute
}
}
}
}
};
};

describe('openCustomPorts', function () {
describe('run', function () {
it('should PASS if no public open ports found', function (done) {
const cache = createCache(describeSecurityGroups, describeSecurityGroupAttribute[0]);
openCustomPorts.run(cache, { restricted_open_ports: 'tcp:22' }, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No public open ports found');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should FAIL if security group has custom ports open to public', function (done) {
const cache = createCache(describeSecurityGroups, describeSecurityGroupAttribute[1]);
openCustomPorts.run(cache, { restricted_open_ports: 'tcp:60,tcp:65-70' }, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('has custom:TCP:60, some of TCP:65-70 open to 0.0.0.0/0');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should PASS if no security groups found', function (done) {
const cache = createCache([]);
openCustomPorts.run(cache, { restricted_open_ports: 'tcp:22' }, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No security groups found');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should UNKNWON unable to describe security groups', function (done) {
const cache = createCache(null, { message: 'Unable to describe security groups'});
openCustomPorts.run(cache, { restricted_open_ports: 'tcp:22' }, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to describe security groups');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});
});
});
47 changes: 47 additions & 0 deletions plugins/alibaba/ecs/openOracleAutoDataWarehouse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var async = require('async');
var helpers = require('../../../helpers/alibaba');

module.exports = {
title: 'Open Oracle Auto Data Warehouse',
category: 'ECS',
description: 'Ensure that security groups does not have TCP port 1522 for Oracle Auto Data Warehouse open to the public.',
more_info: 'While some ports such as HTTP and HTTPS are required to be open to the public to function properly, more sensitive services such as Oracle Auto Data Warehouse should be restricted to known IP addresses.',
link: 'https://www.alibabacloud.com/help/doc-detail/25471.htm',
recommended_action: 'Restrict TCP port 1522 for Oracle Auto Data Warehouse to known IP addresses',
apis: ['ECS:DescribeSecurityGroups', 'ECS:DescribeSecurityGroupAttribute', 'STS:GetCallerIdentity'],

run: function(cache, settings, callback) {
var results = [];
var source = {};
var regions = helpers.regions(settings);

var ports = {
'tcp': [1522]
};

var service = 'Oracle Auto Data Warehouse';

async.each(regions.ecs, function(region, rcb){
var describeSecurityGroups = helpers.addSource(cache, source,
['ecs', 'DescribeSecurityGroups', region]);

if (!describeSecurityGroups) return rcb();

if (describeSecurityGroups.err || !describeSecurityGroups.data) {
helpers.addResult(results, 3,
`Unable to describe security groups: ${helpers.addError(describeSecurityGroups)}`, region);
return rcb();
}

if (!describeSecurityGroups.data.length) {
helpers.addResult(results, 0, 'No security groups found', region);
return rcb();
}

helpers.findOpenPorts(cache, describeSecurityGroups.data, ports, service, region, results);
rcb();
}, function(){
callback(null, results, source);
});
}
};
Loading

0 comments on commit 2cf101c

Please sign in to comment.