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.

rservices.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: binary -*-
  2. ##
  3. #
  4. # This Auxiliary Mixin provides functionality for dealing with BSD R*Services
  5. #
  6. ##
  7. module Msf
  8. module Auxiliary::RServices
  9. def initialize(info = {})
  10. super
  11. register_options(
  12. [
  13. OptString.new('FROMUSER', [ false, 'The username to login from' ]),
  14. OptPath.new( 'FROMUSER_FILE', [ false, 'File containing from usernames, one per line',
  15. File.join(Msf::Config.data_directory, "wordlists", "rservices_from_users.txt") ])
  16. ], Msf::Auxiliary::RServices)
  17. register_advanced_options(
  18. [
  19. OptBool.new('REMOVE_FROMUSER_FILE', [ true, "Automatically delete the FROMUSER_FILE on module completion", false])
  20. ], Msf::Auxiliary::RServices)
  21. end
  22. def connect_from_privileged_port(start_port = 1023)
  23. cport = start_port
  24. sd = nil
  25. while cport > 512
  26. #vprint_status("Trying to connect from port #{cport} ...")
  27. sd = nil
  28. begin
  29. sd = connect(true, { 'CPORT' => cport })
  30. rescue Rex::BindFailed
  31. # Ignore and try again
  32. #vprint_error("Unable to connect: #{$!}")
  33. rescue Rex::ConnectionError => e
  34. vprint_error("Unable to connect: #{$!}")
  35. return :refused if e.class == Rex::ConnectionRefused
  36. return :connection_error
  37. end
  38. break if sd
  39. cport -= 1
  40. end
  41. if not sd
  42. print_error("#{target_host}:#{rport} - Unable to bind to privileged port")
  43. return :bind_error
  44. end
  45. #vprint_status("Connected from #{cport}")
  46. return :connected
  47. end
  48. def load_fromuser_vars
  49. fromusers = extract_words(datastore['FROMUSER_FILE'])
  50. if datastore['FROMUSER']
  51. fromusers.unshift datastore['FROMUSER']
  52. end
  53. fromusers
  54. end
  55. def cleanup_files
  56. super
  57. path = datastore['FROMUSER_FILE']
  58. if path and datastore['REMOVE_FROMUSER_FILE']
  59. ::File.unlink(path) rescue nil
  60. end
  61. end
  62. end
  63. end