posts - 167,  comments - 30,  trackbacks - 0
今天看到了这篇文章:redis未授权访问缺陷导致系统被黑, http://www.blogjava.net/writegull/archive/2015/12/15/428651.html
想起了前段时间也补过这个漏洞,不过没有像楼主服务器遭受到攻击!

总结下修复漏洞方案:

Redis服务器配置不当的体现:

1、redis服务已root账户/权限启动;

2、redis服务无需密码或弱密码进行认证;

3、redis服务器本身对互联网开放了SSH服务,允许key方式登录。


修复方案:

1、不要以root用户允许redis

2、修改运行redis的端口,编辑配置文件(/etc/redis.conf)

port 4321

3、如果只需要本地访问,编辑配置文件(/etc/redis.conf)

bind 127.0.0.1

4、设定密码,编辑配置文件

requirepass ******

5、在启动的时候需要指定配置文件的路径,这些设置才会生效

redis-server /etc/redis.conf

Redis安全配置参考:

http://wiki.wooyun.org/server:redis

服务器上操作过程大家可参考:

第一步:

非root权限启动,建立普通用户并设置密码,redis-server和redis.conf宿主权限修改为普通用户。


[root@cdn bin]# chown -R ugcstore:root /usr/loca/bin/redis-server 

[root@cdn bin]# chown -R ugcstore:root /usr/local/redis/redis.conf


切换到普通用户


su - ugcstore


后台启动redis:


nohup redis-server /usr/local/redis/redis.conf &


查看redis进程,验证宿主用户


ps -ef |grep redis

ugcstore 17602     1  0 22:06 ?        00:00:01 redis-server x.x.x.x:4321       


第二步:

一般是在/etc/redis.conf,如果/etc下没有找到,find搜索下.

操作的服务器redis.conf文件位置: /usr/local/redis/redis.conf


port 4321 #修改端口

requirepass ****** #设置密码

bind x.x.x.x  # 非本机可访问 



第三步:

调整连接redis的程序,设置密码,验证程序是否能正确获取数据.

测试数据:key:foo value:bar


[root@cdn ugc]# telnet x.x.x.x 4321

Trying 65.255.33.64...

Connected to 65.255.33.64.

Escape character is '^]'.

auth E38faeQGtxr##rOP

+OK

set foo bar

+OK

get foo

$3

bar



PHP程序测试:

/data/vfetch/public/test.php

<?php
/**
 * @author david
 
*/

/**
 * 创建redis链接
 
*/
function createConn()
{
    
try
    {
        
$redis=new Redis;
        
$redis->connect('x.x.x.x', 4321);
        
$redis->auth('******');
        
return $redis;
    }
    
catch(RedisException $e)
    {
        
return false;
    }

}

$rediss = createConn();
echo $rediss->get('foo');



Java程序测试:

public class JedisTest {
    
static JedisPool pool = null;

    
public static JedisPool getPool() {
        
if (pool == null) {
            JedisPoolConfig config 
= new JedisPoolConfig();
            config.setMaxActive(
500);
            config.setMaxIdle(
20);
            config.setMaxWait(
1000 * 30);
            config.setTestOnBorrow(
true);
            pool 
= new JedisPool(config, "x.x.x.x"43215000"******");
        }
        System.out.println(pool);
        
return pool;
    }

    
public static void close(JedisPool pool, Jedis redis) {
        
if (redis != null) {
            pool.returnResource(redis);
        }
    }

    
public static String get(String key) {
        String value 
= null;
        JedisPool pool 
= null;
        Jedis jedis 
= null;
        
try {
            pool 
= getPool();
            jedis 
= pool.getResource();
            value 
= jedis.get(key);
        } 
catch (Exception e) {
            pool.returnBrokenResource(jedis);
        } 
finally {
            close(pool, jedis);
        }
        
return value;
    }

    
public static void main(String[] args) {
        System.out.println(get(
"foo"));
    }
}
posted on 2015-12-27 16:49 David1228 阅读(1068) 评论(0)  编辑  收藏 所属分类: NoSql

只有注册用户登录后才能发表评论。


网站导航:
 

<2015年12月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

新闻分类

新闻档案

相册

收藏夹

Java

Linux知识相关

Spring相关

云计算/Linux/虚拟化技术/

友情博客

多线程并发编程

开源技术

持久层技术相关

搜索

  •  

积分与排名

  • 积分 - 353972
  • 排名 - 155

最新评论

阅读排行榜

评论排行榜