spec/payloads/payload_spec.rb in ronin-exploits-0.2.0 vs spec/payloads/payload_spec.rb in ronin-exploits-0.2.1
- old
+ new
@@ -4,10 +4,11 @@
require 'helpers/objects'
describe Payloads::Payload do
before(:each) do
@payload = load_payload('test')
+ @exploit = load_exploit('example')
end
it "should require a name attribute" do
payload = Payloads::Payload.new
payload.should_not be_valid
@@ -34,30 +35,27 @@
:version => '0.0.2'
)
third_payload.should be_valid
end
+ it "should initialize all parameters by default" do
+ @payload.params.should_not be_empty
+ end
+
it "should not have any controls by default" do
@payload.controls.should be_empty
end
it "should specify what behaviors the payload controls" do
- @payload.controlling :memory_read
+ @payload.controlling :memory_read, :memory_write
- @payload.behaviors.first.should == Vuln::Behavior[:memory_read]
+ @payload.behaviors.should == [
+ Vuln::Behavior[:memory_read],
+ Vuln::Behavior[:memory_write]
+ ]
end
- it "should allow for the extending of Helper modules" do
- @payload.instance_eval { helper :shell }.should == true
- end
-
- it "should raise an UnknownHelper when extending an unknown helper" do
- lambda {
- @payload.instance_eval { helper :obvious_not_there }
- }.should raise_error(Payloads::UnknownHelper)
- end
-
it "should not have an Arch by default" do
@payload.arch.should be_nil
end
it "should set the Arch when called with a name" do
@@ -75,21 +73,86 @@
@payload.os(:name => 'FreeBSD', :version => '7.1')
@payload.os.name.should == 'FreeBSD'
@payload.os.version.should == '7.1'
end
+ it "should allow for the extending of Helper modules" do
+ @payload.instance_eval { helper :shell }.should == true
+ end
+
+ it "should raise an UnknownHelper when extending an unknown helper" do
+ lambda {
+ @payload.instance_eval { helper :obvious_not_there }
+ }.should raise_error(Payloads::UnknownHelper)
+ end
+
+ it "should not have an exploit by default" do
+ @payload.exploit.should be_nil
+ end
+
it "should have 'built' and 'unbiult' states" do
@payload.should_not be_built
@payload.build!
@payload.should be_built
end
- it "should return the built payload when calling build" do
- @payload.build!.should == 'code'
+ it "should store the built payload in the @payload instance variable" do
+ @payload.build!
+ @payload.payload.should == "code.func"
end
+ it "should return the built payload when calling build!" do
+ @payload.build!.should == "code.func"
+ end
+
+ it "should use parameters in the building of the payload" do
+ @payload.custom = 'hello'
+ @payload.build!.should == "code.hello"
+ end
+
+ it "should have 'deployed' and 'undeployed' states" do
+ @payload.should_not be_deployed
+ @payload.build!
+ @payload.deploy!
+ @payload.should be_deployed
+ end
+
it "should have a default deployer method" do
@payload.deploy! do |payload|
payload.should == @payload
end
+ end
+
+ it "should pass the built payload to the exploit when deploying" do
+ @payload.exploit = @exploit
+
+ @payload.build!
+ @payload.deploy! do |payload|
+ payload.exploit.payload.should == "code.func"
+ end
+ end
+
+ it "should call the exploit when deployed" do
+ @payload.exploit = @exploit
+
+ @payload.build!
+ @payload.deploy! do |payload|
+ payload.exploit.should be_built
+ payload.exploit.should be_deployed
+ end
+ end
+
+ it "should build and deploy the payload when called" do
+ @payload.call
+
+ @payload.should be_built
+ @payload.should be_deployed
+ end
+
+ it "should return the name and the version when calling to_s" do
+ @payload.to_s.should == 'test 0.1'
+ end
+
+ it "should have a custom inspect method" do
+ @payload.inspect.should == '#<Ronin::Payloads::Payload: test 0.1 {:custom=>"func"}>'
end
end