Skip to content Skip to sidebar Skip to footer

Detecting Malware-added Advertisements On My Site

I recently made a kind of 'Public Service Announcement' on my website telling people that there is only one advertisement on the site and it is neatly placed into the site's design

Solution 1:

Counting images that are standard ad resolutions isn't actually too hard. You just have to loop through document.images checking the resolution as you go. You can skip over your own ad by checking for its unique ID (of course, if it doesn't have an ID you can just skip images of a specific resolution).

var adID = "myAdId";
//incomplete ad resolution list
var widths = [120, 160];
var heights = [600, 600];
var adCount = 0;
for(i = 0; i < document.images.length; i++){
    for(j = 0; j < widths.length; j++){
        if(document.images[i].width == widths[j] 
            && document.images[i].height == heights[j]
            && document.images[i].id != adID){
            adCount++;
            break;
        }
    }
}
if(adCount > 0){
    notifyUser();
}

Notes:

  • A list of standard ad resolutions can be found on Wikipedia.
  • Tested with in Chrome, Firefox, and IE.
  • Not tested with dynamically-inserted ads, but it should most likely work, especially if you add a delay so the extension can insert its ads first.

Post a Comment for "Detecting Malware-added Advertisements On My Site"