Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

msfrpc 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env ruby
  2. # -*- coding: binary -*-
  3. #
  4. # $Id$
  5. #
  6. # This user interface allows users to interact with a remote framework
  7. # instance through a XMLRPC socket.
  8. #
  9. # $Revision$
  10. #
  11. msfbase = __FILE__
  12. while File.symlink?(msfbase)
  13. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  14. end
  15. $:.unshift(File.expand_path(File.join(File.dirname(msfbase), 'lib')))
  16. require 'msfenv'
  17. $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  18. require 'rex/parser/arguments'
  19. # Declare the argument parser for msfrpc
  20. arguments = Rex::Parser::Arguments.new(
  21. "-a" => [ true, "Connect to this IP address" ],
  22. "-p" => [ true, "Connect to the specified port instead of 55553" ],
  23. "-U" => [ true, "Specify the username to access msfrpcd" ],
  24. "-P" => [ true, "Specify the password to access msfrpcd" ],
  25. "-S" => [ false, "Disable SSL on the RPC socket" ],
  26. "-h" => [ false, "Help banner" ]
  27. )
  28. opts = {
  29. 'User' => 'msf',
  30. 'SSL' => true,
  31. 'ServerPort' => 55553,
  32. 'Type' => 'Msg'
  33. }
  34. # Parse command line arguments.
  35. arguments.parse(ARGV) do |opt, idx, val|
  36. case opt
  37. when "-a"
  38. opts['ServerHost'] = val
  39. when "-S"
  40. opts['SSL'] = false
  41. when "-p"
  42. opts['ServerPort'] = val
  43. when '-U'
  44. opts['User'] = val
  45. when '-P'
  46. opts['Pass'] = val
  47. when "-h"
  48. print("\nUsage: #{File.basename(__FILE__)} <options>\n" + arguments.usage)
  49. exit
  50. end
  51. end
  52. unless opts['ServerHost']
  53. $stderr.puts "[-] Error: a server IP must be specified (-a)"
  54. $stderr.puts arguments.usage
  55. exit(0)
  56. end
  57. unless opts['Pass']
  58. $stderr.puts "[-] Error: a password must be specified (-P)"
  59. $stderr.puts arguments.usage
  60. exit(0)
  61. end
  62. $0 = "msfrpc"
  63. require 'msf/core/rpc/v10/client'
  64. require 'rex/ui'
  65. rpc = Msf::RPC::Client.new(
  66. :host => opts['ServerHost'],
  67. :port => opts['ServerPort'],
  68. :ssl => opts['SSL']
  69. )
  70. rpc.login(opts['User'], opts['Pass'])
  71. puts "[*] The 'rpc' object holds the RPC client interface"
  72. puts "[*] Use rpc.call('group.command') to make RPC calls"
  73. puts ''
  74. while(ARGV.shift)
  75. end
  76. Rex::Ui::Text::IrbShell.new(binding).run