【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

图片

欢迎添加本公众号作者微信交流,添加时备注一下“公众号”

图片

图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值