rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
33.49k stars 13.83k forks source link

ArgumentError wrong number of arguments (given 4, expected 5) in some post modules and using "shell" command from meterpreter #13060

Closed Adastra-thw closed 4 years ago

Adastra-thw commented 4 years ago

Steps to reproduce

In my case, I've used two different payloads to test and I get the same results. windows/x64/meterpreter/reverse_tcp and php/meterpreter/reverse_tcp.

In both cases I've got the error "ArgumentError wrong number of arguments (given 4, expected 5)".

How'd you do it?

  1. Generate an executable using the payloads explained above.
  2. Start my handler in msfconsole.
  3. Get the meterpreter session.
  4. Crash when I run the command "shell": ArgumentError wrong number of arguments (given 4, expected 5). The target machine is Windows 10. Windows Defender and Firewall disabled.

It also happens with some post-exploitaition modules:

post(windows/manage/enable_rdp) > exploit

[] Enabling Remote Desktop [] RDP is disabled; enabling it ... [] Setting Terminal Services service startup mode [] The Terminal Services service is not set to auto, changing it to auto ... [] Opening port in local firewall if necessary [] The following Error was encountered: ArgumentError wrong number of arguments (given 4, expected 5) [] For cleanup execute Meterpreter resource file: /home/user/.msf4/loot/20200311225614_default_192.168.1.101_host.windows.cle_656289.txt [] Post module execution completed

Expected behavior

Generate a command prompt, execute the commands needed in the post post-exploitation modules.... that kind of things that always worked in msf....

Current behavior

Crash .

cat ~/.msf4/logs/framework.log /msf/lib/msf/ui/console/command_dispatcher/core.rb:1384:in cmd_sessions' /msf/lib/rex/ui/text/dispatcher_shell.rb:523:inrun_command' /msf/lib/rex/ui/text/dispatcher_shell.rb:474:in block in run_single' /msf/lib/rex/ui/text/dispatcher_shell.rb:468:ineach' /msf/lib/rex/ui/text/dispatcher_shell.rb:468:in run_single' /msf/lib/rex/ui/text/shell.rb:158:inrun' /msf/lib/metasploit/framework/command/console.rb:48:in start' /msf/lib/metasploit/framework/command/base.rb:82:instart' ./msfconsole:49:in `

'

System stuff

Attacker machine: Debian 9, ruby 2.6.0 Victim machine: Windows 10 Home version

Metasploit version

msf5 post(windows/manage/enable_rdp) > version Framework: 5.0.80-dev-47f4f2d981 Console : 5.0.80-dev-47f4f2d981

I installed Metasploit with:

What OS are you running Metasploit on? Debian 9.

EmilioFigueras commented 4 years ago

Same issue.

In my case, I have used different payloads, and the meterpreter shell command and the powershell_shell command of the powershell module always fail me with the error Error running command powershell_shell (or shell): ArgumentError wrong number of arguments (given 4, expected 5).

I have tried to perform the same actions on the victim machine from an old Kali Linux with a Metasploit 4.16.49-dev and it works correctly.

Regarding where it fails:

My version of Metasploit is 5.0.79-dev and my version of Ruby is ruby 2.5.7p206.

Attacker machine: Operating System: Kali GNU / Linux Rolling Kernel: Linux 5.4.0-kali4-amd64

Victim machine: Windows 7 Professional

klaudz commented 4 years ago

I met the same issue after I upgraded Metasploit by msfupdate in Ubuntu. Here is my apt log:

$ cat /var/log/apt/history.log | grep "metasploit-framework"
Commandline: apt-get install -y --allow-downgrades metasploit-framework
Upgrade: metasploit-framework:amd64 (5.0.77+20200226112448~1rapid7-1, 5.0.80+20200311102409~1rapid7-1)

Steps of My Solution

It seems v5.0.80 is not compatible with v5.0.77, and I tried to downgrade it. But I found the old version debs have been taken down from the online sources. I have to downgrade Metasploit locally and here is my solution.

  1. STEP 1: Search the cached debs from apt cache directory.

    $ ls /var/cache/apt/archives | grep "metasploit-framework"
    metasploit-framework_5.0.77+20200226112448~1rapid7-1_amd64.deb
    metasploit-framework_5.0.80+20200311102409~1rapid7-1_amd64.deb

    If you can find an old version deb, follow these...

  2. STEP 2: Copy the old version deb to the current location.

    cp /var/cache/apt/archives/metasploit-framework_5.0.77+20200226112448~1rapid7-1_amd64.deb ./
  3. STEP 3: Purge the newest version of Metasploit.

    sudo apt-get purge metasploit-framework
  4. STEP 4: Install the old version Metasploit.

    sudo apt install ./metasploit-framework_5.0.77+20200226112448~1rapid7-1_amd64.deb
  5. STEP 5: Reset the database of Metasploit.

    msfdb reinit
  6. STEP 6: Launch it!

    msfconsole
timwr commented 4 years ago

https://github.com/rapid7/metasploit-framework/commit/349051531a027f296c97363ab43f0441a31d0834#diff-bbf989c691f38b6309c1f54bfe68b914R36 :trollface: