ãããã¯ã¼ã¯è¨ºæã®ç¾å ´ããï¼netcatç·¨ã»ãã®1ï¼
ã¯ããã«
ãããã¯ã¼ã¯è¨ºæã§ã¯ãèå¼±æ§ã¹ãã£ãã¼ãä¾µå ¥ãã¹ããã¼ã«ãªã©ã®ãã¾ãã¾ãªã½ããã¦ã§ã¢ã使ç¨ãã¾ãããããã¯ã©ããè¤éãªã½ããã¦ã§ã¢ã§ãããããã¤ã³ã¹ãã¼ã«æ¹æ³ããå®éã®æä½ã¾ã§ãäºåã«å¤ãã®ãã¨ãå¦ã¶å¿ è¦ãããã¾ãã
ããããããã¯ã¼ã¯è¨ºæã®ç¾å ´ã§ã¯ãã³ãã³ã1ã¤ã§æä¾ãããã·ã³ãã«ãªãã¼ã«ãå¤ãå©ç¨ããã¦ãã¾ãããã®ãããªç°¡åãªãã¼ã«ã§ãããã¾ã使ãããªãã°ãã¾ãã¾ãªã»ãã¥ãªãã£ãã§ãã¯ãè¡ããã¨ãã§ãã¾ãã
ãã®ã³ã©ã ã§ã¯ãããã¯ã¼ã¯è¨ºæã§ä½¿ããããã¼ã«ã®ä¸ãããä¸è¬çãªUNIX/Linuxã§æ¨æºããã±ã¼ã¸ã¨ãã¦æä¾ããã¦ãããç°¡åã«å©ç¨ã§ããã³ãã³ããç´¹ä»ãã¦ããã¾ãããããã®ãã¼ã«ã¯ãããã¯ã¼ã¯ã®ãã©ãã«ã·ã¥ã¼ãã£ã³ã°ã«ã使ããããã¨ãå¤ãããããµã ããµã¼ãã¼ã»ãããã¯ã¼ã¯ã®æ§ç¯ããã¦ããæ¹ã ã«ãå½¹ç«ã¦ã¦ããã ãããã¨ããã®ããã®ã³ã©ã ã®ãããã§ãã
ä»åã®ã³ã©ã ã§ã¯ãé常ã«ã·ã³ãã«ãã¤å¼·åãªã³ãã³ãã§ãããnetcatããç´¹ä»ãã¾ãããªãã以ä¸ã®å®è¡ä¾ã§ã¯Linux(CentOS 6.6)ãå©ç¨ãã¦ãã¾ãããnetcatã¯å¤ãã®UNIX/Linuxã«ç§»æ¤ããã¦ãã¾ããããå®è¡ããç°å¢ã¯SolarisãFreeBSDãªã©ã§ãæ§ãã¾ããã
netcatã¨ã¯
netcatã¨ã¯ãTCPãããã¯UDPæ¥ç¶ãªã©ãå©ç¨ãã¦ãã³ãã³ãã©ã¤ã³ãããã¼ã¿ãéåä¿¡ããããã®ãã¼ã«ã§ããå®å ãæå®ãã¦å¯¾è±¡ãã¹ãã«æ¥ç¶ããã ãã§ãªããèªãããµã¼ãã¼ã«ãªãã³ãã¯ã·ã§ã³ãå¾ ã¡åãããªã©ããã¾ãã¾ãªéä¿¡ãè¡ããã¨ãã§ãã¾ãã
netcatã§ã©ã®ãããªãã¨ãã§ããã®ããã¾ãã¯ä½¿ç¨ä¾ãè¦ãæ¹ãåãããããã§ããããnetcatã¯é常ãncãã¨ããã³ãã³ãåã§æä¾ããã¦ããã nc ï¼æ¥ç¶å ãã¹ãï¼ ï¼ãã¼ãçªå·ï¼ ã®å½¢ã§å©ç¨ãã¾ãã次ã®ä¾ã§ã¯Webãµã¼ãã¼ã§ãã192.168.2.66ã¨ãããã¹ãã®HTTPãµã¼ãã¹(80/tcp)ã¸æ¥ç¶ãã¦ãã¾ããã³ãã³ããå®è¡ãã¦æ¥ç¶ããå¾ã«ããã¼ãã¼ããããHEAD / HTTP1.0ï¼æ¹è¡ï¼ï¼æ¹è¡ï¼ãã¨ããããã¹ããå ¥åãã¦ããããã®å 容ããã®ã¾ã¾æ¥ç¶å ãã¹ãã«éä¿¡ããã¾ãã
$ nc 192.168.2.66 80 HEAD / HTTP/1.0
ä¸è¨ã®ã³ãã³ããå®è¡ããã¨ã次ã®ããã«Webãµã¼ãã¼ããã®å¿çå 容ã表示ããã¾ããããã¯HTTPã®éä¿¡ã§ãã¬ã¹ãã³ã¹ãããã表示ããä¾ã§ãã
$ nc 192.168.2.66 80 HEAD / HTTP/1.0 HTTP/1.1 200 OK Date: Sun, 14 Jun 2015 13:47:00 GMT Server: Apache Last-Modified: Sun, 14 Jun 2015 13:46:14 GMT ETag: "c06fc-45-5187a909b0945" Accept-Ranges: bytes Content-Length: 69 Connection: close Content-Type: text/html; charset=UTF-8
çãããWebãã¼ã¸ãé²è¦§ããéã«ã¯ãInternet ExplorerãFirefoxãªã©ã®Webãã©ã¦ã¶ãå©ç¨ãã¦ãããã¨ã§ããããWebãã©ã¦ã¶ã§ã¯ã¬ã¹ãã³ã¹ããã£ã®ã¿ã表示ããã¾ãããå®éã®Webãµã¼ãã¼ããã®å¿çå 容ã«ã¯ãã®ãããªã¬ã¹ãã³ã¹ããããä»å ããã¦ããããã®ä¸ã«ã¯ã»ãã¥ãªãã£ä¸ãåé¡ã¨ãªããããªæ å ±ãå«ã¾ãã¦ãããã¨ãããã¾ãã
netcatãå©ç¨ããã¨ãä½è¨ãªå å·¥ããããã«ãµã¼ãã¼æ¥ç¶æã®æ å ±ããã®ã¾ã¾æ±ããã¨ãã§ãã¾ããã»ãã¥ãªãã£ãã§ãã¯ããã©ãã«ã·ã¥ã¼ãã£ã³ã°æã«ã¯ããã®ããã«çã®æ å ±(raw data)ãæ±ãããã¼ã«ã便å©ã§ãã
netcatã®ç¨®é¡
netcatã¯æ´å²ã®å¤ãã½ããã¦ã§ã¢ã§ãããã¨ããããã¾ãã¾ãªæ´¾ççãåå¨ãã¾ããåºæ¬çãªä½¿ãæ¹ã¯ã©ããåãã§ãããå®è£ ãã¦ããæ©è½ããªãã·ã§ã³æå®ã«ã¯å¾®å¦ã«å·®ããããã注æãå¿ è¦ã§ãã2015å¹´ç¾å¨ãããå©ç¨ããã¦ããnetcatã¯ä»¥ä¸ã®3種é¡ã§ãã
- ãªãªã¸ãã«çnetcat (netcat-traditional)
- OpenBSDçnetcat
- Nmapä»å±netcat
ãªãªã¸ãã«çnetcatã¯ã*Hobbit*æ°ã«ãã1995å¹´ã«ãªãªã¼ã¹ãããæåã®netcatã§ããããã¯ãã¨ãã°Ubuntuã§ã¯ãnc.traditional(ä¼çµ±çnc)ã¨ããã³ãã³ãåã§å®è£ ããã¦ãã¾ããå¤å ¸çãªã³ãã³ãã§ããããIPv6ãæ±ããªããªã©ã®å¶éã¯ãããã®ã®ãå®æ度ã¯é«ããç¾å¨ã§ãååã«å®ç¨çã§ãã
OpenBSDçnetcatã¯ããã®åã®éãOpenBSDã§æä¾ããã¦ãããã®ãå種UNIX/Linuxã«ç§»æ¤ãããã®ã§ããRed Hat Enterprise Linuxãã¯ããå¤ãã®UNIX/Linuxã§æ¨æºããã±ã¼ã¸ã¨ãã¦æ¡ç¨ããã¦ãããncã¨ããååã®ã³ãã³ãã¨ãã¦å®è£ ããã¦ãã¾ãããªãªã¸ãã«çã«æ¯ã¹ãIPv6ãUNIXãã¡ã¤ã³ã½ã±ããã«å¯¾å¿ãããªã©ã®æ¡å¼µãå³ããã¦ãã¾ãã
æå¾ã®Nmapä»å±netcatã¯ããã¼ãã¹ãã£ãã¼ã¨ãã¦æåãªNmapã«ä»å±ããã³ãã³ãã§ããããã¯ãã®ã³ãã³ãåããncatã¨å¼ã°ãã¾ããncatã¯ç¾å¨ãéçºãç¶ãã¦ãããSSLæ¥ç¶ã«å¯¾å¿ãããªã©ä»ã®netcatã«æ¯ã¹ã¦é«æ©è½ã§ãããã¨ãããããããã®ä¸»æµã«ãªã£ã¦ããã¨æããã¾ãã
ãã®ã³ã©ã ã§ã¯ãç¾å¨ä¸è¬çã«ãã使ããã¦ãã2ã¤ã®netcatããOpenBSDçnetcatãã¨ãNmapä»å±netcatãã®2ã¤ã«ã¤ãã¦è§£èª¬ãããã¨ã¨ãã¾ãããããã以éãncã¨æ¸ããã¨ãã¯OpenBSDçnetcatããncatã¨æ¸ããã¨ãã¯Nmapä»å±netcatã示ãã¾ãã
netcatã®æºå
netcatã¯å¤ãã®ç°å¢ã§æ¨æºããã±ã¼ã¸ã¨ãã¦æä¾ããã¦ãããããã¤ã³ã¹ãã¼ã«ã¯ç°¡åã§ããCentOS 6.6ã§ã¯ãncã³ãã³ãã¨ncatã³ãã³ãã¯ãããããncããã±ã¼ã¸ããã³nmapããã±ã¼ã¸ã«ä»å±ãã¦ãã¾ãããã®ãã次ã®ããã«ãyumã³ãã³ãã§ç°¡åã«ã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãã
# yum install nc nmap
ãã®ä»ã®å¤ãã®OSã§ããåæ§ã«nc(ãããã¯netcat)ã¨nmapã¨ãã2ã¤ã®ããã±ã¼ã¸åã§æä¾ããã¦ãã¾ããã¾ãFreeBSDã®ããã«ãncã³ãã³ãã¯ããã©ã«ãã§ã¤ã³ã¹ãã¼ã«ããã¦ããOSãããã¾ãã
netcat = network + cat ?
netcatã¯ããã®åã®éãnetwork対å¿ã®catã³ãã³ãã¨ããã¤ã¡ã¼ã¸ã§ä½¿ããã¨ãã§ãã¾ããããã§netcatã«ã¤ãã¦è©³ããè¦ã¦ããåã«ãã¾ãã¯catã³ãã³ãã®åä½ã«ã¤ãã¦ç¢ºèªãã¦ããã¾ããããä½ãä»ããã¨æãããããããã¾ããããcatã³ãã³ãã®æ¨æºå ¥åºåã«å¯¾ããåä½ã¸ã®ç解ãææ§ãªå ´åãnetcatãã·ã§ã«ã¹ã¯ãªãããªã©ããå©ç¨ããéã«ã¤ã¾ãããã¨ã«ãªãã¾ãã
catã³ãã³ãã¨ã¯ãªãã ãã
catã³ãã³ãã¯ãå¤ãã®UNIX/Linuxã§åºæ¬ã¨ãªãã³ãã³ãã§ããããã¯ä½ãããã³ãã³ãããçãã説æã§ããã§ããããããã®è³ªåãããã¨å¤ãã®å ´åããcatã³ãã³ãã¨ã¯ãæå®ããããã¡ã¤ã«ã®å 容ã表示ããã³ãã³ãã§ãããã¨ããçããè¿ã£ã¦ãã¾ããããã¯ã誤ãã¨ã¾ã§ã¯è¨ãã¾ãããä¸æ£ç¢ºã§ãã
ãã¨ãã°æ¬¡ã®ãããªã³ãã³ãã©ã¤ã³ã§ã¯ãcatã³ãã³ãã«ãã¡ã¤ã«ãæå®ãã¦ãã¾ããã
$ echo "Hello, World." | cat Hello, World.
ããã§ã¯ãã¤ãã§ã¤ãªãããechoã³ãã³ãã®åºåããcatã³ãã³ãã表示ãã¦ãã¾ãããã®ã¨ããcatã³ãã³ãã¯æ¬¡ã®ããã«åä½ãã¦ãã¾ãã
UNIX/Linuxã§ã¯ãã³ãã³ããå®è¡ããã¨ãæ¨æºå ¥å(stdin)ããæ¨æºåºå(stdout)ããæ¨æºã¨ã©ã¼åºå(stderr)ãã®3ã¤ã®å ¥åºåãã£ãã«ãéããã¾ãããã®éãæ¨æºå ¥åããåãåã£ããã¼ã¿ã¹ããªã¼ã ãã³ãã³ãå ã§å¦çãããã®çµæãæ¨æºåºåã«åºåããã³ãã³ããããã£ã«ã¿ãã¨å¼ã³ã¾ã(*1)ãgrepãsortãuniqãªã©ãUNIX/Linuxã®å¤ãã®ã³ãã³ãã¯ãã£ã«ã¿ã§ãã
(*1) ãã£ã«ã¿ã«ã¤ãã¦è©³ããã¯ãMike GancarzèãUNIXã¨ããèãæ¹ - ãã®è¨è¨ææ³ã¨å²å¦ã(ãªã¼ã 社)ãèªã¾ãããã¨ããããããã¾ã
catã³ãã³ãã¯ãã£ã¨ãåå§çãªãã£ã«ã¿ã§ããæ¨æºå ¥åãããã¼ã¿ã¹ããªã¼ã ãåãåããå¦çãè¡ã(catã³ãã³ãã®å ´åã¯ãä½ãããªããã¨ããåä½ããããã¨ã«ãªãã¾ã)ããã®çµæãæ¨æºåºåã«åºåãã¦ããããã§ãã
netcatã¯ãããã¯ã¼ã¯æ¥ç¶ãããã£ã«ã¿
netcatããã£ã«ã¿ã¨ãã¦åä½ããã³ãã³ãã§ãããã®ããnetcatã®åä½ã¯ãç´°ããæ¸ãã¨æ¬¡ã®ããã«ãªãã¾ããããã¯ncã³ãã³ããncatã³ãã³ãã®ã©ã¡ãã§ãå ±éã§ãã
- æ¨æºå ¥å(stdin)ãããã¼ã¿ã¹ããªã¼ã ãåãåãã
- ãã®ãã¼ã¿ã¹ããªã¼ã ãå¼æ°ã§æå®ãããæ¥ç¶å ãã¹ãã«ãã®ã¾ã¾éãè¾¼ã¿ã
- æ¥ç¶å ãã¹ãããã®å¿çãããã®ã¾ã¾æ¨æºåºå(stdout)ã«åºåãã
ãã®ãã¨ããã¡ãã¨ç解ãã¦ããã°ãnetcatããã¤ãããªãã¤ã¬ã¯ãã§å©ç¨ããã·ã§ã«ã¹ã¯ãªãããæ¸ãéã«è¿·ããã¨ãããã¾ããã
ã¯ããã«ãnetcatã¨ã¯ãã®ç¯ã§ncã³ãã³ãã®ä½¿ç¨ä¾ãç´¹ä»ãã¾ããããããã§ã¯ãã¼ãã¼ãããHTTPãªã¯ã¨ã¹ããå ¥åãã¾ãããããã¯æ¬¡ã®ããã«ãrequest.txtã¨ããããã¹ããã¡ã¤ã«ã«HTTPãªã¯ã¨ã¹ããæ¸ãã¦ããããããå ¥åãªãã¤ã¬ã¯ããã¦ããã¾ãã¾ããã
$ cat request.txt HEAD / HTTP/1.0 $ nc 192.168.2.66 80 < request.txt HTTP/1.1 200 OK Date: Sun, 14 Jun 2015 13:58:05 GMT Server: Apache Last-Modified: Sun, 14 Jun 2015 13:46:14 GMT ETag: "c06fc-45-5187a909b0945" Accept-Ranges: bytes Content-Length: 69 Connection: close Content-Type: text/html; charset=UTF-8
ãããã¯ãã¤ããå©ç¨ãã¦ãå¥ã®ã³ãã³ãã®åºåçµæã対象ãã¹ãã«ç´æ¥éãè¾¼ããã¨ãã§ãã¾ãã次ã®ä¾ã§ã¯ãechoã³ãã³ãã®åºåããã®ã¾ã¾mail.example.comã¨ããã¡ã¼ã«ãµã¼ãã¼ã®SMTPãµã¼ãã¹(25/tcp)ã«éãè¾¼ã¿ãHELPã³ãã³ããåä½ãããã確èªãã¦ãã¾ãã
$ echo "HELP" | nc mail.example.com 25 220 ubuntu ESMTP Sendmail; Thu, 4 Jun 2015 02:22:39 +0900; 214-2.0.0 This is sendmail version 8.14.4 214-2.0.0 Topics: 214-2.0.0 HELO EHLO MAIL RCPT DATA 214-2.0.0 RSET NOOP QUIT HELP VRFY 214-2.0.0 EXPN VERB ETRN DSN AUTH 214-2.0.0 STARTTLS 214-2.0.0 For more info use "HELP". 214-2.0.0 To report bugs in the implementation see 214-2.0.0 http://www.sendmail.org/email-addresses.html 214-2.0.0 For local information send email to Postmaster at your site. 214 2.0.0 End of HELP info
ä¸ã®ä¾ã§ã¯ããThis is sendmail version 8.14.4ãã¨ããå¿çãããã¾ãããSMTPãµã¼ãã¼ã®è¨å®ã«ãã£ã¦ã¯ããã®ããã«HELPã³ãã³ãã«ãã£ã¦ã½ããã¦ã§ã¢åããã³ãã¼ã¸ã§ã³çªå·ãåå¾ãããã¨ãã§ãã¾ãããã®ãããªæ å ±ãæ»æè ã«åéããããã¨ããã»ãã¥ãªãã£ä¸ã®åé¡ã¨ãªãå¯è½æ§ãããã¾ãã
ãããã¦ãã¤ãããªãã¤ã¬ã¯ããå©ç¨ãããã¨ã§ãnetcatãä»ã®ã³ãã³ãã¨çµã¿åããã¦ã·ã§ã«ã¹ã¯ãªãããªã©ããæè»ã«æ±ããã¨ãã§ãã¾ããã»ãã¥ãªãã£ãã§ãã¯ã®ããã®ãã¼ã«ãªã©ãä½ãéãnetcatã¯ã¨ã¦ã便å©ãªã³ãã³ãã§ãã
netcatãå©ç¨ããä¸ã§ã®æ³¨æç¹
æå¾ã«ãnetcatãå©ç¨ããéã®æ³¨æç¹ã«ã¤ãã¦ãç¥ãããã¦ããã¾ãããã
Windowsçnetcatã¨ã¦ã¤ã«ã¹å¯¾çã½ãã
netcatã¯ä¾¿å©ã§å¼·åãªãã¼ã«ã§ããããã®é«æ©è½ããç½ãããããã¯ãã¢ã®è¨ç½®ãªã©ã«æªç¨ãããã±ã¼ã¹ãããã¾ãããã®ããå¤ãã®ã¦ã¤ã«ã¹å¯¾çã½ããã§ã¯ãnetcatã¯å±éºãªã½ããã¦ã§ã¢ã¨ãã¦æ¤ç¥ããã¾ãããã¨ãã°ãã¬ã³ããã¤ã¯ã社ã®ã¦ã¤ã«ã¹ãã¹ã¿ã¼ã¯ãWindowsçnetcatã®å®è¡ãã¡ã¤ã«nc.exeããHKTL_NETCATãã¨ããã¹ãã¤ã¦ã§ã¢ã¨ãã¦æ¤åºãã¾ãã
ãã®ããã社å LANãªã©ã§Windowsçnetcatãå©ç¨ãããã¨ã¯é¿ããæ¹ãè¯ãã§ããããæ¬ã³ã©ã ã§ã¯ãCentOS 6.6ã§ã®å®è¡ä¾ãç´¹ä»ãã¦ãã¾ãã
èªåã®ç®¡çãã¦ããªããã¹ãã«ã¯æ¥ç¶ããªã
netcatã§ã¯å¯¾è±¡ãã¹ãã«é常ã§ã¯éãããªããããªãªã¯ã¨ã¹ããéä¿¡ãããããã¼ãã¹ãã£ã³ãè¡ã£ãããããã¨ãã§ãã¾ãããããã®æ©è½ã第ä¸è ã®ãã¹ãã«å¯¾ãã¦å®è¡ããã¨æ»æã¨ã¿ãªãããå ´åã«ãã£ã¦ã¯ç¯ç½ªè¡çºã¨ãªãå¯è½æ§ãããã¾ãããã®ããnetcatã®å©ç¨ã«ããã¦ã対象ãã¹ããæå®ããéã«ã¯åå注æããèªãã®ç®¡çä¸ã«ãããã¹ãã®ã¿ã«å®è¡ããããã«ãã¦ãã ããã
ã¾ã¨ã
ä»åã¯ãnetcatã®æ¦è¦ã«ã¤ãã¦ç´¹ä»ãã¾ããã次å以éã¯OpenBSDçnetcatã¨Nmapä»å±netcatã®éãããnetcatã®ãã¾ãã¾ãªãªãã·ã§ã³ãnetcatãå©ç¨ããç°¡åãªã»ãã¥ãªãã£ãã§ãã¯ã®æ¹æ³ãç´¹ä»ãã¾ãã
Writer Profile
å¤§è§ ç¥ä»
Tweet