msfrpc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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) { |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. }
  52. if(not opts['ServerHost'])
  53. $stderr.puts "[-] Error: a server IP must be specified (-a)"
  54. $stderr.puts arguments.usage
  55. exit(0)
  56. end
  57. if(not 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. res = rpc.login(opts['User'], opts['Pass'])
  71. puts "[*] The 'rpc' object holds the RPC client interface"
  72. puts ""
  73. while(ARGV.shift)
  74. end
  75. Rex::Ui::Text::IrbShell.new(binding).run