Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeitwerk msf folder #14629

Merged
merged 13 commits into from
Jan 22, 2021
2 changes: 0 additions & 2 deletions lib/metasploit/framework/command/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def start
# @return [Msf::Ui::Console::Driver]
def driver
unless @driver
# require here so minimum loading is done before {start} is called.
require 'msf/ui'

@driver = Msf::Ui::Console::Driver.new(
Msf::Ui::Console::Driver::DefaultPrompt,
Expand Down
1 change: 0 additions & 1 deletion lib/metasploit/framework/compiler/mingw.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'msf/util/helper'
require 'open3'

module Metasploit
Expand Down
12 changes: 12 additions & 0 deletions lib/msf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
require 'rex/proto/ntlm'
require 'rex/arch'
include Rex::Arch

NTLM_CONST ||= ::Rex::Proto::NTLM::Constants
NTLM_CRYPT ||= ::Rex::Proto::NTLM::Crypt
NTLM_UTILS ||= ::Rex::Proto::NTLM::Utils
NTLM_BASE ||= ::Rex::Proto::NTLM::Base
NTLM_MESSAGE ||= ::Rex::Proto::NTLM::Message

module Msf

LogSource = "core"
end

require 'msf/core/exception' # TODO: temporary require until we can split up the exceptions file and namespace properly
require 'msf_autoload'
8 changes: 3 additions & 5 deletions lib/msf/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: binary -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity question, is this needed still?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't be, it only seems to affect any strings defined in the file and there aren't any 😄
weren't any before so it was probably a copy/paste job

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my understanding too, just calling it out for visibility - as there seemed to be a couple of historical bulk changes to add this to every file:
d656e31

I imagine there was a solid reason for it that, but the commit doesn't have any further details. It could've just been the easiest to automate, adding any missing binary comment regardless of the file's content


# Utilities
require 'msf/util'

# This file is only needed for compatibility with pro
# Once pro removes the explicit require this file can be deleted
require 'msf'
13 changes: 13 additions & 0 deletions lib/msf/base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# framework-base

The base library provides implementations for some of the default
sessions, such as Shell, Meterpreter, DispatchNinja, and VNC. These
sessions are used by modules that come pre-packaged with the default
module distribution of Metasploit and are depended on by their
respective payloads.

Beyond providing the default sessions, framework-base also provides
a wrapper interface to framework-core that makes some of the tasks,
such as exploitation, into easier to manage functions.

framework-base depends on framework-core
1 change: 0 additions & 1 deletion lib/msf/base/logging.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: binary -*-
require 'rex'
require 'msf/core'
module Msf

# This module provides an initialization interface for logging.
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/base/sessions/command_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'shellwords'
require 'rex/text/table'
require "base64"

require 'rex/parser/arguments'
module Msf
module Sessions

Expand Down
1 change: 0 additions & 1 deletion lib/msf/base/sessions/meterpreter_python.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: binary -*-

require 'msf/windows_error'

module Msf
module Sessions
Expand Down
1 change: 0 additions & 1 deletion lib/msf/base/sessions/meterpreter_x64_win.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: binary -*-

require 'msf/windows_error'

module Msf
module Sessions
Expand Down
1 change: 0 additions & 1 deletion lib/msf/base/sessions/meterpreter_x86_win.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: binary -*-

require 'msf/windows_error'

module Msf
module Sessions
Expand Down
44 changes: 3 additions & 41 deletions lib/msf/core.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
# -*- coding: binary -*-
###
#
# framework-core
# --------------
#
# The core library provides all of the means by which to interact
# with the framework insofar as manipulating encoders, nops,
# payloads, exploits, auxiliary, and sessions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments have been useful in the past, does it make sense to move it elsewhere? 🤔

Since we plan on deleting this file - I'm not sure where it would live within our code. I've seen some projects have readme.md files in directories of interest, which act as a bread crumb trail as to what the folders are meant to do at the conceptual level. I don't believe having it in the wiki is the right solution either, as the documentation being colocated with the folder will be naturally found when code spelunking

This comment applies to the previously deleted base.rb comments too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't see a tonne of value in these comments but I'd definitely be down for the readme idea if we can keep it up to date

#
###

# The framework-core depends on Rex
require 'rex'
require 'rex/ui'
require 'rex/arch'

include Rex::Arch

NTLM_CONST ||= ::Rex::Proto::NTLM::Constants
NTLM_CRYPT ||= ::Rex::Proto::NTLM::Crypt
NTLM_UTILS ||= ::Rex::Proto::NTLM::Utils
NTLM_BASE ||= ::Rex::Proto::NTLM::Base
NTLM_MESSAGE ||= ::Rex::Proto::NTLM::Message

module Msf
autoload :Author, 'msf/core/author'
autoload :Platform, 'msf/core/platform'
autoload :Reference, 'msf/core/reference'
autoload :SiteReference, 'msf/core/site_reference'
autoload :Target, 'msf/core/target'

#
# Constants
#

LogSource = "core"
end

# Event subscriber interfaces
require 'msf/events'
# This file is only needed for compatibility with pro
# Once pro removes the explicit require this file can be deleted
require 'msf'
6 changes: 6 additions & 0 deletions lib/msf/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# framework-core

The core library provides all of the means by which to interact
with the framework insofar as manipulating encoders, nops,
payloads, exploits, auxiliary, and sessions.
4 changes: 2 additions & 2 deletions lib/msf/core/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#

require 'metasploit/framework/version'
require 'msf/util'
require 'msf/events'
require 'rex/socket/ssl'
require 'metasploit/framework/thread_factory_provider'
require 'rex/job_container'
require 'rex/thread_factory'
module Msf

###
Expand Down
1 change: 0 additions & 1 deletion lib/msf/core/modules/metadata/cache.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'singleton'
require 'msf/events'
require 'rex/ui/text/output/stdio'
#
# Core service class that provides storage of module metadata as well as operations on the metadata.
Expand Down
2 changes: 1 addition & 1 deletion lib/msf/core/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Msf
###
class Payload < Msf::Module

require 'rex/payloads'
require 'rex/payloads/win32'

# Platform specific includes
require 'metasploit/framework/compiler/mingw'
Expand Down
1 change: 0 additions & 1 deletion lib/msf/core/post/windows/cli_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Windows

module CliParse

require 'msf/windows_error'
require 'rex/logging'
require 'rex/exceptions'

Expand Down
2 changes: 2 additions & 0 deletions lib/msf/core/reflective_dll_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
###

require 'rex/peparsey'

module Msf::ReflectiveDLLLoader

# This is the ordinal of the reflective loader by default
Expand Down
1 change: 0 additions & 1 deletion lib/msf/core/rpc/v10/rpc_console.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: binary -*-
require 'pp'
require 'rex'
require 'msf/ui/web/driver'

module Msf
module RPC
Expand Down
1 change: 0 additions & 1 deletion lib/msf/core/rpc/v10/rpc_module.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: binary -*-

require 'json'
require 'msf/util/document_generator'

module Msf
module RPC
Expand Down
15 changes: 0 additions & 15 deletions lib/msf/scripts/meterpreter.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/msf/scripts/meterpreter/accounts.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/msf/scripts/meterpreter/common.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/msf/scripts/meterpreter/file.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/msf/scripts/meterpreter/registry.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/msf/scripts/meterpreter/services.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/msf/ui.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/msf/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ module Console
end
end

require 'msf/ui/console/driver'
9 changes: 3 additions & 6 deletions lib/msf/ui/console/command_dispatcher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: binary -*-
require 'msf/ui/console/command_dispatcher/common'

require 'rex/ui'

module Msf
module Ui
module Console
Expand Down Expand Up @@ -133,8 +135,3 @@ def remove_lines(text, to_match)

end
end end end

require 'msf/ui/console/module_action_commands'
require 'msf/ui/console/module_command_dispatcher'
require 'msf/ui/console/module_option_tab_completion'
require 'msf/ui/console/command_dispatcher/core'
12 changes: 0 additions & 12 deletions lib/msf/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
# Project
#

require 'msf/ui/console/command_dispatcher/encoder'
require 'msf/ui/console/command_dispatcher/exploit'
require 'msf/ui/console/command_dispatcher/nop'
require 'msf/ui/console/command_dispatcher/payload'
require 'msf/ui/console/command_dispatcher/auxiliary'
require 'msf/ui/console/command_dispatcher/post'
require 'msf/ui/console/command_dispatcher/evasion'
require 'msf/ui/console/command_dispatcher/jobs'
require 'msf/ui/console/command_dispatcher/resource'
require 'msf/ui/console/command_dispatcher/modules'
require 'msf/ui/console/command_dispatcher/developer'
require 'msf/util/document_generator'

require 'msf/core/opt_condition'

Expand Down
1 change: 0 additions & 1 deletion lib/msf/ui/console/command_dispatcher/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'json'
require 'rexml/document'
require 'rex/parser/nmap_xml'
require 'msf/ui/console/command_dispatcher/db/analyze'
require 'metasploit/framework/data_service'
require 'metasploit/framework/data_service/remote/http/core'

Expand Down
5 changes: 1 addition & 4 deletions lib/msf/ui/console/command_dispatcher/modules.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# -*- coding: binary -*-

require 'rex/ui/text/output/buffer/stdout'
require 'msf/ui/console/table_print/rank_styler'
require 'msf/ui/console/table_print/rank_formatter'
require 'msf/ui/console/table_print/highlight_substring_styler'

require 'rex/parser/arguments'

module Msf
module Ui
Expand Down
1 change: 0 additions & 1 deletion lib/msf/ui/console/command_dispatcher/payload.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: binary -*-

require 'rex/parser/arguments'
require 'msf/util/exe'

module Msf
module Ui
Expand Down
6 changes: 0 additions & 6 deletions lib/msf/ui/console/driver.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# -*- coding: binary -*-
require 'msf/ui'
require 'msf/ui/console/framework_event_manager'
require 'msf/ui/console/command_dispatcher'
require 'msf/ui/console/command_dispatcher/db'
require 'msf/ui/console/command_dispatcher/creds'
require 'msf/ui/console/table'
require 'find'
require 'erb'
require 'rexml/document'
Expand Down
1 change: 0 additions & 1 deletion lib/msf/ui/console/module_command_dispatcher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: binary -*-
require 'msf/ui/console/command_dispatcher'
require 'rex/parser/arguments'

module Msf
Expand Down