Skip to content

Commit

Permalink
Added CommandPayload#to_php (closes #140).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 17, 2024
1 parent 3719031 commit 1cbae0a
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/php'
require 'ronin/support/encoding/ruby'

module Ronin
Expand Down Expand Up @@ -51,6 +52,20 @@ def self.payload_type
:command
end

#
# Converts the built command into PHP code.
#
# @return [String]
# The PHP code which executes the command.
#
# @api public
#
# @since 0.3.0
#
def to_php
"system(#{Support::Encoding::PHP.quote(to_s)})"
end

#
# Converts the built command into Ruby 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_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)

expect(subject.to_php).to eq("system(#{php_escaped_string})")
end
end

describe "#to_ruby" do
it "must convert the built command into a Ruby string that is passed to 'system(\"...\")'" do
ruby_escaped_string = Ronin::Support::Encoding::Ruby.quote(subject.to_s)
Expand Down

0 comments on commit 1cbae0a

Please sign in to comment.