Powered By Blogger

Thursday, 4 July 2013

Network Security

IPtables

IPtables work on kernel layers. It is use to filter the network. Also use for NAT. it is configure on port and protocols, IP address and on the interface.
Kernel layer= transport( port protocol)+ network(IP address)+ Data link(interface)

IP Tables Type

                 1) Filter
                 2) NAT
                 3) Mangle.

Filter

Filter is use for allow and deny the packet.

NAT

Redirect and changing the IP address.

NAT havr two type

Prerouting
To redirect the packet before come is called prerouting.
Post routing
To redirect the packet after packet come and use packet or provide the other PC IP or hide the own IP address is called post routing.

Mangle

Change the Packet type.

Syntex:-

#iptables  -t filter (NAT mangle)  –I INPUT (OUTPUT FORWARD PREROUTING             POSTROUTING)  –p tcp (UDP)  –s (Source IP) –d (Destination IP)  –sport (Source Port) –d                ( Destination Port) –I (Interface) –to-source ( IP Address) –to-dest (IP Address) –o (Output Interface) –j ACCEPT ( REJECT DROP SNAT DNAT )

Implement of IPtables

                                 #service iptables restart 
                                 #iptables –F (flush the defaults rule)
                                 #service iptables save ( to save the rule)
                                 #iptables –L –n –v (to check the rules enable (list))
                                 #iptables –L –v –n –line-number
                                 #iptables –L output –v –n (list bye chain type)
                                 #iptables –nvL
                                 #system-config-securitylevel (graphical setting)
                                 #iptables –d OUTPUT ( to delete rules)

Configuration file

                                 #/etc/sysconfig/iptables

Some example of IPtables


 1)      Our sshd server is access by only our network
#iptables –t filter –I INPUT –p tcp –s ! 172.17.1.0/255.255.0.0 –d 172.17.1.1 –dport 22 –j REJECT

2)      We can connect only orkut.com at HTTP request
#iptables –t filter –I OUTPUT –p tcp –s 172.17.1.1 –d! orkut.com –dport 80 –j REJECT

3)      Our network connect to only jabong.com  from our getway server
#iptables –t filter –I FORWARD –s! 172.17.1.0/255.255.0.0 –j REJECT
#iptables –t filter –I FORWARD –s 172.17.1.0/255.255.0.0 –d! jabong.com –j REJECT

4)      If any client/packet come from redhat.com its redirect to jabong.com
#iptables –t NAT –I PREROUTING –p tcp –s redhat.com d 172.17.1.1 –j DNAT –to-dst jabong.com

5)      If anyone connect to our jabong.com server IP shown different 172.17.1.1
 #iptables –t NAT –I POSTROUTING –p tcp –s 172.17.1.10 –d jabong.com –j SNAT –to-source 172.17.1.1

6)      To block all service
# iptables –I INPUT –p tcp –j REJECT

7)      To block all output
#iptables –I OUTPUT –p tcp –j REJECT

8)      To block perticular service to all machine.
#iptables –I INPUT –p tcp –dport 22 –j REJECT

9)      To block service for a machine or network
#iptables –I INPUT –p tcp –dport 22 –s 172.17.1.1 (172.17.1.0/255.255.0.0) –j REJECT

10)  To reject multiple port
#iptables –I INPUT –p tcp –m multiport –dport 22,23,80 –s 172.17.1.0/255.255.0.0 –j REJECT

11)  Apply security according to MAC address
#iptables –I INPUT –m –mac-source (give here MAC) –j reject

12)  To stop ICMP request
#iptables –I INPUT –p icmp –s 172.17.1.1 –j DROP

To create manuly chain

                       #iptables –N rhce
Insert rule in chain
                       #iptables –I INPUT 1 –j rhce
                       1 is here chain number
                       #iptables –A rhce –p tcp –dport 23 –s 172.17.1.1 –j ACCEPT
                       #iptables –x chain name ( to remove chain)

Backup of iptables

                       #iptables-save >  /root/Desktop/kausahal
                       #iptables-restore < /root/Desktop/kaushal


Network Security

TCP Wrapper

TCP wrapper is mainly use for allow or deny any incoming request for access any services.
It work on application layer.we can configure TCP wrapper on those service which have libwrap.so library link.
It works on two files
                        /etc/hosts.allow ( for allow)
                        /etc/hosts.deny (for deny)

Example :-

Daemon Name: client list
                        Sshd: 172.17.1.1

Syntax :-

                       Sshd: 172.17.1.1
                       Sshd: 17217.1.1 192.168.1.1
                       ALL: ALL
                       Sshd: ALL
                       ALL: 192.168.1.10
                       In.telnetd: 172.17.1.1
                       Sshd: 172.17.1.0/255.255.0.0
                       Sshd, vsftpd: 172.17.1.1
                       Sshd: ALL EXCEPT 192.168.1.0/255.255.255.0 or .example.com
                       Sshd: .hcl.com  .test.com
                       ALL EXCEPT Ssshd: ALL
                       Sshd: 172.17.1.1 : ALLOW
                       Sshd: 172.17.1.1 : DENY

Spawn

It execute command at server side when client connect.
                        ALL:ALL:spawn  /bin/echo “hi” >/dev/tty1
                        ALL:ALL:spawn /bin/echo “%s %d %c $(/bin/date)” >> hi
                        %s= server IP %d=demaon name %c=client IP /bin/date=time stamp hi=file name

Twist

Send message to client with deny
                          ALL:ALL:twist /bin/echo “bye”

Banners

Send banner message to client
                           ALL:ALL:banners /var/banners/vsftpd

Type message in this file. File name will a deamon name

Advance Permission

ACL

Access control list
ACL is use to give the permission to the user to access the directory and file.
It provide the specifics rights to the particular user.
     ACL implement on user and group.
+ is the  sign of ACL.

To set the ACL on user

               #setfacl –m  u:username:permission /directory name

                M= modify u=username permission=rwx

To check permission

                #getfacl /directory name

For group

                 #setfacl –m g:groupname:permission /directory name

To remove the user from ACL list


                  #setfacl –x u:username: /directory name

PERMISSION IN LINUX

PERMISSION

Permission have two type
                1) Symbolic method (owner u, group g, other o)
                2) Numerical method (owner, group, other)
Mainly Read (r=4) write (w=2) execute (x=1)
Permission is 4 2 1 according to the Umask.

To check the umask or change

                     # vim /etc/bashrc
To give the permission according to the symbolic method
                     #chmod g+w file name
Note:- default permission on directory is 755 and on the file is 644.
                      #chmod 755 directory name

Advance permission

                             1)      Sticky bit                  =1
                             2)      SGID (set group ID) = 2
                             3)      SUID (set user ID)   =4

Sticky Bit

This permission is use to prevents users for deleting each other file even they have full rights to access the directory.
                        #chmod 1757 file name

SGID

It is use to create collaborate directory. This provide a mechanism to allow on level access to user who are member of the same group that owns the directory while a different level of access to non-user of file in the directory.
                         #chmod 2757 directory name

SUID

This permission implement on user only. This permission allow a local user to work in the root privilege mode on the particular command. This permission is set on the command location.
                           #chmod 4755 /usr/bin/passwd

By defaults the permission on user home directory is 700.

Quota Implement

QUOTA


The quota system allow an administrator to establish limits on the amount of disk resource users consume.
Quota implement on user and group.

Example implement quota for /home

Open /etc/fstab
Hear edit  near /home  defaults,usrquota
After that save the file
              #mount  -a
After that remount the /home
              #mount –o remount /home
              #quotacheck –avum (to check quota for all user)
              #quotaon /home ( to enable quota)
              #quotaoff ( to disable quota)

User Quota Implement

              #edquota –u username
A file will open here
              Filesystem blocks soft hard inode soft hard
              /dev/sda6 64        120  150  8        0   0
Save the file
The grace period is by defaults 7 days
              #repquota –a (for root check the quota)
              #quota (user check the quota)
              #edquota –t (to change the grace period)
              #edquota –T username ( to change the quota for particular user)

Quota on Group

In the /etc/fstab
/home   defaults, usrquota,grpquota
And save
               #usermod –g  groupname username (add a user in group)
               #quotacheck –avgm (  to check the quota on group)

               #edquota –g groupname (to implement the quota in group)

Redundant Array of Inexpensive Disk

RAID

Redundant Array of Inexpensive Disk

Use of RAID 

1) High Availability (Data Backup)
2) Improve Data Disk Performance and provide data redundancy.
3) for clustring
4) Collection of Hardware

Clustering

Clustering is use for high availability of data and use for load balancing of the network.

Type Of RAID

1) Software RAID 
2) Hardware RAID

Software RAID

Creating Manual RAID is called Software RAID.
Mostly Use RAID0, RAID1, RAID5 

RAID0

It is use for striping of data without parity bit. Minimum 2 hard disk required.
In RAID0 no availability (no backup of data). Disk writing speed increase.

RAID 1

It is use for mirroring of data. We require minimum 2 hard disk.It provide high availability of data but writing speed of disk decrease.

RAID5

It Stripping of data without parity bit. Minimum hard disk required 3.High availability and writing speed increase.

Configure RAID1

Crate RAID partition (Partition type is fd) no need to mount the partition.
            
               #mdadm –C /dev/md0 –l 1 –n 2 /dev/sda6 /dev/sda7
                Here -C=create -l=level -n=number of disk
               #mdadm –detail /dev/md0 (to check the details)
               #mdadm –add /dev/md0 /dev/sda8 (add new Hard disk)
               #mkfs.ext3 /dev/md0 (to format the RAID partition)
               #mount /dev/md0 /kaushal (to mount the RAID partition with kaushal directory)
               #df –h (list of mounted directory)

For testing

Copy some data into kaushal directory
               #cp –rvf /usr* /kaushal
After that fail a partition.
               #mdadm –fail /dev/md0 /dev/sda8
               #mdadm –remove /dev/md0 /dev/sda8
               #blkid (to check UUID Number)
If you want permanent mount of your RAID
Create entry in the /etc/fstab.
You can also create all RAID type command are same as above.  you just have to change the Level 0, 1, 5.