반응형

출처: http://www.binarytides.com/linux-netstat-command-examples/

 

 

 

netstat -nlpt

 

 

 

 

1. List out all connections

The first and most simple command is to list out all the current connections. Simply run the netstat command with the a option.

$ netstat -a

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 enlightened:domain      *:*                     LISTEN     
tcp        0      0 localhost:ipp           *:*                     LISTEN     
tcp        0      0 enlightened.local:54750 li240-5.members.li:http ESTABLISHED
tcp        0      0 enlightened.local:49980 del01s07-in-f14.1:https ESTABLISHED
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN     
udp        0      0 enlightened:domain      *:*                                
udp        0      0 *:bootpc                *:*                                
udp        0      0 enlightened.local:ntp   *:*                                
udp        0      0 localhost:ntp           *:*                                
udp        0      0 *:ntp                   *:*                                
udp        0      0 *:58570                 *:*                                
udp        0      0 *:mdns                  *:*                                
udp        0      0 *:49459                 *:*                                
udp6       0      0 fe80::216:36ff:fef8:ntp [::]:*                             
udp6       0      0 ip6-localhost:ntp       [::]:*                             
udp6       0      0 [::]:ntp                [::]:*                             
udp6       0      0 [::]:mdns               [::]:*                             
udp6       0      0 [::]:63811              [::]:*                             
udp6       0      0 [::]:54952              [::]:*                             
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     12403    @/tmp/dbus-IDgfj3UGXX
unix  2      [ ACC ]     STREAM     LISTENING     40202    @/dbus-vfs-daemon/socket-6nUC6CCx

The above command shows all connections from different protocols like tcp, udp and unix sockets. However this is not quite useful. Administrators often want to pick out specific connections based on protocols or port numbers for example.

2. List only TCP or UDP connections

To list out only tcp connections use the t options.

$ netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 enlightened:domain      *:*                     LISTEN     
tcp        0      0 localhost:ipp           *:*                     LISTEN     
tcp        0      0 enlightened.local:36310 del01s07-in-f24.1:https ESTABLISHED
tcp        0      0 enlightened.local:45038 a96-17-181-10.depl:http ESTABLISHED
tcp        0      0 enlightened.local:37892 ABTS-North-Static-:http ESTABLISHED
.....

Similarly to list out only udp connections use the u option.

$ netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
udp        0      0 *:34660                 *:*                                
udp        0      0 enlightened:domain      *:*                                
udp        0      0 *:bootpc                *:*                                
udp        0      0 enlightened.local:ntp   *:*                                
udp        0      0 localhost:ntp           *:*                                
udp        0      0 *:ntp                   *:*                                
udp6       0      0 fe80::216:36ff:fef8:ntp [::]:*                             
udp6       0      0 ip6-localhost:ntp       [::]:*                             
udp6       0      0 [::]:ntp                [::]:*

The above output shows both ipv4 and ipv6 connections.

3. Disable reverse dns lookup for faster output

By default, the netstat command tries to find out the hostname of each ip address in the connection by doing a reverse dns lookup. This slows down the output. If you do not need to know the host name and just the ip address is sufficient then suppress the hostname lookup with the n option.

$ netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 192.168.1.2:49058       173.255.230.5:80        ESTABLISHED
tcp        0      0 192.168.1.2:33324       173.194.36.117:443      ESTABLISHED
tcp6       0      0 ::1:631                 :::*                    LISTEN

The above command shows ALL TCP connections with NO dns resolution. Got it ? Good.

4. List out only listening connections

Any network daemon/service keeps an open port to listen for incoming connections. These too are like socket connections and are listed out by netstat. To view only listening ports use the l options.

$ netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN

Now we can see only listening tcp ports/connections. If you want to see all listening ports, remove the t option. If you want to see only listening udp ports use the u option instead of t.
Make sure to remove the 'a' option, otherwise all connections would get listed and not just the listening connections.

5. Get process name/pid and user id

When viewing the open/listening ports and connections, its often useful to know the process name/pid which has opened that port or connection. For example the Apache httpd server opens port 80. So if you want to check whether any http server is running or not, or which http server is running, apache or nginx, then track down the process name.

The process details are made available by the 'p' option.

~$ sudo netstat -nlpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      1144/dnsmasq    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      661/cupsd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      661/cupsd

When using the p option, netstat must be run with root privileges, otherwise it cannot detect the pids of processes running with root privileges and most services like http and ftp often run with root privileges.

Along with process name/pid its even more useful to get the username/uid owning that particular process. Use the e option along with the p option to get the username too.

$ sudo netstat -ltpe
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 enlightened:domain      *:*                     LISTEN      root       11090       1144/dnsmasq    
tcp        0      0 localhost:ipp           *:*                     LISTEN      root       9755        661/cupsd       
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN      root       9754        661/cupsd

The above example lists out Listening connections of Tcp type with Process information and Extended information.
The extended information contains the username and inode of the process. This is a useful command for network administrators.

Note - If you use the n option with the e option, the uid would be listed and not the username.

6. Print statistics

The netstat command can also print out network statistics like total number of packets received and transmitted by protocol type and so on.

To list out statistics of all packet types

$ netstat -s
Ip:
    32797 total packets received
    0 forwarded
    0 incoming packets discarded
    32795 incoming packets delivered
    29115 requests sent out
    60 outgoing packets dropped
Icmp:
    125 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 125
    125 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 125
... OUTPUT TRUNCATED ...

To print out statistics of only select protocols like TCP or UDP use the corresponding options like t and u along with the s option. Simple!

7. Display kernel routing information

The kernel routing information can be printed with the r option. It is the same output as given by the route command. We also use the n option to disable the hostname lookup.

$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

8. Print network interfaces

The netstat command can also print out the information about the network interfaces. The i option does the task.

$ netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0     31611      0      0 0         27503      0      0      0 BMRU
lo        65536 0      2913      0      0 0          2913      0      0      0 LRU

The above output contains information in a very raw format. To get a more human friendly version of the output use the e option along with i.

$ netstat -ie
Kernel Interface table
eth0      Link encap:Ethernet  HWaddr 00:16:36:f8:b2:64  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::216:36ff:fef8:b264/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:31682 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27573 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29637117 (29.6 MB)  TX bytes:4590583 (4.5 MB)
          Interrupt:18 Memory:da000000-da020000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2921 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2921 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:305297 (305.2 KB)  TX bytes:305297 (305.2 KB)

The above output is similar to the output shown by the ifconfig command.

9. Get netstat output continuously

Netstat can output connection information continuously with the c option.

$ netstat -ct

The above command will output tcp connections continuously.

10. Display multicast group information

The g option will display the multicast group information for IPv4 and IPv6 protocols.

$ netstat -g
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      all-systems.mcast.net
eth0            1      224.0.0.251
eth0            1      all-systems.mcast.net
lo              1      ip6-allnodes
lo              1      ff01::1
eth0            1      ff02::fb
eth0            1      ff02::1:fff8:b264
eth0            1      ip6-allnodes
eth0            1      ff01::1
wlan0           1      ip6-allnodes
wlan0           1      ff01::1

More examples of netstat command

Okay, we covered the basic examples of netstat command above. Now its time to do some geek stuff with style.

Print active connections

Active socket connections are in "ESTABLISHED" state. So to get all current active connections use netstat with grep as follows

$ netstat -atnp | grep ESTA
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 192.168.1.2:49156       173.255.230.5:80        ESTABLISHED 1691/chrome     
tcp        0      0 192.168.1.2:33324       173.194.36.117:443      ESTABLISHED 1691/chrome

To watch a continous list of active connections, use the watch command along with netstat and grep

$ watch -d -n0 "netstat -atnp | grep ESTA"

Check if a service is running

If you want to check if a server like http,smtp or ntp is running or not, use grep again.

$ sudo netstat -aple | grep ntp
udp        0      0 enlightened.local:ntp   *:*                                 root       17430       1789/ntpd       
udp        0      0 localhost:ntp           *:*                                 root       17429       1789/ntpd       
udp        0      0 *:ntp                   *:*                                 root       17422       1789/ntpd       
udp6       0      0 fe80::216:36ff:fef8:ntp [::]:*                              root       17432       1789/ntpd       
udp6       0      0 ip6-localhost:ntp       [::]:*                              root       17431       1789/ntpd       
udp6       0      0 [::]:ntp                [::]:*                              root       17423       1789/ntpd       
unix  2      [ ]         DGRAM                    17418    1789/ntpd

So we found that ntp server is running. Grep for http or smtp or whatever you are looking for.

Well, that was most of what netstat is used for. If you are looking for more advanced information or want to dig deeper, read up the netstat manual (man netstat).

And do leave your feedback and suggestions in the comments box below.

반응형
반응형

출처: http://sisiblog.tistory.com/21


https://nmap.org/book/man.html
http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/


리눅스 nmap 명령어 사용 예제


nmap은 network mapper의 줄임말로 네트워크 탐색과 보안감사를 하는 오픈소스 툴입니다. 이 툴은 거대한 네트워크를 반복적으로 스캔할 수 있도록 디자인 되었지만 단일 호스트에서도 잘 작동합니다. nmap은 네트워크상의 어떤 호스트가 작동중인지, 그 호스트가 어떤 서비스를 하는지, 운영체제가 무엇인지, 어떤 패킷필터나 방화벽을 쓰는지 등을 알아내기 위해 raw ip 패킷을 사용합니다. 이는 보통 보안감사용으로 쓰이지만 네트워크 목록관리 같은 정례적인 작업, 서비스 업그레이드 스케줄 관리, 호스트나 가동중인 서비스의 모니터링에도 유용합니다.


nmap은 옵션에 따라 스캔된 호스트의 추가 정보를 출력하는데 그 정보 중 핵심은 'interesting ports table' 입니다. 이 테이블은 스캔된 포트번호, 프로토콜, 서비스이름, 상태(state)를 출력합니다. state에는 open, filtered, closed, unfiltered가 있습니다. 스캔 결과 출력 시 하나의 상태가 아닌 조합된 값(open|filtered, closed|filtered)을 출력할 수도 있습니다.

  • open: 스캔된 포트가 listen 상태임을 나타냄
  • filtered: 방화벽이나 필터에 막혀 해당 포트의 open, close 여부를 알 수 없을 때
  • closed: 포트스캔을 한 시점에는 listen 상태가 아님을 나타냄
  • unfiltered: nmap의 스캔에 응답은 하지만 해당 포트의 open, close 여부는 알 수 없을 때


1. 단일 호스트 스캔하기

nmap에서 스캔 대상을 지정하는 가장 간단한 방법은 그냥 ip 주소를 지정하거나 호스트이름을 입력하는 방법입니다.

$ nmap scanme.nmap.org
$ nmap 172.16.9.1

좀더 많은 정보가 얻고싶다면 '-v' 옵션을 추가합니다.

$ nmap -v scanme.nmap.org
$ nmap -v 172.16.9.1


2. 다수의 호스트 스캔하기

네트워크에 인접한 호스트 여러대를 스캔하고 싶을 경우 cidr 스타일을 사용할 수 있습니다. 예를 들어 172.16.9.0/24로 주소를 지정한다면 앞에서 24개 비트만 고정하고 172.16.9.0 부터 172.16.9.255 까지의 256개 호스트를 스캔합니다. 172.16.9.100/24 처럼 주소를 지정해도 결과는 동일합니다. 이 방법에 호스트 이름을 사용할 수도 있습니다. 다음과 같이 scanme.nmap.org/16을 주소로 지정할 경우 scanme.nmap.org의 ip인 45.33.32.156으로 계산하여 45.33.0.0에서 45.33.255.255 까지 65536개의 호스트를 스캔합니다.

$ nmap 172.16.0.0/16
$ nmap scanme.nmap.org/24

cidr 스타일은 간단하지만 유연성이 떨어집니다. 예를들어 172.16.9.0/24를 스캔하고 싶지만 특수용도 주소인 .0 이나 .255를 제외하고 싶다면 cidr 스타일만으로는 힘듭니다. 이런 경우 때문에 nmap에는 ip 주소의 범위를 지정할 수 있는 옵션이 있습니다. 사용 방법은 하이픈('-')으로 범위를 지정하거나 쉼표로 여러 범위를 지정하는 것입니다. 예를 들어 172.16.3-5,7.1의 의미는 172.16.3.1, 172.16.4.1, 172.16.5.1, 172.16.7.1을 스캔하라는 명령이고 다른 숫자 없이 하이픈만(172.16.9.-) 넣는다면 0-255와 같은 의미로 사용할 수 있습니다. 또한 스캔하고싶은 호스트들에 일정한 패턴이 없다면 앞에서 언급한 여러가지 스타일을 한번에 사용할 수도 있습니다.

$ nmap 172.16.3-5,7.1

$ nmap scanme.nmap.org 172.16.9.0/24 10.0.0,1,3-7.-v


3. 호스트 목록을 파일에서 읽어오기

'-iL' 옵션은 파일에서 호스트 목록을 가져올 수 있게 합니다. 파일에 입력할 수 있는 포멧은 커맨드 라인에서 입력할 수 있는 것들과 동일하며 ip 주소, 호스트 이름, cidr, ipv6, 범위지정 입니다. 각각의 검색 대상은 스페이스, 탭, 새 줄로 구분해야 합니다. 만약 표준입력을 입력파일로 지정하고 싶으면 파일이름 대신 하이픈을 사용합니다. 여기서 주석은 '#'으로 표시하고 '#'에서 시작하여 그 줄의 끝까지가 주석의 범위입니다.

$ cat ./scanlist.txt

scanme.nmap.org

172.16.9.0/24

172.16.9.1/24

10.0.0,1,3-7.-


$ nmap -iL ./scanlist.txt


4. 탐색 대상에서 특정 호스트 제외하기

다량의 호스트가 탐색 대상일 때 탐색할 필요가 없는 호스트는 제외할 수 있습니다. 옵션은 '--exclude'이고 쉼표로 여러 호스트를 나열할 수 있습니다. 또한 '–-excludefile' 옵션을 통해 제외할 대상을 파일에서 읽어올 수 있습니다.

$ nmap 172.16.9.0/24 --exclude 172.16.9.5

$ nmap 172.16.9.0/24 --exclude 172.16.9.0,172.16.9.255

$ nmap -iL ./scanlist.txt --excludefile ./excludelist.txt


5. 목적지의 운영체제와 버전확인 기능 켜기

'-A' 옵션은 운영체제 탐지, 버전 탐지, script scanning, traceroute 기능을 활성화 합니다. nmap은 호스트 탐색을 커스터마이징 하기 위해 여러가지 옵션을 혼합하여 사용할 수 있습니다.

$ nmap -A 172.16.9.1

$ nmap -v -A 172.16.9.1

$ nmap -A -iL ./scanlist.txt 


6. 호스트가 방화벽에 의해 보호되고 있는지 확인하기

'-sA' 옵션은 tcp ack 스캔으로 특정 호스트를 방화벽 같은 보안장치가 감시하고 있는지 아닌지, 어떤 포트가 필터링 되고 있는지를 확인하는데 주로 사용합니다. 

$ nmap -sA 172.16.9.1

$ nmap -sA scanme.nmap.org


7. 방화벽이 보호하는 호스트 스캔하기 (deprecated)

'-PN' 옵션은 호스트 탐색 없이 바로 포트스캔을 시도하는 기능입니다. 경고 메시지와 대체옵션제안은 '-v'로 볼 수 있습니다.

$ nmap -PN 172.16.9.1

$ nmap -PN scanme.nmap.org


8. ipv6 호스트 스캔하기

ipv6 스캔을 하려면 '-6' 옵션을 추가합니다.

$ nmap -6 scanme.nmap.org

$ nmap -6 2607:f0d0:1002:51::4

$ nmap -v -A -6 2607:f0d0:1002:51::4


9. 특정 네트워크에서 어떤 서버가 기동중인지 확인하기 (deprecated)

호스트 탐색으로 알려진 '-sP' 옵션은 ping 스캔을 통해 해당 호스트가 기동중 인지 확인합니다.

$ nmap -sP 172.16.9.0/24


10. 빠르게 스캔하기

일반적으로 nmap은 가장 많이 쓰는 1000개의 포트를 스캔하는데 '-F' 옵션을 사용해 100개로 줄입니다.

$ nmap -F 172.16.9.1


11. 포트의 상태에 대한 원인보기

각각의 포트가 어떤 이유에 의해 현재의 상태가 되었는지 '--reason' 옵션을 통해 알아볼 수 있습니다.

$ nmap --reason 172.16.9.1

$ nmap --reason scanme.nmap.org


12. open 상태인 포트만 보이기

closed나 filtered, closed|filtered 포트의 정보가 필요하지 않다면 '--open' 옵션을 통해 open, open|filtered, unfiltered 상태인 포트만 출려하게 합니다. 만일 검색된 포트가 엄청나게 많다면 open|filtered, unfiltered 상태인 포트는 요약됩니다.

$ nmap --open 172.16.9.1

$ nmap --open scanme.nmap.org


13. 송수신된 모든 패킷 보이기

nmap은 기본적으로 송수신된 패킷의 정리된 내용만 요약하여 출력합니다. 주로 '--packet-trace' 옵션은 전체 패킷을 모두 출력하게 하여 디버깅용도로 사용합니다. 또한 nmap을 처음 써보는 사용자에게 nmap이 정확히 무슨일을 하는지 이해하려는 목적으로도 사용할 수 있습니다. 다른 옵션을 안쓰고 모든 포트의 송수신 정보를 출력하게 하면 천여줄이 출력되어 알아보기 힘드므로 '-p20-30' 처럼 스캔할 포트의 양을 한정하여 관심있는 분야만 확인할 수도 있습니다.

$ nmap --packet-trace 172.16.9.1

$ nmap --packet-trace scanme.nmap.org


14. 본인의 네트워크 인터페이스와 라우트 정보 보기

'--iflist' 옵션은 nmap이 탐지한 인터페이스 목록과 시스템 라우트를 출력합니다. 이 옵션은 nmap이 장치이름을 이상하게 표시하거나 라우팅 문제가 있을 때 디버깅용으로 사용할 수 있습니다.

$ nmap --iflist


15. 특정 포트만 스캔하기

'-p' 다음에 포트를 지정합니다.

(80번 포트 스캔)

$ nmap -p80 172.16.9.1


(tcp 80번 포트 스캔)

$ nmap -p T:80 172.16.9.1


(udp 53번 포트 스캔)

$ nmap -p U:53 172.16.9.1


(두개의 포트 스캔)

$ nmap -p80,443 172.16.9.1


(범위로 포트 스캔)

$ nmap -p80-443 172.16.9.1


(와일드카드로 모두 스캔)

$ nmap -p "*" 172.16.9.1


(nmap-services 파일에 정의된 가장 많이 쓰는 포트순으로 스캔)

$ nmap --top-ports 5 172.16.9.1

$ nmap --top-ports 10 172.16.9.1


16. 포트 스캔 속도 지정하기

스캔 속도를 지정해 대역폭과 목표 호스트의 자원사용을 조절하도록 하는 옵션으로 '-T' 뒤에 숫자를 붙입니다. 뒤의 숫자는 0부터 5까지 6개가 올 수 있고 숫자가 커질수록 스캔 속도가 빨라집니다. 각각의 템플릿 이름은 paranoid(0), sneaky(1), polite(2), normal(3), aggressive(4), insane(5) 으로 아무 옵션을 사용하지 않으면 기본으로 -T3이 쓰입니다. -T2는 호스트에 crash가 발생하거나 대역폭 문제가 있을까하는 걱정에 사용하는 경우가 있는데 -T3에 비해 열배 정도는 느리고 -T3에서도 앞의 걱정되는 상황은 거의 발생 안합니다. 현대의 일반적인 네트워크에서는 -T4라면 무리없이 돌아갑니다. -T0과 -T1은 ids의 탐지를 회피하는데 유용할 수 있습니다. 하지만 -T0, -T1에 의지하기 보다는 적당한 타이밍을 찾아내 스캔하는게 더 좋습니다.

$ nmap -T5 172.16.9.0/24


17. 원격지의 운영체제 알아내기

'-O' 옵션으로 운영체제 탐지 기능을 활성화 합니다.

$ nmap -O 172.16.9.1

$ nmap -O  --osscan-guess 172.16.9.1

$ nmap -v -O --osscan-guess 172.16.9.1


18. 서비스 버전 알아내기

'-sV' 옵션으로 서버나 데몬의 버전을 출력합니다.

$ nmap -sV 172.16.9.1


19. tcp ack, tcp syn 으로 호스트 스캔

방화벽이 icmp 핑을 막고있을 때 대안으로 사용할 수 있습니다. '-PS' 옵션은 tcp syn ping으로 빈 tcp 패킷에 syn flag를 셋팅하여 호스트 탐지를 실행합니다. 옵션뒤에 검사할 포트 번호를 지정하여 사용할 수 있습니다. '-PA'는 tcp ack ping으로 ack flag를 셋팅하여 사용합니다.

$ nmap -PS 172.16.9.1

$ nmap -PS80,21,443 172.16.9.1

$ nmap -PA 172.16.9.1

$ nmap -PA80,21,200-512 172.16.9.1


20. ip protocol ping으로 스캔하기

'-PO' 옵션으로 icmp ping 이외의 다른 프로토콜로 호스트를 스캔합니다.

$ nmap -PO 172.16.9.1


21. udp ping으로 스캔하기

tcp만 필터링하는 방화벽을 통과하기 위해 '-PU' 옵션으로 udp ping을 합니다.

$ nmap -PU 172.16.9.1

$ nmap -PU2000,2001 172.16.9.1


22. 가장 일반적으로 사용되는 tcp 포트 스캔하기

tcp 스캔에는 스텔스 스캔과 완전연결 스캔이 있습니다. 스텔스 스캔은 3 way handshaking을 완료하지 않고 진행하는 스캔으로 syn을 보내고 syn/ack이 오면 rst를 보내 호스트의 open 여부를 판단하고 상대방 호스트에 로그를 남기지 않으려 연결을 중단시킵니다.

(tcp를 완전히 연결하지 않는 스텔스 스캔)

$ nmap -sS 172.16.9.1


(tcp 연결 스캔, 운영체제 fingerprint 스캔)

$ nmap -sT 172.16.9.1


(tcp 연결 스캔, 운영체제 tcp ack 스캔)

$ nmap -sA 172.16.9.1


(tcp 연결 스캔, 운영체제 tcp window 스캔)

$ nmap -sW 172.16.9.1


(tcp 연결 스캔, 운영체제 tcp maimon 스캔)

$ nmap -sM 172.16.9.1


23. udp 스캔하기

대부분의 인터넷 서비스는 tcp 프로토콜을 사용합니다. 하지만 dns, snmp, dhcp 같은 udp 서비스도 존재합니다. 이를 탐지하기 위해 '-sU' 옵션을 사용해 udp 서비스를 찾아냅니다.

$ nmap -sU nas03

$ nmap -sU 172.16.9.1


24. ip protocol 스캔하기

목표 호스트에서 어떤 ip protocol(tcp, icmp, igmp 등)을 사용하는지 '-sO' 옵션으로 확인합니다.

$ nmap -sO 172.16.9.1


25. 보안 취약점을 찾기위해 방화벽 스캔하기

다음 스캔 유형은 tcp 보안 허점을 확인하고 일반적인 공격에 취약한지 여부를 확인해볼 수 있는 옵션입니다.

(방화벽을 속여 응답을 생성하도록 tcp null 스캔 수행)

(tcp flag 헤더에 아무 비트도 설정하지 않음)

$ nmap -sN 172.16.9.1


(방화벽을 확인하는 tcp fin 스캔)

(tcp fin 비트만 셋팅)

$ nmap -sF 172.16.9.1


(방화벽을 확인하는 tcp xmas 스캔)

(fin, psh, urg flag를 셋팅)

$ nmap -sX 172.16.9.1


26. 방화벽과 ids 회피를 위해 packets fragments 이용하기

'-f' 옵션은 tcp 헤더를 쪼개서 패킷 필터나 침임탐지를 어렵게 합니다.

$ nmap -f 172.16.9.1

$ nmap -f scanme.nmap.org

$ nmap -f 15 scanme.nmap.org


27. 미끼를 던져 스캔을 은폐하기

'-D' 옵션은 탐지할 네트워크의 ids에 혼란을 주기위해 사용합니다. 유인 ip 여러개를 같이 포트 스캔하게 하여 어떤 호스트가 목표인지 유인물인지 판단할 수 없게 합니다.

$ nmap -n -Ddecoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ip


28. mac 주소를 스푸핑하여 스캔하기

'--spoof-mac' 옵션을 통해 mac 주소를 도용할 수 있습니다. mac 주소 대신 0을 넣으면 완전한 랜덤 주소를 생성합니다.

(mac 주소 도용하기)

$ nmap --spoof-mac MAC-ADDRESS-HERE 172.16.9.1


(다른 옵션과 함께)

$ nmap -v -sT -PN --spoof-mac MAC-ADDRESS-HERE 172.16.9.1


(랜덤 mac 주소 사용하기)

$ nmap -v -sT -PN --spoof-mac 0 172.16.9.1


29. 출력결과를 파일로 저장하기

결과를 저장하려면 리눅스 기본 기능인 파이프를 사용해도 되고 '-oN' 옵션을 사용해도 됩니다.

$ nmap 172.16.9.1 > output.txt

$ nmap -oN /path/to/filename 172.16.9.1


30. command line 말고 gui를 원한다면

공식 gui 툴은 zenmap이 있습니다. 이는 linux, windows, osx, bsd 등의 버전이 있습니다. 설치방법은 다음과 같습니다.

$ sudo apt-get install zenmap

$ sudo zenmap


반응형
반응형

출처: http://timedigit.blogspot.kr/2013/10/so-i-tried-this-simple-program-to-test.html

http://stackoverflow.com/questions/21477407/llvm-3-5-fails-to-link

 

 

1.에러 -> term.h 못찾겠다(fatal error: term.h: No such file or directory)

 

해결책

sudo apt-get install libncurses5-dev libncursesw5-dev

로 설치

 

 

2. root@ubuntu:/home/c# gcc -o badterm badterm.c
/tmp/ccolx2wA.o: In function `main':
badterm.c:(.text+0x20): undefined reference to `setupterm'
collect2: error: ld returned 1 exit status

 

 

해결책

root@ubuntu:/home/c# gcc -o badterm badterm.c -ltinfo

 

gcc 뒤에 -ltinfo를 붙이면 정상적으로 컴파일 된다.



반응형
반응형

참고: http://database.sarang.net/study/glibc/12.htm

 

http://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html

 

규범모드 canonical mode 또는 표준 모드 standard mode 라고 부르며, 규범 모드에서는 모든 입력이 줄 단위로 처리된다. 한줄이 완성되기 전까지는(즉, 일반적으로 Enter키를 누를 때까지) 터미널 인터페이스가 모든 키눌림을 관리

 

이 모드의 반대가 비규범 모드이다.

 

 

 

In canonical input processing mode, terminal input is processed in lines terminated by newline ('\n'), EOF, or EOL characters. No input can be read until an entire line has been typed by the user, and the read function (see I/O Primitives) returns at most a single line of input, no matter how many bytes are requested.

In canonical input mode, the operating system provides input editing facilities: some characters are interpreted specially to perform editing operations within the current line of text, such as ERASE and KIL

반응형

+ Recent posts