Skip to content

Add: Maldoc in PDF polyglot fileformat module #20072

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mekhalleh
Copy link
Contributor

The technique is called "MalDoc in PDF". This technique hides malicious Word documents in PDF files, which is why malicious code contained in them cannot be detected by many analysis tools.

The document can be opened in both Microsoft Word and a PDF reader.

However, for the macro to run, you must open this document in Microsoft Word. The attack does not bypass configured macro locks. The malicious macros are also not executed when the file is opened in PDF readers or similar software.

Verification

List the steps needed to make sure this thing works

  • Start msfconsole
  • use auxiliary/fileformat/maldoc_in_pdf_polyglot
  • set FILENAME /tmp/macro.htm
  • run

Options

FILENAME

The input MHT filename with macro embedded.

INJECTED_PDF

The input PDF filename to be injected. (optional)

MESSAGE_PDF

The message to display in the local PDF template (if INJECTED_PDF is NOT used). Default: You must open this document in Microsoft Word

Results

The document can be opened in both Microsoft Word and a PDF reader.

image

A malicious MHT file created can be opened in Microsoft Word even though it has magic numbers and file
structure of PDF.

image

Signed-off-by: RAMELLA Sebastien <[email protected]>
},
'License' => MSF_LICENSE,
'Author' => [
'mekhalleh (RAMELLA Sebastien)' # module author powered by EXA Reunion (https://www.exa.re/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'mekhalleh (RAMELLA Sebastien)' # module author powered by EXA Reunion (https://www.exa.re/)
'RAMELLA "mekhalleh" Sebastien from XA Reunion (https://www.exa.re/)' # module author

Signed-off-by: RAMELLA Sebastien <[email protected]>
Signed-off-by: RAMELLA Sebastien <[email protected]>
Signed-off-by: RAMELLA Sebastien <[email protected]>
Copy link
Contributor

@msutovsky-r7 msutovsky-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mekhalleh, reviewed your module and left some comments. The module itself seems to be working fine.

end

# if no pdf injected is provided, create new PDF from template
if datastore['INJECTED_PDF'].nil? || datastore['INJECTED_PDF'].empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if datastore['INJECTED_PDF'].nil? || datastore['INJECTED_PDF'].empty?
if datastore['INJECTED_PDF'].blank?

Comment on lines +208 to +210
if datastore['MESSAGE_PDF'].nil? || datastore['MESSAGE_PDF'].empty?
fail_with(Failure::BadConfig, 'No MESSAGE_PDF provided')
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if datastore['MESSAGE_PDF'].nil? || datastore['MESSAGE_PDF'].empty?
fail_with(Failure::BadConfig, 'No MESSAGE_PDF provided')
end
fail_with(Failure::BadConfig, 'No MESSAGE_PDF provided') if datastore['MESSAGE_PDF'].blank?

Comment on lines +201 to +203
if content&.empty?
fail_with(Failure::BadConfig, 'The MHT file content is empty')
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if content&.empty?
fail_with(Failure::BadConfig, 'The MHT file content is empty')
end
fail_with(Failure::BadConfig, 'The MHT file content is empty') if content&.empty?


# saving the file
ltype = "auxiliary.fileformat.#{shortname}"
fname = File.basename(datastore['FILENAME']).sub(File.extname(datastore['FILENAME']), datastore['OUTPUT_EXT'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified:

Suggested change
fname = File.basename(datastore['FILENAME']).sub(File.extname(datastore['FILENAME']), datastore['OUTPUT_EXT'])
fname = File.basename(datastore['FILENAME'],'*')+datastore['OUTPUT_EXT']


# saving the file
ltype = "auxiliary.fileformat.#{shortname}"
fname = File.basename(datastore['FILENAME']).sub(File.extname(datastore['FILENAME']), datastore['OUTPUT_EXT'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fname = File.basename(datastore['FILENAME']).sub(File.extname(datastore['FILENAME']), datastore['OUTPUT_EXT'])
fname = File.basename(datastore['FILENAME'],'*')+datastore['OUTPUT_EXT']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants