cloudfox: Go Panic during all-checks

Description of Bug

When running cloudfox aws all-checks the program crashes during the privesc phase with:

[resource-trusts][666412488974-AIDAJBTEDJEDFGHJKLWJU] Supported Services: CodeBuild, ECR, EFS, Glue, Lambda, SecretsManager, S3, SNS, SQS
failed to get shared config profile, 116412344578-AIDAJBTEDJEDFGHJKLWJU
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x101022724]

goroutine 9981 [running]:
github.com/BishopFox/cloudfox/internal.AWSConfigFileLoader({_, _}, {_, _}, {_, _})
	github.com/BishopFox/cloudfox/internal/aws.go:67 +0x3e4
github.com/BishopFox/cloudfox/aws.initCloudFoxS3Client({_, _, _, {_}, {}}, {_, _}, {_, _}, {_, ...})
	github.com/BishopFox/cloudfox/aws/client-initializers.go:48 +0x80
github.com/BishopFox/cloudfox/aws.(*ResourceTrustsModule).getS3Buckets(0x140011a4580, 0x100157644?, 0x14002196660, 0x140006733f0?)
	github.com/BishopFox/cloudfox/aws/resource-trusts.go:371 +0x114
created by github.com/BishopFox/cloudfox/aws.(*ResourceTrustsModule).PrintResources in goroutine 1
	github.com/BishopFox/cloudfox/aws/resource-trusts.go:94 +0x8c8

What should the expected behavior be

Not crash

Platform Affected

macOS Darwin 21.6.0 ARM64 (macOS Monterey)

Steps to Reproduce

  • Install via brew
  • Use aws-vault to start an authenticated shell with STS credentials
  • Run cloudfox aws all-checks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hey @cyberbutler - I understand if you don’t have access anymore, but if you do, can you check out and try the latest. you actually found a completely unrelated bug lol, but i think i fixed it!

Also, thank you so much for taking the time to chime in and report the other bug!

Just commenting here that the patch in seth-dev did not fix the issue for me. I noticed that @johnkeates ran role-trusts command above and not resource-trusts so i’m wondering if the issue is actually resolved on their side as well. Funny thing for me is that manually running resource-trusts worked, but not when it got to the point in all-checks. Sorry, I won’t be able to help debug any further, just wanted to include my two cents if it enabled @johnkeates to help further.

I found another teeny tiny related issue, pmapper expects the same profile as cloud fox, so when you run the suggested pmapper command it wouldn’t be able to find the same profile as the temporarily created profile name because… well it’s temporary isn’t it 😁

Looking at pmapper a bit more, it seems to be able to create a graph with non-profile commands, but I don’t know if it will store the graph values somewhere in a known location vs. how it stores the data in Cloudfox. Maybe it’s not a big deal since the pmapper data is available outside of Cloudfox anyway.

I’ll check it out!

Works 👍 (edited for brevity)

% ./cloudfox aws role-trusts
[🦊 cloudfox v1.13.1-prerelease 🦊 ][] AWS Caller Identity: arn:aws:sts::335430111111:assumed-role/Administrator/1706021397146943000
[🦊 cloudfox v1.13.1-prerelease 🦊 ][] Account is part of an Organization and is a child account. Management Account: 649301222222
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Enumerating role trusts for account 335430111111.
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/table/role-trusts-principals.txt
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/table/role-trusts-principals-root-trusts-without-external-id.txt
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/table/role-trusts-services.txt
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/table/role-trusts-federated.txt
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/csv/role-trusts-principals.csv
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/csv/role-trusts-principals-root-trusts-without-external-id.csv
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/csv/role-trusts-services.csv
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/csv/role-trusts-federated.csv
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/json/role-trusts-principals.json
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/json/role-trusts-principals-root-trusts-without-external-id.json
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/json/role-trusts-services.json
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] Output written to /Users/jkeates/.cloudfox/cloudfox-output/aws/335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000-335430111111/json/role-trusts-federated.json
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] 11 principal role trusts found.
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] 24 principal role trusts found.
[role-trusts][335430111111-AROAU4GJ3AAAAAAAAAAAA_1706021397146943000] 9 principal role trusts found.
[🦊 cloudfox v1.13.1-prerelease 🦊 ][] Cached AWS data written to /Users/jkeates/.cloudfox/cached-data/aws/335430111111

Using a classic (and also via a passthrough credential_process) profile everything works as expected, so that’s good to know.

During a copy-paste mistake I got this interesting (unrelated) panic:

% cloudfox aws --profile=--profile=bftest all-checks
failed to get shared config profile, --profile=bftest
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x103676724]

goroutine 1 [running]:
github.com/BishopFox/cloudfox/internal.AWSConfigFileLoader({_, _}, {_, _}, {_, _})
	github.com/BishopFox/cloudfox/internal/aws.go:67 +0x3e4
github.com/BishopFox/cloudfox/internal.AWSWhoami({0x16d6bf95f, 0x10}, {0x1066a5bc8, 0x6}, {0x0?, 0x102757720?})
	github.com/BishopFox/cloudfox/internal/aws.go:91 +0x38
github.com/BishopFox/cloudfox/cli.awsPreRun(0x1400026b900?, {0x1066a368d?, 0x4?, 0x1066a3691?})
	github.com/BishopFox/cloudfox/cli/aws.go:513 +0xcc
github.com/spf13/cobra.(*Command).execute(0x109816280, {0x140003432e0, 0x1, 0x1})
	github.com/spf13/cobra@v1.8.0/command.go:972 +0x7c0
github.com/spf13/cobra.(*Command).ExecuteC(0x1098100c0)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
	github.com/BishopFox/cloudfox/main.go:19 +0x58

I could create an issue for that, but I suspect most people can figure out why the panic happens in the first place.