Advertisement
Guest User

rpcexample.rb

a guest
Jan 9th, 2011
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.70 KB | None | 0 0
  1. #
  2. # $Id$
  3. # Created by scriptjunkie
  4. #
  5. require "msf/core/rpc"
  6.  
  7. module Msf
  8.  
  9. ###
  10. #
  11. # This file illustrates a sample RPC plugin.  
  12. #
  13. # $Revision$
  14. ###
  15.  
  16.  
  17. #
  18. # This class handles the RPC side of the plugin
  19. #
  20. class Test < RPC::Base
  21.  
  22.     # Each method here will be accessible from RPC
  23.     #
  24.     # The methods must begin with authenticate(token) otherwise unauthenticated users
  25.     # will be able to execute it. The first argument must
  26.     # always be token but is usually not added explicitly by the client.
  27.     #
  28.     # This example method can be executed as "test.info"; i.e. rpc.call("test.info")
  29.     def info(token)
  30.         authenticate(token)
  31.        
  32.         # The methods should return a hash that can have nested hashes,
  33.         # arrays, strings, or integers.
  34.         { "result" => "success" }
  35.     end
  36.  
  37.     # This example method shows arguments passed and could be called
  38.     # with rpc.call("test.argcheck","argument")
  39.     def argcheck(token, argh)
  40.         authenticate(token)
  41.         { "result" => "success" , "argument" => argh }
  42.     end
  43. end
  44.  
  45.  
  46. #
  47. # This class handles the "plugin" side of the plugin. See sample.rb for more info.
  48. #
  49. class Plugin::Test < Msf::Plugin
  50.  
  51.     def name
  52.         "rpcexample"
  53.     end
  54.  
  55.     def desc
  56.         "Example plugin for adding RPC methods."
  57.     end
  58.  
  59.     def initialize(framework, opts)
  60.         super
  61.  
  62.         # Find XMLRPC plugin
  63.         framework.plugins.each { |plugin|
  64.             if (plugin.name == "xmlrpc")
  65.  
  66.                 # Register our RPC class. The name we provide here will be the module
  67.                 # name that the RPC client must use
  68.                 plugin.server.add_handler(::XMLRPC::iPIMethods("test"),
  69.                     ::Msf::RPC::Test.new(framework,plugin.tokens,plugin.users)
  70.                 )
  71.                 return
  72.             end
  73.         }
  74.         # we shouldn't get here, but just in case
  75.         raise "XMLRPC plugin not found!"
  76.     end
  77. end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement