From 2d959b3af88988fa68715d2479f48c8967894a2e Mon Sep 17 00:00:00 2001 From: kidokidofire <52121973+kidokidofire@users.noreply.github.com> Date: Thu, 25 Aug 2022 14:31:48 +0900 Subject: [PATCH] Fix func to get EC2 instance ID by IMDSv2. (#1522) Co-authored-by: kido3160 --- scanner/base.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scanner/base.go b/scanner/base.go index ba86b77b..05463826 100644 --- a/scanner/base.go +++ b/scanner/base.go @@ -398,10 +398,9 @@ func (l *base) detectRunningOnAws() (ok bool, instanceID string, err error) { r := l.exec(cmd, noSudo) if r.isSuccess() { id := strings.TrimSpace(r.Stdout) - if !l.isAwsInstanceID(id) { - return false, "", nil + if l.isAwsInstanceID(id) { + return true, id, nil } - return true, id, nil } cmd = "curl -X PUT --max-time 1 --noproxy 169.254.169.254 -H \"X-aws-ec2-metadata-token-ttl-seconds: 300\" http://169.254.169.254/latest/api/token"