From 6a9bed30954cf6de24ba71f2692b5342fcf59667 Mon Sep 17 00:00:00 2001 From: lovesh-ap Date: Wed, 1 Nov 2023 17:57:12 +0530 Subject: [PATCH] Add mode to operation READ/WRITE/DELETE --- .../instrumentator/dispatcher/Dispatcher.java | 4 +- .../security/schema/helper/RedisCommands.java | 230 ++++++++++++++++++ .../schema/operation/RedisOperation.java | 12 + 3 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/helper/RedisCommands.java diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/dispatcher/Dispatcher.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/dispatcher/Dispatcher.java index 0331eae33..6fcbd18a3 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/dispatcher/Dispatcher.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/dispatcher/Dispatcher.java @@ -242,7 +242,9 @@ private JavaAgentEventBean prepareCachingDataStoreEvent(JavaAgentEventBean event command.put(REDIS_MODE, redisOperation.getMode()); command.put(REDIS_ARGUMENTS, params); command.put(REDIS_TYPE, redisOperation.getType()); - eventBean.setParameters(params); + JSONArray parameter = new JSONArray(); + parameter.add(command); + eventBean.setParameters(parameter); return eventBean; } diff --git a/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/helper/RedisCommands.java b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/helper/RedisCommands.java new file mode 100644 index 000000000..d9f17958e --- /dev/null +++ b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/helper/RedisCommands.java @@ -0,0 +1,230 @@ +package com.newrelic.api.agent.security.schema.helper; + +import java.util.Arrays; +import java.util.List; + +public class RedisCommands { + + public static final List readCommands = Arrays.asList( + "ACL", + "BITCOUNT", + "BITPO", + "CONFIG", + "DBSIZE", + "DUMP", + "ECHO", + "EVAL", + "EVAL_RO", + "EVALSHA", + "EVALSHA_RO", + "EXISTS", + "EXPIRETIME", + "GEODIST", + "GEOHASH", + "GEOPOS", + "GEORADIUS", + "GEORADIUS_RO", + "GEORADIUSBYMEMBER", + "GEORADIUSBYMEMBER_RO", + "GEOSEARCH", + "GET", + "GETBIT", + "GETDEL", + "GETEX", + "GETRANGE", + "GETSET", + "HEXISTS", + "HGET", + "HGETALL", + "HKEYS", + "HLEN", + "HMGET", + "HRANDFIELD", + "HSCAN", + "HSTRLEN", + "HVALS", + "INFO", + "KEYS", + "LINDEX", + "LLEN", + "LPOS", + "LRANGE", + "MEMORY", + "MGET", + "MODULE LIST", + "OBJECT", + "PFCOUNT", + "PTTL", + "RANDOMKEY", + "SCAN", + "SCARD", + "SCRIPT", + "SDIFF", + "SDIFFSTORE", + "SINTER", + "SINTERCARD", + "SINTERSTORE", + "SISMEMBER", + "SLOWLOG", + "SMEMBERS", + "SMISMEMBER", + "SORT", + "SORT_RO", + "SRANDMEMBER", + "SSCAN", + "STRLEN", + "SUNION", + "SUNIONSTORE", + "TOUCH", + "TTL", + "TYPE", + "XACK", + "XINFO", + "XLEN", + "XPENDING", + "XRANGE", + "XREAD", + "XREADGROUP", + "XREVRANGE", + "ZCARD", + "ZCOUNT", + "ZDIFF", + "ZDIFFSTORE", + "ZINTER", + "ZINTERCARD", + "ZLEXCOUNT", + "ZMSCORE", + "ZRANDMEMBER", + "ZRANGE", + "ZRANGEBYLEX", + "ZRANGEBYSCORE", + "ZRANGESTORE", + "ZRANK", + "ZREVRANGE", + "ZREVRANGEBYLEX", + "ZREVRANGEBYSCORE", + "ZREVRANK", + "ZSCAN", + "ZSCORE", + "ZUNION", + "ZUNIONSTORE" + ); + + public static final List writeCommands = Arrays.asList( + "ACL", + "APPEND", + "BITPOS", + "BGREWRITEAOF", + "BITFIELD", + "BITOP", + "BLMOVE", + "BRPOPLPUSH", + "CONFIG", + "COPY", + "DECR", + "DECRBY", + "EVAL", + "EVALSHA", + "EXPIRE", + "EXPIREAT", + "GEOADD", + "GEOSEARCHSTORE", + "GETEX", + "GETSET", + "HINCRBY", + "HINCRBYFLOAT", + "HMSET", + "HSET", + "HSETNX", + "INCR", + "INCRBY", + "INCRBYFLOAT", + "LINSERT", + "LMOVE", + "LPUSH", + "LPUSHX", + "LSET", + "MIGRATE", + "MOVE", + "MSET", + "MSETNX", + "PERSIST", + "PEXPIRE", + "PEXPIREAT", + "PEXPIRETIME", + "PFADD", + "PFMERGE", + "PSETEX", + "RENAME", + "RENAMENX", + "RESTORE", + "RPOPLPUSH", + "RPUSH", + "RPUSHX", + "SADD", + "SCRIPT DEBUG", + "SDIFFSTORE", + "SET", + "SETEX", + "SETBIT", + "SETNX", + "SETRANGE", + "SINTERSTORE", + "SMOVE", + "SUNIONSTORE", + "SWAPDB", + "XADD", + "XAUTOCLAIM", + "XCLAIM", + "XGROUP", + "ZADD", + "ZDIFFSTORE", + "ZINCRBY", + "ZINTERSTORE", + "ZRANGESTORE", + "ZUNIONSTORE" + ); + + public static final List deleteCommands = Arrays.asList( + "ACL", + "BLMPOP", + "BLPOP", + "BRPOP", + "BRPOPLPUSH", + "BZPOPMAX", + "BZPOPMIN", + "DEL", + "DISCARD", + "EVAL", + "EVALSHA", + "FLUSHALL", + "FLUSHDB", + "GETDEL", + "HDEL", + "LMPOP", + "LPOP", + "LREM", + "MEMORY", + "RPOP", + "RPOPLPUSH", + "SCRIPT", + "SLOWLOG", + "SPOP", + "SREM", + "UNLINK", + "LTRIM", + "XDEL", + "XGROUP ", + "XTRIM", + "ZPOPMAX", + "ZPOPMIN", + "ZREM", + "ZREMRANGEBYLEX", + "ZREMRANGEBYRANK", + "ZREMRANGEBYSCORE" + ); + + public static final String READ_COMMAND = "READ"; + public static final String WRITE_COMMAND = "WRITE"; + public static final String DELETE_COMMAND = "DELETE" ; +} diff --git a/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/operation/RedisOperation.java b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/operation/RedisOperation.java index 71e6a01b7..a67731dab 100644 --- a/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/operation/RedisOperation.java +++ b/newrelic-security-api/src/main/java/com/newrelic/api/agent/security/schema/operation/RedisOperation.java @@ -2,6 +2,7 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; +import com.newrelic.api.agent.security.schema.helper.RedisCommands; import java.util.List; @@ -21,6 +22,17 @@ public RedisOperation(String className, String methodName, String type, List