"nc -z"는 무엇에 사용되나요?

"nc -z"는 무엇에 사용되나요?

운동 솔루션에서 다음을 발견했습니다.

nc -z [serverip] [port]

그것은 무엇을 합니까?

nc내가 찾은 맨 페이지 에서

-z zero I/O 모드 [스캔용]

잘 설명이 안되네요... 인터넷으로 검색해서 알아냈어요Netcat 치트 시트이는 다음과 같이 말합니다.

-z: 제로 I/O 모드(데이터가 전송되지 않고 페이로드 없이 패킷만 전송됨)

그렇다면 왜 내용이 없는 패킷을 보내는 걸까요? 핑처럼요?

답변1

-z옵션을 "즉시 연결 끊기"라고 생각하는 것이 더 유용할 수 있습니다. 내 버전에는 nc포트 스캐닝에 대해 다음과 같은 내용이 있습니다.

포트 스캔

 It may be useful to know which ports are open and running services on a target machine.  The -z flag can
 be used to tell nc to report open ports, rather than initiate a connection. Usually it's useful to turn on
 verbose output to stderr by use this option in conjunction with -v option.

 For example:

       $ nc -zv host.example.com 20-30
       Connection to host.example.com 22 port [tcp/ssh] succeeded!
       Connection to host.example.com 25 port [tcp/smtp] succeeded!

 The port range was specified to limit the search to ports 20 - 30, and is scanned by increasing order (un‐
 less the -r flag is set).

 You can also specify a list of ports to scan, for example:

       $ nc -zv host.example.com http 20 22-23
       nc: connect to host.example.com 80 (tcp) failed: Connection refused
       nc: connect to host.example.com 20 (tcp) failed: Connection refused
       Connection to host.example.com port [tcp/ssh] succeeded!
       nc: connect to host.example.com 23 (tcp) failed: Connection refused

 The ports are scanned by the order you given (unless the -r flag is set).

 Alternatively, it might be useful to know which server software is running, and which versions.  This in‐
 formation is often contained within the greeting banners.  In order to retrieve these, it is necessary to
 first make a connection, and then break the connection when the banner has been retrieved.  This can be
 accomplished by specifying a small timeout with the -w flag, or perhaps by issuing a "QUIT" command to the
 server:

       $ echo "QUIT" | nc host.example.com 20-30
       SSH-1.99-OpenSSH_3.6.1p2
       Protocol mismatch.
       220 host.example.com IMS SMTP Receiver Version 0.84 Ready

를 사용하면 를 포함하거나 포함하지 않고 전송된 내용을 tcpdump확인할 수 있습니다 .nc-z

아니요 -z:

carbon# nc -v localhost 25
Connection to localhost 25 port [tcp/smtp] succeeded!
220 carbon.home ESMTP Postfix (Ubuntu)

tcpdump -i lo port 25:

15:59:07.956294 IP6 localhost.41584 > localhost.smtp: Flags [S], seq 717573315, win 65476, options [mss 65476,sackOK,TS val 4044858638 ecr 0,nop,wscale 7], length 0
15:59:07.956309 IP6 localhost.smtp > localhost.41584: Flags [S.], seq 3478976646, ack 717573316, win 65464, options [mss 65476,sackOK,TS val 4044858638 ecr 4044858638,nop,wscale 7], length 0
15:59:07.956320 IP6 localhost.41584 > localhost.smtp: Flags [.], ack 1, win 512, options [nop,nop,TS val 4044858638 ecr 4044858638], length 0
15:59:07.956536 IP6 localhost.smtp > localhost.41584: Flags [P.], seq 1:41, ack 1, win 512, options [nop,nop,TS val 4044858639 ecr 4044858638], length 40: SMTP: 220 carbon.home ESMTP Postfix (Ubuntu)
15:59:07.956548 IP6 localhost.41584 > localhost.smtp: Flags [.], ack 41, win 512, options [nop,nop,TS val 4044858639 ecr 4044858639], length 0
15:59:14.917615 IP6 localhost.41584 > localhost.smtp: Flags [F.], seq 1, ack 41, win 512, options [nop,nop,TS val 4044865599 ecr 4044858639], length 0
15:59:14.917754 IP6 localhost.smtp > localhost.41584: Flags [F.], seq 41, ack 2, win 512, options [nop,nop,TS val 4044865600 ecr 4044865599], length 0
15:59:14.917773 IP6 localhost.41584 > localhost.smtp: Flags [.], ack 42, win 512, options [nop,nop,TS val 4044865600 ecr 4044865600], length 0

그리고 -z:

carbon# nc -zv localhost 25
Connection to localhost 25 port [tcp/smtp] succeeded!

TCP 덤프:

15:59:22.394593 IP6 localhost.41592 > localhost.smtp: Flags [S], seq 449578009, win 65476, options [mss 65476,sackOK,TS val 4044873076 ecr 0,nop,wscale 7], length 0
15:59:22.394605 IP6 localhost.smtp > localhost.41592: Flags [S.], seq 3916701833, ack 449578010, win 65464, options [mss 65476,sackOK,TS val 4044873076 ecr 4044873076,nop,wscale 7], length 0
15:59:22.394615 IP6 localhost.41592 > localhost.smtp: Flags [.], ack 1, win 512, options [nop,nop,TS val 4044873076 ecr 4044873076], length 0
15:59:22.394683 IP6 localhost.41592 > localhost.smtp: Flags [F.], seq 1, ack 1, win 512, options [nop,nop,TS val 4044873076 ecr 4044873076], length 0
15:59:22.394828 IP6 localhost.smtp > localhost.41592: Flags [P.], seq 1:41, ack 2, win 512, options [nop,nop,TS val 4044873077 ecr 4044873076], length 40: SMTP: 220 carbon.home ESMTP Postfix (Ubuntu)
15:59:22.394840 IP6 localhost.41592 > localhost.smtp: Flags [R], seq 449578011, win 0, length 0

220 carbon.home ESMTP Postfix (Ubuntu)서버가 여전히 인사말( )을 보냈지만 인쇄하지 않은 것을 볼 수 있습니다 nc(아마도 읽지 않았을 것입니다).

관련 정보