Skip to content
KitploitKITPLOIT
उपकरणब्लॉग
जमा करें
उपकरणब्लॉग
जमा करें

हैकिंग, पेनटेस्ट और साइबर सुरक्षा उपकरण आपके सुरक्षा शस्त्रागार के लिए!

Kitploit हैकिंग, साइबर सुरक्षा और पेंटेस्टिंग टूल्स की एक निर्देशिका है। कमजोरियों को खोजने, सिस्टम का विश्लेषण करने, परीक्षण को स्वचालित करने और अपनी सुरक्षा को मजबूत करने के लिए नवीनतम प्रोजेक्ट अपडेट खोजें।

··फ़ीड·संपर्क·गोपनीयता·© 2026 Kitploit

टूल निर्देशिका

श्रेणियाँ

सभी श्रेणियाँ देखें
Loading categories
उपकरण/GitHubGitHub/pandamingx/cve-2020-5421
भेद्यता विश्लेषणकोड विश्लेषणशोषणवेब एप्लिकेशन शोषणपेनिट्रेशन टेस्टिंगलर्निंग और शिक्षा
GitHubpandamingx/cve-2020-5421

CVE-2020-5421

Spring सुरक्षा भेद्यता CVE-2020-5421 पुनरुत्पादन

रिपॉजिटरी देखें
35 साल पहलेअभी तक समीक्षित नहीं

सबसे लोकप्रिय

सभी देखें →

हमारे समुदाय द्वारा सबसे अधिक उपयोग किए जाने वाले उपकरण खोजें।

सभी उपकरण खोजें

हमारे उपकरणों का संग्रह ब्राउज़ करें

सभी उपकरण देखें →
साझा करें

Spring सुरक्षा भेद्यता CVE-2020-5421 पुनरुत्पादन

भेद्यता अवलोकन

CVE-2020-5421, jsessionid पथ पैरामीटर के माध्यम से RFD हमलों से बचाव करने वाली सुरक्षा को बायपास कर सकता है। पहले की RFD सुरक्षा, CVE-2015-5211 से निपटने के लिए जोड़ी गई थी।
RFD क्या है

रिफ्लेक्टेड फ़ाइल डाउनलोड भेद्यता (RFD) एक हमला तकनीक है। किसी विश्वसनीय डोमेन से फ़ाइल को वस्तुतः डाउनलोड कराकर, हमलावर पीड़ित के कंप्यूटर तक पूर्ण पहुँच प्राप्त कर सकता है।

प्रभावित संस्करण

Spring Framework 5.2.0 - 5.2.8
Spring Framework 5.1.0 - 5.1.17
Spring Framework 5.0.0 - 5.0.18
Spring Framework 4.3.0 - 4.3.28

भेद्यता पुनरुत्पादन

github पता: https://github.com/pandaMingx/CVE-2020-5421

संस्करण

SpringBoot-2.1.7.RELEASE, Spring-xxx-5.1.9.RELEASE के आधार पर परीक्षण किया गया।

root@kitploit:~
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

पुनरुत्पादन कोड

root@kitploit:~
@Controller
@RequestMapping(value = "spring")
public class cve20205421 {

    // localhost:8080/spring/input?input=hello
    @RequestMapping("input")
    @ResponseBody
    public String input(String input){
        return input;
    }
}

अतिरिक्त कॉन्फ़िगरेशन

root@kitploit:~
spring.mvc.pathmatch.use-suffix-pattern=true
spring.mvc.contentnegotiation.favor-path-extension=true

URL में ;jsessionid= जोड़ें, जैसे http://localhost:8080/spring/;jsessionid=/input.bat?input=calc, तो input.bat नाम की एक निष्पादन योग्य फ़ाइल डाउनलोड होगी।

भेद्यता विश्लेषण

CVE-2020-5421, CVE-2015-5211 के समाधान को बायपास करने की विधि है। CVE-2015-5211 के समाधान कोड का पता लगाएं: org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor. addContentDispositionHeader

root@kitploit:~
/**
	 * Check if the path has a file extension and whether the extension is
	 * either {@link #WHITELISTED_EXTENSIONS whitelisted} or explicitly
	 * {@link ContentNegotiationManager#getAllFileExtensions() registered}.
	 * If not, and the status is in the 2xx range, a 'Content-Disposition'
	 * header with a safe attachment file name ("f.txt") is added to prevent
	 * RFD exploits.
	 */
	private void addContentDispositionHeader(ServletServerHttpRequest request, ServletServerHttpResponse response) {
		HttpHeaders headers = response.getHeaders();
		if (headers.containsKey(HttpHeaders.CONTENT_DISPOSITION)) {
			return;
		}

		try {
			int status = response.getServletResponse().getStatus();
			if (status < 200 || status > 299) {
				return;
			}
		}
		catch (Throwable ex) {
			// ignore
		}

		HttpServletRequest servletRequest = request.getServletRequest();
		String requestUri = rawUrlPathHelper.getOriginatingRequestUri(servletRequest);

		int index = requestUri.lastIndexOf('/') + 1;
		String filename = requestUri.substring(index);
		String pathParams = "";

		index = filename.indexOf(';');
		if (index != -1) {
			pathParams = filename.substring(index);
			filename = filename.substring(0, index);
		}

		filename = decodingUrlPathHelper.decodeRequestString(servletRequest, filename);
		String ext = StringUtils.getFilenameExtension(filename);

		pathParams = decodingUrlPathHelper.decodeRequestString(servletRequest, pathParams);
		String extInPathParams = StringUtils.getFilenameExtension(pathParams);

		if (!safeExtension(servletRequest, ext) || !safeExtension(servletRequest, extInPathParams)) {
			headers.add(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=f.txt");
		}
	}

rawUrlPathHelper.getOriginatingRequestUri विधि का अनुसरण करने पर, org.springframework.web.util.UrlPathHelper.removeJsessionid विधि मिलती है, जो अनुरोध URL में ;jsessionid= स्ट्रिंग से शुरू करके (या अगले ; से पहले) भाग को काट देती है।

root@kitploit:~
private String removeJsessionid(String requestUri) {
        int startIndex = requestUri.toLowerCase().indexOf(";jsessionid=");
        if (startIndex != -1) {
            int endIndex = requestUri.indexOf(59, startIndex + 12);
            String start = requestUri.substring(0, startIndex);
            requestUri = endIndex != -1 ? start + requestUri.substring(endIndex) : start;
        }

        return requestUri;
    }

चूँकि यह कोड ;jsessionid= को हटा देता है, इसलिए ;jsessionid= हटाने के बाद CVE-2015-5211 का आगामी सुरक्षा कोड अनुरोध के वास्तविक सफ़िक्स फ़ाइल नाम को प्राप्त नहीं कर पाता, जिससे RDF सुरक्षा कोड बायपास हो जाता है।

सुधार सुझाव

भेद्यता पुनरुत्पादन की प्रक्रिया के दौरान, applcation.properties में दो पैरामीटर जोड़े गए: spring.mvc.pathmatch.use-suffix-pattern=true, spring.mvc.contentnegotiation.favor-path-extension=true (SpringBoot में डिफ़ॉल्ट रूप से false है) इससे स्पष्ट है कि CVE-2020-5421 के शोषण के लिए सफ़िक्स मैचिंग मोड और content negotiation तंत्र का सक्षम होना अनिवार्य है। यदि SpringBoot प्रोजेक्ट में ये दोनों मोड सक्षम नहीं हैं, तो भेद्यता के शोषण की स्थिति मौजूद नहीं है, इसलिए इससे निपटने की आवश्यकता नहीं है।
यदि भेद्यता के शोषण की स्थिति मौजूद है, तो यहाँ दो समाधान दिए गए हैं, जिनमें से समाधान 2 उन प्रोजेक्ट्स के लिए उपयुक्त है जहाँ Spring संस्करण अपग्रेड करने का जोखिम अधिक है।

समाधान 1: Spring संस्करण को सुरक्षित संस्करण में अपग्रेड करें

Spring Framework 5.2.9
Spring Framework 5.1.18
Spring Framework 5.0.19
Spring Framework 4.3.29

समाधान 2: सुरक्षा फ़िल्टर जोड़ें

समाधान 2, ;jsessionid= वाले URL के सफ़िक्स की जाँच करेगा कि क्या यह एक सुरक्षित सफ़िक्स है; यदि नहीं, तो Content-Disposition=inline;filename=f.txt सेट की जाती है, जिससे प्रतिक्रिया की सामग्री को f.txt नाम की फ़ाइल में डाउनलोड करने के लिए बाध्य किया जाता है। (यह विधि Spring के RDF सुरक्षा तंत्र के अनुरूप है)

root@kitploit:~
public class SpringJsessionidRdfFilter implements Filter {

    private final Set<String> safeExtensions = new HashSet<>();
    /* Extensions associated with the built-in message converters */
    private static final Set<String> WHITELISTED_EXTENSIONS = new HashSet<>(Arrays.asList(
            "txt", "text", "yml", "properties", "csv",
            "json", "xml", "atom", "rss",
            "png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp"));

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION);
        if (!"".equals(contentDisposition)&&null != contentDisposition) {
            return;
        }

        try {
            int status = response.getStatus();
            if (status < 200 || status > 299) {
                return;
            }
        }
        catch (Throwable ex) {
            // ignore
        }

        String requestUri = request.getRequestURI();

        System.out.println(requestUri);

        if(requestUri.contains(";jsessionid=")){
            int index = requestUri.lastIndexOf('/') + 1;
            String filename = requestUri.substring(index);
            String pathParams = "";

            index = filename.indexOf(';');
            if (index != -1) {
                pathParams = filename.substring(index);
                filename = filename.substring(0, index);
            }

            UrlPathHelper decodingUrlPathHelper = new UrlPathHelper();
            filename = decodingUrlPathHelper.decodeRequestString(request, filename);
            String ext = StringUtils.getFilenameExtension(filename);

            pathParams = decodingUrlPathHelper.decodeRequestString(request, pathParams);
            String extInPathParams = StringUtils.getFilenameExtension(pathParams);

            if (!safeExtension(request, ext) || !safeExtension(request, extInPathParams)) {
                response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=f.txt");
            }
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }

    private boolean safeExtension(HttpServletRequest request, @Nullable String extension) {
        if (!StringUtils.hasText(extension)) {
            return true;
        }
        extension = extension.toLowerCase(Locale.ENGLISH);
        this.safeExtensions.addAll(WHITELISTED_EXTENSIONS);
        if (this.safeExtensions.contains(extension)) {
            return true;
        }
        String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        if (pattern != null && pattern.endsWith("." + extension)) {
            return true;
        }
        if (extension.equals("html")) {
            String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE;
            Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(name);
            if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) {
                return true;
            }
        }
        return false;
    }

}

संदर्भ दस्तावेज़

  • https://www.xf1433.com/4595.html
  • https://www.nsfocus.com.cn/html/2020/39_0921/976.html
  • https://zhuanlan.zhihu.com/p/161166505
  • https://github.com/spring-projects/spring-framework/commit/2281e421915627792a88acb64d0fea51ad138092
टूल डाउनलोड करें