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

Feature/959 | Added SSM Agent Auto Update Enabled plugin, spec file #308

Merged
merged 76 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
76 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
7156c66
Updated status in result of failure
AkhtarAmir Aug 18, 2020
2ec1d26
Sploit-959: Added SSM Agent Auto Update Enabled plugin
AkhtarAmir Sep 1, 2020
cea1d0c
Merge branch 'master' into feature/SPLOIT-959
AkhtarAmir Sep 6, 2020
6902eb3
updated ssmAgenAutoUpdateEnabled plugin
AkhtarAmir Sep 6, 2020
c1fe709
updated ssmAgenAutoUpdateEnabled plugin
AkhtarAmir Sep 6, 2020
ea96ebc
Merge branch 'feature/SPLOIT-959' of https://github.com/AkhtarAmir/sc…
AkhtarAmir Sep 6, 2020
dc84b0b
Accommodated requested PR changes
AkhtarAmir Sep 20, 2020
e44f072
Modified plugin to use arn for resource
AkhtarAmir Sep 22, 2020
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
4 changes: 4 additions & 0 deletions collectors/aws/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ var calls = {
MaxResults: 50
},
paginate: 'NextToken'
},
listAssociations: {
property: 'Associations',
paginate: 'NextToken'
}
},
STS: {
Expand Down
1 change: 1 addition & 0 deletions exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ module.exports = {
'ssmEncryptedParameters' : require(__dirname + '/plugins/aws/ssm/ssmEncryptedParameters.js'),
'ssmActiveOnAllInstances' : require(__dirname + '/plugins/aws/ssm/ssmActiveOnAllInstances.js'),
'ssmAgentLatestVersion' : require(__dirname + '/plugins/aws/ssm/ssmAgentLatestVersion.js'),
'ssmAgentAutoUpdateEnabled' : require(__dirname + '/plugins/aws/ssm/ssmAgentAutoUpdateEnabled'),

'lambdaOldRuntimes' : require(__dirname + '/plugins/aws/lambda/lambdaOldRuntimes.js'),
'lambdaVpcConfig' : require(__dirname + '/plugins/aws/lambda/lambdaVpcConfig.js'),
Expand Down
80 changes: 80 additions & 0 deletions plugins/aws/ssm/ssmAgentAutoUpdateEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
var async = require('async');
var helpers = require('../../../helpers/aws');

module.exports = {
title: 'SSM Agent Auto Update Enabled',
category: 'SSM',
description: 'Ensures the SSM agent is configured to automatically update to new versions',
more_info: 'To ensure the latest version of the SSM agent is installed, it should be configured to consume automatic updates.',
link: 'https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent-automatic-updates.html',
recommended_action: 'Update the SSM agent configuration for all managed instances to use automatic updates.',
apis: ['SSM:describeInstanceInformation', 'SSM:listAssociations'],

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

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

var listAssociations = helpers.addSource(cache, source,
['ssm', 'listAssociations', region]);

if (!describeInstanceInformation || !listAssociations) return rcb();

if (describeInstanceInformation.err || !describeInstanceInformation.data) {
helpers.addResult(results, 3,
'Unable to query SSM describe instance information: ' + helpers.addError(describeInstanceInformation), region);
return rcb();
}

if (listAssociations.err || !listAssociations.data) {
helpers.addResult(results, 3,
'Unable to query SSM list associations: ' + helpers.addError(listAssociations), region);
return rcb();
}

if(!describeInstanceInformation.data.length) {
helpers.addResult(results, 0,
'No managed instances found', region);
return rcb();
}

var associatedInstances = [];

if (listAssociations.data.length) {
listAssociations.data.forEach(association => {
if (association.Name && association.Name === 'AWS-UpdateSSMAgent' && association.Targets && association.Targets.length) {
association.Targets.forEach(function(target){
if(target.Key && target.Key === 'InstanceIds' && target.Values && target.Values.length) {
target.Values.forEach(function(instanceId){
if(!associatedInstances.includes(instanceId) && association.ScheduleExpression){
associatedInstances.push(instanceId);
}
});
}
});
}
});
}

describeInstanceInformation.data.forEach(function(instance) {
var resource = instance.InstanceId;
AkhtarAmir marked this conversation as resolved.
Show resolved Hide resolved
if (associatedInstances.includes(resource) || associatedInstances.includes('*')) {
helpers.addResult(results, 0,
'Instance has SSM Agent auto update enabled', region, resource);
}
else {
helpers.addResult(results, 2,
'Instance does not have SSM Agent auto update enabled', region, resource);
}
});

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

const describeInstanceInformation = [
{
"InstanceId": "i-0c8993c98fdb46a97",
"PingStatus": "Online",
"LastPingDateTime": 1599395666.201,
"AgentVersion": "2.3.1644.0",
"IsLatestVersion": true,
"PlatformType": "Linux",
"PlatformName": "Amazon Linux",
"PlatformVersion": "2",
"ResourceType": "EC2Instance",
"IPAddress": "172.31.44.20",
"ComputerName": "ip-172-31-44-20.ec2.internal",
"AssociationStatus": "Success",
"LastAssociationExecutionDate": 1599393759.647,
"LastSuccessfulAssociationExecutionDate": 1599393759.647,
"AssociationOverview": {
"DetailedStatus": "Success",
"InstanceAssociationStatusAggregatedCount": {
"Success": 2
}
}
}
];

const listAssociations = [
{
"Name": "AWS-UpdateSSMAgent",
"AssociationId": "fbf42ad7-0e04-45e4-9a95-b5bea99fa311",
"AssociationVersion": "2",
"DocumentVersion": "$DEFAULT",
"Targets": [
{
"Key": "InstanceIds",
"Values": [
"*"
]
}
],
"LastExecutionDate": 1599393759.647,
"Overview": {
"Status": "Success",
"DetailedStatus": "Success",
"AssociationStatusAggregatedCount": {
"Success": 1
}
},
"ScheduleExpression": "rate(30 days)",
"AssociationName": "test-asso-959"
},
{
"Name": "AWS-UpdateSSMAgent",
"AssociationId": "fbf42ad7-0e04-45e4-9a95-b5bea99fa311",
"AssociationVersion": "2",
"DocumentVersion": "$DEFAULT",
"Targets": [
{
"Key": "InstanceIds",
"Values": [
"*"
]
}
],
"LastExecutionDate": 1599393759.647,
"Overview": {
"Status": "Success",
"DetailedStatus": "Success",
"AssociationStatusAggregatedCount": {
"Success": 1
}
},
"AssociationName": "test-asso-959"
},
{
"Name": "AWS-AttachEBSVolume",
"AssociationId": "a068476e-b759-478e-9ea0-d61e4381fefe",
"AssociationVersion": "1",
"Targets": [
{
"Key": "aws:NoOpAutomationTag",
"Values": [
"AWS-NoOpAutomationTarget-Value"
]
}
],
"LastExecutionDate": 1599378755.529,
"Overview": {
"Status": "Failed",
"DetailedStatus": "InvalidAutomationParameters",
"AssociationStatusAggregatedCount": {}
},
"AssociationName": "test1-947"
}
];

const createCache = (instances, associations) => {
return {
ssm: {
describeInstanceInformation: {
'us-east-1': {
data: instances
},
},
listAssociations: {
'us-east-1': {
data: associations
}
}
},
};
};

const createErrorCache = () => {
return {
ssm: {
describeInstanceInformation: {
'us-east-1': {
err: {
message: 'error describing instance information'
},
},
},
listAssociations: {
'us-east-1': {
err: {
message: 'error listing associations'
},
},
},
},
};
};

const createNullCache = () => {
return {
ssm: {
describeInstanceInformation: {
'us-east-1': null,
},
listAssociations: {
'us-east-1': null,
},
},
};
};

describe('ssmAgentAutoUpdateEnabled', function () {
describe('run', function () {
it('should PASS if SSM Agent has SSM Agent auto update enabled', function (done) {
const cache = createCache([describeInstanceInformation[0]], listAssociations);
ssmAgentAutoUpdateEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});

it('should FAIL if instance does not have SSM Agent auto update enabled', function (done) {
const cache = createCache([describeInstanceInformation[0]], listAssociations[1]);
ssmAgentAutoUpdateEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
done();
});
});

it('should PASS if no managed instances found', function (done) {
const cache = createCache([], []);
ssmAgentAutoUpdateEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});

it('should UNKNOWN if error while fetching instance information', function (done) {
const cache = createErrorCache();
ssmAgentAutoUpdateEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
done();
});
});

it('should not return any results if unable to fetch any instance information', function (done) {
const cache = createNullCache();
ssmAgentAutoUpdateEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(0);
done();
});
});

});
});