JDK 是 1.7 的ssrf可能存在gopher file ftp http https jar mailto netdoc 八种利用协议
其中最有意思的是 gopher 协议,可以用来构造其它协议的请求。但是,gopher 在 JDK8 中已经被移除
1、URLConnection
HttpURLConnection.connect
HttpURLConnection.getInputStream
URLConnection //如果只有这个可以File://读文件
URL.openStream //回显
2、org.apache.http.client.HttpClien
HttpClient.execute
HttpClient.executeMethod
3、javax.imageio.ImageIO类,该类是JDK自带的类,用于操作图片
ImageIO.createImageInputStream
createImageInputStream
ImageIO.read
ImageIO.write
之前遇到过这个的真实漏洞,能判断任意文件是否存在,比较低危
4、OkHttp
client.newCall(request).execute();
5、HttpRequest
HttpRequest.get(URL)
RequestBuilder
6、BasicHttpEntityEnclosingRequest 该类是HttpRequest 的最底层的本质
7、parseProxyAddress/ProxyAddress
看了一些代码,发现存在这样一个方法很爱用,就是获取代理的方法,想从代理获取地址,从而造成的SSRF
例如存在CVE-2019-9827
这个漏洞其实是比较鸡肋的。首先他parseProxyAddress获取了URL地址后,通过whitelist.isAllowed() 判判断URL是否为 localhost、127.0.0.1或者用户自己更新的白名单列表,那么大概率就是只能ssrf本地的端口了。
<%
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
response.setContentType("text/xml; charset=GBK");
String rssUrl = request.getParameter("rssUrl");
String charEncode = request.getParameter("charEncode");
//关键代码从这里里开始
URL url = new URL(rssUrl);
//利用URL类构造一个url对象,该对象由rssUrl实例化
HttpURLConnection con = (HttpURLConnection) url.openConnection();
//利用url的openConnection方法获取一个HttpURLConnection的实例
//这里限定了HTTP协议,如果不限定就是URLConnection
String line = null;
InputStream in = con.getInputStream();
//调用getInputStream拿到InputStream,如果rssURl可控,就存在ssrf
BufferedReader br = new BufferedReader(new InputStreamReader(in,charEncode));
out.clearBuffer();
while((line=br.readLine())!=null){
//System.out.println("=============="+line);
out.println(line);
}
in.close();
con.disconnect();
%>
ssrf里的文件下载(当为ssrf漏洞并且设置了attachment)SSRF就变成了任意文件下载了
url=file:///c:%5c%5c1.txt
参考资料
https://www.cnblogs.com/nice0e3/p/13683023.html
https://www.cnblogs.com/nice0e3/p/13682434.html
https://note.youdao.com/ynoteshare1/index.html?id=caa2f6ef1819b5c561c2f1efb6c941de&type=note
https://xz.aliyun.com/t/206/
https://xz.aliyun.com/t/2761#toc-1
https://xz.aliyun.com/t/7186#toc-6
修复方式:
1、避免回显
2、使用白名单校验HTTP请求地址
3、禁用用不到的协议