-
Notifications
You must be signed in to change notification settings - Fork 621
OpenRASP支持InforSuiteAS V10.0代码提交 #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.3.8
Are you sure you want to change the base?
Changes from 8 commits
6f419b5
927ca96
009385b
d063716
155ae40
1d6c4cf
3db0709
aa08870
246d591
8eae8be
38d1263
e20e704
7270f52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright 2017-2022 Baidu Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.baidu.openrasp.detector; | ||
|
|
||
| import com.baidu.openrasp.tool.Reflection; | ||
| import com.baidu.openrasp.tool.model.ApplicationModel; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.security.ProtectionDomain; | ||
|
|
||
| /** | ||
| * Created by inforsuite on 22-2-12. | ||
| */ | ||
| public class InforSuiteDetector extends ServerDetector { | ||
|
|
||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
| return "com/cvicse/loong/enterprise/inforsuite/bootstrap/ASMain".equals(className); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean handleServerInfo(ClassLoader classLoader, ProtectionDomain domain) { | ||
| String version = ""; | ||
| try { | ||
| // if (classLoader == null) { | ||
| // classLoader = ClassLoader.getSystemClassLoader(); | ||
| // } | ||
| classLoader = Thread.currentThread().getContextClassLoader(); | ||
| Class clazz = classLoader.loadClass("com.cvicse.loong.appserv.server.util.Version"); | ||
| if (!isJboss(classLoader)) { | ||
| version = (String) Reflection.invokeMethod(null, clazz, "getFullVersion", new Class[]{}); | ||
| } | ||
| } catch (Throwable t) { | ||
| logDetectError("handle inforsuite startup failed", t); | ||
| } | ||
| if (!isJboss(classLoader)) { | ||
| if(version != null){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加个空格,e.g |
||
| ApplicationModel.setServerInfo("inforsuite", version); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean isJboss(ClassLoader classLoader) { | ||
| Package jbossBootPackage = null; | ||
| try { | ||
| Method getPackageMethod = ClassLoader.class.getDeclaredMethod("getPackage", String.class); | ||
| getPackageMethod.setAccessible(true); | ||
| jbossBootPackage = (Package) getPackageMethod.invoke(classLoader, "org.jboss"); | ||
| if (jbossBootPackage == null) { | ||
| jbossBootPackage = (Package) getPackageMethod.invoke(classLoader, "org.jboss.modules"); | ||
| } | ||
| } catch (Throwable e) { | ||
| // ignore | ||
| } | ||
| return jbossBootPackage != null; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,10 @@ public synchronized static void checkServerPolicy() { | |
| HookHandler.doRealCheckWithoutRequest(CheckParameter.Type.POLICY_SERVER_BES, CheckParameter.EMPTY_MAP); | ||
| } else if ("TongWeb8".equals(serverName)) { | ||
| HookHandler.doRealCheckWithoutRequest(CheckParameter.Type.POLICY_SERVER_TONGWEB8, CheckParameter.EMPTY_MAP); | ||
| }else if ("inforsuite".equals(serverName)){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| HookHandler.doRealCheckWithoutRequest(CheckParameter.Type.POLICY_SERVER_INFORSUITE,CheckParameter.EMPTY_MAP); | ||
| } | ||
|
|
||
| } catch (Throwable t) { | ||
| LogTool.warn(ErrorType.HOOK_ERROR, "failed to do server policy checking: " + t.getMessage(), t); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ private ServerDetectorManager() { | |
| detectors.add(new TongWeb7Detector()); | ||
| detectors.add(new TongWeb8Detector()); | ||
| detectors.add(new BESDetector()); | ||
|
|
||
| detectors.add(new InforSuiteDetector()); | ||
| } | ||
|
|
||
| public static ServerDetectorManager getInstance() { | ||
|
|
@@ -61,10 +61,16 @@ public static ServerDetectorManager getInstance() { | |
| * @param classLoader 该类的加载器 | ||
| */ | ||
| public void detectServer(String className, ClassLoader classLoader, ProtectionDomain domain) { | ||
| try { | ||
| try { | ||
| for (ServerDetector detector : detectors) { | ||
| if (detector.isClassMatched(className) && detector.handleServer(className, classLoader, domain)) { | ||
| HookHandler.LOGGER.info("detect server class: " + className); | ||
| if(className.equals("com/cvicse/loong/enterprise/inforsuite/bootstrap/ASMain")){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码格式调整下, |
||
| detectors.subList(0,13).clear(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里清理detectors的目的是?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. detect server时,区分中创应用服务器和Tomcat。
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么是
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前detects列表中共14个服务器名称,0-13。
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你好,这个代码不能合入,你需要看看是否有其他方式能解决问题
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个代码我做了更新,动态获取。是否可行? |
||
| HookHandler.LOGGER.info("detect server class: " + className); | ||
| break; | ||
| }else{ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| HookHandler.LOGGER.info("detect server class: " + className); | ||
| } | ||
| } | ||
| } | ||
| } catch (Throwable e) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import com.baidu.openrasp.HookHandler; | ||
| import com.baidu.openrasp.config.Config; | ||
| import com.baidu.openrasp.hook.AbstractClassHook; | ||
| import com.baidu.openrasp.hook.server.inforsuite.InforSuiteHttpResponseHook; | ||
| import com.baidu.openrasp.hook.server.weblogic.WeblogicHttpOutputHook; | ||
| import com.baidu.openrasp.hook.server.websphere.WebsphereHttpOutputHook; | ||
| import com.baidu.openrasp.messaging.LogTool; | ||
|
|
@@ -89,6 +90,8 @@ public static void appendResponseData(Object output) { | |
| Object outputStream = Reflection.getField(output, "outputStream"); | ||
| int flag = (Integer) Reflection.getField(outputStream, "state"); | ||
| isClosed = flag == 1; | ||
| }else if("com/cvicse/inforsuite/grizzly/http/io/OutputBuffer".equals(InforSuiteHttpResponseHook.clazzName)){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码格式改下, |
||
| isClosed = (Boolean) Reflection.getSuperField(output, "closed"); | ||
| } else { | ||
| if (serverName.equals("tomcat") && ApplicationModel.getVersion().compareTo("6") < 0) { | ||
| isClosed = (Boolean) Reflection.getField(output, "closed"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright 2017-2022 Baidu Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.baidu.openrasp.hook.server.inforsuite; | ||
|
|
||
| import com.baidu.openrasp.hook.server.ServerRequestHook; | ||
| import com.baidu.openrasp.tool.annotation.HookAnnotation; | ||
| import javassist.CannotCompileException; | ||
| import javassist.CtClass; | ||
| import javassist.NotFoundException; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * @description: inforsuite applicationFilter hook | ||
| * @author: inforsuite | ||
| * @create: 2022/05/20 | ||
| */ | ||
| @HookAnnotation | ||
| public class InforSuiteApplicationFilterHook extends ServerRequestHook { | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#isClassMatched(String) | ||
| */ | ||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
| return className.endsWith("apache/catalina/core/ApplicationFilterChain"); | ||
| } | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#hookMethod(CtClass) | ||
| */ | ||
| @Override | ||
| protected void hookMethod(CtClass ctClass) throws IOException, CannotCompileException, NotFoundException { | ||
| String src = getInvokeStaticSrc(ServerRequestHook.class, "checkRequest", | ||
| "$0,$1,$2", Object.class, Object.class, Object.class); | ||
| insertBefore(ctClass, "doFilter", null, src); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.baidu.openrasp.hook.server.inforsuite; | ||
|
|
||
| import com.baidu.openrasp.hook.server.ServerOutputCloseHook; | ||
| import com.baidu.openrasp.tool.annotation.HookAnnotation; | ||
| import javassist.CannotCompileException; | ||
| import javassist.CtClass; | ||
| import javassist.NotFoundException; | ||
|
|
||
| /** | ||
| * @description: inforsuite output close hook | ||
| * @author: inforsuite | ||
| * @create: 2022/05/20 | ||
| */ | ||
| @HookAnnotation | ||
| public class InforSuiteHttpResponseHook extends ServerOutputCloseHook { | ||
|
|
||
| public static String clazzName = null; | ||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
| if ("com/cvicse/inforsuite/grizzly/http/io/OutputBuffer".equals(className)) { | ||
| clazzName = className; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected void hookMethod(CtClass ctClass, String src) throws NotFoundException, CannotCompileException { | ||
| insertBefore(ctClass, "close", "()V", src); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.baidu.openrasp.hook.server.inforsuite; | ||
|
|
||
| import com.baidu.openrasp.HookHandler; | ||
| import com.baidu.openrasp.hook.server.ServerInputHook; | ||
| import com.baidu.openrasp.messaging.LogTool; | ||
| import com.baidu.openrasp.request.AbstractRequest; | ||
| import com.baidu.openrasp.tool.Reflection; | ||
| import com.baidu.openrasp.tool.annotation.HookAnnotation; | ||
| import com.baidu.openrasp.tool.model.ApplicationModel; | ||
|
|
||
| import javassist.CannotCompileException; | ||
| import javassist.CtClass; | ||
| import javassist.NotFoundException; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * @description: inforsuite input buffer hook,将得到的buffer信息在本类中处理 | ||
| * @author: inforsuite | ||
| * @create: 2022/05/20 | ||
| */ | ||
| @HookAnnotation | ||
| public class InforSuiteInputBufferHook extends ServerInputHook { | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#isClassMatched(String) | ||
| */ | ||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
|
|
||
| if ("com/cvicse/inforsuite/grizzly/http/io/InputBuffer".equals(className)){ | ||
| return true; | ||
| } | ||
| return false; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#hookMethod(CtClass) | ||
| */ | ||
| @Override | ||
| protected void hookMethod(CtClass ctClass) throws IOException, CannotCompileException, NotFoundException { | ||
| String bufferSrc = getInvokeStaticSrc(InforSuiteInputBufferHook.class, "onInputStreamRead", | ||
| "$_", Object.class); | ||
| insertAfter(ctClass, "getBuffer",null, bufferSrc); | ||
| String readSrc = getInvokeStaticSrc(ServerInputHook.class, "onInputStreamRead", | ||
| "$_,$0,$1,$2", int.class, Object.class, byte[].class, int.class); | ||
| insertAfter(ctClass, "read", "([BII)I", readSrc); | ||
| } | ||
|
|
||
| //handle inputStream | ||
| public static void onInputStreamRead(Object inputStream) { | ||
| if (HookHandler.requestCache.get() != null) { | ||
| AbstractRequest request = HookHandler.requestCache.get(); | ||
|
|
||
| if (request.getInputStream() == null) { | ||
| request.setInputStream(inputStream); | ||
| } | ||
| if (request.getInputStream() == inputStream) { | ||
| try { | ||
| byte[] heap = (byte[])Reflection.getSuperField(inputStream, "heap"); | ||
| Integer offset = (Integer) Reflection.getSuperField(inputStream, "offset"); | ||
| Integer cap = (Integer) Reflection.getSuperField(inputStream, "cap"); | ||
| request.appendBody(heap, offset, cap); | ||
| } catch (Exception e) { | ||
| LogTool.traceHookWarn(ApplicationModel.getServerName() + " get request body failed: " + | ||
| e.getMessage(), e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // end | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.baidu.openrasp.hook.server.inforsuite; | ||
|
|
||
| import com.baidu.openrasp.hook.server.ServerPreRequestHook; | ||
| import com.baidu.openrasp.tool.annotation.HookAnnotation; | ||
| import javassist.CannotCompileException; | ||
| import javassist.CtClass; | ||
| import javassist.NotFoundException; | ||
|
|
||
| /** | ||
| * @description: inforsuite pre-request hook | ||
| * @author: inforsuite | ||
| * @create: 2022/05/20 | ||
| */ | ||
| @HookAnnotation | ||
| public class InforSuitePreRequestHook extends ServerPreRequestHook { | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#isClassMatched(String) | ||
| */ | ||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
| return className.endsWith("org/apache/catalina/connector/CoyoteAdapter"); | ||
| } | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see ServerPreRequestHook#hookMethod(CtClass, String) | ||
| */ | ||
| @Override | ||
| protected void hookMethod(CtClass ctClass, String src) throws NotFoundException, CannotCompileException { | ||
| insertBefore(ctClass, "service", null, src); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.baidu.openrasp.hook.server.inforsuite; | ||
|
|
||
| import com.baidu.openrasp.hook.server.ServerRequestEndHook; | ||
| import com.baidu.openrasp.tool.annotation.HookAnnotation; | ||
| import javassist.CannotCompileException; | ||
| import javassist.CtClass; | ||
| import javassist.NotFoundException; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * @description: inforsuite response end hook | ||
| * @author: inforsuite | ||
| * @create: 2022/05/20 | ||
| */ | ||
| @HookAnnotation | ||
| public class InforSuiteRequestEndHook extends ServerRequestEndHook { | ||
|
|
||
| /** | ||
| * (none-javadoc) | ||
| * | ||
| * @see com.baidu.openrasp.hook.AbstractClassHook#isClassMatched(String) | ||
| */ | ||
| @Override | ||
| public boolean isClassMatched(String className) { | ||
| return className.endsWith("org/apache/catalina/core/ApplicationFilterChain"); | ||
| } | ||
|
|
||
| @Override | ||
| protected void hookMethod(CtClass ctClass) throws IOException, CannotCompileException, NotFoundException { | ||
| String requestEndSrc = getInvokeStaticSrc(ServerRequestEndHook.class, "checkRequestEnd", ""); | ||
| insertAfter(ctClass, "doFilter", null, requestEndSrc, true); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释删除