|
2 | 2 |
|
3 | 3 | import org.joychou.security.SecurityUtil;
|
4 | 4 | import org.joychou.security.ssrf.SSRFException;
|
| 5 | +import org.joychou.service.HttpService; |
5 | 6 | import org.joychou.util.HttpUtils;
|
6 | 7 | import org.joychou.util.WebUtils;
|
7 | 8 | import org.slf4j.Logger;
|
8 | 9 | import org.slf4j.LoggerFactory;
|
| 10 | +import org.springframework.http.HttpHeaders; |
| 11 | +import org.springframework.http.MediaType; |
9 | 12 | import org.springframework.web.bind.annotation.*;
|
10 | 13 |
|
| 14 | +import javax.annotation.Resource; |
11 | 15 | import javax.servlet.http.HttpServletResponse;
|
12 | 16 | import java.io.*;
|
13 | 17 | import java.net.*;
|
|
23 | 27 | @RequestMapping("/ssrf")
|
24 | 28 | public class SSRF {
|
25 | 29 |
|
26 |
| - private static Logger logger = LoggerFactory.getLogger(SSRF.class); |
| 30 | + private static final Logger logger = LoggerFactory.getLogger(SSRF.class); |
27 | 31 |
|
| 32 | + @Resource |
| 33 | + private HttpService httpService; |
28 | 34 |
|
29 | 35 | /**
|
30 | 36 | * http://localhost:8080/ssrf/urlConnection/vuln?url=file:///etc/passwd
|
@@ -266,4 +272,27 @@ public String HttpSyncClients(@RequestParam("url") String url) {
|
266 | 272 | }
|
267 | 273 |
|
268 | 274 |
|
| 275 | + /** |
| 276 | + * http://127.0.0.1:8080/ssrf/restTemplate/vuln?url=http://www.baidu.com <p> |
| 277 | + * Only support HTTP protocol. <p> |
| 278 | + * Redirects: GET HttpMethod follow redirects by default, other HttpMethods do not follow redirects<p> |
| 279 | + * User-Agent: Java/1.8.0_102 <p> |
| 280 | + */ |
| 281 | + @GetMapping("/restTemplate/vuln1") |
| 282 | + public String RestTemplateUrlBanRedirects(String url){ |
| 283 | + HttpHeaders headers = new HttpHeaders(); |
| 284 | + headers.setContentType(MediaType.APPLICATION_JSON_UTF8); |
| 285 | + return httpService.RequestHttpBanRedirects(url, headers); |
| 286 | + } |
| 287 | + |
| 288 | + |
| 289 | + @GetMapping("/restTemplate/vuln2") |
| 290 | + public String RestTemplateUrl(String url){ |
| 291 | + HttpHeaders headers = new HttpHeaders(); |
| 292 | + headers.setContentType(MediaType.APPLICATION_JSON_UTF8); |
| 293 | + return httpService.RequestHttp(url, headers); |
| 294 | + } |
| 295 | + |
| 296 | + |
| 297 | + |
269 | 298 | }
|
0 commit comments