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/metasploit/framework/ntds/parser.rb
Views: 11784
module Metasploit1module Framework2module NTDS3require 'metasploit/framework/ntds/account'4# This class represent an NTDS parser. It interacts with the Meterpreter Client5# to provide a simple interface for enumerating AD user accounts.6class Parser78# The size, in Bytes, of a batch of NTDS accounts9BATCH_SIZE = (Metasploit::Framework::NTDS::Account::ACCOUNT_SIZE * 20)1011#@return [Rex::Post::Meterpreter::Channels::Pool] The Meterpreter NTDS Parser Channel12attr_accessor :channel13#@return [Msf::Session] The Meterpreter Client14attr_accessor :client15#@return [String] The path to the NTDS.dit file on the remote system16attr_accessor :file_path1718def initialize(client, file_path='')19raise ArgumentError, "Invalid Filepath" unless file_path.present?20@file_path = file_path21@channel = client.extapi.ntds.parse(file_path)22@client = client23end2425# Yields a [Metasploit::Framework::NTDS::Account] for each account found26# in the remote NTDS.dit file.27#28# @yield [account]29# @yieldparam account [Metasploit::Framework::NTDS::Account] an AD user account30# @yieldreturn [void] does not return a value31def each_account32raw_batch_data = pull_batch33until raw_batch_data.nil?34batch = raw_batch_data.dup35while batch.present?36raw_data = batch.slice!(0,Metasploit::Framework::NTDS::Account::ACCOUNT_SIZE)37# Make sure our data isn't all Null-bytes38if raw_data.match(/[^\x00]/)39account = Metasploit::Framework::NTDS::Account.new(raw_data)40yield account41end42end43raw_batch_data = pull_batch44end45channel.close46end4748private4950def pull_batch51if channel.cid.nil?52dlog("NTDS Parser Channel was closed, reopening")53reopen_channel54end55begin56raw_batch_data = channel.read(BATCH_SIZE)57rescue EOFError => e58elog('NTDS Parser: Error pulling batch', error: e)59raw_batch_data = nil60end61raw_batch_data62end6364def reopen_channel65@channel = client.extapi.ntds.parse(file_path)66end6768end69end70end71end727374