Loading...
Searching...
No Matches
getrawdata.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief testing getrawdata service - input validation (security)
4 @details table must be a well-formed LIBREF.DATASET (the trailing
5 format-catalog suffix is permitted), filter must be an integer and
6 type one of the supported download types. An invalid value aborts
7 the service before any request content can execute. The abort is
8 asserted from the child job state: the payloads either resolve to a
9 real table when executed as macro code, or write a file outside the
10 WORK directory (verified by live probe) - so on the vulnerable
11 service the job completes, and only the validating service cancels
12 it. The assertion cannot pass against a service that does not
13 validate.
14
15 <h4> SAS Macros </h4>
16 @li mpe_assert_abort.sas
17 @li mp_assert.sas
18 @li mpe_execute.sas
19
20**/
21
22%let _program=&appLoc/services/public/getrawdata;
23
24/**
25 * Test 1 - macro content in table must abort the service
26 * (the payload resolves to a real table when executed as macro code)
27 */
28data work.params1;
29 length name $32 value $1000;
30 name='type';value='CSV';output;
31 name='table';value='%sysfunc(coalescec(&mpelib..MPE_X_TEST,))';output;
32 name='filter';value='0';output;
33run;
34
35%mpe_execute(&_program,
36 viyacontext=&defaultcontext,
37 inputparams=work.params1,
38 outref=web1,
39 outstatus=work.ab1,
40 failfast=0,
41 viyaresult=WEBOUT_TXT
42)
43
44%mpe_assert_abort(
45 desc=Macro content in table aborts the service,
46 outstatus=work.ab1,
47 msg=Invalid table
48)
49
50/**
51 * Test 2 - sql injection in filter must abort the service
52 */
53data work.params2;
54 length name $32 value $1000;
55 name='type';value='CSV';output;
56 name='table';value="&dclib..MPE_X_TEST";output;
57 name='filter';value='0 or 1=1';output;
58run;
59
60%mpe_execute(&_program,
61 viyacontext=&defaultcontext,
62 inputparams=work.params2,
63 outref=web2,
64 outstatus=work.ab2,
65 failfast=0,
66 viyaresult=WEBOUT_TXT
67)
68
69%mpe_assert_abort(
70 desc=SQL injection in filter aborts the service,
71 outstatus=work.ab2,
72 msg=Invalid filter
73)
74
75/**
76 * Test 3 - path traversal in table must abort the service
77 * (verified by live probe: on a vulnerable service this writes
78 * ../SECPROBE.csv outside the WORK directory and completes)
79 */
80data work.params3;
81 length name $32 value $1000;
82 name='type';value='CSV';output;
83 name='table';value='../secprobe';output;
84 name='filter';value='0';output;
85run;
86
87%mpe_execute(&_program,
88 viyacontext=&defaultcontext,
89 inputparams=work.params3,
90 outref=web3,
91 outstatus=work.ab3,
92 failfast=0,
93 viyaresult=WEBOUT_TXT
94)
95
96%mpe_assert_abort(
97 desc=Path traversal in table aborts the service,
98 outstatus=work.ab3,
99 msg=Invalid table
100)
101
102/**
103 * Test 4 - the valid request must still work (positive control)
104 */
105data work.params4;
106 length name $32 value $1000;
107 name='type';value='CSV';output;
108 name='table';value="&dclib..MPE_X_TEST";output;
109 name='filter';value='0';output;
110run;
111
112%mpe_execute(&_program,
113 viyacontext=&defaultcontext,
114 inputparams=work.params4,
115 outref=web4,
116 viyaresult=WEBOUT_TXT
117)
118
119%let ok4=0;
120data _null_;
121 infile web4;
122 input;
123 if _infile_=:'PRIMARY_KEY_FIELD' then do;
124 call symputx('ok4',1);
125 stop;
126 end;
127run;
128
129%mp_assert(
130 iftrue=(&ok4=1),
131 desc=Valid table request still returns data,
132 outds=work.test_results
133)
134
135/**
136 * dump results to the log for offline inspection
137 */
138data _null_;
139 set work.test_results;
140 putlog 'TEST_RESULT_LINE: ' test_result ' - ' test_description;
141run;