Iframes are a legitimate HTML feature used to embed content from external sources, but they can be exploited to host malicious code, facilitate adversary-in-the-middle attacks, and create convincing phishing sites that harvest user credentials.
iFrames in Cyber Attacks
Now, iframes aren't an attack in themselves, but can be utilized to carry out an attack.
Just a reminder that this is for educational and ethical hacking purposes only. This is to protect systems, not to compromise them.
Iframes are really designed to pull together information from several different pages, or even several different sites. A good example of this is like YouTube. There are times when we want to bring a YouTube video into our website. Well, YouTube is a whole other site, so how do we get the YouTube video to play on our site? An iframe is one of the ways that we can do that.
What we see right here is website number one. In website number one, we want to embed an object into it from another site or another page. And so what we do is we go and get the embedded coding into that — in this case, we're going to use iframes right here — and then we're going to grab the information from website number two so we can display it on our website.
But they can be used for malicious purposes. One way is that there could be a legitimate website that has some iframes that are pointing to some sort of malicious code. So one thing that a hacker can do is hack the website and put this iframe in there, and then maybe the owners of the legitimate website and all the other users that are visiting this page don't realize that there's even some sort of malicious code on this site.
The reverse can happen as well. You could have a malicious site that pretends to be another site, so this is a legitimate site that's being used inside this malicious site. The advantage of this is that this malicious site can see all the activities and what's happening on the legitimate site.
One thing that was really common about 20 years ago is that we had websites that were offering some sort of advertising. They wanted to use advertising space on their website to make money. What they would do is they would go to some sort of service provider that did advertising — Google is an example of this — and so then Google could put their advertising on your website and you could make money off of that. People would click those links and then you would make money. So this is your website and you would have this advertisement.
And then what they would do is they would go and find all of these users that wanted to advertise. These users then would submit their advertisements to a place like Google, who would then advertise on your website. What would happen though is that adversaries were submitting malware onto these advertising companies, and then that malware would get embedded onto your site. So now people who visited your site would have this malware that would be installed on their machine or working on their machine, and this was problematic. This was something that commonly happened until these advertisers started making sure that what was being submitted didn't have any malware on it before they started advertising on these sites.
They would use these for compromising sites. They do adversary in the middle. They collect data. There's a lot of reasons why they would have this malicious code embedded on a website.
Let's look at the reverse. Let's say I have some sort of malicious site that I'm hosting, and then I am redirecting this traffic, or I'm using the iframe to really pull in all the data from a legitimate site. Maybe it's a bank account login. So now when you go to this site, you think that you're getting the legitimate site, but what you don't see is that it's actually my site and I'm collecting data as people log into these accounts.
Here's an example of this. I'm on what appears to be the TechKnowSurge website, and so it looks legitimate. Everything is set up exactly the way I have it set up on my actual website. But if you notice here, I'm not actually on the TechKnowSurge website. I'm on some sort of other site that I set up, but that is then pulling in through an iframe the data of my TechKnowSurge website. And so this can be very problematic.
In fact, on this other tab, I have my actual site. If you notice, there's just one slight little difference here — well, there's a couple of differences. One is the URL is a little different here. And then it happens to have this little secondary bar on the right side here. So that's really the only difference that we have between these two sites that's a sign that something is off.
This is the iframe.htm. So if you look at this setup, that's what this is referencing here: iframe.htm. And I brought this up so that way you could see the actual code. It's very simplistic in what it is. There's a couple of little style information here, and then this techknowsurge.com. So I have the iframe here. And really, I just needed the iframe, but to make it a little more convincing, I put a couple of other elements in here so that way it looked a little more like you're visiting the actual site.
So this is all there is. Just a few lines of code, and you can easily create this deceptive site where it looks like I'm on one site, but I'm actually on another site.
TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.
Explore free tools and programs →