Skip to content

Instantly share code, notes, and snippets.

@samqi
Last active September 8, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samqi/c72f851dcc8ec0c78c72d92309a6a3de to your computer and use it in GitHub Desktop.
Save samqi/c72f851dcc8ec0c78c72d92309a6a3de to your computer and use it in GitHub Desktop.
aws inspector cli
# SETUP RESOURCE GROUP
#reference https://docs.aws.amazon.com/cli/latest/reference/inspector/index.html
aws inspector create-resource-group --resource-group-tags key=SecurityScan,value=true
#from previous step get resgroupARN
aws inspector create-assessment-target \
--assessment-target-name GamesDevTargetGroup \
--resource-group-arn <ResourceGroupARN>
#see available rules packages
aws inspector list-rules-packages
#you get something like
{
"rulesPackageArns": [
"arn:aws:inspector:us-west-2:xxxxxxxxx:rulespackage/0-9hgA516p",
"arn:aws:inspector:us-west-2:xxxxxxxxx:rulespackage/0-H5hpSawc",
"arn:aws:inspector:us-west-2:xxxxxxxxx:rulespackage/0-JJOtZiqQ",
"arn:aws:inspector:us-west-2:xxxxxxxxx:rulespackage/0-rD1z6dpl"
]
}
#################end of set of rules
#run each of the rulepackagearns details individually for each
aws inspector describe-rules-packages --query rulesPackages[*].[name,description] --output text --rules-package-arns <RulesPackageArns>
aws inspector describe-rules-packages --query rulesPackages[*].[name,description] --output text --rules-package-arns <RulesPackageArns>
aws inspector describe-rules-packages --query rulesPackages[*].[name,description] --output text --rules-package-arns <RulesPackageArns>
aws inspector describe-rules-packages --query rulesPackages[*].[name,description] --output text --rules-package-arns <RulesPackageArns>
#take note of the one with network reachability and exclude that for the next command
# CREATE ASSESSMENT TEMPLATE WITH CIS COMMON VULNERABILITY BEST PRACTICE with Rules
#shorten default duration from 900 to 100 and add rulespackagearn without network reachibility
aws inspector create-assessment-template \
--assessment-target-arn <AssessmentTargetArn> \
--assessment-template-name CISCommonVulerBestPract-Short \
--duration-in-seconds 100 --rules-package-arns <RulesPackageArns> <RulesPackageArns> <RulesPackageArns>
#copy assessmentemplate ARN value for next command
# START ASSESSMENT SCAN
# check which hosts will run the scan
#use target-ARN values from previous command
aws inspector preview-agents --preview-agents-arn <assessmentTargetArn>
#observe JSON for reporting agents
# start the assessment based on TemplateARN from 2 steps/commands back
aws inspector start-assessment-run \
--assessment-run-name FirstAssessment \
--assessment-template-arn <assessmentTemplateArn>
#copy assessmentRunARN value for next commands
#check status of assessment by pasting value from prev step
aws inspector describe-assessment-runs --assessment-run-arn <assessmentRunArn>
# first time should see COLLECTING DATA
#view agents sending data
aws inspector list-assessment-run-agents --assessment-run-arn <assessmentRunArn>
# info for agentHealthCode, agentHealth, telemetryData should be shown
# review results on console at https://ap-southeast-2.console.aws.amazon.com/inspector/home?region=ap-southeast-2#/finding
# or use CLI to view if needed
aws inspector list-findings
# you will get a ton of findings arns to use in next command
aws inspector describe-findings --finding-arns <findingsARN>
@samqi
Copy link
Author

samqi commented Sep 8, 2020

@samqi
Copy link
Author

samqi commented Sep 8, 2020

if fixing with SSM:

aws ssm describe-document --name "AWS-PatchInstanceWithRollback" --query "Document.[Name,Description,PlatformTypes]"

# get instance ID for EC2 to apply patch
aws ssm describe-instance-information  --query "InstanceInformationList[*]" --filters "Key=tag:SecurityScan,Values=true"
# copy instanceID to be applied later

# start automation document for patching
aws ssm start-automation-execution \
  --document-name "AWS-PatchInstanceWithRollback" \
  --parameters "InstanceId=<InstanceId>,ReportS3Bucket=<LogBucket>,AutomationAssumeRole=<SSMRole>"

#review in web console AWS Console -> Systems Manager -> Automation

#review patch installation results in s3 bucket <logbucket> as json  earlier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment