start	end	text
5060	6200	Hi everyone.
6200	10060	Well, let's start my talk.
10140	11440	The title is U.S.
11440	20080	C1 Shuffle, Lateral Movements and Other Creative Steps that Attackers Take in AWS Cloud Environments and How to Detect Them.
20460	22500	So, who am I?
22500	24880	Well, my name is Felipe Esposito.
24880	26760	I'm also known as Proteus.
26920	37580	And a little bit more than 10 years of experience in IT security, mostly on researching and sysadmin stuff.
37580	40980	I'm also a proud father of a girl.
41140	43420	I'm also a booting instructor.
43420	47620	And my main job right now, I'm a security researcher at AT&T Security.
47800	56980	And as a researcher, most of my job is Googling around, reading documentations and creating bugs and testing security stuff.
56980	63640	But sometimes, we are asked to help our clients with some questions they have.
63640	76580	And I remember that day when I was reading docs, Googling around, and one of our clients asked us, hey, can you take a look on these network diagrams and his IAM profiles?
76580	77960	And we said yes.
78000	80880	And he was doing all kinds of nasty stuff.
80880	85980	He was doing stuff like VPC peering between projects in the environment.
86300	91540	He has cross accounts roles between almost all their accounts.
91640	93060	And I said, well, no.
93400	97360	You can't do like this because there's a thing called lateral movements.
97560	100000	And an attacker can take advantage of it.
100140	102200	And he was like, what?
102200	102860	Yeah.
102860	106700	So I made this statement.
106700	108660	I know it's a bold statement.
108980	112220	But I have support.
112220	113920	I have arguments to support this.
113920	117660	So cloud security is more complex than on-premise security.
120020	129820	So by the title of this talk, I was looking for titles who might be lateral movements.
129820	137500	And the only thing that I could remember that moves laterally is Caranguejo or CREBs in English.
137500	140540	And I was like, not a good title for this talk.
140540	146140	But my boss, Ciera, he remembered this kind of dance he's calling Texas Shuffle.
146200	149740	And it looks a little bit more like this.
180000	181320	Seems fun, right?
181320	194200	So as I'm a Brazilian, and I'm also from Rio de Janeiro, I had to bring up something different just to make a contrast between the Texas Shuffle and any other kind of dancing style.
194200	200120	So I brought you what we call Brazilian funky.
200120	202960	And it's something like this.
224550	225130	Yeah.
225130	226590	Seems hard, huh?
226590	231850	So well, let's jump to cloud.
231850	235570	But take those two dances in perspective.
235570	251810	So when we talk about lateral movements on AWS, we can say things about like an attacker can move laterally between an instance on a VPC on account A and a VPC in account B.
251830	257050	If they have a VPC peer established between each other, you know, routes and everything.
258590	261150	And this is what we call the data plane.
261150	270810	And if you take this into consideration, the data plane seems like on-premises network, because we have networks, some networks, house between those networks.
271030	279670	And the attacker can also move laterally between those networks on the data plane and also on-premises networks.
279730	283690	But in cloud, we do have one thing that we call the control plane.
283690	291050	And the control plane is basically how the AWS or other cloud providers control the data plane.
291050	302710	So the control plane basically is all the APIs that we call for creating resources, deleting resources, changing properties on those resources, and things like that.
302850	308730	So in also the control plane, that's where we have the IAM.
308730	312870	And that's the thing that controls permissions on AWS.
313150	324750	So what happens is you can have a role on the control plane, and you can assume another role on the same account.
324750	329970	So if you have an account moderator, you can assume a role administrator on this account.
329970	331890	And this is kind of a lateral movement.
331990	340970	But we can also assume, we can also exact something on the EC2 instance that is on the same account.
341310	350630	So you are in the control plane, and then you can jump to the data plane by executing a command on an EC2 instance in this VPC.
351190	360390	But if that EC2 instance also has a role, you can also jump from between the data plane to the control plane by assuming this role.
361330	364490	So things get a bit more complex, right?
364490	371270	And you can also assume a role from the account A to account B.
371270	374410	So you can assume another role in another account.
374710	387390	And you can also assume a role from the EC2 instance on the VPC A on another account, on account B, for example.
387390	399550	And you can also execute any command from this role here on the account B to any instance on account on the VPC B.
399550	410990	So this makes it much more complex to understand lateral movement possibilities, and much more complex to track this kind of lateral movement possibilities.
410990	421770	So I promised my sister-in-law, she's a dancing teacher, that we can't compare dancing styles, but we can compare aspects.
421830	427950	So if you guys remember those two dances, which one of you seems more difficult to learn?
427970	435630	The Brazilian funk is faster for sure, has a lot of fast movements, but he's dancing alone.
435730	442970	And when you get Texas Shuffle, for instance, you have the interaction between the partners.
443470	449630	They have to balance each other to understand where they are in the space.
449630	452070	They have to coordinate this with the rhythm.
452070	458270	And they can also dance alone by themselves, also always looking for the other partner.
458270	466790	So Texas Shuffle has some aspects that are more complex than Brazilian funk.
467970	483510	So in order to illustrate how the attackers can take creative steps, I was wondering what can I bring to you guys, would you remember this?
483510	487070	And then I remember a music, it's called Cupid Shuffle.
487070	494630	It's like to the left, to the left, to the right, to the right, now kick, now kick, now walk it by yourself, walk it by yourself.
494630	497230	Most of you guys might remember this.
497270	500030	So it's like Macarena for Brazilians.
500750	505570	Yeah, so we have some steps that are called to the left, to the left.
505570	514330	And this happens between EC2 instance to EC2 instance in different accounts, for example, if they have VPC peering.
514330	520690	So what happens is that ARP protocol doesn't work as expected on AWS.
520690	526350	So in AWS, the ARP protocol doesn't have the broadcast.
526350	532870	So there's no easy way to find what are the other networks that you have on the data plane.
533190	538650	So you have to go to the default mode that's scanning.
538870	542210	So yeah, you can use an Nmap for scanning this.
542210	544750	So you can scan a range slash eight.
544750	546870	It's nice, but it's effective.
547130	551030	And you can use this comment right here to do it.
551830	563750	And once you find another machine, after that, you can hack your way into this new instance and then jump in between EC2 instance, also between accounts.
566420	570400	There's another movement that are called step up and diagonal.
570880	581130	That happens when you have an EC2 instance or a Lambda or ECS or a batch job, et cetera, anything that can run any kind of
584580	585780	a program .
586040	589340	And that it has a role to assume.
589340	595560	So there's also a Maitreya tactics for this.
595560	600080	The technique is called 1550.001.
600080	614100	And if the attacker lands for somehow an exploit or any vulnerability on an EC2 instance that has a role to it, he can assume a role and jump from the data plane to the control plane.
614240	622100	So for this, so the attacker lands here, he can get a STS get caller identity to find out each role he has.
622120	627940	And then he can just use the service that's called instance metadata.
628240	643100	He's a service in AWS who allows him to get credentials, find out each IP address he has and do a lot of stuff, finding the host name and things like that.
643980	651920	So with the service, he would be able to get the credentials as we saw right here.
651920	655960	And with those credentials, he can jump to the data to the control plane.
656180	661600	And by jumping to the control plane, he would be able to use tools like Paku.
661600	666700	If you guys don't know Paku, it's like the meta exploit for AWS.
666780	669560	So it's open source AWS exploitation framework.
669560	670740	Pretty good.
671580	679480	And it was developed by the guys of Rhino Security, especially by the late Spencer Gittin.
679840	688980	So it's a great tool if you have AWS credentials to explore and to get doing more nasty stuff on the AWS.
689420	695480	So another letter of movement, I call it step down.
695760	712540	And that happens if any user with any user or role with SSCM or instance, creating instance actions and actions are kind of permissions on AWS, they can execute code and jump to the data plane.
712540	733240	So if you have a user, A, who wants to jump to a specific VPC or a specific subnetwork, and this user has the ability to execute anything, like create, execute an instance that already exists on this VPC.
733240	743730	Or if he can also, if he can create an instance, he could create an instance on this VPC, execute code, and then jump from the control plane to the data plane.
744360	755660	So this is a comment that an attacker would do to make an EC2 instance create a reverse shell for his IP address.
755660	762240	So he's doing an AWS run shell script with these parameters.
762240	766420	And this is what the EC2 instance will exec.
768840	775180	So another movement that I call here, called to the right, to the right.
775180	782140	And that is when you can assume a role between accounts and cross accounts between AWS.
782200	798740	So if you have an account A, you can do an account B has this policy, that means that any principal on account A can assume a role in account B.
799220	805540	So if you have, you can assume a role from account A to account B, right?
805720	828420	But if you are in account B, after assumed a role in it from account A, and you want to assume a role in account C, just jumping between accounts, you might think that's the necessary thing to do is, it's have this policy in account C, like any entity from account B can assume a role in account C.
828420	830520	But the thing is, that's not true.
830520	843400	Because when it comes from account A, an attacker can assume the role in account B, he's not an instance of account B, he's an instance of account A.
843400	846700	So this is not possible.
846700	853260	The only thing that would be possible from assuming a role from B to C, would be a policy like this.
853300	858480	So anything on B, we've assumed the role, and the name of the role, and the value.
858480	866720	Because when you assume a role, you do a temporary value for this, like a comment for this assumed role.
867000	869300	And this might also be true.
869300	876500	But these kind of things, just to be honest with you guys, I never saw in production in any of our clients.
876500	884920	So I don't believe it's feasible to find any other environment with this kind of assumed role, right?
884920	888800	So this won't work for most of the things.
888800	899980	But one thing that one attacker can do is jumping from the account B to a data plane, and then assuming a role in account C.
900000	908120	But this thing here, what we call assume a role for account A, and assume a role for account C, it's called role chaining for AWS.
908120	910700	And it also has a hard limit of one hour.
910860	930420	So one hour might not seem a lot, but when we're talking about control plane, the things that has a lot of APIs, really well documented from AWS, you can just script your attack, and one hour is enough time to run any kind of scripts.
930500	934900	But yeah, this thing has a hard limit to one hour.
934900	939340	But there is a bypass for that, that I call now kick and now kick.
940100	945800	And that's an error when you have account A with assumed role in account B.
946280	950580	And the account B, account C, has assumed role from account B.
950580	968540	What an attacker can do is jump from the control plane to the data plane, gives the EC2 instance the privilege to assume role, and as this EC2 instance is an entity from account B, this policy in account C will work.
968780	992360	And by doing this kind of movement, simplified here, the attacker can bypass this hard limit of one hour, because EC2 instances, are not treated as the same way the other instances are treated for assumed role operations.
993080	996280	So this is well documented here.
997060	1000680	And this bypass can work up to 12 hours.
1003860	1008280	So what are the attacker requirements to do things like this?
1008280	1010300	It has to have enough privileges.
1010400	1013960	For example, it has to assume role in resource star.
1014420	1017560	He also must know a related account ID.
1018180	1024520	And for finding this related account ID, he can find this in CloudTrail, IAM policies, and also through OSINT.
1025280	1029940	And they also need to know the origin of a role to assume the new account.
1029940	1046940	So it can be brute force, or if he came from the master account, if the account has a SSO single-site organizations, and if he came from the master, he'd be able to find another account pretty easily.
1047360	1054520	So to have enough permissions, there's also a thing that we call AWS privilege escalations.
1054600	1061280	And privilege escalations are basically a set of actions that allows you as a principal to increase their privileges.
1061280	1067000	So there was a great research by the late Spencer Gittin, also from the Greenhouse Security Labs.
1067000	1072580	He found out around 28 no-privilege escalation techniques.
1072720	1078980	And there will be a new one just released by Spooker Labs in his talk called Village.
1078980	1080920	Watch it, don't miss it.
1080920	1084760	And even more possibilities with the IAM pass role.
1084840	1094720	And there is a research by Nolan Daham, where he's looking for IAM pass role possibilities and how to privilege escalation with that.
1094740	1104180	But the thing is, privilege escalation is a thing in AWS, and that's not pretty easy to find out and understand those things.
1104180	1112040	But not all privilege escalations are created equal, because not all techniques have the same effectiveness.
1112220	1113120	And how so?
1113120	1115520	So we have here two techniques.
1115520	1117960	One is called create policy version.
1118240	1134660	And if an attacker got credentials, and he has not all actions on AWS, but he has a great policy version, he can create a new policy version for him with the system administrator permissions.
1134660	1139120	And then he becomes a system administration on that AWS account.
1140060	1146780	But there's another technique that's called IAM set default policy version.
1146920	1157760	That means that the attacker has the version v1 right now on his, and he has this privilege set default policy version.
1157760	1166900	But to become a system administrator, he needs that the previous version, or any of the previously versions, has the system administrator possibility.
1167280	1173350	So he has a precondition to privilege escalate in this technique.
1180400	1185960	So how do we find out possibilities of privilege escalation?
1185960	1194310	There is a tool, there is called CloudExplaining, and was created by Ken McQuaid, was first released on 30 April of 2020.
1195830	1199310	And this is a IAM security assessment tool.
1199310	1217430	This tool is able to create, to find out privilege escalation possibilities in customer policies, inline policies on AWS, and also find out about data filtration possibilities, resource exposure, credential exposure, and infrastructure modification.
1217490	1219790	So this tool is really great.
1220720	1231110	And if you didn't know, you can use it to find out possibilities of privilege escalations in your environment, right?
1232770	1245250	So any other, what are the requirements that an attacker would need to move laterally between AWS accounts, would be an ID of the related account.
1245250	1249470	So it can be found in CloudTrail, IAM policies, and also SYNT.
1249530	1260250	And you can also, for example, you know, SYNT stuff, you can find out the company GitHub, find Terraform scripts, and other kind of things.
1260250	1268750	And those numbers might be, or might not be, but they are probably hard-coded on those files, right?
1269110	1287050	So in this, we have an example of CloudTrail, and we can find out there's account ID doing anything here with the account ID, and you can find out the account IDs also from the CloudTrail.
1289710	1302250	So if the attackers also use AWS organizations or Control Tower, the attacker also, he needs to know a role to assume on these accounts.
1302250	1314810	So he's in account A, he wants to assume a role in account B, but he also knows a role, he has to know a name, the ID of the account, and he has to know the name of the role to assume.
1315550	1326890	But if the organizations use AWS, if the AWS accounts use organizations or Control Tower, the attacker knows the name of those roles because they are hard-coded.
1327050	1345930	So if the attacker gets access to the master account, it's game over, it's final dance, because from the master, the attacker with the assumed role condition can assume any role, can assume a role called organizational account access role, or he can also assume a role called AWS Control Tower execution.
1345930	1351530	And those roles, by default, they have admin privileges in all the accounts with the same organizations.
1351830	1355950	So protect your master account as much as possible.
1355950	1364030	If useful, if it's used, well, do not use any kind of workload on the master accounts.
1364630	1374850	So there are some scenarios, our best practice from AWS that we can explore to understand ladder movements possibilities.
1374990	1380250	So the first scenario is called Rub and Spoke.
1380250	1386090	This is a really well understood network design from AWS.
1386090	1391890	So we have several accounts, accounts A, accounts B, accounts C, a shared services account.
1392350	1403510	And what you can do, the wrong things that you can do is create an EC2 instance with two network interfaces on the shared services.
1403510	1408030	And those interfaces connect to the account A to the account C.
1408030	1411430	So it might be a route point.
1411430	1417810	So an attacker who got an account A, he can hack this instance, and then jump to account C.
1418290	1424810	But you can also do you can also do a VPC peering between account A, account B and account C.
1424950	1434870	This also might break the network interface that want to work on this network.
1434870	1437230	So don't do it.
1437230	1438750	Please don't do it.
1438750	1439870	Right.
1439870	1452030	And another AWS pattern and possible thing that you can do is to cross back, cross account back to master all CICD accounts.
1452030	1459770	So this we have a partner, a pattern that we call, and the user logins to the master account.
1459770	1463210	And this user, he has access to CICD.
1463770	1469950	And he has access also to dev and to staging, but he doesn't have access to prod.
1470330	1471170	Right.
1471170	1479090	But what happens if the administrator of this account do a cross account between the dev and CICD?
1479810	1487650	This user, as an attacker, he can just do a cross account to the master and just jump to the dev.
1487650	1489030	He can also jump to the dev.
1489030	1496790	But the CICD account, as he has permissions to deploy in prod, he can also make a jump to prod.
1496830	1508870	So also do not never cross accounts between your dev environments and staging environments back to a master or CICD account.
1509670	1518690	So in order to find out in our clients, we tested a lot of tools, but none of did what we wanted to do.
1518690	1521490	We test AWS PX.
1521490	1524330	We tested CloudMapper from dual labs.
1524330	1534670	We tested several tools, but none of them was able to deliver what we were thinking about.
1535310	1539930	What we thought that would be a good delivery to find out a lot of movements.
1540010	1542330	So we have to create your own.
1542330	1545130	So we had some requirements for that.
1545130	1568670	One of our requirements is to use open source and free tools, automatically download the necessary information from the AWS APIs, plot an easy to understand graph with graphs, what an attacker could do at a control plane data plane as well, and has a carry language to allow alerts to be raised automatically.
1568850	1575810	So as a backend, use Gremlin as a carry language.
1575810	1587150	We also use Cloud Splane to download all the information, not all the information, but some information automatically, and also understand what previous collision techniques would be useful.
1587150	1591110	And we also use D3.js for visualization.
1591850	1602630	So what we model, we model things like if anything is to instance or a lambda, anything from data plane is a square.
1603270	1606350	Anything from the control plane is a circle.
1607070	1614930	Anything that has, if it has the same account, AWS account, it has the same color, different colors, different accounts.
1614930	1624230	And we also model a row and arrow, and that's a directional relationship between any of those instances, right?
1625470	1627790	So kind of demo time.
1628090	1630070	Well, the name has no name.
1630070	1631390	The tool has no name yet.
1631390	1643090	So there was, back on the Cloud Village, there was a pool on Twitter to find out the name of this tool.
1644630	1656070	We are in some days to release this tool, so keep up, keep looking for our Twitter accounts, and we'll be released soon, right?
1656070	1659810	So for the demo time,
1664920	1669500	as I said, the tool has no name yet.
1671240	1684340	And by clicking search, it downloads all the information and plot the graphs, and you can also zoom, you can pan in, pan out, move laterally things.
1693110	1696470	As you can see, there are several colors here.
1696470	1703670	And this data, it came from a simulation that one of our clients who has hacked it.
1703670	1708030	So one of our clients lost his credentials for one of his accounts.
1709390	1719010	And by the end of the time, the end of the day, the attacker just created an EC2 instance and running some crypto miners on that.
1719010	1725110	So we were able to catch it pretty quickly and clean up the account.
1725290	1737490	But what the attacker could do, if he has the visibility of the possibilities that he could do, it's much more scary than just crypto mining.
1740990	1748930	So just organize, you can move things, you can just organize things here.
1749030	1751550	The thing is, the attacker lost control of this
1754910	1758570	account , and he would be able to create an EC2 instance.
1758730	1762050	This EC2 instance has an assumed role.
1764510	1771170	He would be able to jump to all other accounts, because this EC2 instance was in a master account.
1771170	1773370	And he also has a VPC peering.
1773450	1779670	And if you see, if you watch closely, all the connections between VPCs are two-way connections.
1779670	1781150	So you have EC2 instance.
1781150	1786670	We have a connection from this EC2 instance to this EC2 instance, and back and forth.
1786810	1796530	And he could also jump from this to this EC2 instance, and then also assume a role in this account here.
1805080	1809360	As you can see, he could assume a role in another account.
1827520	1836400	He could also jump to this EC2 instance right here, and then become an administrator on this orange account.
1843570	1854850	One thing that we find out, the easiest way to analyze these things is to look for big clusters like this, because they have the most interactions, like this.
1854850	1861610	And things like this are just lambdas with assumed roles, and they're not really well connected to the graph.
1861610	1867610	So by analyzing, the easiest way is to be looking for large clusters.
1867610	1885450	And you can also have a filter here for privileged escalations, that you could find out that this role here has a privileged escalation possibility to this role, that's the administrator role, by creating a new policy version, as you can see here.
1885950	1889890	So you can also find out privileged escalation possibilities.
1893610	1897630	So what's the future or our to-do list for EC2?
1897630	1903710	We want to evaluate all the restrictions of all privileged escalation techniques, so it just takes a little bit more time.
1903710	1913650	We also want to support, to add support for other resources like S3 and RDS, and also support for resource-based policies.
1913990	1927610	And a little bit better visualization and filtering, because there's what this visualization thing was just a POC, a POC, and was using another open source tool, it's called GraphXL, something like this.
1929090	1932190	But we want to do better with this.
1932790	1946390	So in order to conclude, what you have to have in mind, so also try to apply the least privilege to IAM role permissions, and this is said and done, we know that.
1946450	1957530	But you can use SCPs and IAM boundaries, and please, please try to never use a resource star, that brings a lot of possibilities to attackers.
1957870	1961450	And don't run any workloads in your master account.
1961450	1976850	So if you run any workloads in a master account, and if you by accident give this workload, EC2 instance, assume role, you can recruit a jump between all those accounts in your environment.
1976850	1983530	And also don't cross-account any accounts to master, or any accounts to CICD accounts, and things like that.
1983530	1990710	So always review all your trusted cross-account policies, and segment your network and accounts as much as possible.
1993050	1997790	So thank you guys, thank you for coming, watching my talk.
1997830	2002890	Hope to see you guys next year on CloudVillage and DEF CON 31.
2003390	2009870	So these are my contacts, Twitter, the TTC security Twitter, and my LinkedIn.
2010230	2013690	So if you have any questions, just keep in touch.
2013750	2014290	See you!
