警惕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.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:0f16cb34c58f1d5c
redis_mode:standalone
os:Linux 4.4.0-148-generic x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:5.4.0
process_id:25972
run_id:690a8c9961de91f091d21e3967df2b9318b9547f
tcp_port:6379
uptime_in_seconds:14
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:2093900
executable:/usr/bin/redis-server
config_file:
# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0

# Memory
used_memory:424
used_memory_human:424B
used_memory_rss:434176
used_memory_rss_human:424.07KB
used_memory_peak:424
used_memory_peak_human:424B
used_memory_peak_perc:100.00%
used_memory_overhead:384
used_memory_startup:858552
used_memory_dataset:40
used_memory_dataset_perc:100.00%
allocator_allocated:496
allocator_active:512
allocator_resident:16384
total_system_memory:8227379712
total_system_memory_human:7.67G
used_memory_lua:0
used_memory_lua_human:0B
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.03
allocator_frag_bytes:16
allocator_rss_ratio:0.03
allocator_rss_bytes:15872
rss_overhead_ratio:0.03
rss_overhead_bytes:16384
mem_fragmentation_ratio:1022.05
mem_fragmentation_bytes:433752
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:0
mem_aof_buffer:0
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1621998795
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:28
total_net_output_bytes:444
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
rejected_commands:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:172
migrate_cached_sockets:0
# Replication
role:master
connected_slaves:0
master_replid:3f04c4aa4a4b9eafb24658d0ab2a7bba5b5bb5b5
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.022178
used_cpu_user:0.019325
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000

# Cluster
cluster_enabled:0
# Keyspace
db0: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
+OK
INFO
...

以上就是关于警惕Redis默认1234端口存在安全漏洞的一些介绍和注意事项。我们需要时刻关注Redis的安全问题,并进行合理的防范。


数据运维技术 » 警惕Redis默认1234端口存在安全漏洞(redis端口号漏洞)