Skip to content

Commit 44dd45e

Browse files
committed
Use a const instead of hardcoding "tcp" everywhere
1 parent 76bfaa6 commit 44dd45e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/msf/core/db_manager.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
class Msf::DBManager
2424
extend Metasploit::Framework::Require
2525

26+
# Default proto for making new `Mdm::Service`s. This should probably be a
27+
# const on `Mdm::Service`
28+
DEFAULT_SERVICE_PROTO = "tcp"
29+
2630
autoload :Adapter, 'msf/core/db_manager/adapter'
2731
autoload :Client, 'msf/core/db_manager/client'
2832
autoload :Connection, 'msf/core/db_manager/connection'

lib/msf/core/db_manager/exploit_attempt.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def report_exploit_failure(opts)
3838

3939
wspace = opts[:workspace] || workspace
4040
port = opts[:port]
41-
prot = opts[:proto] || "tcp"
41+
prot = opts[:proto] || Msf::DBManager::DEFAULT_SERVICE_PROTO
4242
svc = opts[:service]
4343

4444
# Look up the service as appropriate
@@ -75,14 +75,14 @@ def report_exploit_success(opts)
7575

7676
wspace = opts[:workspace] || workspace
7777
port = opts[:port]
78-
prot = opts[:proto] || "tcp"
78+
prot = opts[:proto] || Msf::DBManager::DEFAULT_SERVICE_PROTO
7979
svc = opts[:service]
8080

8181
# Look up or generate the service as appropriate
8282
if port and svc.nil?
8383
# it is rude to modify arguments in place
8484
opts = opts.dup
85-
opts[:proto] ||= "tcp"
85+
opts[:proto] ||= Msf::DBManager::DEFAULT_SERVICE_PROTO
8686
opts[:service] = report_service(
8787
workspace: wspace, host: host, port: port, proto: prot
8888
)
@@ -168,7 +168,7 @@ def do_report_failure_or_success(opts)
168168

169169
if port and svc.nil?
170170
attempt_info[:port] = port
171-
attempt_info[:proto] = prot || "tcp"
171+
attempt_info[:proto] = prot || Msf::DBManager::DEFAULT_SERVICE_PROTO
172172
end
173173

174174
host.exploit_attempts.create(attempt_info)

lib/msf/core/db_manager/service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def report_service(opts)
8585
end
8686
=end
8787

88-
proto = opts[:proto] || 'tcp'
88+
proto = opts[:proto] || Msf::DBManager::DEFAULT_SERVICE_PROTO
8989

9090
service = host.services.where(port: opts[:port].to_i, proto: proto).first_or_initialize
9191
opts.each { |k,v|
@@ -126,4 +126,4 @@ def services(wspace = workspace, only_up = false, proto = nil, addresses = nil,
126126
wspace.services.includes(:host).where(conditions).order("hosts.address, port")
127127
}
128128
end
129-
end
129+
end

0 commit comments

Comments
 (0)