首页 > 解决方案 > 用于提取 URL 特征的 Chrome 扩展内容脚本

问题描述

这只是构建 Chrome 扩展程序以检测网络钓鱼 URL 的代码片段。下面的代码用于提取 URL 特征。我不明白的是function predict(data,weight). 重量中的数字是什么?例如:weight = [3.33346292e-01, ...]

var testdata;
var prediction;

function predict(data,weight){
    var f = 0;
    weight = [3.33346292e-01,-1.11200396e-01,-7.77821806e-01,1.11058590e-01,3.89430647e-01,1.99992062e+00,4.44366975e-01,-2.77951957e-01,-6.00531647e-05,3.33200243e-01,2.66644002e+00,6.66735991e-01,5.55496098e-01,5.57022408e-02,2.22225591e-01,-1.66678858e-01];
    for(var j=0;j<data.length;j++) {
      f += data[j] * weight[j];
    }
    return f > 0 ? 1 : -1;
}

function isLongURL(){
    var url = window.location.href;    
    if(url.length<54){
        console.log("NP");
        return -1;
    } 
    else if(url.length>=54 && url.length<=75){
        console.log("Maybe");
        return 0;
    }
    else{
        console.log("P");
        return 1;
    }
}

testdata = [isLongURL(),isTinyURL(),isAlphaNumericURL(),isRedirectingURL(),isHypenURL()];

prediction = predict(testdata);

chrome.extension.sendRequest(prediction);

还有许多其他 URL 功能功能代码,但这里我只包括一个示例,即检查长 URL。

标签: javascriptgoogle-chrome-extensionfeature-extractioncontent-scriptphishing

解决方案


推荐阅读