Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/drda/utils.rb
Views: 11702
# -*- coding: binary -*-123module Rex4module Proto5module DRDA6class Utils78# Creates a packet with EXCSAT_DDM and an ACCSEC_DDM. This will elicit9# a response from the target server.10def self.client_probe(dbname=nil)11pkt = [12Rex::Proto::DRDA::Packet::EXCSAT_DDM.new,13Rex::Proto::DRDA::Packet::ACCSEC_DDM.new(:dbname => dbname)14]15pkt.map {|x| x.to_s}.join16end1718# Creates a packet with EXCSAT_DDM and an SECCHK_DDM.19# In order to ever succeed, you do need a successful probe first.20def self.client_auth(args={})21dbname = args[:dbname]22dbuser = args[:dbuser]23dbpass = args[:dbpass]24pkt = [25Rex::Proto::DRDA::Packet::ACCSEC_DDM.new(:format => 0x41),26Rex::Proto::DRDA::Packet::SECCHK_DDM.new(:dbname => dbname, :dbuser => dbuser, :dbpass => dbpass)27]28pkt.map {|x| x.to_s}.join29end3031def self.server_packet_info(obj)32info_hash = {}33return info_hash unless obj.kind_of? Rex::Proto::DRDA::Packet::SERVER_PACKET34obj.each do |ddm|35case ddm.codepoint36when Constants::EXCSATRD37info_hash.merge!(_info_excsatrd(ddm))38when Constants::ACCSECRD39info_hash.merge!(_info_accsecrd(ddm))40when Constants::RDBNFNRM41info_hash.merge!(_info_rdbnfnrm(ddm))42when Constants::SECCHKRM43info_hash.merge!(_info_secchkrm(ddm))44else45next46end47end48return info_hash49end5051def self._info_excsatrd(ddm)52info_hash = {:excsatrd => true}53ddm.payload.each do |param|54case param.codepoint55when Constants::SRVNAM56info_hash[:instance_name] = Rex::Text.from_ebcdic(param.payload)57when Constants::SRVCLSNM58info_hash[:platform] = Rex::Text.from_ebcdic(param.payload)59when Constants::SRVRLSLV60info_hash[:version] = Rex::Text.from_ebcdic(param.payload)61else62next63end64end65return info_hash66end6768def self._info_accsecrd(ddm)69info_hash = {:accsecrd => true}70ddm.payload.each do |param|71case param.codepoint72when Constants::SECMEC73info_hash[:plaintext_auth] = true if param.payload =~ /\x00\x03/n74when Constants::SECCHKCD75info_hash[:security_check_code] = param.payload.unpack("C").first76# A little spurious? This is always nonzero when there's no SECCHKRM DDM.77info_hash[:db_login_success] = false unless info_hash[:security_check_code].zero?78else79next80end81end82return info_hash83end8485def self._info_rdbnfnrm(ddm)86info_hash = {:rdbnfnrm => true}87info_hash[:database_found] = false88ddm.payload.each do |param|89case param.codepoint90when Constants::RDBNAM91info_hash[:db_name] = Rex::Text.from_ebcdic(param.payload).unpack("A*").first92when Constants::SRVDGN93info_hash[:error_message] = Rex::Text.from_ebcdic(param.payload)94else95next96end97end98return info_hash99end100101def self._info_secchkrm(ddm)102info_hash = {:secchkrm => true}103ddm.payload.each do |param|104case param.codepoint105when Constants::SRVCOD106info_hash[:severity_code] = param.payload.unpack("n").first107when Constants::SECCHKCD108info_hash[:security_check_code] = param.payload.unpack("C").first109else110next111end112end113if info_hash[:severity_code].to_i.zero? and info_hash[:security_check_code].to_i.zero?114info_hash[:db_login_success] = true115end116return info_hash117end118119end120121end122end123end124125126