Reputation: 5418
Look into this post which describes a technique to put an executable code in the first 128 bytes of a DICOM file i.e. in the preamble section. This way the DICOM can be viewed as both a DICOM and an PE executable file.
This git repo demonstrates the same. However they don't show the code, instead only has the binaries.
Now my question. How can an executable be kept only in 128 bytes because I understand a minimal exe will take at least a few KBs from this, this and this SO posts?
Upvotes: 0
Views: 496
Reputation: 5418
Before answering how to put an executable in 128 bytes, we need to understand a few things first.
DICM
(File extension) on the bytes 121-124 (Prefix section) to be recognized as a dicom fileCreating a PEDICOM file:
IMAGE_DOS_HEADER
) has 1 field named e_lfanew
which contains the offset of the actual PE content. This allows to keep an entire executable code in at least 2 memory locations.IMAGE_NT_HEADER
) has the number of sections and the pointes to the sections (Code, Data, Stack etc.)Now to answer the original question, an entire executable can't be kept in 128 bytes. However 128 bytes of data are sufficient to declare a file as executable i.e. the dos header
and the dos stub
can be kept in the 128 bytes while the rest of the executable can be kept somewhere else, in this case in a private dicom tag and a field in the header can point to this. Make the containing file a valid and legitimate executable.
Upvotes: 0
Reputation: 808
From looking at image 1 it appears pretty simple, the valid DOS header is placed in the free area while the full PE image is embedded later in the file, the author put it between two legitimate DICOM meta entries for example. The DOS header is really short and has a field named e_lfanew which holds the file offset to IMAGE_NT_HEADERS. In other words you don't actually need 128 bytes for the full image, you can embed it anywhere in the file as long as it doesn't interfere with DICOM, all that's needed at the start is the dos header.
Upvotes: 1