/
githubmirror
/
metasploit-framework
Обзор
Документация
Войти
/
githubmirror
/
metasploit-framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/metasploit/framework/spec/threads/logger.rb
47 строк
1 KB
adfoster-r7
Add additional import tests
11 июн 2026, 00:17
11 июн 2026, 00:17
cf67b7f
Код
Авторство
О чём код?
# # Standard Library # require 'securerandom' # # Project # require 'metasploit/framework/spec/threads/suite' # Guard against double-patching if loaded via both RUBYOPT and spec_helper unless Thread.respond_to?(:_metasploit_thread_logger_enabled) original_thread_new = Thread.method(:new) # Patches `Thread.new` so that if logs `caller` so thread leaks can be traced Thread.define_singleton_method(:new) { |*args, &block| uuid = SecureRandom.uuid # tag caller with uuid so that only leaked threads caller needs to be printed lines = ["BEGIN Thread.new caller (#{uuid})"] caller.each do |frame| lines << " #{frame}" end lines << 'END Thread.new caller' Metasploit::Framework::Spec::Threads::Suite::LOG_PATHNAME.parent.mkpath Metasploit::Framework::Spec::Threads::Suite::LOG_PATHNAME.open('a') { |f| # single puts so threads can't write in between each other. f.puts lines.join("\n") } options = {original_args: args, uuid: uuid} original_thread_new.call(options) { # record uuid for thread-leak detection can used uuid to correlate log with this thread. Thread.current[Metasploit::Framework::Spec::Threads::Suite::UUID_THREAD_LOCAL_VARIABLE] = options.fetch(:uuid) block.call(*options.fetch(:original_args)) } } # Marker method to indicate the logger patch has been applied Thread.define_singleton_method(:_metasploit_thread_logger_enabled) { true } end