Once everything has been installed and synced, you can view the Neo4j web interface at http://localhost:7474. You can view the reference on this here.
ℹ️ Already know how to query Neo4j? You can skip to our reference material!
If you already know Neo4j and just need to know what are the nodes, attributes, and graph relationships for our representation of infrastructure assets, you can skip this handholdy walkthrough and see our sample queries.
Table of Contents generated with DocToc
- What RDS instances are installed in my AWS accounts?
- Which RDS instances have encryption turned off?
- Which EC2 instances are directly exposed to the internet?
- Which S3 buckets have a policy granting any level of anonymous access to the bucket?
- How many unencrypted RDS instances do I have in all my AWS accounts?
- Learning more
- Data Enrichment
- Extending Cartography with Analysis Jobs
- Mapping AWS Access Permissions
MATCH (aws:AWSAccount)-[r:RESOURCE]->(rds:RDSInstance)
return *
In this query we asked Neo4j to find all [:RESOURCE]
relationships from AWSAccounts to RDSInstances, and return the nodes and the :RESOURCE
relationships.
We will do more interesting things with this result next.
You can adjust the node colors, sizes, and captions by clicking on the node type at the top of the query. For example, to change the color of an AWSAccount node, first click the "AWSAccount" icon at the top of the view to select the node type
and then pick options on the menu that shows up at the bottom of the view like this:
Which RDS instances have encryption turned off?
MATCH (a:AWSAccount)-[:RESOURCE]->(rds:RDSInstance{storage_encrypted:false})
RETURN a.name, rds.id
The results show up in a table because we specified attributes like a.name
and rds.id
in our return statement (as opposed to having it return *
). We used the "{}" notation to have the query only return RDSInstances where storage_encrypted
is set to False
.
If you want to go back to viewing the graph and not a table, simply make sure you don't have any attributes in your return statement -- use return *
to return all nodes decorated with a variable label in your MATCH
statement, or just return the specific nodes and relationships that you want.
Let's look at some other AWS assets now.
Which EC2 instances are directly exposed to the internet?
MATCH (instance:EC2Instance{exposed_internet: true})
RETURN instance.instanceid, instance.publicdnsname
These instances are open to the internet either through permissive inbound IP permissions defined on their EC2SecurityGroups or their NetworkInterfaces.
If you know a lot about AWS, you may have noticed that EC2 instances don't actually have an exposed_internet field. We're able to query for this because Cartography performs some data enrichment to add this field to EC2Instance nodes.
Which S3 buckets have a policy granting any level of anonymous access to the bucket?
MATCH (s:S3Bucket)
WHERE s.anonymous_access = true
RETURN s
These S3 buckets allow for any user to read data from them anonymously. Similar to the EC2 instance example above, S3 buckets returned by the S3 API don't actually have an anonymous_access field and this field is added by one of Cartography's data augmentation steps.
A couple of other things to notice: instead of using the "{}" notation to filter for anonymous buckets, we can use SQL-style WHERE
clauses. Also, we used the SQL-style AS
operator to relabel our output header rows.
Let's go back to analyzing RDS instances. In an earlier example we queried for RDS instances that have encryption turned off. We can aggregate this data by AWSAccount with a small change:
MATCH (a:AWSAccount)-[:RESOURCE]->(rds:RDSInstance)
WHERE rds.storage_encrypted = false
RETURN a.name as AWSAccount, count(rds) as UnencryptedInstances
If you want to learn more in depth about Neo4j and Cypher queries you can look at this tutorial and see this reference card.
Cartography adds custom attributes to nodes and relationships to point out security-related items of interest. Unless mentioned otherwise these data augmentation jobs are stored in cartography/data/jobs/analysis
. Here is a summary of all of Cartography's custom attributes.
-
exposed_internet
indicates whether the asset is accessible to the public internet.-
Elastic Load Balancers: The
exposed_internet
flag is set toTrue
when the load balancer'sscheme
field is set tointernet-facing
, and the load balancer has an attached source security group with rules allowing0.0.0.0/0
ingress on ports or port ranges matching listeners on the load balancer. This scheme indicates that the load balancer has a public DNS name that resolves to a public IP address. -
Application Load Balancers: The
exposed_internet
flag is set toTrue
when the load balancer'sscheme
field is set tointernet-facing
, and the load balancer has an attached security group with rules allowing0.0.0.0/0
ingress on ports or port ranges matching listeners on the load balancer. This scheme indicates that the load balancer has a public DNS name that resolves to a public IP address. -
EC2 instances: The
exposed_internet
flag on an EC2 instance is set toTrue
when any of following apply:-
The instance is part of an EC2 security group or is connected to a network interface connected to an EC2 security group that allows connectivity from the 0.0.0.0/0 subnet.
-
The instance is connected to an Elastic Load Balancer that has its own
exposed_internet
flag set toTrue
. -
The instance is connected to a TargetGroup which is attached to a Listener on an Application Load Balancer (elbv2) that has its own
exposed_internet
flag set toTrue
.
-
-
ElasticSearch domain:
exposed_internet
is set toTrue
if the ElasticSearch domain has a policy applied to it that makes it internet-accessible. This policy determination is made by using the policyuniverse library. The code for this augmentation is implemented atcartography.intel.aws.elasticsearch._process_access_policy()
.
-
-
anonymous_access
indicates whether the asset allows access without needing to specify an identity.- S3 buckets:
anonymous_access
is set toTrue
on an S3 bucket if this bucket has an S3Acl with a policy applied to it that allows the predefined AWS "Authenticated Users" or "All Users" groups to access it. These determinations are made by using the policyuniverse library.
- S3 buckets:
You can add your own custom attributes and relationships without writing Python code! Here's how.
Cartography can map permissions between IAM Principals and resources in the graph. Here's how.