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

156 阅读2分钟

图片

【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

安全路上,与你并肩前行!!!!

图片

图片