GithubHelp home page GithubHelp logo

rams3sh / aaia Goto Github PK

View Code? Open in Web Editor NEW
280.0 19.0 41.0 416 KB

AWS Identity and Access Management Visualizer and Anomaly Finder

License: GNU General Public License v3.0

Python 93.62% Shell 6.38%
aws iam security security-tools pentesting graph neo4j

aaia's Introduction

Aaia

(A)n(a)lysis of (I)dentity and (A)ccess

Note: Expansion created post the name was decided :P

What does Aaia do ?

Aaia (pronounced as shown here ) helps in visualizing AWS IAM and Organizations in a graph format with help of Neo4j. This helps in identifying the outliers easily. Since it is based on neo4j , one can query the graph using cypher queries to find the anomalies.

Aaia also supports modules to programatically fetch data from neo4j database and process it in a custom fashion. This is mostly useful if any complex comparision or logic has to be applied which otherwise would not be easy through cypher queries.

Aaia was initially intended to be a tool to enumerate privelege esclation possibilities and find loop holes in AWS IAM. It was inspired from the quote by @JohnLaTwC

"Defenders think in lists. Attackers think in graphs. As long as this is true, attackers win."

Why the name "Aaia" ?

Aaia in Tamil means grandma. In general, Aaia knows everything about the family. She can easily connect who is related to whom; and how ;and give you the connection within a split second. She is a living graph database. :P

Since "Aaia" (this tool) also does more or less the same, hence the name.

Installation

Install the neo4j Database

1. Installation using Docker (Recommended)

i. Install Docker Runtime

Check the official documentation regarding installation here.

ii. Run the following docker command

docker run -p 7687:7687 -p 7474:7474 -v `pwd`/neo4j/data:/data -v `pwd`/neo4j/logs:/logs -e NEO4J_AUTH=neo4j/test neo4j:3.5.17

Note : Above command persists neo4j data in your disk. However, feel free to modify for your needs and change the auth according to your preference. The credentials provided here should be configured in Aaia.conf file as well.

2. Installation using binary

Instructions here

Setup the username , password and bolt connection uri in Aaia.conf file. An example format is given in Aaia.conf file already.

Note: Aaia has been tested with neo4j v 3.5.17. It may work with older versions. Neo4j has introduced some new changes post v 4.0 which has been found not compatible with Aaia's current codebase.

Install OS dependency

Debian :-

apt-get install awscli jq

Redhat / Fedora / Centos / Amazon Linux :-

yum install awscli jq

Note:

These packages are needed for Aaia_aws_collector.sh script. Ensure these packages are present in the base system from where the collector script is being run.

Clone this repository

git clone https://github.com/rams3sh/Aaia

cd Aaia/

Create a virtual environment

python3 -m venv env

Activate the virtual environment

source env/bin/activate

Note: Aaia depends on pyjq library which is not stable in windows currently. Hence Aaia is not supported for Windows OS.

Install the dependencies

python -m pip install -r requirements.txt

Using Aaia

Setting up Permissions in AWS

Aaia would require following AWS permissions for collector script to collect relevant data from AWS

iam:GenerateCredentialReport
iam:GetCredentialReport
iam:GetAccountAuthorizationDetails
iam:ListUsers
iam:GetUser
iam:ListGroups
iam:ListRoles
iam:GetRole
iam:GetPolicy
iam:GetAccountPasswordPolicy
iam:GetAccountSummary
iam:ListAccountAliases
organizations:ListAccountsForParent
organizations:ListOrganizationalUnitsForParent
organizations:DescribeOrganization
organizations:ListRoots
organizations:ListAccounts
organizations:ListTagsForResource
organizations:ListPolicies
organizations:ListTargetsForPolicy
organizations:DescribePolicy
organizations:ListAWSServiceAccessForOrganization

"Organizations" related permissions can be ommitted. However , all the above mentioned "IAM" related permissions are necessary.

Ensure the permissions are available to the user / role / any aws principal which will be used for collection of data for the collector script.

Collecting data from AWS

Ensure you have aws credentials configured. Refer this for help.

Once the crendential is setup.

Run:-

./Aaia_aws_collector.sh <profile_name>

Ensure the output format of the aws profile being used for data collection is set to json as Aaia expects the data collected to be in json format.

Note:-

In case of a requirement where data has to be collected from another instance; copy "Aaia_aws_collector.sh" file to the remote instance , run it and copy the generated "offline_data" folder to the Aaia path in the instance where Aaia is setup and carry on with following steps. This will be helpful in cases of consulting or client audit.

Loading the collected data to Neo4j DB

python Aaia.py -n <profile_name> -a load_data

-n supports "all" as value which means load all data collected and present within offline_data folder.

Note:

Please ensure you do not have profile as "all" in the credentials file as it may conflict with the argument. :P

Now we are ready to use Aaia.

Audit IAM through a custom module

As of now , a sample module is given as a skeleton example. One can consider this as a reference for building custom modules.

python Aaia.py -n all -m iam_sample_audit

Thanks to

Aaia is influenced and inspired from various amazing open source projects. Huge Shoutout to :-

Aaia in Action

asciicast

Screenshots

A sample visual of a dummy AWS Account's IAM

Image of AWS IAM Neo4j Visual

A sample visual of a result of a cypher query to find all relations of a user in AWS IAM

Image of AWS IAM query result Visual

TO DO

  • Write a detailed documentation for understanding Aaia's Neo4j DB Schema
  • Write a detailed documentation for developing custom modules for Aaia
  • Write custom modules to evaluate 28 AWS privelege escalation methods identified by RhinoSecurity.
  • Provide a cheatsheet of queries for identifying simple issues in AWS IAM
  • Extend Aaia to other cloud providers.

aaia's People

Contributors

rams3sh avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aaia's Issues

ImportError: No module name 'actions.aws.load_data'

Strange issue I'm running into here. Any ideas?

(env) ubuntu@ip-172-31-84-11:~/Aaia/Aaia$ python3 ./Aaia.py -n default -a load_Data
Traceback (most recent call last):
  File "/home/ubuntu/Aaia/Aaia/actions/aws/main.py", line 18, in main
    library=importlib.import_module(__package__+"."+args.action+".main")
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'actions.aws.load_Data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./Aaia.py", line 19, in <module>
    action.main(config,args)
  File "/home/ubuntu/Aaia/Aaia/actions/aws/main.py", line 30, in main
    except ModuleNotFoundError:
NameError: name 'ModuleNotFoundError' is not defined

Also this:

(env) ubuntu@ip-172-31-84-11:~/Aaia/Aaia$ python Aaia.py -n default -a help

Aaia

available actions:
clean_db : cleans the aws data from Aaia (Warning : This deletes all data from Aaia)
Traceback (most recent call last):
  File "Aaia.py", line 19, in <module>
    action.main(config,args)
  File "/home/ubuntu/Aaia/Aaia/actions/aws/main.py", line 15, in main
    help()
  File "/home/ubuntu/Aaia/Aaia/actions/aws/main.py", line 43, in help
    library.help()
  File "/home/ubuntu/Aaia/Aaia/actions/aws/clean_db/main.py", line 21, in help
    library=importlib.import_module(__package__+"."+module_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ubuntu/Aaia/Aaia/actions/aws/clean_db/clean.py", line 2, in <module>
    from neo4j.v1 import GraphDatabase
ImportError: No module named 'neo4j'

OSX Sierra Issue

Not sure if anyone else is having this issue:

python ./Aaia.py -n dev -a load_data INFO:actions.aws.load_data.iam:[*] Loading AWS Managed Policies into neo4j instance for AWS account 'dev' Traceback (most recent call last): File "./Aaia.py", line 19, in <module> action.main(config,args) File "/Users/jtirrell/Aaia/Aaia/actions/aws/main.py", line 28, in main library.main(config,args) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/main.py", line 14, in main library.main(config, args) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/iam.py", line 1194, in main loadAWSIAM(neo4j_uri,neo4j_user,neo4j_password,data_path,account_name) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/iam.py", line 1136, in loadAWSIAM loadAWSManagedPolicies(neo4j_session,data_path,account_name) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/iam.py", line 88, in loadAWSManagedPolicies managed_policies=getAWSManagedPolicies(data_path,account_name) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/iam.py", line 38, in getAWSManagedPolicies data=getAWSIamAccountAuthorizationDetailsInfo(data_path,account_name,jqQuery) File "/Users/jtirrell/Aaia/Aaia/actions/aws/load_data/iam.py", line 31, in getAWSIamAccountAuthorizationDetailsInfo file_content=json.loads(filein.read()) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

` tree offline_data
offline_data
└── aws
└── dev
├── iam
│   ├── iam-get-account-authorization-details.json
│   ├── iam-get-account-password-policy.json
│   ├── iam-get-account-summary.json
│   ├── iam-get-credential-report.json
│   ├── iam-get-policy
│   ├── iam-get-role
│   ├── iam-get-user
│   ├── iam-list-account-aliases.json
│   ├── iam-list-groups.json
│   ├── iam-list-roles.json
│   └── iam-list-users.json
└── organizations
├── organizations-describe-organization.json
├── organizations-describe-policy
├── organizations-list-accounts.json
├── organizations-list-aws-service-access-for-organization.json
├── organizations-list-policies.json
├── organizations-list-roots.json
├── organizations-list-tags-for-resource
├── organizations-list-targets-for-policy
└── ou_tree

11 directories, 13 files
`

Cannot merge the following node because of null property value for ‘ServiceName’

Getting the following issue:

INFO:actions.aws.load_data.iam:[*] Loading AWS Role Principal relation into neo4j instance for AWS account ‘default’
Traceback (most recent call last):
  File “/Users/me/Aaia/Aaia/Aaia.py”, line 19, in <module>
    action.main(config,args)
  File “/Users/me/Aaia/Aaia/actions/aws/main.py”, line 28, in main
    library.main(config,args)
  File “/Users/me/Aaia/Aaia/actions/aws/load_data/main.py”, line 14, in main
    library.main(config, args)
  File “/Users/me/Aaia/Aaia/actions/aws/load_data/iam.py”, line 1269, in main
    loadAWSIAM(neo4j_uri,neo4j_user,neo4j_password,data_path,account_name)
  File “/Users/me/Aaia/actions/aws/load_data/iam.py”, line 1238, in loadAWSIAM
    loadAWSRolePrincipalRelations(neo4j_session,data_path,account_name)
  File “/Users/me/Aaia/Aaia/actions/aws/load_data/iam.py”, line 943, in loadAWSRolePrincipalRelations
    neo4j_session.run(ingest_assume_role_principal,Aaia_ExpandedAction=policy_statement_details[‘Aaia_ExpandedAction’],ServiceName=arn.ARN(principal).tech,PrincipalArn=principal,RoleArn=role_data[‘Arn’],AccountNo=role_data[‘Arn’].split(“:”)[4],SourceRoleArn=role_data[‘Arn’],DocumentVersion=policy_document_details[‘Version’],DocumentId=policy_document_details[‘Id’],Effect=policy_statement_details[‘Effect’],ActionKey=policy_statement_details[‘ActionKey’],Action=str(statement_action).replace(“’”,“”).replace(“{”,“”).replace(“}”,“”).replace(“[”,“”).replace(“]”,“”),Condition=policy_statement_details[‘Condition’],Sid=policy_statement_details[‘Sid’],ResourceKey=policy_statement_details[‘ResourceKey’],Resource=str(statement_resource).replace(“’”,“”).replace(“{”,“”).replace(“}”,“”).replace(“[”,“”).replace(“]”,“”),Principal=str(json.dumps(statement_principal)),PrincipalKey=policy_statement_details[‘PrincipalKey’])
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/work/session.py”, line 317, in run
    self._auto_result._run(
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/work/result.py”, line 166, in _run
    self._attach()
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/work/result.py”, line 274, in _attach
    self._connection.fetch_message()
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/io/_common.py”, line 180, in inner
    func(*args, **kwargs)
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/io/_bolt.py”, line 826, in fetch_message
    res = self._process_message(tag, fields)
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/io/_bolt5.py”, line 370, in _process_message
    response.on_failure(summary_metadata or {})
  File “/Users/me/.pyenv/versions/aaia/lib/python3.10/site-packages/neo4j/_sync/io/_common.py”, line 247, in on_failure
    raise Neo4jError.hydrate(**metadata)
neo4j.exceptions.ClientError: {code: Neo.ClientError.Statement.SemanticError} {message: Cannot merge the following node because of null property value for ‘ServiceName’: (:AWSPolicyPrincipal:AWSService {ServiceName: null})}

Any help would be greatly appreciated.

Thanks!

Provide a Dockerfile or Docker Image for the Aaia tool itself

Installation process is a bit tedious - and I ran into multiple issues with dependencies failing to install (both on WSL and a fresh Amazon Linux EC2 Instance). Providing a Dockerfile (Or Image on a public repository) would alleviate these issues and allow people to get up and running with the tool in a very quick manner.

Licensing?

There is no license file in this repo. Can you please add one so folks can if they are permitted to clone or fork the repo?

Can I run it in MAC I get the following error

Hi
I am getting the following error when I run it on my Mac

File "Aaia.py", line 19, in
action.main(config,args)
File "Aaia/Aaia/actions/aws/main.py", line 28, in main
library.main(config,args)
File "Aaia/Aaia/actions/aws/load_data/main.py", line 14, in main
library.main(config, args)
File "Aaia/Aaia/actions/aws/load_data/iam.py", line 1194, in main
loadAWSIAM(neo4j_uri,neo4j_user,neo4j_password,data_path,account_name)
File "Aaia/Aaia/actions/aws/load_data/iam.py", line 1133, in loadAWSIAM
neo4j_driver = GraphDatabase.driver( neo4j_uri, auth=neo4j_auth,)
File "/usr/local/lib/python3.7/site-packages/neo4j/init.py", line 116, in driver
return Driver(uri, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/init.py", line 157, in new
return subclass(uri, **config)
File "/usr/local/lib/python3.7/site-packages/neo4j/init.py", line 231, in new
pool.release(pool.acquire())
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 719, in acquire
return self.acquire_direct(self.address)
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 612, in acquire_direct
connection = self.connector(address, error_handler=self.connection_error_handler)
File "/usr/local/lib/python3.7/site-packages/neo4j/init.py", line 228, in connector
return connect(address, **dict(config, **kwargs))
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 976, in connect
raise last_error
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 967, in connect
s, der_encoded_server_certificate = _secure(s, host, security_plan.ssl_context, **config)
File "/usr/local/lib/python3.7/site-packages/neobolt/direct.py", line 858, in _secure
s = ssl_context.wrap_socket(s, server_hostname=host if HAS_SNI and host else None)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.