Skip to content

Commit 219f9d5

Browse files
committed
updating parts of cisco to use creds
1 parent 4024066 commit 219f9d5

File tree

2 files changed

+140
-68
lines changed

2 files changed

+140
-68
lines changed

lib/msf/core/auxiliary/cisco.rb

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,54 @@ def cisco_ios_decrypt7(inp)
3232
end
3333
clear
3434
end
35+
36+
def create_credential_and_login(opts={})
37+
return nil unless active_db?
3538

36-
def cisco_ios_config_eater(thost, tport, config)
39+
if self.respond_to?(:[]) and self[:task]
40+
opts[:task_id] ||= self[:task].record.id
41+
end
42+
43+
core = opts.fetch(:core, create_credential(opts))
44+
access_level = opts.fetch(:access_level, nil)
45+
last_attempted_at = opts.fetch(:last_attempted_at, nil)
46+
status = opts.fetch(:status, Metasploit::Model::Login::Status::UNTRIED)
47+
48+
login_object = nil
49+
retry_transaction do
50+
service_object = create_credential_service(opts)
51+
login_object = Metasploit::Credential::Login.where(core_id: core.id, service_id: service_object.id).first_or_initialize
52+
53+
if opts[:task_id]
54+
login_object.tasks << Mdm::Task.find(opts[:task_id])
55+
end
56+
57+
login_object.access_level = access_level if access_level
58+
login_object.last_attempted_at = last_attempted_at if last_attempted_at
59+
if status == Metasploit::Model::Login::Status::UNTRIED
60+
if login_object.last_attempted_at.nil?
61+
login_object.status = status
62+
end
63+
else
64+
login_object.status = status
65+
end
66+
login_object.save!
67+
end
68+
69+
login_object
70+
end
71+
3772

38-
#
39-
# Create a template hash for cred reporting
40-
#
41-
# cred_info = {
42-
# :host => thost,
43-
# :port => tport,
44-
# :user => "",
45-
# :pass => "",
46-
# :type => "",
47-
# :collect_type => "",
48-
# :active => true
49-
# }
73+
def cisco_ios_config_eater(thost, tport, config)
5074

5175
credential_data = {
5276
address: thost,
5377
port: tport,
5478
protocol: 'tcp',
5579
workspace_id: myworkspace_id,
56-
5780
origin_type: :service,
5881
module_fullname: self.fullname,
82+
status: Metasploit::Model::Login::Status::UNTRIED
5983
}
6084

6185
# Default SNMP to UDP
@@ -87,8 +111,8 @@ def cisco_ios_config_eater(thost, tport, config)
87111

88112
cred = credential_data.dup
89113
cred[:private_data] = shash
90-
cred[:private_type] = :password_hash
91-
create_credential(cred)
114+
cred[:private_type] = :password
115+
create_credential_and_login(cred)
92116

93117
end
94118

@@ -100,7 +124,7 @@ def cisco_ios_config_eater(thost, tport, config)
100124
cred = credential_data.dup
101125
cred[:private_data] = shash
102126
cred[:private_type] = :password
103-
create_credential(cred)
127+
create_credential_and_login(cred)
104128
end
105129

106130
when /^\s*enable password (.*)/i
@@ -110,7 +134,7 @@ def cisco_ios_config_eater(thost, tport, config)
110134
cred = credential_data.dup
111135
cred[:private_data] = spass
112136
cred[:private_type] = :password
113-
create_credential(cred)
137+
create_credential_and_login(cred)
114138

115139
#
116140
# SNMP
@@ -120,21 +144,17 @@ def cisco_ios_config_eater(thost, tport, config)
120144
scomm = $1.strip
121145
print_good("#{thost}:#{tport} SNMP Community (#{stype}): #{scomm}")
122146

147+
cred = credential_data.dup
123148
if stype.downcase == "ro"
124-
ptype = "password_ro"
149+
cred[:access_level] = "RO"
125150
else
126-
ptype = "password"
151+
cred[:access_level] = "RW"
127152
end
128-
129-
cred = cred_info.dup
130-
cred[:sname] = "snmp"
131-
cred[:pass] = scomm
132-
cred[:type] = ptype
133-
cred[:collect_type] = ptype
134-
cred[:proto] = "udp"
135-
cred[:port] = 161
136-
store_cred(cred)
137-
153+
cred[:protocol] = "udp"
154+
cred[:port] = 161
155+
cred[:private_data] = scomm
156+
cred[:private_type] = :password
157+
create_credential_and_login(cred)
138158
#
139159
# VTY Passwords
140160
#

spec/lib/msf/core/auxiliary/cisco_spec.rb

Lines changed: 90 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,82 @@ def framework
1313
'DeferModuleLoads' => true
1414
)
1515
end
16+
def active_db?
17+
true
18+
end
1619
def print_good(str=nil)
1720
raise StandardError.new("This method needs to be stubbed.")
1821
end
1922
def store_cred(hsh=nil)
2023
raise StandardError.new("This method needs to be stubbed.")
2124
end
2225
def fullname
23-
"Dummy Class / Dummy Ref"
26+
"auxiliary/scanner/snmp/cisco_dummy"
2427
end
2528
end
2629

2730
subject(:aux_cisco) { DummyClass.new }
2831

32+
context '#create_credential_and_login' do
33+
34+
let(:session) { FactoryGirl.create(:mdm_session) }
35+
36+
let(:task) { FactoryGirl.create(:mdm_task, workspace: workspace)}
37+
38+
let(:user) { FactoryGirl.create(:mdm_user)}
39+
40+
let(:workspace) { FactoryGirl.create(:mdm_workspace) }
41+
42+
subject(:test_object) { DummyClass.new }
43+
44+
let(:workspace) { FactoryGirl.create(:mdm_workspace) }
45+
let(:service) { FactoryGirl.create(:mdm_service, host: FactoryGirl.create(:mdm_host, workspace: workspace)) }
46+
let(:task) { FactoryGirl.create(:mdm_task, workspace: workspace) }
47+
48+
let(:login_data) {
49+
{
50+
address: service.host.address,
51+
port: service.port,
52+
service_name: service.name,
53+
protocol: service.proto,
54+
workspace_id: workspace.id,
55+
origin_type: :service,
56+
module_fullname: 'auxiliary/scanner/smb/smb_login',
57+
realm_key: 'Active Directory Domain',
58+
realm_value: 'contosso',
59+
username: 'Username',
60+
private_data: 'password',
61+
private_type: :password,
62+
status: Metasploit::Model::Login::Status::UNTRIED
63+
}
64+
}
65+
it 'creates a Metasploit::Credential::Login' do
66+
expect{test_object.create_credential_and_login(login_data)}.to change{Metasploit::Credential::Login.count}.by(1)
67+
end
68+
it "associates the Metasploit::Credential::Core with a task if passed" do
69+
login = test_object.create_credential_and_login(login_data.merge(task_id: task.id))
70+
expect(login.tasks).to include(task)
71+
end
72+
end
73+
2974
context '#cisco_ios_config_eater' do
3075

3176
it 'deals with udp ports' do
3277
expect(aux_cisco).to receive(:print_good).with('127.0.0.1:161 Unencrypted Enable Password: 1511021F0725')
3378
expect(aux_cisco).to receive(:store_loot).with(
3479
"cisco.ios.config", "text/plain", "127.0.0.1", "enable password 1511021F0725", "config.txt", "Cisco IOS Configuration"
3580
)
36-
expect(aux_cisco).to receive(:store_cred).with(
81+
expect(aux_cisco).to receive(:create_credential_and_login).with(
3782
{
38-
host: "127.0.0.1",
83+
address: "127.0.0.1",
3984
port: 161,
40-
user: "",
41-
pass: "1511021F0725",
42-
type: "password",
43-
collect_type: "password",
44-
active: true,
45-
proto: 'udp'
85+
protocol: "udp",
86+
workspace_id: nil,
87+
origin_type: :service,
88+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
89+
private_data: "1511021F0725",
90+
private_type: :password,
91+
status: Metasploit::Model::Login::Status::UNTRIED
4692
}
4793
)
4894
aux_cisco.cisco_ios_config_eater('127.0.0.1',161,'enable password 1511021F0725')
@@ -58,18 +104,20 @@ def fullname
58104
expect(aux_cisco).to receive(:store_loot).with(
59105
"cisco.ios.config", "text/plain", "127.0.0.1", "enable password 0 password0", "config.txt", "Cisco IOS Configuration"
60106
)
61-
expect(aux_cisco).to receive(:create_credential).with(
107+
expect(aux_cisco).to receive(:create_credential_and_login).with(
62108
{
63109
address: "127.0.0.1",
64110
port: 1337,
65111
protocol: "tcp",
66112
workspace_id: nil,
67113
origin_type: :service,
68-
module_fullname: "Dummy Class / Dummy Ref",
114+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
69115
private_data: "password0",
70-
private_type: :password
116+
private_type: :password,
117+
status: Metasploit::Model::Login::Status::UNTRIED
71118
}
72119
)
120+
73121
aux_cisco.cisco_ios_config_eater('127.0.0.1',1337,'enable password 0 password0')
74122
end
75123

@@ -86,16 +134,17 @@ def fullname
86134
expect(aux_cisco).to receive(:store_loot).with(
87135
"cisco.ios.config", "text/plain", "127.0.0.1", "enable password 7 1511021F0725", "config.txt", "Cisco IOS Configuration"
88136
)
89-
expect(aux_cisco).to receive(:create_credential).with(
137+
expect(aux_cisco).to receive(:create_credential_and_login).with(
90138
{
91139
address: "127.0.0.1",
92140
port: 1337,
93141
protocol: "tcp",
94142
workspace_id: nil,
95143
origin_type: :service,
96-
module_fullname: "Dummy Class / Dummy Ref",
144+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
97145
private_data: "cisco",
98-
private_type: :password
146+
private_type: :password,
147+
status: Metasploit::Model::Login::Status::UNTRIED
99148
}
100149
)
101150
aux_cisco.cisco_ios_config_eater('127.0.0.1',1337,'enable password 7 1511021F0725')
@@ -108,16 +157,17 @@ def fullname
108157
expect(aux_cisco).to receive(:store_loot).with(
109158
"cisco.ios.config", "text/plain", "127.0.0.1", "enable password 1511021F0725", "config.txt", "Cisco IOS Configuration"
110159
)
111-
expect(aux_cisco).to receive(:create_credential).with(
160+
expect(aux_cisco).to receive(:create_credential_and_login).with(
112161
{
113162
address: "127.0.0.1",
114163
port: 1337,
115164
protocol: "tcp",
116165
workspace_id: nil,
117166
origin_type: :service,
118-
module_fullname: "Dummy Class / Dummy Ref",
167+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
119168
private_data: "1511021F0725",
120-
private_type: :password
169+
private_type: :password,
170+
status: Metasploit::Model::Login::Status::UNTRIED
121171
}
122172
)
123173
aux_cisco.cisco_ios_config_eater('127.0.0.1',1337,'enable password 1511021F0725')
@@ -127,35 +177,37 @@ def fullname
127177

128178
it 'with RO' do
129179
expect(aux_cisco).to receive(:print_good).with('127.0.0.1:1337 SNMP Community (RO): 1511021F0725')
130-
expect(aux_cisco).to receive(:store_cred).with(
180+
expect(aux_cisco).to receive(:create_credential_and_login).with(
131181
{
132-
:host=>"127.0.0.1",
133-
:port=>161,
134-
:user=>"",
135-
:pass=>"1511021F0725",
136-
:type=>"password_ro",
137-
:collect_type=>"password_ro",
138-
:sname=>"snmp",
139-
:proto=>"udp",
140-
:active=>true
182+
address: "127.0.0.1",
183+
port: 161,
184+
protocol: "udp",
185+
workspace_id: nil,
186+
origin_type: :service,
187+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
188+
private_data: "1511021F0725",
189+
private_type: :password,
190+
status: Metasploit::Model::Login::Status::UNTRIED,
191+
access_level: 'RO'
141192
}
142193
)
143194
aux_cisco.cisco_ios_config_eater('127.0.0.1',1337,'snmp-server community 1511021F0725 RO')
144195
end
145196

146197
it 'with RW' do
147198
expect(aux_cisco).to receive(:print_good).with('127.0.0.1:1337 SNMP Community (RW): 1511021F0725')
148-
expect(aux_cisco).to receive(:store_cred).with(
199+
expect(aux_cisco).to receive(:create_credential_and_login).with(
149200
{
150-
:host=>"127.0.0.1",
151-
:port=>161,
152-
:user=>"",
153-
:pass=>"1511021F0725",
154-
:type=>"password",
155-
:collect_type=>"password",
156-
:sname=>"snmp",
157-
:proto=>"udp",
158-
:active=>true
201+
address: "127.0.0.1",
202+
port: 161,
203+
protocol: "udp",
204+
workspace_id: nil,
205+
origin_type: :service,
206+
module_fullname: "auxiliary/scanner/snmp/cisco_dummy",
207+
private_data: "1511021F0725",
208+
private_type: :password,
209+
status: Metasploit::Model::Login::Status::UNTRIED,
210+
access_level: 'RW'
159211
}
160212
)
161213
aux_cisco.cisco_ios_config_eater('127.0.0.1',1337,'snmp-server community 1511021F0725 RW')

0 commit comments

Comments
 (0)