memcachedã®éæ¾ãã¼ã(11211/tcp, 11211/udp)ããµã¯ã£ã¨ç¢ºèªãã
æ¨æ¥(2018/02/27)ã«ãJPCERTããmemcached のアクセス制御に関する注意喚起ãåºã¦ãã¾ããã
ã¨ãããã¨ã§memcachedã®ãã¼ã(11211/tcp, 11211/udp)ãéæ¾ããã¦ããªããã®ç¢ºèªæ¹æ³ã«ã¤ãã¦ã¡ã¢ãã¦ããã¾ãã
memcachedéæ¾ã«ããèµ·ããåé¡
ã¯ããã«ãmemcachedã®ãã¼ããå¤é¨ããæ¥ç¶å¯è½ã«ãã¦ãã¾ãã¨ä½ãåé¡ãæ´çãã¾ãããã
å é¨æ å ±ã®æ¼æ´©
1ã¤ã¯ããã«æãä»ããã¨ã§ãããå é¨æ å ±ã®æ¼æ´©ã§ããmemcachedã¯èªè¨¼ã®ç¡ããããã³ã«ã§ãããã(æ£ç¢ºã«ã¯ãããã©ã誰ã(?)使ã£ã¦ãªã)ãå¤é¨ããæ¥ç¶ã§ããã°å³ãã£ãã·ã¥ä¸ã®å¤ãåå¾ãããã¨ãã§ãã¾ãã
ãã¨ãã°php.iniã§ä»¥ä¸ã®ããã«è¨å®ãã¦ããã°ã
session.save_handler = memcached session.save_path = "localhost:11211â
ã»ãã·ã§ã³æ å ±ãå¤é¨ããåå¾å¯è½ã¨ãªã£ã¦ãã¾ãã¾ãããã®ä»ããã£ãã·ã¥ã«ä¹ã£ã¦ããå¤ãæ ¹ãããåå¾ã§ãã¦ãã¾ãã¾ãã
UDP Reflection Attackã®è¸ã¿å°ã¨ãªã
2018å¹´2æç¾å¨ã¯ãæ å ±æ¼æ´©ããããã¡ãã®è¢«å®³ãåé¡è¦ããã¦ãã¾ãã
UDPã¯ã³ãã¯ã·ã§ã³ã¬ã¹ã§ããéä¿¡å
å½è£
ã容æãªããããªã¯ã¨ã¹ãã«å¯¾ãã¦ã¬ã¹ãã³ã¹ã大ãããããã³ã«ã¯ãå½è£
ããéä¿¡å
(=æ»æå
)ã¸ã®ãè·³ãè¿ããã«ããDDoSæ»æã«å©ç¨ã§ãã¾ãã
ãã¨ãã°æ°å¹´åã«ã¯ãntpã®monlistæ©è½ã§ãã®ãããªDDoSãææãããæ»æè
ã«å©ç¨ããã¦ãã¾ãã¾ããã(åè:ntpd の monlist 機能を使った DDoS 攻撃に関する注意喚起)
memcachedã§ããªã¯ã¨ã¹ãã«å¯¾ãã¦ã¬ã¹ãã³ã¹ã大ããããã¨ã§ããæãã¤ãã®ã¯ãç¶æ 表示ããããªãstatsã³ãã³ãã§ãããã
# printf "stats\r\n" | nc 192.168.2.67 11211 STAT pid 10330 STAT uptime 5559 STAT time 1519825560 STAT version 1.4.15 STAT libevent 2.0.21-stable STAT pointer_size 64 STAT rusage_user 0.055732 STAT rusage_system 0.057469 STAT curr_connections 10 STAT total_connections 37 STAT connection_structures 11 STAT reserved_fds 20 STAT cmd_get 11 STAT cmd_set 6 ...(ç¥)... END
ä¸è¨ã®ä¾ã®ããã«ãstatsã¨ããã³ãã³ãã ãã§å¤§éã®ã¬ã¹ãã³ã¹ãå¾ããã¾ãããªãmemcachedã¯CRLFãæ¹è¡ã¨ã¿ãªãã®ã§ããã®ä¾ã¯å¾åã«printfã§"\r\n"ãä»ãã¦ã¾ãã
ããã«ã(詳ããæä½ã¯å¿µã®ããä¼ãã¾ãã)å¤é¨ããmemcachedãæä½å¯è½ãªãã°ãé©å½ãªkeyã«ã¨ã¦ãé·ãå¤ãsetãã¦ãéä¿¡å ãå½è£ ããUDPéä¿¡ã§getããã ãã§ã大ããã¬ã¹ãã³ã¹ãå½è£ å ã¸éãã¤ãããã¨ãã§ãã¾ãããã®ãã memcachedã®UDPãã¼ããå¤é¨ã«éæ¾ãã¦ããã¨ãUDP Reflection Attackã«ããDDoSã¸è¸ã¿å°ã¨ãã¦è·æ ãã¦ãã¾ããã¨ã«ãªãã¾ãã
memchacedã§UDPãoffã«ããã«ã¯ãã-U 0ãã¨ãããªãã·ã§ã³ãä»å ãã¾ããCentOS 7ã®ããã±ã¼ã¸ãªãã°ã以ä¸ã®ããã« /etc/sysconfig/memcached ãã¡ã¤ã«ã®ãOPTIONSãã«è¨è¿°ãã¾ãã
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS="-U 0"
ãã®ã-Uãã¯æ¬æ¥ã¯UDPã®å¾ ã¡åããã¼ããæå®ãããªãã·ã§ã³ãªã®ã§ãããmanã«è¨è¼ã®éããã¼ããæå®ããã¨UDPã®LISTENèªä½ãOFFã«ãã¾ãã
ãã¼ãéæ¾ã®ç¢ºèª
memcachedã¯ãTCPã»UDPã¨ãã«11211ãã¼ããããã©ã«ãã§å©ç¨ããã¾ããé常ã¯TCPãã使ãããªããããUDPã¯æ示çã«æèããªãéã使ããã¨ã¯ãªãã§ãããã
ãããmemcachedããã©ã«ãã§ã¯TCPã ãã§ãªãUDPãéæ¾ããããã(memcached 1.5.6ããã¯UDPã¯ããã©ã«ãã§ã¯ç¡å¹ããã)ãç¹ã«UDPã®ãã£ã«ã¿ã¯è¦è½ã¨ããã¡ã§ãã
ããããã¯ãå¤é¨ã¸æ¬å½ã«ãã¼ãéæ¾ãã¦ããªããã確èªããæ¹æ³ãè¨è¿°ãã¾ãããªããã¡ãã«æ¸ããææ³ã¯ãã¼ãã¹ãã£ã³ã«å½ãããããå¿ ãèªãã管çãããã¹ãã®ã¿ã«è¡ãã第ä¸è ã®ãã¹ãã»ãããã¯ã¼ã¯ãã¹ãã£ã³ãããã¨ã®ç¡ãããã«ãã¦ãã ããã
nmapãå©ç¨
ãã¼ã確èªãªãã°ãã¾ãæãã¤ãã®ã¯nmapã§ãããã
TCPãã¼ããopenãã¦ããã確èªããã ããªãã°ãSYNã¹ãã£ã³(-sS)ããã ãã§ååã§ããåºåã¯-oNãªãã·ã§ã³ã§ããã¹ãã«è½ã¨ãã¦ããã¨è¯ãã§ããããããã§ã¯192.168.2.0/24ãã¹ãã£ã³ãããªãã·ã§ã³ã«ã¯-nãä»ãã¦éå¼ãããªãããã«ãã¦ãã¾ãã
# nmap -n -sS -p11211 -oN output.txt 192.168.2.0/24
åºåã«ã¯closedãfilteredã®ãã®ãæ··ããã®ã§ãopenãæ¤ç´¢ãã¾ãã
...(ç¥)... Nmap scan report for 192.168.2.65 Host is up (0.000091s latency). PORT STATE SERVICE 11211/tcp filtered memcache MAC Address: E0:3F:49:XX:XX:XX (Asustek Computer) Nmap scan report for 192.168.2.67 Host is up (0.00014s latency). PORT STATE SERVICE 11211/tcp open memcache MAC Address: 00:0C:29:CC:C7:B0 (VMware) Nmap scan report for 192.168.2.99 Host is up (0.00022s latency). ...(ç¥)...
TCPã1ãã¼ãã ãã®ãã¼ãã¹ãã£ã³ãªãã°ãç¸å½åºããããã¯ã¼ã¯å¸¯ã§ãã£ã¦ãæ°ç§〜æ°åã§çµããã§ãããã
ãã¦11211/tcpã®éæ¾ãã§ãã¯ã¯ç°¡åã§ãããUDPã¨ãªãã¨å°ã ãã£ããã§ããå¨ç¥ã®éããUDPã®ãã¼ãã¹ãã£ã³ã¯å¾ã ã«ãã¦ä¸æ£ç¢ºã§ãnmapã®UDPã¹ãã£ã³ãªãã·ã§ã³ã§ãã-sUããã ãã§ã¯æ¬¡ã®ããã«ãopen|filteredãã¨ãªãè¦éãã¦ãã¾ãã¾ãã
# nmap -n -sU -p11211 192.168.2.67 Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-28 22:58 JST Nmap scan report for 192.168.2.67 Host is up (0.00018s latency). PORT STATE SERVICE 11211/udp open|filtered memcache MAC Address: 00:0C:29:CC:C7:B0 (VMware) Nmap done: 1 IP address (1 host up) scanned in 0.24 seconds
ãã®ããnmapã«ããUDPã¹ãã£ã³ã®å ´åã¯ãå°ã å¿çæéãå¢ãã¾ããã-sVã§ãã¼ã¸ã§ã³æ¤åºãä»å ããã¨æ£ããOpenãå¤æãã¦ããã¾ãã
# nmap -n -sU -sV -p11211 192.168.2.67 Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-28 23:01 JST Nmap scan report for 192.168.2.67 Host is up (0.00018s latency). PORT STATE SERVICE VERSION 11211/udp open memcached Memcached 1.4.15 MAC Address: 00:0C:29:CC:C7:B0 (VMware) Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 0.48 seconds
ãã®éããã±ãããã£ããã£ãã¦ã¿ãã¨ã以ä¸ã®ããã«UDPä¸ã§ãstatsãã³ãã³ããæã£ã¦ãããã¨ãåããã¾ãã
ãªããUDPã¹ãã£ã³ã¯ã¨ã¦ãé ãã¹ãã£ã³ã§ããç¹ã«å¯¾è±¡UDPãã¼ãããå¿çãç¡ãå ´åãä¸è¨ã®ãªãã·ã§ã³ã®ã¾ã¾ã§ã¯ã¿ã¤ã ã¢ã¦ãå¾ ã¡ã¨ãªã1å以ä¸ãããã®ãæ®éã§ããç¾å ´ã§ã¯æ¬¡ã®ããã«ã-Pn(ICMPãªã©ã«ããhost discoveryãè¡ããªã)ã--host-timeout(ä½ç§ã§ãããããã)ãåæã«æå®ãã¦é«éåãå³ãã¨è¯ãã§ãããã
# nmap -n -Pn --host-timeout 3 -sU -sV -p11211 192.168.2.67
æ¥æ¬èªã®manã§ã¯host-timeoutã®å¼æ°ã¯ãããªç§ãã¨æ¸ããã¦ãã¾ããããã®è¨è¿°ã¯å¤ããç¾å¨ã®åä½ã¯ãç§ãã§ãã3ç§ã¨ããã®ã¯ã¢ã°ã¬ãã·ããããæ°ããã¾ãããå ã memcachedã¯é«éå¿çããªãã¨æå³ããªããããã³ã«ã®ããããããªããã§ããããç°è«ã¯èªããã
ã¡ãªã¿ã«nmapã§ãã£ã¨è©³ç´°æ å ±ãå¾ããå ´åãmemcached-infoã¨ããnseã¹ã¯ãªãããå©ç¨ã§ãã¾ãã
# nmap -p11211 --script memcached-info 192.168.2.67 Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-28 23:12 JST Nmap scan report for 192.168.2.67 Host is up (0.00020s latency). PORT STATE SERVICE 11211/tcp open memcache | memcached-info: | Process ID 10330 | Uptime 7147 seconds | Server time 2018-02-28T14:12:28 | Architecture 64 bit | Used CPU (user) 0.077393 | Used CPU (system) 0.066839 | Current connections 10 | Total connections 42 | Maximum connections 1024 | TCP Port 11211 | UDP Port 11211 |_ Authentication no MAC Address: 00:0C:29:CC:C7:B0 (VMware) Nmap done: 1 IP address (1 host up) scanned in 1.19 seconds
nc(netcat)ãå©ç¨
æ¬å½ã«ã¡ããã£ã¨ç¢ºèªãããã ããªãã°ãnc(netcat)ã便å©ã§ãã以ä¸ã®ããã«11211ã«æ¥ç¶ã§ãããã©ããã§ããã¼ãéæ¾ãå¤æã§ãã¾ãã
$ nc 192.168.2.67 11211 stats â ã³ãã³ããæ㤠STAT pid 10330 â çµæãè¿ã STAT uptime 7382 STAT time 1519827383 STAT version 1.4.15 STAT libevent 2.0.21-stable ...(ç¥)...
ãªãnc(netcat)ã«ã¯UDPã¢ã¼ããããã¾ãããã³ãã³ãã©ã¤ã³ããUDPã§æ¥ç¶ãã¦TCPåæ§ã«æã§ã³ãã³ããæã£ã¦ãæ£ããåä½ãã¾ããã次ã®ããã«statsã³ãã³ããçµã¿ç«ã¦ãå¿ è¦ãããã¾ãã
# echo -en "\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n" | nc -u 192.168.2.67 11211
â»ä¸è¨ã³ãã³ãã¯Cloudflareã®ããã°è¨äºãMemcrashed - Major amplification attacks from UDP port 11211ãåèã«ããã¦é ãã¾ããã
ãã®ä»ã®ãã¼ã«é¡
memcached-toolãå©ç¨
memcached-toolã¯ãPerlã§æ¸ãããmemcachedæä½ãã¼ã«ã§ãã
åç¬ã®ã¹ã¯ãªãããªã®ã§ããã®ãã¡ã¤ã«1ã¤ããã¦ã³ãã¼ããã¦Perlã§å®è¡ããã ãã§æ°è»½ã«è©¦ãã¾ãããã ããæ¥ç¶ã¯TCPã®ã¿ãµãã¼ããã¦ãããããUDPã®ç¢ºèªã¯ã§ãã¾ããã
å¼æ°ãªãã§å®è¡ããã¨ãã«ããåºã¾ãã
# perl memcached-tool Usage: memcached-tool <host[:port] | /path/to/socket> [mode] memcached-tool 10.0.0.5:11211 display # shows slabs memcached-tool 10.0.0.5:11211 # same. (default is display) memcached-tool 10.0.0.5:11211 stats # shows general stats memcached-tool 10.0.0.5:11211 settings # shows settings stats memcached-tool 10.0.0.5:11211 sizes # shows sizes stats memcached-tool 10.0.0.5:11211 dump # dumps keys and values ...(ç¥)...
便å©ãªã®ã¯ãdumpã³ãã³ãã§ãããããå®è¡ããã¨ç¾å¨ãã£ãã·ã¥ããã¦ããå ¨ã¦ã®keyã¨å¤ãåºåãã¦ããã¾ãã
# perl memcached-tool 192.168.2.67:11211 dump Dumping memcache contents Number of buckets: 3 Number of items : 3 Dumping bucket 1 - 1 total items add key1 0 1519820001 3 100 Dumping bucket 12 - 1 total items add key3 0 1519820001 1000 012345678901234567890...ï¼çç¥ï¼...0123456789012345678901234567890123456789012345678901234567890123456789 Dumping bucket 4 - 1 total items add key2 0 1519820001 100 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 root@kali:~#
shodan
åå¥ã®ãã¹ãæ¢ç´¢ã«ã¯ãã¾ãé©ãã¾ããããä¸çä¸ã®ãã¹ããã©ã®ç¨åº¦11211/tcpãéæ¾ãã¦ãããã¯ãshodanã§ç¢ºèªã§ãã¾ãã
ãport:11211ãã¨ããã¯ã¨ãªã§æ¤ç´¢ã§ãã¾ãããªããã®ã¯ã¨ãªã¯ãã°ã¤ã³ãã¦ããªãã¨å©ç¨ã§ãã¾ããããã¢ã«ã¦ã³ãä½æèªä½ã¯ç¡æã§ãã
åèæç®ã»ãªã³ã¯
- Memcrashed - Major amplification attacks from UDP port 11211
- memcached のアクセス制御に関する注意喚起
- Nmapの真実
- Software Design 2016年5月号ãããªã¼ã§å§ããã»ãã¥ãªãã£ãã§ãã¯ãåç·¨ã Nmapã«ãããã¼ãã¹ãã£ã³ã