diff --git a/lib/ronin/payloads/command_payload.rb b/lib/ronin/payloads/command_payload.rb index 9eb93614..3c0946b6 100644 --- a/lib/ronin/payloads/command_payload.rb +++ b/lib/ronin/payloads/command_payload.rb @@ -23,6 +23,7 @@ require_relative 'metadata/os' require_relative 'encoders/command_encoder' +require 'ronin/support/encoding/perl' require 'ronin/support/encoding/php' require 'ronin/support/encoding/python' require 'ronin/support/encoding/ruby' @@ -54,6 +55,20 @@ def self.payload_type :command end + # + # Converts the built command into Perl code. + # + # @return [String] + # The Perl code which executes the command. + # + # @api public + # + # @since 0.3.0 + # + def to_perl + "system(#{Support::Encoding::Perl.quote(to_s)})" + end + # # Converts the built command into PHP code. # diff --git a/spec/command_payload_spec.rb b/spec/command_payload_spec.rb index ef27e801..6820d655 100644 --- a/spec/command_payload_spec.rb +++ b/spec/command_payload_spec.rb @@ -31,6 +31,14 @@ def build let(:payload_class) { TestCommandPayload::TestPayload } subject { payload_class.new } + describe "#to_perl" do + it "must convert the built command into a Perl string that is passed to 'system(\"...\")'" do + perl_escaped_string = Ronin::Support::Encoding::Perl.quote(subject.to_s) + + expect(subject.to_perl).to eq("system(#{perl_escaped_string})") + end + end + describe "#to_php" do it "must convert the built command into a PHP string that is passed to 'system(\"...\")'" do php_escaped_string = Ronin::Support::Encoding::PHP.quote(subject.to_s)