forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from aquasecurity/master
Master branch updated in local
- Loading branch information
Showing
136 changed files
with
3,239 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var collectors = {}; | ||
|
||
var directories = fs.readdirSync(__dirname).filter(function(file) { | ||
return fs.statSync(path.join(__dirname, file)).isDirectory(); | ||
}); | ||
|
||
directories.forEach(function(directory) { | ||
collectors[directory] = {}; | ||
|
||
fs | ||
.readdirSync(__dirname + '/' + directory) | ||
.filter(function(file) { | ||
return (file.indexOf('.') !== 0); | ||
}) | ||
.forEach(function(file) { | ||
var collector = require(path.join(__dirname + '/' + directory, file)); | ||
var name = file.substring(0, file.indexOf('.js')); | ||
collectors[directory][name] = collector; | ||
}); | ||
}); | ||
|
||
module.exports = collectors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var index = require(__dirname + '/index.js'); | ||
|
||
module.exports = function(AlibabaConfig, collection, region, callback) { | ||
index('getBucketInfo', AlibabaConfig, collection, region, callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var async = require('async'); | ||
const OSS = require('ali-oss'); | ||
|
||
module.exports = function(callKey, AlibabaConfig, collection, region, callback) { | ||
var store = new OSS(AlibabaConfig); | ||
|
||
async.eachLimit(collection.oss.listBuckets[region].data, 10, function(bucket, bcb){ | ||
let bucketName = bucket.name; | ||
collection.oss[callKey][region][bucketName] = {}; | ||
|
||
store[callKey](bucketName).then((result) => { | ||
collection.oss[callKey][region][bucketName].data = result.bucket; | ||
bcb(); | ||
}, (err) => { | ||
collection.oss[callKey][region][bucketName].err = err; | ||
bcb(); | ||
}); | ||
}, function(){ | ||
callback(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const OSS = require('ali-oss'); | ||
|
||
module.exports = function(AlibabaConfig, collection, region, callback) { | ||
const store = new OSS(AlibabaConfig); | ||
collection.oss.listBuckets[region].data = []; | ||
|
||
var execute = function(nextToken) { | ||
store.listBuckets({ | ||
'max-keys': 1, | ||
'marker': nextToken | ||
}).then((result) => { | ||
callCB(null, result); | ||
}, (err) => { | ||
callCB(err); | ||
}); | ||
}; | ||
|
||
var callCB = function(err, data) { | ||
if (err) { | ||
collection.oss.listBuckets[region].err = err; | ||
callback(); | ||
} | ||
collection.oss.listBuckets[region].data = collection.oss.listBuckets[region].data.concat(data.buckets); | ||
if (data.nextMarker) execute(data.nextMarker); | ||
else callback(); | ||
}; | ||
|
||
execute(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
var helpers = require('../shared.js'); | ||
|
||
function defaultRegion(settings) { | ||
if (settings.defaultRegion) return settings.defaultRegion; | ||
return 'cn-hangzhou'; | ||
} | ||
|
||
function createArn(service, account, resourceType, resourceId, region) { | ||
if (!region) region = ''; | ||
return `arn:acs:${service}:${region}:${account}:${resourceType}/${resourceId}`; | ||
} | ||
|
||
function findOpenPorts(cache, groups, ports, service, region, results) { | ||
// console.log(JSON.stringify(cache, null, 2)); | ||
var found = false; | ||
|
||
for (var group of groups) { | ||
if (!group.SecurityGroupId) continue; | ||
|
||
var accountId = helpers.addSource(cache, {}, ['sts', 'GetCallerIdentity', defaultRegion, 'data']); | ||
|
||
var resource = createArn('ecs', accountId, 'securitygroup', group.SecurityGroupId, region); | ||
|
||
var describeSecurityGroupAttribute = helpers.addSource(cache, {}, | ||
['ecs', 'DescribeSecurityGroupAttribute', region, group.SecurityGroupId]); | ||
|
||
if (!describeSecurityGroupAttribute || describeSecurityGroupAttribute.err || !describeSecurityGroupAttribute.data) { | ||
helpers.addResult(results, 3, | ||
`Unable to query security group attributes: ${describeSecurityGroupAttribute}`, region, resource); | ||
continue; | ||
} | ||
|
||
var string; | ||
var openV4Ports = []; | ||
|
||
if (describeSecurityGroupAttribute.data.Permissions && describeSecurityGroupAttribute.data.Permissions.Permission && describeSecurityGroupAttribute.data.Permissions.Permission.length){ | ||
for (var permission of describeSecurityGroupAttribute.data.Permissions.Permission) { | ||
if (permission.Direction && permission.Direction !== 'ingress') continue; | ||
let protocol = permission.IpProtocol.toLowerCase(); | ||
if (permission.SourceCidrIp === '0.0.0.0/0' && ports[protocol]) { | ||
for (var port of ports[protocol]) { | ||
let fromPort = (Number(permission.PortRange.split('/')[0])) ? | ||
Number(permission.PortRange.split('/')[0]) : Number(permission.PortRange); | ||
let toPort = (Number(permission.PortRange.split('/')[1])) ? | ||
Number(permission.PortRange.split('/')[1]) : Number(permission.PortRange); | ||
|
||
if (port.toString().indexOf('-') > -1) { | ||
var rangeFrom = Number(port.split('-')[0]); | ||
var rangeTo = Number(port.split('-')[1]); | ||
|
||
for (let i = rangeFrom; i <= rangeTo; i++) { | ||
if (fromPort<= i && toPort >= i) { | ||
string = `some of ${permission.IpProtocol}:${port}`; | ||
openV4Ports.push(string); | ||
found = true; | ||
break; | ||
} | ||
} | ||
} else { | ||
port = Number(port); | ||
if (fromPort <= port && toPort >= port) { | ||
string = `${permission.IpProtocol}:${port}`; | ||
if (openV4Ports.indexOf(string) === -1) openV4Ports.push(string); | ||
found = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (openV4Ports.length) { | ||
var resultsString = ''; | ||
if (openV4Ports.length) { | ||
resultsString = `Security group: ${group.SecurityGroupId} has ${service}:${openV4Ports.join(', ')} open to 0.0.0.0/0`; | ||
} | ||
|
||
helpers.addResult(results, 2, resultsString, region, resource); | ||
} | ||
} | ||
|
||
if (!found) { | ||
helpers.addResult(results, 0, 'No public open ports found', region); | ||
} | ||
|
||
return; | ||
} | ||
|
||
module.exports = { | ||
defaultRegion: defaultRegion, | ||
createArn: createArn, | ||
findOpenPorts: findOpenPorts | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var shared = require(__dirname + '/../shared.js'); | ||
var functions = require('./functions.js'); | ||
var regRegions = require('./regions.js'); | ||
|
||
var regions = function() { | ||
return regRegions; | ||
}; | ||
|
||
var helpers = { | ||
regions: regions, | ||
MAX_REGIONS_AT_A_TIME: 6 | ||
}; | ||
|
||
for (var s in shared) helpers[s] = shared[s]; | ||
for (var f in functions) helpers[f] = functions[f]; | ||
|
||
module.exports = helpers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Source: https://www.alibabacloud.com/global-locations | ||
|
||
var regions = [ | ||
'cn-hangzhou', // China (Hangzhou) | ||
'cn-shanghai', // China (Shanghai) | ||
'cn-qingdao', // China (Qingdao) | ||
'cn-beijing', // China (Beijing) | ||
'cn-zhangjiakou', // China (Zhangjiakou) | ||
'cn-huhehaote', // China (Hohhot) | ||
'cn-wulanchabu', // China (Ulanqab) | ||
'cn-shenzhen', // China (Shenzhen) | ||
'cn-heyuan', // China (Heyuan) | ||
'cn-chengdu', // China (Chengdu) | ||
'cn-hongkong', // China(Hong Kong) | ||
'cn-guangzhou', // China (Guangzhou) | ||
'ap-southeast-1', // Singapore | ||
'ap-southeast-2', // Australia (Sydney) | ||
'ap-southeast-3', // Malaysia (Kuala Lumpur) | ||
'ap-southeast-5', // Indonesia (Jakarta) | ||
'ap-northeast-1', // Japan (Tokyo) | ||
'ap-south-1', // India (Mumbai) | ||
'eu-central-1', // Germany (Frankfurt) | ||
'eu-west-1', // UK(London) | ||
'us-west-1', // US (Silicon Valley) | ||
'us-east-1', // US (Virginia) | ||
'me-east-1', // UAE (Dubai) | ||
]; | ||
|
||
module.exports = { | ||
default: ['cn-hangzhou'], | ||
all: regions, | ||
ecs: regions, | ||
polardb: regions, | ||
ram: ['cn-hangzhou'], | ||
vpc: regions, | ||
rds: regions, | ||
sts: ['cn-hangzhou'], | ||
oss: ['cn-hangzhou'], | ||
kms: regions | ||
}; |
Oops, something went wrong.