Sei sulla pagina 1di 6

################################################################################

###
###
Display Sockets Summary
######################
#########
### ############################################################################
## ###
################################################################################
### ###
ss -s
################################################################################
###
###
Display All Open Network Ports
###################
############
### ############################################################################
## ###
################################################################################
### ###
ss -l
####Type the following to see process named using open socket:####
ss -pl
####Find out who is responsible for opening socket / port # 4949:####
ss -lp | grep 4949
####Sample output:####
####munin-node (PID # 3772) is responsible for opening port # 4949. You can get
more information about this process (like memory used, users, current working di
rectory and so on) visiting /proc/3772 directory:
cd /proc/3772
ls -l
################################################################################
###
###
Display all TCP Sockets
###############################
### ############################################################################
## ###
################################################################################
### ###
ss -t -a
################################################################################
###
###
Display All UDP Sockets
###############################
### ############################################################################
## ###
################################################################################
### ###
ss -u -a
################################################################################
###
### Display All Established SMTP Connections ###############################
### ############################################################################
## ###
################################################################################
### ###
ss -o state established '( dport = :smtp or sport = :smtp )'

################################################################################
###
### Display All Established HTTP Connections ###############################
### ############################################################################
## ###
################################################################################
### ###
ss -o state established '( dport = :http or sport = :http )'
################################################################################
###
### Find All Local Processes Connected To X Server ##########################
#####
### ############################################################################
## ###
################################################################################
### ###
ss -x src /tmp/.X11-unix/*
################################################################################
###
### List All The Tcp Sockets in State FIN-WAIT-1 ############################
###
### ############################################################################
## ###
################################################################################
### ###
####List all the TCP sockets in state -FIN-WAIT-1 for our httpd to network 202.5
4.1/24 and look at their timers:####
ss -o state fin-wait-1 '( sport = :http or sport = :https )' dst 202.54.1/24
################################################################################
###
### How Do I Filter Sockets Using TCP States? ###############################
### ############################################################################
## ###
################################################################################
### ###
####The syntax is as follows:####
####tcp ipv4####
ss -4 state FILTER-NAME-HERE
####tcp ipv6####
ss -6 state FILTER-NAME-HERE
########Where FILTER-NAME-HERE can be any one of the following:########
established
syn-sent
syn-recv
fin-wait-1
fin-wait-2
time-wait
closed
close-wait
last-ack
listen

closing
all : All of the above states
connected : All the states except for listen and closed
synchronized : All the connected states except for syn-sent
bucket : Show states, which are maintained as minisockets, i.e. time-wait and sy
n-recv.
big : Opposite to bucket state.
Examples
####Type the following command to see closing sockets:####
ss -4 state closing
################################################################################
###
### How Do I Matches Remote Address And Port Numbers? #########################
######
### ############################################################################
## ###
################################################################################
### ###
###Use the following syntax:###
ss dst ADDRESS_PATTERN
### Show all ports connected from remote 192.168.1.5###
ss dst 192.168.1.5
##
ss
ss
ss

show all ports connected from remote 192.168.1.5:http port###


dst 192.168.1.5:http
dst 192.168.1.5:smtp
dst 192.168.1.5:443

###Find out connection made by remote 123.1.2.100:http to our local virtual serv
ers:###
ss dst 123.1.2.100:http
################################################################################
###
### How Do I Matches Local Address And Port Numbers? ##########################
#####
### ############################################################################
## ###
################################################################################
### ###
ss src ADDRESS_PATTERN
### find out all ips connected to nixcraft.com ip address 75.126.153.214 ###
## Show all ports connected to local 75.126.153.214##
ss src 75.126.153.214
## http (80) port only ##
ss src 75.126.153.214:http
ss src 75.126.153.214:80
## smtp (25) port only ##
ss src 75.126.153.214:smtp
ss src 75.126.153.214:25

################################################################################
###
### How Do I Compare Local and/or Remote Port To A Number? #####################
##########
### ############################################################################
## ###
################################################################################
### ###
##Use the following syntax:##
## Compares remote port to a number ##
ss dport OP PORT
## Compares local port to a number ##
sport OP PORT
########Where OP can be one of the following:########
<= or le : Less than or equal to port
>= or ge : Greater than or equal to port
== or eq : Equal to port
!= or ne : Not equal to port
< or gt : Less than to port
> or lt : Greater than to port
Note: le, gt, eq, ne etc. are use in unix shell and are accepted as well.
####Examples####
################################################################################
###
### Do not forget to escape special characters when typing them in command line
###
################################################################################
###
ss
ss
ss
ss
ss
ss
ss
ss
ss
ss

sport = :http
dport = :http
dport \> :1024
sport \> :1024
sport \< :32000
sport eq :22
dport != :22
state connected sport = :http
\( sport = :http or sport = :https \)
-o state fin-wait-1 \( sport = :http or sport = :https \) dst 192.168.1/24

################################################################################
###
### ss vs netstat Speed ###############################
### ############################################################################
## ###
################################################################################
### ###
###Use the time command to run both programs and summarize system resource usage
. Type the netstat command as follows:###

time netstat -at


###Now, try the ss command:###
time
################################################################################
##########################################
### find out if your server is under attack or not. You can also list abusive IP
address using this method. ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n
#######Dig out more information about a specific ip address:#######
netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n
################################################################################
##########################################
### Get List Of All Unique IP Address ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################
###To print list of all unique IP address connected to server, enter:###
netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq
###To print total of all unique IP address, enter:###
netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq | wc -l
################################################################################
##########################################
### Find Out If Box is Under DoS Attack or Not ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################
###If you think your Linux box is under attack, print out a list of open connect
ions on your box and sorts them by according to IP address, enter:###
netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c
| sort -n
################################################################################
##########################################
### Display Summary Statistics for Each Protocol ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################
netstat
netstat
netstat
netstat
netstat

-s
-t
-u
-w
-s

| less
-s | less
-s | less
-s | less

###Display Interface Table###


netstat --interfaces eth0
################################################################################
##########################################
### nmap network scanning: http://www.cyberciti.biz/networking/nmap-command-exam
ples-tutorials/ ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################

################################################################################
##########################################
### Displaying the Status of Your Firewall ###############################
### ############################################################################
## #######################################################
################################################################################
### ##########################################
iptables -L -n -v
###-L : List rules.
###-v : Display detailed information. This option makes the list command show th
e interface name, the rule options, and the TOS masks. The packet and byte count
ers are also listed, with the suffix 'K', 'M' or 'G' for 1000, 1,000,000 and 1,0
00,000,000 multipliers respectively.
###-n : Display IP address and port in numeric format. Do not use DNS to resolve
names. This will speed up listing.
################################################################################
##########################################
### http://www.cyberciti.biz/tips/linux-iptables-examples.html #################
##############
### ############################################################################
## #######################################################
################################################################################
### ##########################################

#9: Blocking an IP Address (BLOCK IP)


To block an attackers ip address called 1.2.3.4, enter:
# iptables -A INPUT -s 1.2.3.4 -j DROP
# iptables -A INPUT -s 192.168.0.0/24 -j DROP
#10: Block Incoming Port Requests (BLOCK PORT)
To block all service requests on port 80, enter:
# iptables -A INPUT -p tcp --dport 80 -j DROP
# iptables -A INPUT -i eth1 -p tcp --dport 80 -j DROP
To block port 80 only for an ip address 1.2.3.4, enter:
# iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP
# iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP

Potrebbero piacerti anche