posts - 167,  comments - 30,  trackbacks - 0
          今天看到了這篇文章:redis未授權訪問缺陷導致系統被黑, http://www.aygfsteel.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


          切換到普通用戶


          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 閱讀(1095) 評論(0)  編輯  收藏 所屬分類: NoSql

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

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

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          Java

          Linux知識相關

          Spring相關

          云計算/Linux/虛擬化技術/

          友情博客

          多線程并發編程

          開源技術

          持久層技術相關

          搜索

          •  

          積分與排名

          • 積分 - 359152
          • 排名 - 154

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 伊金霍洛旗| 潍坊市| 武邑县| 仁化县| 原阳县| 靖宇县| 珠海市| 汾阳市| 荆门市| 蕉岭县| 高雄市| 万荣县| 驻马店市| 崇义县| 德保县| 招远市| 衡山县| 安远县| 松江区| 五原县| 安康市| 改则县| 淮南市| 察哈| 沾化县| 宁阳县| 抚宁县| 广宁县| 龙胜| 平舆县| 西安市| 井陉县| 闽侯县| 仲巴县| 阿拉善右旗| 衡山县| 醴陵市| 仁怀市| 长治县| 五台县| 斗六市|