bookboons

All PDF Details And All in one Detail like Improve Your Knowledge

Saturday, December 31, 2022

[New post] Combining zipdump, file-magic And myjson-filter

Site logo image Didier Stevens posted: " In this blog post, I show how you can combine my tool zipdump.py, file-magic.py and myjson-filter.py to select and analyze files of a particular type. I start with a daily batch of malware files published by Malware Bazaar. I let it produce JSO" Didier Stevens

Combining zipdump, file-magic And myjson-filter

Didier Stevens

Dec 31

In this blog post, I show how you can combine my tool zipdump.py, file-magic.py and myjson-filter.py to select and analyze files of a particular type.

I start with a daily batch of malware files published by Malware Bazaar.

I let it produce JSON output using option --jsonoutput, that can be consumed by some of my tools, like file-magic.py, my tool to identify files based on the content using the libmagic library.

In the output above, we can see that most files are PE files (Windows executables).

For this example, I'm interested in Office files (ole files). I can filter the output of file-magic.py for that with option -r. Libmagic identifies this type of file as "Composite Document File ...", thus I filter for Composite:

This gives me a list of malicious Office documents. I want to extract URLs from them, but I don't want to extract all of these files from the ZIP container to disk, and do the URL extraction file per file.

I want to do this with a one-liner. 🙂

What I'm going to do, is use file-magic's option --jsonoutput, so that it augments the json output of zipdump with the file type, and then I use my tool myjson-filter.py to filter that json output for files that are only of a type that contains the word Composite. With this command:

This produces JSON output that contains the content of each file of type Composite, found inside the ZIP container.

This output can be consumed by my tool strings.py, to extract all the strings.

Side note: if you want to know first which files were selected for processing, use option -l:

Let's pipe the filtered JSON output into strings.py, with options to produce a list of unique strings (-u) that contain the word http (-s http), like this:

I use my tool re-search.py to extract a list of unique URLs:

I filter out common URLs found in Office documents:

And finally, I sort the URLs by domain name using my tool sortcanon.py:

The adobe URLs are not malicious, but the other ones could be.

This one-liner allows me to quickly process daily malware batches, looking for easy IOCs (cleartext URLs in Office documents) without writing any malicious file to disk.

zipdump.py --jsonoutput 2020-10-24.zip | file-magic.py --jsoninput --jsonoutput | myjson-filter.py -t Composite | strings.py --jsoninput -u -s http | re-search.py -u -n url -F officeurls | sortcanon.py -c domain

Remark that by using an option to search for strings with the word http (-s http), I reduce the output of strings to be processed by re-search.py, so that the search is faster. But that limits you (mostly) to URLs with protocol http or https.

Leave out this option if you want to search for all possible protocols, or try -s "://".

Comment
Tip icon image You can also reply to this email to leave a comment.

Unsubscribe to no longer receive posts from Didier Stevens.
Change your email settings at manage subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
http://blog.didierstevens.com/2022/12/31/combining-zipdump-file-magic-and-myjson-filter/

Powered by WordPress.com
Download on the App Store Get it on Google Play
at December 31, 2022
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

JUNE 2025 FilmFreeway Discount Codes – 50% off codes!

Submit to some of the top festivals in the world today. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏...

  • New & Noteworthy J-pop of the Week (June 30, 2024)
    In connection with my desire to fully keep up with the J-pop industry, I'm p...
  • Sleeping Dogs (2024) Movie Review
    Sleeping Dogs - Movie Review Director: Adam Cooper Writer: Adam Cooper...
  • Handling The Undead (2024) Film Review
    On a hot summer day in Oslo, the dead mysteriously awaken, and three families ar...

Search This Blog

  • Home

About Me

bookboons
View my complete profile

Report Abuse

Blog Archive

  • June 2025 (3)
  • May 2025 (4)
  • April 2025 (5)
  • March 2025 (5)
  • February 2025 (4)
  • January 2025 (6)
  • December 2024 (3)
  • November 2024 (4)
  • October 2024 (1)
  • August 2024 (2405)
  • July 2024 (2925)
  • June 2024 (2960)
  • May 2024 (3057)
  • April 2024 (2967)
  • March 2024 (3077)
  • February 2024 (2890)
  • January 2024 (3023)
  • December 2023 (2680)
  • November 2023 (2216)
  • October 2023 (1706)
  • September 2023 (1319)
  • August 2023 (1194)
  • July 2023 (1113)
  • June 2023 (1201)
  • May 2023 (2369)
  • April 2023 (2849)
  • March 2023 (1637)
  • February 2023 (1153)
  • January 2023 (1234)
  • December 2022 (1086)
  • November 2022 (1005)
  • October 2022 (809)
  • September 2022 (649)
  • August 2022 (778)
  • July 2022 (763)
  • June 2022 (759)
  • May 2022 (802)
  • April 2022 (779)
  • March 2022 (593)
  • February 2022 (493)
  • January 2022 (697)
  • December 2021 (1568)
  • November 2021 (3175)
  • October 2021 (3250)
  • September 2021 (3142)
  • August 2021 (3265)
  • July 2021 (3227)
  • June 2021 (2032)
Powered by Blogger.