Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/msf/core/exploit/remote/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(info = {})
register_autofilter_ports([ 21, 2121])
register_autofilter_services(%W{ ftp })

@ftpbuff = ""
@ftpbuff = +""

end

Expand Down Expand Up @@ -326,7 +326,7 @@ def recv_ftp_resp(nsock = self.sock)
left = ""
if !@ftpbuff.empty?
left << @ftpbuff
@ftpbuff = ""
@ftpbuff = +""
end
while true
data = nsock.get_once(-1, ftp_timeout)
Expand Down
48 changes: 48 additions & 0 deletions test/modules/test_ftp_frozen_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'test/unit'
require 'msf/core'

class TestFtpMixinFrozenString < Test::Unit::TestCase
include Msf

def setup
@module = Msf::Module.new
@module.extend(Exploit::Remote::Ftp)
end

def test_ftpbuff_is_mutable
# Initialize the FTP mixin
@module.send(:initialize, {})

# Access the internal @ftpbuff variable
ftpbuff = @module.instance_variable_get(:@ftpbuff)

# Verify it's not frozen
assert_not_predicate(ftpbuff, :frozen?, "@ftpbuff should be mutable even with frozen_string_literal: true")

# Verify we can modify it
assert_nothing_raised do
ftpbuff << "test data"
end
end

def test_recv_ftp_resp_with_frozen_string_literal
# This test verifies that recv_ftp_resp works correctly
# when the module uses frozen_string_literal: true

# Mock the socket
mock_socket = Object.new
def mock_socket.get
"220 Welcome\r\n"
end

@module.instance_variable_set(:@sock, mock_socket)

# This should not raise FrozenError
assert_nothing_raised do
result = @module.send(:recv_ftp_resp)
assert_equal("220 Welcome", result)
end
end
end
Loading