2

httpリクエストのレスポンスからjsスクリプトを実行しようとしています。

以下はコードです。

#!/usr/bin/perl
use WWW::Scripter;
use URI;

$w = new WWW::Scripter;
$w->use_plugin('JavaScript');
$response=$w->get("sdt1.corp.xyz.com:8080/click/phoenix/339cd9314fe0136d3c30f6e9984b1ddc?clickId=sfshsksk1234go");

$data_ref = $response->content_ref( );

#this response is a html code with a js link enbedded
my $h = $$data_ref;


my $u = new URI 'data:';
$u->media_type('text/html');
$u->data( $h );
$w->get($u);

$h の html コードは次のとおりです (読みやすくするために空白が追加されています)

<html>
 <body>
  <div id="iat-click-js"></div>
  <script>
   var _clickurl="http://sdt1.corp.xyz.com:8080/click/phoenix/339cd9314fe0136d3c30f6e9984b1ddc?clickId=sfshsksk1234go&csrdmnb=1343895381009";
   var _fpdatakey="afpdata";
   (function(){
    var e=document.createElement('script');
    e.src='https://d3hhytn20582jn.cloudfront.net/iatclickbeacon.js';
    e.async=true;
    document.getElementById('iat-click-js').appendChild(e);
   }());
  </script>
 </body>
</html>

jsの内容は以下の通りです。

fortyone=new function(){this.e=(new Date(2005,0,15)).getTimezoneOffset();this.f=(new  Date(2005,6,15)).getTimezoneOffset();this.plugins=[];this.d={Flash:["ShockwaveFlash.ShockwaveFlash",function(b){return b.getVariable("$version")}],Director:["SWCtl.SWCtl",function(b){return b.ShockwaveVersion("")}]};this.r=function(b){var c;try{c=document.getElementById(b)}catch(d){}if(c===null||typeof c==="undefined")try{c=document.getElementsByName(b)[0]}catch(e){}if(c===null||typeof c==="undefined")for(var f=0;f<document.forms.length;f++)for(var g=document.forms[f],h=0;h<g.elements.length;h++){var a=g[h];if(a.name===b||a.id===b)return a}return c};this.b=function(b){var c="";try{if(typeof this.c.getComponentVersion!=="undefined")c=this.c.getComponentVersion(b,"ComponentID")}catch(d){b=d.message.length;b=b>40?40:b;c=escape(d.message.substr(0,b))}return c};this.exec=function(b){for(var c=0;c<b.length;c++)try{var d=eval(b[c]);if(d)return d}catch(e){}return""};this.p=function(b){var c="";try{if(navigator.plugins&&navigator.plugins.length){var d=RegExp(b+".* ([0-9._]+)");for(b=0;b<navigator.plugins.length;b++){var e=d.exec(navigator.plugins[b].name);if(e===null)e=d.exec(navigator.plugins[b].description);if(e)c=e[1]}}else if(window.ActiveXObject&&this.d[b])try{var f=new ActiveXObject(this.d[b][0]);c=this.d[b][1](f)}catch(g){c=""}}catch(h){c=h.message}return c};this.q=function(){for(var b=["Acrobat","Flash","QuickTime","Java Plug-in","Director","Office"],c=0;c<b.length;c++){var d=b[c];this.plugins[d]=this.p(d)}};this.g=function(){return Math.abs(this.e-this.f)};this.h=function(){return this.g()!==0};this.i=function(b){var c=Math.min(this.e,this.f);return this.h()&&b.getTimezoneOffset()===c};this.n=function(b){var c=0;c=0;if(this.i(b))c=this.g();return c=-(b.getTimezoneOffset()+c)/60};this.j=function(b,c,d,e){if(typeof e!=="boolean")e=false;for(var f=true,g;(g=b.indexOf(c))>=0&&(e||f);){b=b.substr(0,g)+d+b.substr(g+c.length);f=false}return b};this.m=function(){return(new Date(2005,5,7,21,33,44,888)).toLocaleString()};this.k=function(b){var c=new Date,d=[function(){return"TF1"},function(){return"015"},function(){return ScriptEngineMajorVersion()},function(){return ScriptEngineMinorVersion()},function(){return ScriptEngineBuildVersion()},function(a){return a.b("{7790769C-0471-11D2-AF11-00C04FA35D02}")},function(a){return a.b("{89820200-ECBD-11CF-8B85-00AA005B4340}")},function(a){return a.b("{283807B5-2C60-11D0-A31D-00AA00B92C03}")},function(a){return a.b("{4F216970-C90C-11D1-B5C7-0000F8051515}")},function(a){return a.b("{44BBA848-CC51-11CF-AAFA-00AA00B6015C}")},function(a){return a.b("{9381D8F2-0288-11D0-9501-00AA00B911A5}")},function(a){return a.b("{4F216970-C90C-11D1-B5C7-0000F8051515}")},function(a){return a.b("{5A8D6EE0-3E18-11D0-821E-444553540000}")},function(a){return a.b("{89820200-ECBD-11CF-8B85-00AA005B4383}")},function(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-00401C608555}")},function(a){return a.b("{45EA75A0-A269-11D1-B5BF-0000F8051515}")},function(a){return a.b("{DE5AED00-A4BF-11D1-9948-00C04F98BBC9}")},function(a){return a.b("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}")},function(a){return a.b("{44BBA842-CC51-11CF-AAFA-00AA00B6015B}")},function(a){return a.b("{3AF36230-A269-11D1-B5BF-0000F8051515}")},function(a){return a.b("{44BBA840-CC51-11CF-AAFA-00AA00B6015C}")},function(a){return a.b("{CC2A9BA0-3BDD-11D0-821E-444553540000}")},function(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-00401C608500}")},function(){return eval("navigator.appCodeName")},function(){return eval("navigator.appName")},function(){return eval("navigator.appVersion")},function(a){return a.exec(["navigator.productSub","navigator.appMinorVersion"])},function(){return eval("navigator.browserLanguage")},function(){return eval("navigator.cookieEnabled")},function(a){return a.exec(["navigator.oscpu","navigator.cpuClass"])},function(){return eval("navigator.onLine")},function(){return eval("navigator.platform")},function(){return eval("navigator.systemLanguage")},function(){return eval("navigator.userAgent")},function(a){return a.exec(["navigator.language","navigator.userLanguage"])},function(){return eval("document.defaultCharset")},function(){return eval("document.domain")},function(){return eval("screen.deviceXDPI")},function(){return eval("screen.deviceYDPI")},function(){return eval("screen.fontSmoothingEnabled")},function(){return eval("screen.updateInterval")},function(a){return a.h()},function(a){return a.i(c)},function(){return"@UTC@"},function(a){return a.n(c)},function(a){return a.m()},function(){return eval("screen.width")},function(){return eval("screen.height")},function(a){return a.plugins.Acrobat},function(a){return a.plugins.Flash},function(a){return a.plugins.QuickTime},function(a){return a.plugins["Java Plug-in"]},function(a){return a.plugins.Director},function(a){return a.plugins.Office},function(){return(new Date).getTime()-c.getTime()},function(a){return a.e},function(a){return a.f},function(){return c.toLocaleString()},function(){return eval("screen.colorDepth")},function(){return eval("window.screen.availWidth")},function(){return eval("window.screen.availHeight")},function(){return eval("window.screen.availLeft")},function(){return eval("window.screen.availTop")},function(a){return a.a("Acrobat")},function(a){return a.a("Adobe SVG")},function(a){return a.a("Authorware")},function(a){return a.a("Citrix ICA")},function(a){return a.a("Director")},function(a){return a.a("Flash")},function(a){return a.a("MapGuide")},function(a){return a.a("MetaStream")},function(a){return a.a("PDFViewer")},function(a){return a.a("QuickTime")},function(a){return a.a("RealOne")},function(a){return a.a("RealPlayer Enterprise")},function(a){return a.a("RealPlayer Plugin")},function(a){return a.a("Seagate Software Report")},function(a){return a.a("Silverlight")},function(a){return a.a("Windows Media")},function(a){return a.a("iPIX")},function(a){return a.a("nppdf.so")},function(a){return a.o()}];this.q();for(var e="",f=0;f<d.length;f++){if(b){e+=this.j(d[f].toString(),'"',"'",true);e+="="}var g;try{g=d[f](this)}catch(h){g=""}e+=b?g:escape(g);e+=";";if(b)e+="\\n"}return e=this.j(e,escape("@UTC@"),(new Date).getTime())};this.l=function(b){try{if(!b)return this.k();var c;c=this.r(b);if(c!==null)try{c.value=this.k()}catch(d){c.value=escape(d.message)}}catch(e){}};this.a=function(b){try{if(navigator.plugins&&navigator.plugins.length)for(var c=0;c<navigator.plugins.length;c++){var d=navigator.plugins[c];if(d.name.indexOf(b)>=0)return d.name+(d.description?"|"+d.description:"")}}catch(e){}return""};this.o=function(){var b=document.createElement("span");b.innerHTML="&nbsp;";b.style.position="absolute";b.style.left="-9999px";document.body.appendChild(b);var c=b.offsetHeight;document.body.removeChild(b);return c}};try{fortyone.c=document.createElement("span");typeof fortyone.c.addBehavior!=="undefined"&&fortyone.c.addBehavior("#default#clientCaps")}catch(i){}window.fortyone=fortyone;window.fortyone.collect=fortyone.l;

function sendclickping(){
var req;
if (window.XMLHttpRequest) {
    req=new XMLHttpRequest();
} else {
    req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != null) {
    req.open("POST",_clickurl,true);
    req.onreadystatechange= function() {
        if (req.readyState==4 && req.status==200)
        {   
    var _rurl=req.getResponseHeader("location");
    if (_rurl && _rurl.length != 0) {
                window.location.replace(_rurl);
    } else {
        console.log("could not get the redirect url");
    }
        }
    }
    req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    var _pbody=_fpdatakey+"="+escape(fortyone.collect());
    req.send(_pbody);
} else {
    console.log("AJAX (XMLHTTP) not supported.");
}
}
sendclickping();

今朝まではまったく問題なく動作しており、コードは 1 行も変更されていません。perl スクリプトを実行すると、次のエラーが表示されます。

gurudutt@MK-QA-28:~$ ./js1.pl 
ReferenceError: The variable ActiveXObject has not been declared at   https://d3hhytn20582jn.cloudfront.net/iatclickbeacon.js, line 8.</p>

何が悪かったのかわかりません。

js を見ると、else 条件の中に入る必要はありませんでした。これが機能している間は、if 条件が満たされていたと思います。しかし、何らかの理由で、今日は if 条件にはなりません。

if (window.XMLHttpRequest) { req=new XMLHttpRequest(); } else { req=new     ActiveXObject("Microsoft.XMLHTTP"); }

このスクリプトでは、この部分が鍵を握っています

my $u = new URI 'data:'; $u->media_type('text/html'); $u->data( $h ); $w->get($u);

text/html の代わりに何か他のものを使用して、media_style と何か関係がありますか?

4

0 に答える 0