Yang menarik dari file packet capture ini adalah ada banyak packet ICMP yang memiliki data berupa gambar PNG kecil, seperti yang terlihat pada screenshot di atas.
Maka dari itu, langkah pertama saya adalah mengekstrak semua file-file PNG ini. Untuk itu, saya menjalankan script berikut.
from scapy.all import *
import os
# Read packets from the pcap file
packets = rdpcap("ququerer.pcap")
# To save output files
output_dir = "output_png"
os.makedirs(output_dir, exist_ok=True)
# Filter and print packets that are ICMP and from 127.0.0.1
cnt = 0
for pkt in packets:
if ICMP in pkt and IP in pkt and pkt[IP].src == "127.0.0.1":
if Raw in pkt:
load = pkt[Raw].load[4:]
end_index = load.find(b"\xAE\x42\x60\x82")
if end_index != -1:
new_load = load[:end_index + 4]
# Write into a PNG file
filename = os.path.join(output_dir, f"{cnt:04}.png")
with open(filename, "wb") as f:
f.write(new_load)
cnt += 1
print(new_load)
print("SUCCESS!")
Tampaknya, masing-masing gambar ini adalah bagian dari sebuah QR code. Maka dari itu, langkah berikutnya adalah menggabungkan kesemua gambar yang ada menjadi satu kesatuan. Untuk ini, saya menggunakan script berikut.
from PIL import Image
import os
# Folder containing the PNG files
folder = "output_png"
# Load and sort the images by filename
image_files = sorted([f for f in os.listdir(folder) if f.endswith(".png")])
# Load all images
images = [Image.open(os.path.join(folder, fname)) for fname in image_files]
# Determine total width and total height
width = max(img.width for img in images)
total_height = sum(img.height for img in images)
# Create a new blank image with the total size
combined_image = Image.new("RGBA", (width, total_height))
# Paste each image below the previous one
y_offset = 0
for img in images:
combined_image.paste(img, (0, y_offset))
y_offset += img.height
# Save the combined image
combined_image.save("combined.png")
print("Saved combined image as combined.png")