You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 14.04下msfrpcd执行时Gemfile报‘Can't modify frozen String’错误求助

Fixing "can't modify frozen String" Error in Metasploit with Ruby 2.4.2 (rbenv)

Let's break down how to resolve this frozen string error you're hitting with Metasploit and Ruby 2.4.2. This issue stems from Ruby 2.3+ enabling frozen string literals by default, which clashes with an older snippet in Metasploit's gemspec file.

Step 1: Fix the Frozen String Issue in the Gemspec

The error points directly to line 112 in /opt/metasploit-framework/metasploit-framework.gemspec. The problem is that RUBY_VERSION is a frozen string in Ruby 2.4.2, and the code tries to use it in a way that implicitly modifies it. Here's how to fix it:

  1. Open the gemspec file with your preferred editor (e.g., nano or vim):
    sudo nano /opt/metasploit-framework/metasploit-framework.gemspec
    
  2. Locate this block of code around line 112:
    if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
      spec.add_runtime_dependency 'xmlrpc'
    end
    
  3. Modify it to create a mutable copy of RUBY_VERSION using dup:
    ruby_version = RUBY_VERSION.dup
    if Gem::Version.new(ruby_version) >= Gem::Version.new('2.3.0')
      spec.add_runtime_dependency 'xmlrpc'
    end
    
  4. Save and close the file.

Step 2: Reinstall Metasploit Dependencies

Now that the gemspec is fixed, you need to re-run Bundler to ensure all dependencies are properly installed with the corrected configuration:

cd /opt/metasploit-framework
bundle install

Note: Make sure you're using the rbenv-managed Ruby 2.4.2 here. If you run into permission issues, you might need to adjust the ownership of the /opt/metasploit-framework directory to your user (instead of running everything with sudo).

Step 3: Verify the Fix

Try running your original msfrpcd command again:

sudo -E ./msfrpcd -U USER -P PASSWORD -a 127.0.0.1 -p 55554 -S

The frozen string error should no longer appear, and the Metasploit RPC daemon should start up as expected. The same fix will also resolve the error in the Armitage teamserver script, since it relies on the same gemspec configuration.

Additional Notes

  • Ruby 2.4.2 is quite outdated (released in 2017), and newer versions of Metasploit may have better compatibility with more recent Ruby versions. If you run into further issues down the line, consider upgrading Ruby via rbenv (e.g., to 2.7.x, which is a common compatible version for older Metasploit builds).
  • Ensure that rbenv is properly loaded in your shell environment so that Metasploit uses the correct Ruby version. You can confirm this with rbenv version in the Metasploit directory.

内容的提问来源于stack exchange,提问作者briansyph

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:27:48