I have been noticing ad insertions by MTNL in Mumbai area for past few months. The ads occasionally appear in arbitrary web pages. For example, here is an MTNL inserted ad at BBC website.
This is annoying and comes on the way of browsing. I wondered how are they doing this insertion. After some digging in the source code I found that their method is very sinister. They are hijacking Google’s ad generating code and placing their own code.
Various websites display ads using the ad service of Google. They place some code of Google on their website and the code generates the ads on the webpages. The code usually depends on some standard Google libraries. Therefore, the webpages also fetch the library code from Google servers. For example, the following code that manages Google publisher tagging.
MTNL code insertion is interfering with this mechanism. Sometimes when MTNL insert the ads, MTNL does not deliver the original gpt.js to the browser instead it sends its own gpt.js (exact mechanism is not clear to me. Possible theories, dns manipulation or sending redirection message).
Here is the gpt.js that MTNL delivered in the above example, which has the code that inserts the ads.
I suppose google should be quite unhappy.
This sounds very unfair practice by MTNL.
I have observed that they have replaced scripts of other web services too.