上传文件可以作为一个漏洞来进行攻击,但是目前一般都有检查对应的文件名,不过window下还是有方法可以绕过这个检查的,下面举个例子:
1、 新建一个文件,取名为test.txt
2、 后台MyServlet代码:
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/xml;charset=utf-8");
PrintWriter out = response.getWriter();
String title = request.getParameter("title");
File file = new File(getServletContext().getRealPath("/")+title);
if(!file.exists())
file.createNewFile();
…
}
3、 前台html代码:
<div>
<form action="MyServlet"method="post">
<inputtype="file" name="title" />
<inputtype="submit" value="submit">
</form>
</div>
4、 网页上上传文件处选择该文件,上传完毕后打开Fiddler
5、 Fiddler设置拦截请求
6、 点击submit
7、 Fiddler此时会拦截住这个请求,将里面的文件名修改成test.php:test.jpg,如下:
6、Fiddler中点击Run to Completion,
7、查看后台servlet创建文件路径下生成的文件名,经测试为test.php
总结:
Window下创建文件会过滤掉一些特殊字符,因此像上面的test.php:test.jpg后面的:test.jpg就会被过滤掉,不过要是后台将文件名重命名就无效了。Windows在创建文件时,在文件名末尾不管加多少点都会自动去除,那么上传时filename可以这么写shell.php......
也可以这么写shell.php::$DATA.......
下面是一些网上找来的常用过滤字符: