Skip to content

Commit

Permalink
Added CommandPayload#to_python (closes #142).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 17, 2024
1 parent b9833e8 commit eb199cf
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 @@ -24,6 +24,7 @@
require_relative 'encoders/command_encoder'

require 'ronin/support/encoding/php'
require 'ronin/support/encoding/python'
require 'ronin/support/encoding/ruby'
require 'ronin/support/encoding/node_js'

Expand Down Expand Up @@ -67,6 +68,20 @@ def to_php
"system(#{Support::Encoding::PHP.quote(to_s)})"
end

#
# Converts the built command into Python code.
#
# @return [String]
# The Python code which executes the command.
#
# @api public
#
# @since 0.3.0
#
def to_python
"import os; os.system(#{Support::Encoding::Python.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 @@ -39,6 +39,14 @@ def build
end
end

describe "#to_python" do
it "must convert the built command into a Python string that is passed to 'import os; os.system(\"...\")'" do
python_escaped_string = Ronin::Support::Encoding::Python.quote(subject.to_s)

expect(subject.to_python).to eq("import os; os.system(#{python_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 eb199cf

Please sign in to comment.