Welcome to my session.
Today I'm going to talk about the potential risk of using telephone providers or telephone modules in a cloud environment.
But before we jump with that, I would like to introduce myself.
So my name is Uri.
I'm the CEO and co-founder of Zest Security.
I have spent over decades working in cybersecurity, specializing in both offensive and defensive security practices.
As a former security architect, I have tackled countless of security challenges in my career, and some of them I would like to share with you today.
So the agenda for today, we're going to talk about a telephone, specific for telephone modules and providers, and why we should evaluate any tools that we want to use in the organization.
Then I will share with you some analysis we perform on those providers' modules from a vulnerability perspective.
And after that, we're going to talk about why we should take care of that and what is the impact of those risks on your organization.
And next, I'm going to show you two attack scenarios.
One of them will be involving vulnerable providers, and the second one will be malicious modules, and how this could be a significant risk for your organization.
And last, it's what we can do to prevent it or even to reduce the risk.
All right.
So as a security architect or security engineer, your main goal is to make sure your organization is secure.
To do that, sometimes you need to read the documentation for the tool to understand how it operates in your organization, if there is any potential risk there.
In this case, I'm talking about Terraform.
Terraform is a powerful tool that helps an organization specific for DevOps and SRE to manage their cloud resources by code, or what we know as IAC.
What cut my eyes here was this section from documentation.
By the way, they did a great job about document everything.
So in this case, Terraform configuration will have full access to the variable in Terraform state.
And other than that, Terraform cannot prevent a malicious provider's module for exfiltrating the sensitive data.
Other than that, they also recommend to use only a trust module and provider in your Terraform configuration.
That raised me a few questions.
First, what is Terraform providers?
The second one, of course, is what is Terraform modules?
And how can an attacker exploit this to their purpose?
So let's understand what is Terraform providers and what is Terraform modules.
Terraform is based on plug-in called the provider to interact with a cloud provider, a SaaS provider, and other API targets.
Each provider defined a set of data resource type and data sources that help Terraform to manage the resources.
In other end, modules are a combination of TFL that located in the same directory that help the user to define what kind of configuration resource they want to deploy to the cloud environment.
So actually what happened, when user want to create a new resource, it will create a TFL file, what we call also modules.
With all the configuration to apply to the resource, then the Terraform core will translate to the Terraform provider, and the Terraform provider actually will transmit the task to the cloud provider.
From attack surface perspective, it's interesting because Terraform provider is written in the Go language program.
The communication between Terraform core and the Terraform provider is based on protocol RPC.
And the communication between Terraform to the target, Terraform provider to the target, is HTTPS.
And I'm sure all of us know how many vulnerability each one of the components has.
So again, Terraform is a powerful tool, but it's not bulletproof.
And let's be honest, in this scenario, we need to take care of this attack surface, because it could be very dangerous for the organization.
But before we jump to the risk analysis we perform, I would like to share with you how AshiCorp managed those providers modules.
So AshiCorp have three different tiers.
The official one is owned by AshiCorp itself, and they develop providers and modules.
And the second one is the partner, other company that develop their own providers modules, but they have some partnership with AshiCorp itself.
And the last one is community, is individual contributor that develop their own Terraform providers and modules.
Another interesting part here Is that each one of the providers modules that are part Of those tiers are also public accessible in a repository in GitHub, which means everybody can read the code, everybody Can answer for a vulnerability, and review the code,
and even If they do a great job, they can do a step further and inject Some malicious code.
All right.
Let's talk about the analysis we perform.
So we tested closely the ten widely used Terraform providers And modules from each one of the tiers i mentioned before.
And what we found was all of them have some critical Vulnerability.
The highest number was in the Community, which makes sense because individual Contributor probably take care less of the vulnerability.
But it doesn't mean the other official partner is not risky For us, because still we're talking about 11%, almost 12% For the official one that has critical vulnerability, and Almost 30% for the partner.
Again, even if it's a critical To exploit this vulnerability, it doesn't mean we don't need to Take care or to understand what is the risk of that.
Now i have a question for you.
It's a tricky question.
Does having more non-vulnerability make you more Secure?
i think it's a tricky question.
Because in my opinion, when you have more vulnerability, maybe It's because the owner or the organization trying to handle Those vulnerabilities in order to fix those.
And if you have less, maybe the owner or the organization are Not checking for a vulnerability.
This is why i think it's kind of tricky.
But i have another question for you.
And feel free to raise them.
How many of you know using Telephone production?
all right.
How many of you know which telephone providers you are Using?
all right.
And the last question, are you scanning those for Vulnerabilities?
all right.
So let's understand why i asked those questions.
So we took a closer look on the community, which has the highest Risk, and we tried to figure out how many downloads they have.
Like how many users use those providers from the community.
So what you can see here, we're talking about millions, and This is only for one month.
Think about it for one second.
One month, and we have a million downloads, which means every Download could be introduced for an attack for an attacker's Side.
So this is like a huge number.
And this is another reason why we need to take care.
And of course it's also a reminder to understand what we Are pulling to our environment.
So why it's important.
As you have seen before, like the slide before, we're talking About millions, which means it's kind of a cold mine for Attackers.
Because it's very attractive And a lot of users use it, it could be that the attacker will Try to exploit it or to use it to manipulate the users.
Another spot is kind of a blind spot for application security Processes and sdlc.
Somehow, as you see, almost none Of us raise their hand, take part of the scanning the Provider's modules for some vulnerabilities.
And last, all of us, i'm sure all of us know how manual and Expensive it is to fix things and it's consuming a lot of time And it's not efficient.
So i share with you about Terraform providers.
I also share with you some Analysis we perform on those both terraform providers and Modules and what are the risk of that and why we need to take Care of that.
Now it's time for the fun part.
I'm going to share with you two scenarios.
One of them, how can attacker exploit a vulnerable provider.
And the second one is how can attacker manipulate the user to Install malicious terraform and install some backdoor there.
So in this case, i'm going to share with you a cv from 2021.
Even though it's a bit old, the reason i decided to share with You is because i faced it just two years ago.
And it was very close to being in the production.
And lucky for us, we managed to find it in time and prevent it.
So the vulnerability itself is part of the vault provider, Which if you remember the tiers that i mentioned before, it's The official one.
That should be more secure or Trusted.
So the risk here is that the Vault provider didn't map the bound labels correctly, which Caused some unauthorized access to some service account from gcp.
Let's see in reality how it will work.
So the attacker read only access for some service account.
So if we are talking about previous attack, we know that Many of the attacks that happened recently obtained tokens From some public repository or s3 bucket that was open to Everybody.
So this step, it's kind of Easier for the attacker.
Next, the attacker needs to Identify that the user defined vault by terraform itself.
In this side, by the way, the user acts as it should be.
Defined the bound service account.
Defined bound label as you can see on the top.
But what happened when he executed the terraform apply, The vault terraform provider took the bound label and mapped It to a non-variable, which make it the bound label empty.
In this case, when the attacker identified that the user used The terraform vault to authenticate, he just needs to Use the token that he obtained from the repository.
And even if he didn't have any access to that, when he will Authenticate with vault, surprisingly, we get access.
From this point, what you need to do is just authenticate with Gcloud, and you will get access to the admin role.
And from this point, you can do whatever you want.
You can do lateral movement, data exfiltration, and service Disruption.
You name it.
Another interesting part about exploitation specific in the Terraform provider, because it's public accessible to the Internet, if you will go to the provider itself and search from Issues or some security issue, you will find a lot of new Security issues there,
or old.
Some of them open.
Some of them closed.
But the interesting part here, A lot of them are not associated with any cv.
Which means if you will scan those providers for Vulnerability, you will miss it, because they don't have any cv.
And this is another reason why we need to review the code, Review the issues to understand if they close the security issue Or not.
All right.
Let's jump for the second part.
The malicious modules.
So in this case, a target can upload a malicious module to Terraform registry or github.
It has a lot of options to Convince the user to install it.
Could be a local path, Terraform registry, github, and so on.
In this example, i'm going to show you a terraform module That creates an ec2 instance.
It will look very normal.
Nothing suspicious there.
But behind the scene, it will Use user data from aws to inject the backdoor.
If you are not aware of the user data, user data is the kind of Feature that aws helped to install some software and Components before a launch.
So in this case, the attacker Used a social engineer to convince the user to install the Malicious modules.
Once the user installs it, you Will use it, as you can see in the bottom, import the malicious Modules, and there is nothing malicious, looking malicious, Just the word malicious, but in reality, you're not going to see That.
So the user creates the ec2 Instance, as the module should do.
And we execute the terraform apply.
Once you do that, you basically not only create the ec2 Instance, but you also create the access to the attacker.
How the malicious module looks from the attacker's side, it Looks exactly like that.
Still, nothing malicious, Because he obfuscated all the malicious stuff in base 64.
And another important thing to say here is in my career, i've Seen many devops team in sre use base 64 to encode the user Data, because it makes the code much more readable and easy for Them to manage it.
So we talk about two attacks And one of them involving a vulnerable provider, the second One involved in a malicious module.
There is another one, but Unfortunately, we don't have time.
It's a malicious provider.
But let's talk about what we can do to reduce the risk.
So the best practice, read the documentation, read the code, Try to review all the issues that you have there, and try to Find a scandal repository for a vulnerability.
Even if they have a lot of vulnerability, it's good to Understand how the owner takes care of that.
If they have a vulnerability, for example, for a long time, Which means probably the attacker, the owner doesn't care About that, so it could raise a flag there.
Version pinning.
Pin the version of your Provider to reduce the possibility of introducing Vulnerability.
It's where you can find all the Versions from providers.
So you can keep tracking the Version that the provider has there, and you can also scan it With some open source tool to understand if you're using the Latest version or not.
Another important thing is to Enable the state locking.
State locking is kind of mirror What the user do with terraform, and what terraform Apply on the cloud.
Which one, which attacker, When attacker have access to it, you can manipulate the state File and cause a lot of problem to your infrastructure.
Monitoring your terraform plan and state file, and try to Identify some unexpected changes specifically in the state file.
Scan your configuration with iac tool.
That will help you to prevent some misconfiguration that Deploy to the cloud.
All right.
What about mitigation?
you can also implement some Control to reduce the risk, to help you to kind of minimize The exposure or use some high privileges in your environment.
So, for example, you can protect the cicd system Application log, especially the state file by using iam role And give terraform just these privileges and use only the Temporary cadential rather than the log lib secret.
You can use a network restriction like vpc load Balancer to enable only noncommunication between services.
You also can use cwpp to prevent nonmalicious communication From your infrastructure.
And last, you can use cloud Watch, and this is specific for aws, to create an alert to Detect if someone tried to read your state file or to do some Manipulation there.
Question?
All right.
One second.
What scanning tools do you recommend?
That's a good question.
So there are tons of open Source that you can use to scan those.
I really like for repository to scan, if you're familiar, part Of aqua repository.
You can use checkup.
There is another tool called clear for images, if you want to Scan those.
There are a ton of tools.
I can share with you later on if you want.
That's it.
No, so checkup, scanning a Telephone file, trivy can scan the repository where the Providers and modules are located.
Okay.
Any other questions?
All right.
Thank you, guys.
Thank you very much.
Thank you.