@@ -53,17 +53,25 @@ public class WebTest {
5353
5454    private  static  final  String  TEST_NAME 
5555        = "request-dispatcher-directory-traversal" ;
56+     private  static  final  String  TEST_NAME2 
57+         = "request-dispatcher-directory-traversal-type2" ;
58+     private  static  final  String  TEST_NAME3 
59+         = "request-dispatcher-directory-traversal-type3" ;
5660
5761    private  static  final  String  EXPECTED  = "This is OK." ;
5862
5963    private  String  host ;
6064    private  String  port ;
6165    private  String  contextRoot ;
66+     private  String  appserverTestPath ;
67+     private  String  adminPort ;
6268
6369    public  WebTest (String [] args ) {
6470        host  = args [0 ];
6571        port  = args [1 ];
6672        contextRoot  = args [2 ];
73+         appserverTestPath  = args [3 ];
74+         adminPort  = args [4 ];
6775    }
6876
6977    public  static  void  main (String [] args ) {
@@ -80,6 +88,18 @@ public void doTest() {
8088            stat .addStatus (TEST_NAME , stat .FAIL );
8189            ex .printStackTrace ();
8290        }
91+         try  {
92+             invokeValidationTestForDoubleDot ();
93+         } catch  (Exception  ex ) {
94+             stat .addStatus (TEST_NAME2 , stat .FAIL );
95+             ex .printStackTrace ();
96+         }
97+         try  {
98+             invokeValidationTestForColon ();
99+         } catch  (Exception  ex ) {
100+             stat .addStatus (TEST_NAME3 , stat .FAIL );
101+             ex .printStackTrace ();
102+         }
83103    }
84104
85105    private  void  invoke () throws  Exception  {
@@ -113,6 +133,7 @@ private void invoke() throws Exception {
113133            } else  {
114134                System .err .println ("Missing expected response: "  + EXPECTED );
115135            }
136+             
116137        } finally  {
117138            try  {
118139                if  (os  != null ) os .close ();
@@ -128,4 +149,89 @@ private void invoke() throws Exception {
128149            } catch  (IOException  ex ) {}
129150        }
130151    }
152+     
153+     private  void  invokeValidationTestForDoubleDot () throws  Exception  {
154+         
155+         Socket  sock  = null ;
156+         OutputStream  os  = null ;
157+         InputStream  is  = null ;
158+         BufferedReader  bis  = null ;
159+         try  {
160+             // Validating the ".." file traversal check 
161+             sock  = new  Socket (host , Integer .valueOf (adminPort ));
162+             os  = sock .getOutputStream ();
163+             String  get  = "GET "  + "/theme/META-INF/%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af" 
164+                     + "%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af" 
165+                     + "%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af" 
166+                     + "%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af" 
167+                     + "%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae%c0%af%c0%ae%c0%ae" 
168+                     + "%c0"  + appserverTestPath  + "/domains/domain1/config/local-password HTTP/1.1\n " ;
169+             System .out .println (get );
170+             os .write (get .getBytes ());
171+             os .write ("Host: localhost\n " .getBytes ());
172+             os .write ("\n " .getBytes ());
173+             is  = sock .getInputStream ();
174+             bis  = new  BufferedReader (new  InputStreamReader (is ));
175+             String  line  = bis .readLine ();
176+             if  (line  != null  && line .contains ("200" )) {
177+                 stat .addStatus (TEST_NAME2 , stat .FAIL );
178+             } else  {
179+                 stat .addStatus (TEST_NAME2 , stat .PASS );
180+             }
181+         }
182+         finally  {
183+             try  {
184+                 if  (os  != null ) os .close ();
185+             } catch  (IOException  ex ) {}
186+             try  {
187+                 if  (is  != null ) is .close ();
188+             } catch  (IOException  ex ) {}
189+             try  {
190+                 if  (sock  != null ) sock .close ();
191+             } catch  (IOException  ex ) {}
192+             try  {
193+                 if  (bis  != null ) bis .close ();
194+             } catch  (IOException  ex ) {}
195+         }
196+     }
197+     
198+     private  void  invokeValidationTestForColon () throws  Exception  {
199+         
200+         Socket  sock  = null ;
201+         OutputStream  os  = null ;
202+         InputStream  is  = null ;
203+         BufferedReader  bis  = null ;
204+         try  {
205+             // Validating the ":" file traversal check 
206+             sock  = new  Socket (host , Integer .valueOf (adminPort ));
207+             os  = sock .getOutputStream ();
208+             String  get  = "GET "  + "/resource/file%3a///etc/passwd/ HTTP/1.1\n " ;
209+             System .out .println (get );
210+             os .write (get .getBytes ());
211+             os .write ("Host: localhost\n " .getBytes ());
212+             os .write ("\n " .getBytes ());
213+             is  = sock .getInputStream ();
214+             bis  = new  BufferedReader (new  InputStreamReader (is ));
215+             String  line  = bis .readLine ();
216+             if  (line  != null  && line .contains ("200" )) {
217+                 stat .addStatus (TEST_NAME3 , stat .FAIL );
218+             } else  {
219+                 stat .addStatus (TEST_NAME3 , stat .PASS );
220+             }
221+         }
222+         finally  {
223+             try  {
224+                 if  (os  != null ) os .close ();
225+             } catch  (IOException  ex ) {}
226+             try  {
227+                 if  (is  != null ) is .close ();
228+             } catch  (IOException  ex ) {}
229+             try  {
230+                 if  (sock  != null ) sock .close ();
231+             } catch  (IOException  ex ) {}
232+             try  {
233+                 if  (bis  != null ) bis .close ();
234+             } catch  (IOException  ex ) {}
235+         }
236+     }
131237}
0 commit comments