--- -- A minimal RDP (Remote Desktop Protocol) library. Currently has functionality to determine encryption -- and cipher support. -- -- -- @author "Patrik Karlsson " -- @copyright Same as Nmap--See http://nmap.org/book/man-legal.html -- local bin = require("bin") local nmap = require("nmap") local stdnse = require("stdnse") _ENV = stdnse.module("rdp", stdnse.seeall) Packet = { TPKT = { new = function(self, data) local o = { data = tostring(data), version = 3 } setmetatable(o, self) self.__index = self return o end, __tostring = function(self) return bin.pack(">CCSA", self.version, self.reserved or 0, (self.data and #self.data + 4 or 4), self.data ) end, parse = function(data) local tpkt = Packet.TPKT:new() local pos pos, tpkt.version, tpkt.reserved, tpkt.length = bin.unpack(">CCS", data) pos, tpkt.data = bin.unpack("A" .. (#data - pos), data, pos) return tpkt end }, ITUT = { new = function(self, code, data) local o = { data = tostring(data), code = code } setmetatable(o, self) self.__index = self return o end, parse = function(data) local itut = Packet.ITUT:new() local pos pos, itut.length, itut.code = bin.unpack("CC", data) if ( itut.code == 0xF0 ) then pos, itut.eot = bin.unpack("C", data, pos) elseif ( itut.code == 0xD0 ) then pos, itut.dstref, itut.srcref, itut.class = bin.unpack(">SSC", data, pos) end pos, itut.data = bin.unpack("A" .. (#data - pos), data, pos) return itut end, __tostring = function(self) local len = (self.code ~= 0xF0 and #self.data + 1 or 2) local data = bin.pack("CC", len, self.code or 0 ) if ( self.code == 0xF0 ) then data = data .. bin.pack("C", 0x80) -- EOT end return data .. self.data end, }, } Request = { ConnectionRequest = { new = function(self, proto) local o = { proto = proto } setmetatable(o, self) self.__index = self return o end, __tostring = function(self) local cookie = "mstshash=nmap" local itpkt_len = 21 + #cookie local itut_len = 16 + #cookie local data = bin.pack(">SSCA", 0x0000, -- dst reference 0x0000, -- src reference 0x00, -- class and options ("Cookie: %s\r\n"):format(cookie)) if ( self.proto ) then data = data .. bin.pack("