Skip to content

Commit

Permalink
Added CommandPayload#to_perl (closes #143).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 19, 2024
1 parent eb199cf commit b7675f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ronin/payloads/command_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
#
Expand Down
8 changes: 8 additions & 0 deletions spec/command_payload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b7675f4

Please sign in to comment.