System.Zip.TZipFile.ExtractZipFile throws error with certain files. Why? - delphi

When extracting a ZIP file with System.Zip.TZipFile:
System.Zip.TZipFile.ExtractZipFile('C:\test.zip', 'R:\_TEST\');
for a specific ZIP file I get this error message box:
Stream read error.
Why?
The zip file which to reproduce the error, base64 encoded:
UEsDBC0ACAAIAHyDiEcAAAAA//////////8WABQATmV1ZXMgVGV4dGRva3VtZW50LnR4dAEAEAAA AAAAAAAAAAIAAAAAAAAAAwBQSwcIAAAAAAIAAAAAAAAAAAAAAAAAAABQSwECLQstAAgACAB8g4hH AAAAAP//////////FgA4AAAAAAABAAAAAAAAAAAATmV1ZXMgVGV4dGRva3VtZW50LnR4dAEAEAAA AAAAAAAAAAIAAAAAAAAACgAgAAAAAAABABgA1LFkAs0x0QHUsWQCzTHRAdSxZALNMdEBUEsFBgAA AAABAAEAfAAAAGIAAAAAAA==
Go to http://www.motobit.com/util/base64-decoder-encoder.asp
Decode this to your local storage as test.zip (don't change the character set)
The MD5 of the decoded binary file must be:
7357193E8F27FE1FB5AF2B8B6AF1F24C

Reference: The structure of a PKZip file
by Florian Buchholz.
Your ZIP file is stored using the ZIP64 extended variant of the format. The Delphi ZIP code does not support ZIP64.
I deduced that the file was ZIP64 by looking at the local file header. The compressed and uncompressed size fields are both 0xffffffff. From the reference above:
Compressed size: if archive is in ZIP64 format, this filed is 0xffffffff and the length is stored in the extra field
Uncompressed size: if archive is in ZIP64 format, this filed is 0xffffffff and the length is stored in the extra field
For the library to support ZIP64 it needs to detect these conditions and read the 64 bit values out of the additional headers. The Delphi code does not and attempts to read 0xffffffff bytes that are not there.
You will need to find a different ZIP file library, one that supports ZIP64, in order to operate on such a ZIP file. Alternatively, you could side-step the problem if you could arrange that whatever creates the ZIP files uses the plain ZIP format.

Related

Is there any offline safe method to prevent web-shell uploading in aspnet?

I have a simple page in asp net 5, and users can upload their images there. Valid files are: *.jpg, *.png, so I'm doing steps below to validating the files:
Validating filename length : e.g: file name must be less than 50 alphabet characters
Validating filename : replacing any hidden or invalid characters
Validating file size : based on our configurations (e.g: less than 10MB)
Validating file extensions : based on our white-list: *.jpg, *.png
Validating Mimetypes : based on our white-list for IMAGE/JPEG, IMAGE/PNG
Validating file's first bytes (Magic Number) : based on our white-list for JPG: "FF-D8-FF-DB", "FF-D8-FF-E0" , "FF-D8-FF-EE" ,"FF-D8-FF-E1" and PNG: "89-50-4E-47"
Uploading the file with a random (guid) filename in the temp folder outside webroot: without any executing permissions.
Scanning the file with AV (Kaspersky or Norton Security) service installed.
But, some webshells can bypass these steps, like Insomnia webshell or others (they use the magic number headers at the first of file headers and inject their codes into some part of the file).
So my question is :
how can I detect and prevent webshell uploading?
Should I read and check the whole file for some black-list keywords?
Or what?
btw :We can't use any online webshell detection services.
This is a simple shell injected into a PNG file by woanware.co.uk:

How to decode Base64 encoded binary(encoded using LZX algorithm) back to original string

I'm trying to decode a string which is encoded using LZX algorithm with a LZX window size of 2 megabytes (binary) and then converted to base64.
I'm receiving this string in response from Microsoft's Update API (GetUpdateData).
As per Microsoft documentation for the lzx/lz77 algorithm, the XmlUpdateBlobCompressed field is:
compressed using a LZX variant of the Lempel-Ziv compression algorithm. The LZX window size used for compressing this field is 2 megabytes.
I tried to decode/decompress the string back to its original XML with no success. I tried the lz_string library (NodeJS/Ruby) and some other libraries but had no success so far.
Here is a sample I'm trying to decode/decompress back to the original XML:
TVNDRgAAAACPIwAAAAAAACwAAAAAAAAAAwEBAAEAAAAAAAAAQQAAAAIAAxVIwwAAAAAAAAAAAAAAAAAAYmxvYgCF1k7pgBgAgFuAgI0MIIQ0QRAABDMDNSMAYAAAaW+qrcgkd7l8ck7bM0VOsi0C+61/XVRtf4SU9i2F0gKBAO2Bv7e37Zu22t50m5yTNmlRiEcikSCfz+5ztUnyzQoR9BaupQIpgBYaiaUIHGOuCNSOXBj5SFWJcDqQuSIAmSGAmgMARjDL0O1rqggvgGaQNgADBjP2RgIHw83o+jG9NdKT1j66rC8nipxrKyXpu7a+U12KV1Y/Lp04nt1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SCoLDsan4vTjrRdGe6856P4Eybd58uOHiBGmJWvOEbW/ldFXOvAwaXZq+jPQkJUoPkhZSydnYAegnOl7rY077wEOseWitVjnryYV4sh8d1GTi33nddf4fvGbwj1HH4SONsmK0fQcrwPfmy1hxiTXN/J6wwmAo51pjK3jNYBDx2Oi9+JSnwcoHJV4j2f7i1FU7Ibr3caR5po6rNZQ1TFO7Uh4jeO+JA+hkWw7muVAMZ7ITHQ9i6Ay4Ma6M7cKzfebYsnUhqZGPpw9Nx/a7W6NeNXEzZ7Tt6k7g3GTi59IzhO7SYdyl7E+d49BVee/KoxbUu2OMM6stRyAPodbtnRY/ds7dWqyK1SOF6leR98gxL3DHHMR6SvGFD2KO0rZwqZ2M9AXjotJomUg9WVqovPvnZ1FuiAR+tLY52c9hdrkz1JCZz4tLNEtW3q1UauvluOoBWXIfFmJLa7U53qJ3QsXw4MbbpRN/Om7hKN68u1udURZuK4TzqgJYAZ3G0LbnNuo8TmDtHO7ZXylns2nfcbjqCarY7FkL2mxWcXVU81a+IZjurno+rOVm4uPLZPVkNAPJSW6Z81ixzyOdwvujjTVBjkefGzZVufr3YAdxtHp+klnd2TjeOwyoLdZgcBu071fhzb+lenvbFc6XpiHn9wl0S49RxMDktEbbS1kO2huG7MBv//SgtEgFtHeNju6ducFUatT7te62cI0y3jqsPmYddFf7telkjleeq+mLHM+dd+M/G2Nbc13BBFdzxObiwJbPxU/kP62Uqq4zN7dY+bS0iKdG3r31Vc4xoV69dAULH3rxr4wYWgd1Mh6YB5vm7AacMYpk2UK6xcuALsrPJC49282vVLVBLY1cZiitzrTmfOnaOcrOV7RxBAAednIjwwNH2ZwCTO9VNxuBQVQPtAW7OQJjq1T4uj6Wavnni22Xj+My2O4YlTsNREWzgCL2Y2Gbb4GZiifMM2gLNyenuXRdU9TSwIw+RDrfuJyhcGxOpnccp5F/l++Qpu72rOJR7mxphiKYABw==
Has anybody had success doing this?
As added in comment by Dave, it was the cab file which was there in response.
I have saved the cab file & extracted it using libmspack
cab_file_path = "/Users/kalpesh/playground/xml.cab"
cab_file = File.open(cab_file_path, "wb")
# Save Cab file
cab_file.puts Base64.decode64(xml_blob) # xml_blob is the sample which I have given in description
# Extract cab file
blob_xml_path = "/Users/kalpesh/playground/xml_blob.txt"
cab_decompressor = LibMsPack::CabDecompressor.new
cab = cab_decompressor.open(cab_file_path)
cab_decompressor.extract(cab.files, blob_xml_path)

Unicode representation in iOS

I'm saving a file with unicode(korean) in its name and I'm storing the name of the file in memory for bookkeeping in my app. The file is saved fine, what's bothering me is the way the name is given back to me by the OS.
IF I make a fcntl(fd, F_GETPATH, charArray) call on the file's fd, the filename being returned is different to the file name returned by listing out its directory contents. I did some research on the filenames returned in the two cases and found out that the format in the initial case is Hangul Symbols(length of filename in bytes:18) and in the later case it is Hangul Jamo(length in bytes:36). IOS seamlessly works with the two formats, if I do a localizedcompare on the two names being returned it'll return a 1.
When I'm doing the bookkeeping I store the path to the file(including its name) and the length of this path. I'll do a quick compare on these two attributes when a request comes in and return a handle to the file only if they match. The problem now is when the file is being stored the fcntl call gives me the path in Hangul symbols and when the user requests it back the run time gives me the file path in hangul jamo. As I've stored the path in Hangul symbols, the app'll think its a different file that's somehow not created by the user and returns an 'invalid file' popup.
Visually the korean text looks the same in both the encoding schemes, the only difference is in the byte representation.
다른 문서.docx - Hangul Symbols - returned during file creation by FD
다른 문서.docx - Hangul Jamo - returned by the OS in runtime and also if I list the directory contents.
char *fileName1="다른 문서.docx"; //Hangul Symbols
NSLog(#"fileName3:%s length:%lu", fileName3, strlen(fileName3));
char *fileName2="다른 문서.docx"; //Hangul Jamo
NSLog(#"fileName4:%s length:%lu", fileName4, strlen(fileName4));
If you run the above code you could see the names are different in their memory footprint. Any idea on how/why iOS is changing the filename at run time from one scheme to another? and also if someone could explain how localizedcompare is returning 1 in both the cases would be great.

DXGI_FORMAT in dds file

I am parsing DDS file to read its header data. I want to modify format of image, but it seems that header mentioned at this site does not specify where DXGI_FORMAT (internal format) is stored. Where I can I get internal format in file ?
Like DXGI_FORMAT_BC1_UNORM value is 71, but i did not find it in header

Read/Write file from a .zip archive

Should I work with files within the archive file. (Read - write). By the following code, I get a list of files on my needs.
Zip := TZipFile.Create;
try
Zip.Open(FilePath, TZipMode.zmRead);
For File_Name in Zip.FileNames do
begin
//some code
end;
finally
Zip.Close;
FreeAndNil(Zip);
end;
I used the TZipFile.Read method to reads a file from a .zip archive .
This method returns the complete content of file into a buffer of type TByte. But just need to read a 1MB file from the beginning, not the complete file.
After reading and analyzing a 1MB file, if needed, should be read complete file and make changes to the file and re-save the file to archive.
Memory and speed of the program is very important. I used to set the buffer size of the function SetLength, unfortunately complete content of file files are stored in the buffer.
What do you think?
Use the overloaded version of TZipFile.Read() that returns a TStream instead of a TBytes. That way, you do not have to read the entire file into memory, and can read just its beginning bytes as needed.
Unfortunately, there is no way to modify data inside of a zip archive using TZipFile. Although you can Extract() a particular file, modify it externally as needed, and then Add() it back into TZipFile, there is no way to remove/replace a given file in TZipFile. TZipFile is a simple framework, it can only read a zip archive and add new files to it, nothing else. If you need more control over a zip archive, you are better off using a more complete third-party solution, such as ZipForge.

Resources