package com.drops.poc;

import com.drops.entity.ControllersFactory;
import com.drops.exp.util.H2DatabaseUtil;
import com.drops.ui.MainController;
import com.drops.utils.HTTPUtils;
import com.drops.utils.URLUtil;
import com.drops.utils.Utils;

/**
 * @ClassName: H2DatabaseConsoleJNDIRCEPOC
 * @Description: TODO
 * @Author: Summer
 * @Date: 2021/8/5 13:58
 * @Version: v1.0.0
 * @Description:
 **/
public class H2DatabaseConsoleJNDIRCEPOC {

    private final MainController mainController;


    public H2DatabaseConsoleJNDIRCEPOC() {
        this.mainController = (MainController) ControllersFactory.controllers.get(MainController.class.getSimpleName());

    }

    public boolean hasH2DatabaseConsoleJNDIRCE(String target){
        String rootpath = URLUtil.getROOT(target);
        if (H2DatabaseUtil.hasH2Database(target)){
            int stats = HTTPUtils.getRequest(rootpath + "/h2-console").getStatus();
            if (stats == 200){
                this.mainController.logTextArea.appendText(Utils.log("存在 H2DatabaseConsoleJNDIRCE 漏洞！"));
                return true;
            }
        }

        return false;
    }


}
