Created
April 22, 2023 00:05
-
-
Save Wind010/d7de6e9b438483061ce6a63cdeccb34d to your computer and use it in GitHub Desktop.
A python script to see if images have residual data after cropping (CVE-2023-21036).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| STANDARD_IEND = b'\x00\x00\x00\x00IEND\xae\x42\x60\x82' | |
| # https://en.wikipedia.org/wiki/PNG | |
| # https://en.wikipedia.org/wiki/ACropalypse | |
| # https://github.com/infobyte/CVE-2023-21036 | |
| # USAGE: detect_bad_crop_simple.py <png1> <png2> ... | |
| if len(sys.argv) == 1: | |
| print(f"Usage: {sys.argv[0]} png_file1 png_file2 ...") | |
| # DEBUG: | |
| #sys.argv.append("./image.png") | |
| sys.exit(1) | |
| for filename in sys.argv[1:]: | |
| try: | |
| with open(filename, "rb") as f: | |
| all_bytes = f.read() | |
| count = all_bytes.count(STANDARD_IEND) | |
| if count > 1: | |
| # Additional data found after footer likely. | |
| print(filename) | |
| except Exception as ex: | |
| print(f"{filename}: {ex}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment