Skip to content

Commit

Permalink
Use "...".unpack("m0").first for Ruby < 2.4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 16, 2024
1 parent 8d666f4 commit b7d952a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/ronin/payloads/encoders/builtin/ruby/base64_encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class Base64Encode < RubyEncoder

description <<~DESC
Encodes the given Ruby code as a Base64 string, then decodes it
using `"...".unpack1('m0')`, and then evaluates the decoded Ruby
code using `eval()`.
using `"...".unpack('m0').first`, and then evaluates the decoded
Ruby code using `eval()`.
puts('PWNED') -> eval("cHV0cygnUFdORUQnKQ==".unpack1("m0"))
puts('PWNED') -> eval("cHV0cygnUFdORUQnKQ==".unpack("m0").first)
DESC

Expand All @@ -61,7 +61,7 @@ class Base64Encode < RubyEncoder
def encode(ruby)
base64 = Support::Encoding::Base64.encode(ruby, mode: :strict)

%{eval("#{base64}".unpack1("m0"))}
%{eval("#{base64}".unpack("m0").first)}
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/encoders/builtin/ruby/base64_encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

describe "#encode" do
let(:ruby) { "puts('PWNED')" }
let(:encoded) { %{eval("cHV0cygnUFdORUQnKQ==".unpack1("m0"))} }
let(:encoded) { %{eval("cHV0cygnUFdORUQnKQ==".unpack("m0").first)} }

it "must encode the given Ruby code as a Base64 string and embed it into the 'eval(\"...\".unpack1(\"m0\")' string" do
expect(subject.encode(ruby)).to eq(encoded)
Expand Down

0 comments on commit b7d952a

Please sign in to comment.