Skip to content

Commit 2294ea0

Browse files
author
Tod Beardsley
committed
Squash commit for blank creds search and test
This should fix up rapid7#4642 with respect to rapid7#4504. Squashed commit of the following: commit 124d53ccb00cd200bede092e893dda7e033d3e17 Merge: cb2bef8 ccad159 Author: Tod Beardsley <[email protected]> Date: Mon Jan 26 16:23:03 2015 -0600 Merge branch 'feature/creds-blank-finders' into temp commit ccad159 Author: Tod Beardsley <[email protected]> Date: Mon Jan 26 15:58:02 2015 -0600 Clean out whitespace, make vars more meaningful commit 266b45d Author: Tod Beardsley <[email protected]> Date: Mon Jan 26 15:54:32 2015 -0600 Add some specs for regular users and blank users commit 2e51503 Author: Tod Beardsley <[email protected]> Date: Mon Jan 26 15:04:03 2015 -0600 Users should be able to find blank user/pass
1 parent cb2bef8 commit 2294ea0

File tree

2 files changed

+77
-0
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+77
-0
lines changed

lib/msf/ui/console/command_dispatcher/db.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,16 @@ def creds_search(*args)
868868
# Exclude creds that don't match the given type
869869
next if type.present? && !core.private.kind_of?(type)
870870

871+
# Exclude non-blank username creds if that's what we're after
872+
if user_regex.present? && user_regex == // && !core.public.username.blank?
873+
next
874+
end
875+
876+
# Exclude non-blank password creds if that's what we're after
877+
if pass_regex.present? && pass_regex == // && !core.private.data.blank?
878+
next
879+
end
880+
871881
# Exclude creds that don't match the given user
872882
if user_regex.present? && !core.public.username.match(user_regex)
873883
next

spec/lib/msf/ui/console/command_dispatcher/db_spec.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,73 @@
6565
it { is_expected.to respond_to :set_rhosts_from_addrs }
6666

6767
describe "#cmd_creds" do
68+
69+
describe "-u" do
70+
let(:username) { "thisuser" }
71+
let(:password) { "thispass" }
72+
let(:nomatch_username) { "thatuser" }
73+
let(:nomatch_password) { "thatpass" }
74+
let(:blank_username) { "" }
75+
let(:blank_password) { "" }
76+
let(:nonblank_username) { "nonblank_user" }
77+
let(:nonblank_password) { "nonblank_pass" }
78+
before(:each) do
79+
priv = FactoryGirl.create(:metasploit_credential_password, data: password)
80+
pub = FactoryGirl.create(:metasploit_credential_username, username: username)
81+
core = FactoryGirl.create(:metasploit_credential_core,
82+
origin: FactoryGirl.create(:metasploit_credential_origin_import),
83+
private: priv,
84+
public: pub,
85+
realm: nil,
86+
workspace: framework.db.workspace)
87+
nonblank_priv = FactoryGirl.create(:metasploit_credential_password, data: nonblank_password)
88+
blank_pub = FactoryGirl.create(:metasploit_credential_blank_username)
89+
core = FactoryGirl.create(:metasploit_credential_core,
90+
origin: FactoryGirl.create(:metasploit_credential_origin_import),
91+
private: nonblank_priv,
92+
public: blank_pub,
93+
realm: nil,
94+
workspace: framework.db.workspace)
95+
end
96+
context "when the credential is present" do
97+
it "should show a user that matches the given expression" do
98+
db.cmd_creds("-u", username)
99+
@output.should =~ [
100+
"Credentials",
101+
"===========",
102+
"",
103+
"host service public private realm private_type",
104+
"---- ------- ------ ------- ----- ------------",
105+
" thisuser thispass Password",
106+
]
107+
end
108+
context "and when the username is blank" do
109+
it "should show a user that matches the given expression" do
110+
db.cmd_creds("-u", "")
111+
@output.should =~ [
112+
"Credentials",
113+
"===========",
114+
"",
115+
"host service public private realm private_type",
116+
"---- ------- ------ ------- ----- ------------",
117+
" nonblank_pass Password"
118+
]
119+
end
120+
end
121+
end
122+
context "when the credential is absent" do
123+
it "should return a blank set" do
124+
db.cmd_creds("-u", nomatch_username)
125+
@output.should =~ [
126+
"===========",
127+
"Credentials",
128+
"",
129+
"---- ------- ------ ------- ----- ------------",
130+
"host service public private realm private_type"
131+
]
132+
end
133+
end
134+
end
68135
describe "add-password" do
69136
let(:username) { "username" }
70137
let(:password) { "password" }

0 commit comments

Comments
 (0)