【Java开发记录】上传zipfile.jsp文件-Tools(四)


 
【Java开发记录】上传zipfile.jsp文件-Tools(四)
Java 上传zipfile编写上传,开始尝试自己写文件上传IO类,尝试很久,效果不是很好,对比了一下目前这个http-request相对方便好用。
在日常的java poc或者exp快速编写可用建议用这个依赖jar包。
 
https://mvnrepository.com/artifact/com.github.kevinsawicki/http-request/6.0
 
 
或者下面直接粘贴到pom.xml里面
 
<!-- https://mvnrepository.com/artifact/com.github.kevinsawicki/http-request --> <dependency> <groupId>com.github.kevinsawicki</groupId> <artifactId>http-request</artifactId> <version>6.0</version> </dependency>
 
 
简单介绍一下这个http-request这个包用法:
GET请求操作:
 
@Test public void getRequest() throws UnsupportedEncodingException { // 如果URL中含有特殊的字符值,那么需要编码一下 String symbolValue = URLEncoder.encode("&", "UTF-8"); String url = "http://www.thelostworld.com/thelostworld.jsp"; HttpRequest httpRequest = HttpRequest.get(url); // 执行请求,并返回请求体数据 String responseBody = httpRequest.body(); int responseCode= httpRequest.code(); System.out.println( "Thelostworld 输出返回请求体:\n"+responseBody); System.out.println( "Thelostworld 输出返回请求状态:\n"+responseCode); }
 
 
POST请求操作:
 
@Test public void postRequestTest() { HttpRequest httpRequest = new HttpRequest("http://www.thelostworld.com/thelostworld.jsp", "POST"); httpRequest.contentType("application/x-www-form-urlencoded", "UTF-8"); // 将请求体信息放入send中 httpRequest.send("data"); System.out.println("thelostworld 输出返回请求体:"+httpRequest.body()); }
 
 
如果POST需要多种参数添加:通过HashMap方式存储相关header参数:
 
@Test public void postRequest() { Map<String,String> Headers=new HashMap<String,String>(); Headers.put("Content-Type","application/x-www-form-urlencoded"); Headers.put("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"); Headers.put("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); Headers.put("Content-Length","10"); String Url= "http://www.thelostworld.com/thelostworld.jsp"; String Data = "data"; HttpRequest res = HttpRequest.post(Url).headers(Headers).send(Data).followRedirects(false).readTimeout(5000); System.out.println(String.format("Thelostworld 输出返回请求状态:%s",res.code())); System.out.println(String.format("Thelostworld 输出返回请求体:%s",res.body())); }
 
 
本次测试主要用到request.part()方法:
 
 
测试zip上传:上传前访问文件
 
 
尝试访问上传zip cmd小🐎文件:
 
 
后台打印上传和访问jsp的状态均为200
 
 
浏览器尝试访问页面是否存在:
访问路径现在页面存在:
 
 
也可通过前面的POST的命令执行方式进行验证:
 
 
注意:⚠️
免责声明:本站提供安全工具、程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!
如果本文内容侵权或者对贵公司业务或者其他有影响,请联系作者删除。
转载声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
订阅查看更多复现文章、学习笔记
thelostworld
安全路上,与你并肩前行!!!!
 
个人知乎:https://www.zhihu.com/people/fu-wei-43-69/columns 个人简书:https://www.jianshu.com/u/bf0e38a8d400 个人CSDN:https://blog.csdn.net/qq_37602797/category_10169006.html 个人博客园:https://www.cnblogs.com/thelostworld/ FREEBUF主页:https://www.freebuf.com/author/thelostworld?type=article 语雀博客主页:https://www.yuque.com/thelostworld
 
 
欢迎添加本公众号作者微信交流,添加时备注一下“公众号”
 
 
 
 
本文使用 文章同步助手 同步
posted @ 2021-09-23 09:32  thelostworld  阅读(115)  评论(0编辑  收藏  举报