msfrpc 2.1 KB

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. rpc = Msf::RPC::Client.new(
  65. :host => opts['ServerHost'],
  66. :port => opts['ServerPort'],
  67. :ssl => opts['SSL']
  68. )
  69. rpc.login(opts['User'], opts['Pass'])
  70. puts "[*] The 'rpc' object holds the RPC client interface"
  71. puts "[*] Use rpc.call('group.command') to make RPC calls"
  72. puts ''
  73. while(ARGV.shift)
  74. end
  75. Rex::Ui::Text::IrbShell.new(binding).run