警惕Redis默认1234端口存在安全漏洞(redis端口号漏洞)
警惕:Redis默认1234端口存在安全漏洞
Redis是一款非常流行的键值对数据库,广泛应用于缓存、实时数据分析、消息队列等场景。然而,在使用Redis时我们也需要注意到其默认1234端口存在安全漏洞。本文将介绍该漏洞的原理和防范措施。
漏洞原理:
Redis的默认端口为6379,但是它也支持其他端口的使用。当在未授权的情况下,通过Redis的1234端口进行访问时,会收到如下提示:
NOAUTH Authentication required.
这表明该端口是需要进行身份验证的,但是如果没有进行身份验证,我们仍然可以获取服务器的信息、配置、数据等敏感信息。以下为相关代码:
$ telnet 127.0.0.1 1234
Trying 127.0.0.1...Connected to 127.0.0.1.
Escape character is '^]'.NOAUTH Authentication required.
INFO# Server
redis_version:6.2.1redis_git_sha1:00000000
redis_git_dirty:0redis_build_id:0f16cb34c58f1d5c
redis_mode:standaloneos:Linux 4.4.0-148-generic x86_64
arch_bits:64multiplexing_api:epoll
atomicvar_api:atomic-builtingcc_version:5.4.0
process_id:25972run_id:690a8c9961de91f091d21e3967df2b9318b9547f
tcp_port:6379uptime_in_seconds:14
uptime_in_days:0hz:10
configured_hz:10lru_clock:2093900
executable:/usr/bin/redis-serverconfig_file:
# Clientsconnected_clients:1
client_recent_max_input_buffer:2client_recent_max_output_buffer:0
blocked_clients:0
# Memoryused_memory:424
used_memory_human:424Bused_memory_rss:434176
used_memory_rss_human:424.07KBused_memory_peak:424
used_memory_peak_human:424Bused_memory_peak_perc:100.00%
used_memory_overhead:384used_memory_startup:858552
used_memory_dataset:40used_memory_dataset_perc:100.00%
allocator_allocated:496allocator_active:512
allocator_resident:16384total_system_memory:8227379712
total_system_memory_human:7.67Gused_memory_lua:0
used_memory_lua_human:0Bused_memory_scripts:0
used_memory_scripts_human:0Bnumber_of_cached_scripts:0
maxmemory:0maxmemory_human:0B
maxmemory_policy:noevictionallocator_frag_ratio:1.03
allocator_frag_bytes:16allocator_rss_ratio:0.03
allocator_rss_bytes:15872rss_overhead_ratio:0.03
rss_overhead_bytes:16384mem_fragmentation_ratio:1022.05
mem_fragmentation_bytes:433752mem_not_counted_for_evict:0
mem_replication_backlog:0mem_clients_slaves:0
mem_clients_normal:0mem_aof_buffer:0
mem_allocator:libcactive_defrag_running:0
lazyfree_pending_objects:0
# Persistenceloading:0
rdb_changes_since_last_save:0rdb_bgsave_in_progress:0
rdb_last_save_time:1621998795rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0aof_enabled:0
aof_rewrite_in_progress:0aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:okaof_last_write_status:ok
aof_last_cow_size:0module_fork_in_progress:0
module_fork_last_cow_size:0
# Statstotal_connections_received:1
total_commands_processed:1instantaneous_ops_per_sec:0
total_net_input_bytes:28total_net_output_bytes:444
instantaneous_input_kbps:0.00instantaneous_output_kbps:0.00
rejected_connections:0rejected_commands:0
expired_keys:0evicted_keys:0
keyspace_hits:0keyspace_misses:0
pubsub_channels:0pubsub_patterns:0
latest_fork_usec:172migrate_cached_sockets:0
# Replicationrole:master
connected_slaves:0master_replid:3f04c4aa4a4b9eafb24658d0ab2a7bba5b5bb5b5
master_replid2:0000000000000000000000000000000000000000master_repl_offset:0
second_repl_offset:-1repl_backlog_active:0
repl_backlog_size:1048576repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPUused_cpu_sys:0.022178
used_cpu_user:0.019325used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
# Clustercluster_enabled:0
# Keyspacedb0:keys=3,expires=0,avg_ttl=0
如上所示,未授权的访问者可以查看到该Redis服务器的所有运行状态,甚至可以进行字符型操作。而这显然是不安全的。
防范措施:
防范Redis的安全问题,主要可以从以下几点来考虑:
1. 修改Redis端口号:我们可以指定Redis默认的端口号,以免更改默认端口造成的不便。例如,修改成夫20799端口:
# vim redis.conf
port 20799
2. 设置Redis密码:我们可以为Redis设置一个旁人无法破解的密码,这样就可以保证访问者无法访问我们的Redis服务器。
# vim redis.conf
requirepass yourredispassword
设置完密码之后我们就需要通过验证才能查看到服务器的信息了:
$ telnet 127.0.0.1 20799
Trying 127.0.0.1...Connected to 127.0.0.1.
Escape character is '^]'.AUTH yourredispassword
+OKINFO
...
以上就是关于警惕Redis默认1234端口存在安全漏洞的一些介绍和注意事项。我们需要时刻关注Redis的安全问题,并进行合理的防范。