Skip to content

Commit d0700e8

Browse files
committed
Add central directory zip spoofing
1 parent 6d72860 commit d0700e8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/rex/zip/archive.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ def save_to(fname)
8080
f.close
8181
end
8282

83-
84-
#
8583
# Compress this archive and return the resulting zip file as a String.
8684
#
87-
def pack
85+
# @param spoof [Hash{String => String}] The entries whose name need to be spoofed in the Central
86+
# Directory.
87+
# @return [String] The resulting zip file
88+
def pack(spoof={})
8889
ret = ''
8990

9091
# save the offests
@@ -104,7 +105,7 @@ def pack
104105
idx = 0
105106
@entries.each { |ent|
106107
cfd = CentralDir.new(ent, offsets[idx])
107-
ret << cfd.pack
108+
ret << cfd.pack(spoof)
108109
idx += 1
109110
}
110111

lib/rex/zip/blocks.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,16 @@ def initialize(entry, offset)
115115
@hdr_offset = offset
116116
end
117117

118-
def pack
118+
# Creates the central directory information about the particular Zip Entry.
119+
#
120+
# @param spoof [Hash{String => String}] The entries whose name need to be spoofed in the Central
121+
# Directory.
122+
# @return [String] The resulting zip file
123+
def pack(spoof={})
119124
path = @entry.relative_path
125+
if spoof.key?(path)
126+
path = spoof[path]
127+
end
120128

121129
ret = [ SIGNATURE, ZIP_VERSION ].pack('Vv')
122130
ret << [ ZIP_VERSION ].pack('v')

0 commit comments

Comments
 (0)