ÿØÿà JFIF    ÿÛ „ !.%+&8&+/1555$;@;4?.451 4,$,44444444444414444444444444444444444444444444444444ÿÀ  á á" ÿÄ     ÿÄ ?    !1AQaq"2‘¡±ÁðBRbrÑá#‚’¢²3S CñÿÄ   ÿÄ !    !1QAa‘2ÿÚ   ? 5˜Z¯V¦cø)›t/? z¨±>Õ5€¶‹Á¤·¼z¼Ü¬+ñ®v¤¨_ˆR­BFn©—˜ý®ç̝P8gýt·ÉSTŦˆìät?þé¼íìN/Þa)ì–í6ô… Ï¿øÃj´¿KÇü]ÿ ªô¹-eKànëÕHTx}ýSÜ›ÿ ”7Ø×&µ<¦  ¥ÑO¶[Ù¯ä¨ÞÃÿ PZ-¬;#õ|•oaÿ ©CìÞz3˜öː/¤­ñTûIØ}š^ mÓ%ªxˆ¥ÉŸu=Z+ISe¿45™¼u;ú&WØ÷€æßQ™®{|íx*TC“#ZŠìZ§²‹ 6pv…³¿¡äª*áZÐ%ÒOáˆo"x«OHk w±æ+¬V(kMúŸ5Vö«$ ÁrÏbàb57/luR ¸ÑÛj Òµì`Мq­û žICÀÊ•©4€Âcà¨Ï€O´<èÐ:›ù(Ë^L8þ‘ÍÌ#¸Ð_Ì©ÙK(Öz 4¬û+¸;ü’V’84‘¬ÃŽ:[â‡ÔÌáõp¢~§ªlæ£ö{®G>J¼"°‡7¯ÆÉèßû ‹É‹§ÁòÃýâßî ^ƾÙõ‹×óH#«LP½ïX=xÑÍ$|W?•~• îëÔ©ª‹ {ÝT…Kÿ ”hûâá)J*ö˜–ÔU;iÇ€/ ÆþjóZ\ýwØ=Ìm ºèËL9 ýèÆð/¨’¥öo=nË.%Îì ŽÕ¯È|{Oj²ƒE6e/ßdÄõ²Ìâ1O®ò×TsəԸhOMýíMˆ¿¼H˜l²,7Â¥#MF/Úf°Ö½± ¸–dr‹NýÊ íjqx{œÉ ä-È ¦ øÄër¨q°ð †nцýÑÄÆ’mä…n<0È™;ÁÝá¯ÁZƒ7FÀmì­ É&9ˆîéi¶ùN§Y• ÃZãAâ?•‡©‰ , ó¾IŸŠc1 4â&y­&pŠ­6;M À 0¹qç»p.á …ŸÅáK@%6·y6ƒ‰3?”úºŽ‰éX5ªPT §µ!=Mž«Ú½‹ÅgÂSâÉaþÓoö–¯ÁÔìR>5éÿ üs¶ÆUcÌ kÇR ]ÿ ù¬¼«VŽ;Â|‡~¢¦”ÏŰæ {L™Õ°Óv¹ò¸írޡעCÃ!íVÕ {¶»sŒNPg/ "uÕbkm²“$ďå¿é¹§°½æz¯6 †s¿!s–wÚÝ“™Œ °.ûj>·+™Òa…©Œ&rÝÎtÛë긪Ît’LAVp%c Úý[ÄzJ¾ÇàXXç@˜ó<êL]·T˜¾¥1Ó©V‡g´æ½¦Ý@¹óø!_@´ÞâSÁ —S3™•& ]@JHÚý©ZŽ €×æÔr»Áf!‡yÞ4Mv*èÓã_{‘åóUuљØ«Oïé*®EvÑ Œ÷‡U \"㪒ÍK+À 4“M¡ï:0¥5í!'<@î´”>Ç»&Z–ïCCV˜Ì5Šo&îhè.žû |ÓK©h$s6KìŒëã)¹hI¦GïOåóI;ììü#É$Š0…Ææ¥TØ.5­¾gn´ “ÂÖ\:hœ89G)J@„}œ:’Ò{/Š"¦_Æ×7Æ3VÇŠÊa]ÚŒÙ€Ä–=®uÁßâACZƒ§§£ Qnâ:«,×{tyø¬iÛcœÜÄ€H½ÄÍCk´÷šß .W'b¤Íåh]÷€=,Žv×cÚEÚHXJX¶îo¨FÒtèöŸ>ªª6[J®Fµ£sGÁeqõfe\íjÒÐïÄÐGˆe1Ø‹.Ø”‘Ëuø Y­ˆÜ ŽG|zùªüMpDnQWÄ”%JŠ™)â*p@Örš«ÕT2Ð%ˆG#ª„ ·¤!°ŸOTÂT¸aÚ%4&h™LµšØüÐ.F¿²ÐÞ_Ç‚¾ÅÃaÜ÷09Æ q€öy˜v‡85õN÷]¬äѼóS{°_MެúÔ#°Ç¸0åÞè2ëôPcvÆw9®ií1Ä8F™˜à‰´+‰Ik1òÝ7“Ñ×ÒsÝ\x‚h`ÞÑ`ó"|µEcý£n˜h`}GÞ !±ù²Ápü²ß6 0ïi󜵩SÈÇ7˜-ÕURO˜¦´f$ªž-Í6(œ}<„ éc øs]ŽŽ„*—¾ ìdŽ„)méª\¿êÎIg¾ØÞ~I#C/¼¼´EÁÈŽi8“©õådô·>euä ƒ'Ê×लR1ÉJE1ÐAát`t;ÇР%Ý<‡¥„ÍÆ`×Oyó)õiI€ñQaŸ4Ûù\áàaÃÔ¹HÃu¹*k€¦<„e S‡&õÏ B!ŽhüÞ`yj}mªf×\¿ Ç~æ­9‡û\՞Ǖg²1Žû5V7 !àöšm° c`ܬøÇìµÒ'P"?…´Ö,"§^•õލsÔ)6˜sæéÍR¼ ò|Sl”‹7 nPW Gòú÷½§O¯‡„l¡kSÞŒr½PÊ@æ¢pŽ-mÿ #Ÿ˜Àº¶Áä¦;ïÔæ$1££`“Õ>„—·ž)ßð³ñ#Ï Ô$¶œ‰ÊE‹À;÷º ¯«P:Ñ”8–IÊtpÞ3ª“>ê“þës4ò2OÏÕ­±zô†Õ§‰.÷ä¸;¿˜“'œ›žª}«Œ{ª±Ì 9ÔóÞÕ‡0 $íWV3Üì¬ —@kÝ4@¿r¼±½¬™›?øØæ´'Áé®CË3-g$˜ö‡×auÚi´Žp/êÛ æF›Ú2v‹ã¿¿,nB1̨ƃqÞa5͝@&Æû“él÷ \C²½UÍc ¯k×¢U ÖéQå™—-r wô ÞÏ<Ò=&=ÿ Ôê Òêˈt,i—;LîÜ á¸*ÚÃ1$êL•LÍ <É)ýÐà’ ;F™{ƒ™˜€&'}‚ãÄK`¡ÞT@I;®žZóè‚s’7®°›+§O­Åq©é»²9<Ô J ¼9O’HL»Ùïì¸rk¼Ž_ý‘TŸu[²ßÚŒ·ü÷B%¯E ŸÔX5êO´ Ç•€’I0 ÉJX` ñ¹õ%;µŸD‘«´€àwÒ™U ûئžÖö\×®×´8 ½‡ºÐÆÓ§?Àkmœ=;d5*@-ì0F Rªýš[Ü6âö̃ڸr*KA9· u*µæ£?U¸Âêí†8@¦X4 e-ò„0s{ HâUpU?¼mñRa°®a%Ð'tÉ×’\¾ÊÉ]t›h>·(Ë@R¼¡Ãt h}’O÷au<+nT…Ö…MӐ??Óe95 q>í/;&JSû °¯ÊéÞ øƒ*Ã2½Ài&:nôUl=¾¿5eˆ3”ñc|Ú2V”>„»&eE;«ÚäC p¢Û úy 9š[ŒÌx¼擼A&DåÒ¯ˆ¤ÀÌ;"˜ ÏQä¸åhÊ}Ûq«Û0WžÒ|»€ø®öCm5•\ÇÀ§Pe3£]0ÃàLDÉ‰1øªxjgwT‚÷¿LΨK‹›ùs—xˆÜ±µ kæ¸f‰‰ÜGk/LÛØ6d9ò¶ùA{ƒA3š/¬D¬khÓk‰`˜"㯒r¿±Óã jx‡°e}<Ñø\3y:'À•/h½Í€Ç4~g ?Û(¼]v‘ªlKÎâ~?O‚W%{Ì:“'©úNq¾›úo(X’¥¯ˆ nFê{Ç€ü?º'ë ø‹ì Þ09ŒÌç9Æ —ËC`j@ÓÄ(+a‹un¸#ÂꟋ{K`‘ÑÍÍ'à´»/Û,KW;Þ4²þð ï Nm|~fGÏ(…³Ã)«1ö­Õ ¥‡¨©ƒÃ™ü-s=à=U66Ï«Ýc蓦W¹íž®›nÔ%êÇìŒ<#Ü×84ån®Ð ÒåOC` ñânÑs‡¢ç 1õ%Îhì½Ã½® e:ݼUZo™`  ÅZŸŒÊ«ê1ÏÄo$q¹Þ€©ˆhÐÉä¯ñ[!…Ú˜àJ:x2$Íß&PåT£6ç— ‡Í*4Ýšçjÿ ‰É nófÐ ó(L5C•åÆ\rMÒ@ò }y-W}™üýVù—ú¢=Ù”c®‘< M ž ´Phr ¦©TD ‘ù.$´÷O‡‘V2Æò.=IUŒ=ž‡â¬i™aþÓåÙ?òUø'ØÖ•.~* šTŒ!•-×áºTâ®ä#õü'´ eýlYÅÓeÕKÂrT"CÚ@u!Óxƒ{š3€}1¿(r}%«nËamjÑ%ÑNEò v ˜à  σöK³,*º.àzù¨™Ó ÚçâU¦*¿ 9{%Ö¹ njûdaXöb) kÛÆ±ûÓ\°M7ˆÂ=û›ç¿Ã‚­V»Cg–8ÙêE- j)k$º`Ã-ùEýeBÆÇ]c¡°ñty&Òd0nõ'¡W+ƒ*|–øµFa\GQªEAÔp5\Ǽ·¼Ç8·õ -â§Ú[ ‡ uZeÖ 3}×d'+¹:ð+K†Û®s!Ï$úe€<Û”x)1»a­¡LC]¸µík…ÚàA»AYº{†ªS[¦5HÒ7ù --,ísòDØ€èk ÞÀîÜ ò@â( ËNˆë›4ô½•/¦o‡€Û7 ê•ÆêòðÜy'Án½µ á˜ݦ ndeo…[ì¶Ê,¥R³Ä=À±—–ß;£™´ñSâ*g§”ïaið‘Jå~™ÓÞ ß³Õ¢»8x埒²52>AÊb&-÷\7´éÄù€T˜,w;3{ï˜k…à¹ÄqÀ«œ{€\ ˆ¾[´¨јr &Úé„Ívˆ±8†¿]|¬ņ4I×pÞS1ÈÖz‰#Ìv‡G!YNògñ:màTz¢Ý1ô©^O=~ë|5Bã™ç•¼µõ•bÆ@úÕS¬ÈŒ#¬zünrŸ û” Z²•èðV"ÁHÚý©wÝ €7¼Ìu1hÑa3Éä û f$o¿É ™Ú›ÝçnpÒ3äÌ3†Í§,Äï]$‰/pê †«À¼¸e9­Æê_C]žƒ·ý·frÁN«, E=›Çq -‰öŒ:aÏ¿±í&£Í:-} 84‘ÿ eƒQÑeëSsuiA ³g㟥ú£?ÿ ʼn*”“÷aühe:ÊWa@ÒÞk±eØ] F Ô—r.åä˜ @ö¥ªZoÐýYL·¥S²G/‡ñ <~*ZÆ´è>JlòàÛÆ½ÿ 窘ìGN¢:I®KšJp/`íIÁÀõ#Ä-€ö­šµŒoF4|ÆQØÆ@Ì|£Ô…¢À{9˜è½Üó›€ôYÒÎYsið;ís¤€à²ˆ‚4qÉVŒI$ ‰"° æµ8cXGjœˏ¡Aâý•ËÜ¢ûï e·çLx']á"oÅÎê3¯Ç—¹”ó0nå‚âg{Œñ> S´˜îè°g238‚ãköÝfÚd´6Ò€;ò÷±¢™¼›º ¢Æ'¥Ðx'e¬ç ]bÈÆV¢ó‹kýBO ðÊâ$Ÿ!×T 3Mýמ žìٍàÌü‘8÷€àæØ8æ©6‰©L´«…oãpð„~Çk‰!ñ;‹”ÛžÍ àž±z Ÿôû øŸÝužÏ;ÿ #|u6™Þ¬ÚˆÐõA4¶â|ôl|Ê2ŽÇ¤ÝÅÇY.<#Aí.k§hóF‚”Y; M½Ö4hŸ4&›­¿tès´%FìL¥£Ãk‰ÇT¤haÁ¤ÚxfÉ`ÑìË›>i 3t‚:,–+^÷´–{Û–Nxi"x‘Ûg î¨>¥Õ܁ùZH,2Û“:8xÊ¢Çí9.É-Ìâã-=çjwµS˜dütžçwýGòú®®ûº_ˆýx$–¡ãøO EÚÛÏ÷R„×w+3£Á£öUMyR²¹âŒ°š›¸Ñãò9§Ó_Dl+Ùßc›úšGÅÌc†Ž!Ko=¶.‘Îÿ c²(2®V mª.ÿ ¹B›¹å ù„öŸSV>™ü¯$y:G¢Z×àøúdî¹û­·ýÇ´:•c LÍõi_‹ö+ÎæGÊè>OŠ•äž´§Þ{X}¨1ÚTc›»Qþ•êô°t¿OP?eæ~É{5]•ÙR£r5†nZ\ã@ &îJõ ¾àC°þV>fé¥/ü5ñÊIº_é5 ;e­h<@ Ä&æÃëE%;X,ÒãÆÞ`Oò¦kŸm#˜!ÀyÄ¢| óLšò¥Ä` ¶R=|ÈCâh5ò3DˆïF†ðÒ#ÅìÛœ?¸yhBãœí ZxßÎÄhºRK„`Þödvײ™ÀÈÑÒgŒuY w³%†ƒÓzõ ÖÏp‚dH®¦A´ù§»ÓÇMæ~)ˆð‡û:ù&Ä •vGD´À n ݇¼Ö8Fö óáà£~Ë¥x`oK|Ä?fxiØü%pìR>éò+Û±éÎ>núlFŤ'tq8LZÏvÃ?„¡ß±È⽆¯³íü@x|PöUäèØã¡ð‚ŒAìÏ"vÍwóŸÍ{ ý0.z È•Ö{,N¡£¡ŸKÕÙž>Ýœþ ÍÀ°<×EA!Å‚D™IúOÍ¡>ôG}Â` ÍßkÜL™Ž Þð™ {IøF²¹òQ3&!ÃÂÞz.d&Ï-sH¸,Ôõ˜ŽP€ 77ˆÝ¼ÊëÜw =cÕ Ú,ØÐ5ÎYÐ)ì´öœgŒ[¤ßv㙑8心>h]§µháYš£²ºÑ.{Ï7Sð•?´~×SÃKýJÛ˜ ™Íäiúu<µX¶1õ^kâçIÑ£sZ4h>j*ÔšD:4­¿_ ÷¸ Õxæÿ ¸?Mù _•­ÊÐ ä ÷ý ÑwL œ­ïnTkÛUÍN©ë:¦fV ¶ÜÔÜMªÅâA½–¿R×TXš-%iTÊT•‡Ù‚JôϐZxWÑè‰f‰òG º ×Õû2aZ7OU3[“×AT–ÞŒ…-‘¤”Ì ì&(ˆ¿­•ƒkï’:ðY¦W‘ Å)“†‘˜³Åtcø˜ñTÂwÚÇ4|üLÇªí–v- qˆèU qPE.†â‘˜µ Æ,ÐÅs]8¾„oúÑ i>ÜxxÈó)ƒ ´æÁâØ$À‰vžŸf$Ž |ãw;ÀÁIJ»b` {¦Ó¤Ú$©YÀ‘n@Óïž«9J¼êG m¤ ܯ¹ÌW4€ÐÒÅÛ‡#褕Ÿn-?í|с¥÷Ú¹¬'´ÞÜ9ÓK `hê£SÄSà?7—Wí_´…óB›»:=Ãïq`<8ñÓŒÑlú2d¬ê³£hÖ[l|$vÝro~'R®‰§°ñmY ͧäP |PUª¹·:3Œ[Û{Xÿ ºâ@‚W–Äé u‚ ¯´*=íή.pûÒdt @G‰¬ s¸ ëÉücr ÞæÑ¨Ê@>¤¢Ö±. Þ'¯°ÌME[YéïĵÂCå½ Ué©Áû'Ê9%eÔðNU”ë‘ÌsD3/®+UI˜9h.WC”빓$#:pz:YÓ ¿xž* ³$Í +$kñAŠ‹†¢ Uê>¸)_š¬÷©ßAÂÔb9ÇU ¯¾á•9¯ÏÏ÷O÷¼¼Fähal1‰3Ì[Ïr•´UCksNÐ] R‘¸¥H+§Šé†c©vÖÞ0iÓ76s†î!§=ß ¼~Ô'°Ãmäoäš³ªøi1úÉ)³yV8 CLÄØÁ‘WYïi€H6ÖÑiámø^ÈY´°Ñ7¥Û*—Ñ©L«Qƒï—Ùrÿ ›£Ð*š¸ˆL©ˆ$ˆ ÷¾D§9È®«qbqC)–ˆïv´çñsÑVT­Ø, <àïºÀO«Jý·õ àfPìð .wFšir´þ’2_Y *Æ€x\« ì€9š@ Ž|F⇥ˆkZ@hÖÄ0t¿-<“‹qµ¾*ZL¤Ú)&BJpÓF5=$„at*Zš$’ÑtdûÝRI1 2މ$€$I$#‰SÞ’Hë¬ï;Á$¡t$’`<(ñÇt)$‡Ð.Êf¢X’Kt=Éé$‚ˆªè¢oÝëòI%Rgcª÷ŠyI%¡‰ÿ !ñ)´õ $¤ Ô’IIGÿÙ--- -- ASN.1 functions. -- -- Large chunks of this code have been ripped right out from snmp.lua. -- -- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html -- -- @author Patrik Karlsson -- @class module -- @name asn1 -- -- Version 0.3 -- Created 01/12/2010 - v0.1 - Created by Patrik Karlsson -- Revised 01/28/2010 - v0.2 - Adapted to create a framework for SNMP, LDAP and future protocols -- Revised 02/02/2010 - v0.3 - Changes: o Re-designed so that ASN1Encoder and ASN1Decoder are separate classes -- o Each script or library should now create its own Encoder and Decoder instance -- local math = require "math" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("asn1", stdnse.seeall) BERCLASS = { Universal = 0, Application = 64, ContextSpecific = 128, Private = 192 } --- The decoder class -- ASN1Decoder = { new = function(self,o) o = o or {} setmetatable(o, self) self.__index = self return o end, --- Tells the decoder to stop if it detects an error while decoding. -- -- This should probably be the default, but some scripts depend on being -- able to decode stuff while lacking proper ASN1 decoding functions. -- @name ASN1Decoder.setStopOnError -- @param val boolean, true if decoding should stop on error, -- otherwise false (default) setStopOnError = function(self, val) self.stoponerror = val end, --- Registers the base simple type decoders -- @name ASN1Decoder.registerBaseDecoders registerBaseDecoders = function(self) self.decoder = {} -- Boolean self.decoder["\x01"] = function( self, encStr, elen, pos ) local val = string.byte(encStr, pos) return val ~= 0, pos + 1 end -- Integer self.decoder["\x02"] = function( self, encStr, elen, pos ) return self.decodeInt(encStr, elen, pos) end -- Octet String self.decoder["\x04"] = function( self, encStr, elen, pos ) return string.unpack("c" .. elen, encStr, pos) end -- Null self.decoder["\x05"] = function( self, encStr, elen, pos ) return false, pos end -- Object Identifier self.decoder["\x06"] = function( self, encStr, elen, pos ) return self:decodeOID( encStr, elen, pos ) end -- Context specific tags -- self.decoder["\x30"] = function( self, encStr, elen, pos ) return self:decodeSeq(encStr, elen, pos) end end, --- Table for registering additional tag decoders. -- -- Each index is a tag number as a hex string. Values are ASN1 decoder -- functions. -- @name tagDecoders -- @class table -- @see asn1.decoder --- Template for an ASN1 decoder function. -- @name asn1.decoder -- @class function -- @param self The ASN1Decoder object -- @param encStr Encoded string -- @param elen Length of the object in bytes -- @param pos Current position in the string -- @return The decoded object -- @return The position after decoding --- Allows for registration of additional tag decoders -- @name ASN1Decoder.registerTagDecoders -- @param tagDecoders table containing decoding functions -- @see tagDecoders registerTagDecoders = function(self, tagDecoders) self:registerBaseDecoders() for k, v in pairs(tagDecoders) do self.decoder[k] = v end end, --- Decodes the ASN.1's built-in simple types -- @name ASN1Decoder.decode -- @param encStr Encoded string. -- @param pos Current position in the string. -- @return The decoded value(s). -- @return The position after decoding decode = function(self, encStr, pos) local etype, elen local newpos = pos etype, newpos = string.unpack("c1", encStr, newpos) elen, newpos = self.decodeLength(encStr, newpos) if self.decoder[etype] then return self.decoder[etype]( self, encStr, elen, newpos ) else stdnse.debug1("no decoder for etype: %s", stdnse.tohex(etype)) return nil, newpos end end, --- -- Decodes length part of encoded value according to ASN.1 basic encoding -- rules. -- @name ASN1Decoder.decodeLength -- @param encStr Encoded string. -- @param pos Current position in the string. -- @return The length of the following value. -- @return The position after decoding. decodeLength = function(encStr, pos) local elen, newpos = string.unpack('B', encStr, pos) if (elen > 128) then elen = elen - 128 local elenCalc = 0 local elenNext for i = 1, elen do elenCalc = elenCalc * 256 elenNext, newpos = string.unpack('B', encStr, newpos) elenCalc = elenCalc + elenNext end elen = elenCalc end return elen, newpos end, --- -- Decodes a sequence according to ASN.1 basic encoding rules. -- @name ASN1Decoder.decodeSeq -- @param encStr Encoded string. -- @param len Length of sequence in bytes. -- @param pos Current position in the string. -- @return The decoded sequence as a table. -- @return The position after decoding. decodeSeq = function(self, encStr, len, pos) local seq = {} local sPos = 1 local sStr, newpos = string.unpack("c" .. len, encStr, pos) while (sPos < len) do local newSeq newSeq, sPos = self:decode(sStr, sPos) if ( not(newSeq) and self.stoponerror ) then break end table.insert(seq, newSeq) end return seq, newpos end, -- Decode one component of an OID from a byte string. 7 bits of the component -- are stored in each octet, most significant first, with the eighth bit set in -- all octets but the last. These encoding rules come from -- http://luca.ntop.org/Teaching/Appunti/asn1.html, section 5.9 OBJECT -- IDENTIFIER. decode_oid_component = function(encStr, pos) local octet local n = 0 repeat octet, pos = string.unpack("B", encStr, pos) n = n * 128 + (0x7F & octet) until octet < 128 return n, pos end, --- Decodes an OID from a sequence of bytes. -- @name ASN1Decoder.decodeOID -- @param encStr Encoded string. -- @param len Length of sequence in bytes. -- @param pos Current position in the string. -- @return The OID as an array. -- @return The position after decoding. decodeOID = function(self, encStr, len, pos) local last local oid = {} local octet last = pos + len - 1 if pos <= last then oid._snmp = '\x06' octet, pos = string.unpack("B", encStr, pos) oid[2] = math.fmod(octet, 40) octet = octet - oid[2] oid[1] = octet//40 end while pos <= last do local c c, pos = self.decode_oid_component(encStr, pos) oid[#oid + 1] = c end return oid, pos end, --- -- Decodes an Integer according to ASN.1 basic encoding rules. -- @name ASN1Decoder.decodeInt -- @param encStr Encoded string. -- @param len Length of integer in bytes. -- @param pos Current position in the string. -- @return The decoded integer. -- @return The position after decoding. decodeInt = function(encStr, len, pos) if len > 16 then stdnse.debug2("asn1: Unable to decode %d-byte integer at %d", len, pos) return nil, pos end return string.unpack(">i" .. len, encStr, pos) end, } --- The encoder class -- ASN1Encoder = { new = function(self) local o = {} setmetatable(o, self) self.__index = self o:registerBaseEncoders() return o end, --- -- Encodes an ASN1 sequence -- @name ASN1Encoder.encodeSeq -- @param seqData A string of sequence data -- @return ASN.1 BER-encoded sequence encodeSeq = function(self, seqData) -- 0x30 = 00110000 = 00 1 10000 -- hex binary Universal Constructed value Data Type = SEQUENCE (16) return "\x30" .. self.encodeLength(#seqData) .. seqData end, --- -- Encodes a given value according to ASN.1 basic encoding rules for SNMP -- packet creation. -- @name ASN1Encoder.encode -- @param val Value to be encoded. -- @return Encoded value. encode = function(self, val) local vtype = type(val) if self.encoder[vtype] then return self.encoder[vtype](self,val) else return nil end return '' end, --- Table for registering additional tag encoders. -- -- Each index is a lua type as a string. Values are ASN1 encoder -- functions. -- @name tagEncoders -- @class table -- @see asn1.encoder --- Template for an ASN1 encoder function. -- @name asn1.encoder -- @param self The ASN1Encoder object -- @param val The value to encode -- @return The encoded object -- @class function --- Allows for registration of additional tag encoders -- @name ASN1Decoder.registerTagEncoders -- @param tagEncoders table containing encoding functions -- @see tagEncoders registerTagEncoders = function(self, tagEncoders) self:registerBaseEncoders() for k, v in pairs(tagEncoders) do self.encoder[k] = v end end, --- Registers the base ASN.1 Simple types encoders -- -- * boolean -- * integer (Lua number) -- * string -- * null (Lua nil) -- @name ASN1Encoder.registerBaseEncoders registerBaseEncoders = function(self) self.encoder = {} -- Boolean encoder self.encoder['boolean'] = function( self, val ) if val then return '\x01\x01\xFF' else return '\x01\x01\x00' end end -- Table encoder self.encoder['table'] = function( self, val ) assert('table' == type(val), "val is not a table") assert(#val.type > 0, "Table is missing the type field") assert(val.value ~= nil, "Table is missing the value field") return stdnse.fromhex(val.type) .. self.encodeLength(#val.value) .. val.value end -- Integer encoder self.encoder['number'] = function( self, val ) local ival = self.encodeInt(val) local len = self.encodeLength(#ival) return "\x02" .. len .. ival end -- Octet String encoder self.encoder['string'] = function( self, val ) local len = self.encodeLength(#val) return "\x04" .. len .. val end -- Null encoder self.encoder['nil'] = function( self, val ) return '\x05\x00' end end, -- Encode one component of an OID as a byte string. 7 bits of the component are -- stored in each octet, most significant first, with the eighth bit set in all -- octets but the last. These encoding rules come from -- http://luca.ntop.org/Teaching/Appunti/asn1.html, section 5.9 OBJECT -- IDENTIFIER. encode_oid_component = function(n) local parts = {} parts[1] = string.char(n % 128) while n >= 128 do n = n >> 7 parts[#parts + 1] = string.char(n % 128 + 0x80) end return string.reverse(table.concat(parts)) end, --- -- Encodes an Integer according to ASN.1 basic encoding rules. -- @name ASN1Encoder.encodeInt -- @param val Value to be encoded. -- @return Encoded integer. encodeInt = function(val) local lsb = 0 if val > 0 then local valStr = "" while (val > 0) do lsb = math.fmod(val, 256) valStr = valStr .. string.pack("B", lsb) val = math.floor(val/256) end if lsb > 127 then -- two's complement collision valStr = valStr .. "\0" end return string.reverse(valStr) elseif val < 0 then local i = 1 local tcval = val + 256 -- two's complement while tcval <= 127 do tcval = tcval + 256^i * 255 i = i+1 end local valStr = "" while (tcval > 0) do lsb = math.fmod(tcval, 256) valStr = valStr .. string.pack("B", lsb) tcval = math.floor(tcval/256) end return string.reverse(valStr) else -- val == 0 return '\0' end end, --- -- Encodes the length part of a ASN.1 encoding triplet using the "primitive, -- definite-length" method. -- @name ASN1Encoder.encodeLength -- @param len Length to be encoded. -- @return Encoded length value. encodeLength = function(len) if len < 128 then return string.char(len) else local parts = {} while len > 0 do parts[#parts + 1] = string.char(len % 256) len = len >> 8 end assert(#parts < 128) return string.char(#parts + 0x80) .. string.reverse(table.concat(parts)) end end } --- Converts a BER encoded type to a numeric value -- -- This allows it to be used in the encoding function -- -- @param class number - see BERCLASS -- @param constructed boolean (true if constructed, false if primitive) -- @param number numeric -- @return number to be used with encode function BERtoInt(class, constructed, number) local asn1_type = class + number if constructed == true then asn1_type = asn1_type + 32 end return asn1_type end --- -- Converts an integer to a BER encoded type table -- -- @param i number containing the value to decode -- @return table with the following entries: -- * class -- * constructed -- * primitive -- * number function intToBER( i ) local ber = {} if i & BERCLASS.Application == BERCLASS.Application then ber.class = BERCLASS.Application elseif i & BERCLASS.ContextSpecific == BERCLASS.ContextSpecific then ber.class = BERCLASS.ContextSpecific elseif i & BERCLASS.Private == BERCLASS.Private then ber.class = BERCLASS.Private else ber.class = BERCLASS.Universal end if i & 32 == 32 then ber.constructed = true ber.number = i - ber.class - 32 else ber.primitive = true ber.number = i - ber.class end return ber end local unittest = require 'unittest' if not unittest.testing() then return _ENV end test_suite = unittest.TestSuite:new() do local decode_tests = { {unittest.is_false, "\x01\x01\x00", nil, "decode false"}, {unittest.is_true, "\x01\x01\x01", nil, "decode true"}, {unittest.is_true, "\x01\x01\xff", nil, "decode true (not 1)"}, {unittest.equal, "\x02\x01\x01", 1, "decode integer"}, {unittest.equal, "\x02\x02\xff\xff", -1, "decode negative integer"}, {unittest.equal, "\x02\x03\x01\x00\x02", 65538, "decode integer"}, {unittest.equal, "\x04\x04nmap", "nmap", "decode octet string"}, {unittest.is_false, "\x05\x00", nil, "decode null as false"}, {unittest.identical, "\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x09\x04\x31", {1, 2, 840, 113549, 1, 9, 4, _snmp="\x06"}, "decode OID" }, {unittest.identical, "\x30\x09\x02\x01\x01\x02\x01\xff\x02\x01\x42", {1, -1, 0x42}, "decode sequence" }, } local test_decoder = ASN1Decoder:new() test_decoder:registerBaseDecoders() for _, test in ipairs(decode_tests) do test_suite:add_test(test[1](test_decoder:decode(test[2], 1), test[3]), test[4]) end end return _ENV;