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.

builder_spec.rb 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # -*- coding:binary -*-
  2. require 'spec_helper'
  3. require 'rex/java/serialization'
  4. require 'rex/proto/rmi'
  5. require 'msf/core/exploit/java/rmi/builder'
  6. describe Msf::Exploit::Remote::Java::Rmi::Builder do
  7. subject(:mod) do
  8. mod = ::Msf::Exploit.new
  9. mod.extend ::Msf::Exploit::Remote::Java::Rmi::Builder
  10. mod.send(:initialize)
  11. mod
  12. end
  13. let(:default_header) { "JRMI\x00\x02\x4b" }
  14. let(:header_opts) do
  15. {
  16. :version => 1,
  17. :protocol => Rex::Proto::Rmi::Model::MULTIPLEX_PROTOCOL
  18. }
  19. end
  20. let(:opts_header) { "JRMI\x00\x01\x4d" }
  21. let(:default_call) do
  22. "\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
  23. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff" +
  24. "\xff\x00\x00\x00\x00\x00\x00\x00\x00"
  25. end
  26. let(:call_opts) do
  27. {
  28. message_id: Rex::Proto::Rmi::Model::CALL_MESSAGE,
  29. object_number: 2,
  30. uid_number: 0,
  31. uid_time: 0,
  32. uid_count: 0,
  33. operation: 0,
  34. hash: 0xf6b6898d8bf28643
  35. }
  36. end
  37. let(:opts_call) do
  38. "\x50\xac\xed\x00\x05\x77\x22\x00\x00\x00\x00\x00\x00\x00\x02\x00" +
  39. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
  40. "\x00\xf6\xb6\x89\x8d\x8b\xf2\x86\x43"
  41. end
  42. let(:default_dgc_ack) { "\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }
  43. let(:dgc_ack_opts) do
  44. {
  45. :unique_identifier => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x04\x03\x02\x01"
  46. }
  47. end
  48. let(:opts_dgc_ack) { "\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x04\x03\x02\x01" }
  49. describe "#build_header" do
  50. context "when no opts" do
  51. it "creates a Rex::Proto::Rmi::Model::OutputHeader" do
  52. expect(mod.build_header).to be_a(Rex::Proto::Rmi::Model::OutputHeader)
  53. end
  54. it "creates a default OutputHeader" do
  55. expect(mod.build_header.encode).to eq(default_header)
  56. end
  57. end
  58. context "when opts" do
  59. it "creates a Rex::Proto::Rmi::Model::OutputHeader" do
  60. expect(mod.build_header(header_opts)).to be_a(Rex::Proto::Rmi::Model::OutputHeader)
  61. end
  62. it "creates a OutputHeader with data from opts" do
  63. expect(mod.build_header(header_opts).encode).to eq(opts_header)
  64. end
  65. end
  66. end
  67. describe "#build_call" do
  68. context "when no opts" do
  69. it "creates a Rex::Proto::Rmi::Model::Call" do
  70. expect(mod.build_call).to be_a(Rex::Proto::Rmi::Model::Call)
  71. end
  72. it "creates a default Call" do
  73. expect(mod.build_call.encode).to eq(default_call)
  74. end
  75. end
  76. context "when opts" do
  77. it "creates a Rex::Proto::Rmi::Model::Call" do
  78. expect(mod.build_call(call_opts)).to be_a(Rex::Proto::Rmi::Model::Call)
  79. end
  80. it "creates a Call with data from opts" do
  81. expect(mod.build_call(call_opts).encode).to eq(opts_call)
  82. end
  83. end
  84. end
  85. describe "#build_dgc_ack" do
  86. context "when no opts" do
  87. it "creates a Rex::Proto::Rmi::Model::DgcAck" do
  88. expect(mod.build_dgc_ack).to be_a(Rex::Proto::Rmi::Model::DgcAck)
  89. end
  90. it "creates a default Call" do
  91. expect(mod.build_dgc_ack.encode).to eq(default_dgc_ack)
  92. end
  93. end
  94. context "when opts" do
  95. it "creates a Rex::Proto::Rmi::Model::DgcAck" do
  96. expect(mod.build_dgc_ack(dgc_ack_opts)).to be_a(Rex::Proto::Rmi::Model::DgcAck)
  97. end
  98. it "creates a DgcAck with data from opts" do
  99. expect(mod.build_dgc_ack(dgc_ack_opts).encode).to eq(opts_dgc_ack)
  100. end
  101. end
  102. end
  103. end