Skip to content

Commit

Permalink
Added CommandPayload#to_node_js (closes #141).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 17, 2024
1 parent 88240cd commit d284bb4
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 @@ -25,6 +25,7 @@

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

module Ronin
module Payloads
Expand Down Expand Up @@ -80,6 +81,20 @@ def to_ruby
"system(#{Support::Encoding::Ruby.quote(to_s)})"
end

#
# Converts the built command into Node.js code.
#
# @return [String]
# The Node.js code which executes the command.
#
# @api public
#
# @since 0.3.0
#
def to_node_js
"exec(#{Support::Encoding::NodeJS.quote(to_s)},(error,stdout,stderr)=>{console.log(stdout);});"
end

alias to_command to_s

end
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 @@ -47,6 +47,14 @@ def build
end
end

describe "#to_node_js" do
it "must convert the built command into a Node.js string that is passed to 'exec(\"...\",(error,stdout,stderr)=>{console.log(stdout);});'" do
node_js_escaped_string = Ronin::Support::Encoding::NodeJS.quote(subject.to_s)

expect(subject.to_node_js).to eq("exec(#{node_js_escaped_string},(error,stdout,stderr)=>{console.log(stdout);});")
end
end

describe "#to_command" do
it "must return #to_s" do
expect(subject.to_command).to eq(subject.to_s)
Expand Down

0 comments on commit d284bb4

Please sign in to comment.