今天看到了這篇文章:
redis未授權訪問缺陷導致系統被黑, http://m.tkk7.com/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 |
切換到普通用戶
后臺啟動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", 4321, 5000, "******");
}
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 閱讀(1090)
評論(0) 編輯 收藏 所屬分類:
NoSql