Monday, May 21, 2018

Linux Security

  • Linux server security: Three steps to secure each system

Auditing
To audit a Linux system we use our open source tool Lynis and perform a system scan. It runs on almost all Unix and Linux based systems and only requires a shell and root permissions. After the scan all findings will be reported and additional information will be stored in the log files (/var/log/lynis.log). Also a hardening index will be displayed, to give the auditor a first impression on how well the system is hardened.

Hardening
After running Lynis it’s time to deal with the findings.

Compliance
maintain the effect or earlier security efforts, it’s important to keep measuring your security level and compare them with baselines.Every system should be checked on a regular base and deviations to your standard should be detected as soon as possible. By determining the risk level of this deviations, it will be much easier to take an appropriate action or implement different security measures.
https://linux-audit.com/linux-server-security-three-steps-to-secure-each-system/


  • the su command requires you to enter the password of the target user.

There's another way to switch to the root user: run the 'su -' command:

Now, what's the difference between 'su' and 'su -' ? Well, the former keeps the environment of the old/original user even after the switch to root has been made, while the latter creates a new environment (as dictated by the ~/.bashrc of the root user), similar to the case when you explicitly log in as root user from the log-in screen.
The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly.

So, you'll agree that logging in with 'su -' makes more sense. But as the 'su' command also exists, one might wonder when that's useful.
the benefits and pitfalls of the 'su' command

It sometimes can be advantageous for a system administrator to use the shell account of an ordinary user rather than its own. In particular, occasionally the most efficient way to solve a user's problem is to log into that user's account in order to reproduce or debug the problem.
However, in many situations it is not desirable, or it can even be dangerous, for the root user to be operating from an ordinary user's shell account and with that account's environmental variables rather than from its own. While inadvertently using an ordinary user's shell account, root could install a program or make other changes to the system that would not have the same result as if they were made while using the root account. For instance, a program could be installed that could give the ordinary user power to accidentally damage the system or gain unauthorized access to certain data.

-, -l, --login
Provide an environment similar to what the user would expect had the user logged in directly.

When - is used, it must be specified as the last su option. The other forms (-l and --login) do not have this restriction.

su -c
It lets you provide a command that you want to run after switching to the target user.


Sudo vs Su
The primary difference between the two is the password they require: while 'sudo' requires current user's password, 'su' requires you to enter the root user password
Quite clearly, 'sudo' is a better alternative between the two as far as security is concerned.
For example, consider the case of computer being used by multiple users who also require root access. Using 'su' in such a scenario means sharing the root password with all of them

Moreover, in case you want to revoke the superuser/root access of a particular user, the only way is to change the root password and then redistribute the new root password among all the other users.

With Sudo, on the other hand, you can handle both these scenarios effortlessly. Given that 'sudo' requires users to enter their own password, you don't need to share the root password will all the users in the first place. And to stop a particular user from accessing root privileges, all you have to do is to tweak the corresponding entry in the 'sudoers' file.

The other difference between the two commands is in their default behavior. While 'sudo' only allows you to run a single command with elevated privileges, the 'su' command launches a new shell, allowing you to run as many commands as you want with root privileges until you explicitly exit that sell.

So the default behavior of the 'su' command is potentially dangerous given the possibility that the user can forget the fact that they are working as root

Logging
Although commands run through 'sudo' are executed as the target user (which is 'root' by default), they are tagged with the sudoer's user-name. But in case of 'su', it's not possible to directly trace what a user did after they su'd to the root account.

Flexibility
The 'sudo' command is far more flexible in that you can even limit the commands that you want the sudo-ers to have access to. In other words, users with access to 'sudo' can only be given access to commands that are required for their job. However, with 'su' that's not possible - either you have the privilege to do everything or nothing.

Sudo su
some Linux distributions - like Ubuntu - disable the root user account by default.

In case you want to enable the root account on your system
sudo passwd root

https://www.howtoforge.com/tutorial/sudo-vs-su/

  • If sudo has been configured to allow the user to run root's shell, the user can run sudo -s or sudo -i to mimic su or su -l, respectively, and supply his own password or no password rather than root's password. Similarly, sudo -u john -i mimics su -l john if you are allowed to run john's shell

The default behavior of su is to remain within the current directory and to maintain the environmental variables of the original user (rather than switch to those of the new user).

it is advisable that administrative users, as well as any other users that are authorized to use su (and it is suggested that there be very few, if any) acquire the habit of always running the su command with the -l/--login option. It has two effects:
     switches from the current directory to the home directory of the new user (e.g., to /root in the case of the root user) by logging in as that user
    changes the environmental variables to those of the new user as dictated by their ~/.bashrc. That is, the current directory and environment will be changed to what would be expected if the new user had actually logged on to a new session (rather than just taking over an existing session).

su and wheel
BSD su allows only members of the "wheel" group to assume root's identity by default. This is not the default behavior of GNU su, but this behavior can be mimicked using PAM. Uncomment the appropriate line in /etc/pam.d/su and /etc/pam.d/su-l:

https://wiki.archlinux.org/index.php/Su


  •  Configuring and Using Chroot Jails

 A chroot operation changes the apparent root directory for a running process and its children. It allows you to run a program with a root directory other than /. The program cannot see or access files outside the designated directory tree. Such an artificial root directory is called a chroot jail, and its purpose is to limit the directory access of a potential attacker. The chroot jail locks down a given process and any user ID that it is using so that all they see is the directory in which the process is running. To the process, it appears that the directory in which it is running is the root directory
 The chroot mechanism cannot defend against intentional tampering or low-level access to system devices by privileged users. For example, a chroot root user could create device nodes and mount file systems on them. A program can also break out of a chroot jail if it can gain root privilege and use chroot() to change its current working directory to the real root directory. For this reason, you should ensure that a chroot jail does not contain any setuid or setgid executables that are owned by root
 https://docs.oracle.com/cd/E37670_01/E36387/html/ol_cj_sec.html


  •  the chroot “Jail” we built to watch his activities

 With these holes he could often subvert the uucp and bin accounts in short order, and then root.
 We added a few fake services, and I wrote a script to scan the logs daily.

 FTP: The scanner produces a report of all login names that were attempted.
 It also reports the use of a tilde (a possible probe of an old FTP bug), all attempts to obtain FTP’s /etc/passwd and /etc/group files, and a list of all files stored in the
pub directory.

 Telnet/login:All login attempts are logged and reviewed daily

 Guest/visitor accounts:A public computer account is the first thing a cracker looks for.
 The cracker can also get a list of hosts trusted by this machine from the /etc/hosts.equiv and various personal .rhosts files

 Finger: Finger provides a lot of information useful to crackers: account names, when the account was last used, and a few things to try as passwords.

 http://www.cheswick.com/ches/papers/berferd.pdf

  • How do I change the root directory of a command?
How do I change the root directory of a process such as web-server using a chroot command to isolate file system?
How do I use a chroot to recover password or fix the damaged Linux/Unix based environment?
Each process/command on Linux and Unix-like system has current working directory called root directory of a process/command.
You can change the root directory of a command using chroot command, which ends up changing the root directory for both current running process and its children.
A process/command that is run in such a modified environment cannot access files outside the root directory. This modified environment is commonly known as “jailed directory” or “chroot jail”.
Only a privileged process and root user can use chroot command

    Privilege separation for unprivileged process such as Web-server or DNS server.
    Setting up a test environment.
    Run old programs or ABI in-compatibility programs without crashing application or system.
    System recovery.
    Reinstall the bootloader such as Grub or Lilo.
    Password recovery – Reset a forgotten password and more.

https://www.cyberciti.biz/faq/unix-linux-chroot-command-examples-usage-syntax/


  • Chroot is an operation that changes the apparent root directory for the current running process and their children. A program that is run in such a modified environment cannot access files and commands outside that environmental directory tree. This modified environment is called a chroot jail.
Changing root is commonly done for performing system maintenance on systems where booting and/or logging in is no longer possible. Common examples are:

    Reinstalling the bootloader.
    Rebuilding the initramfs image.
    Upgrading or downgrading packages.
    Resetting a forgotten password.
    Building packages in a clean chroot, see DeveloperWiki:Building in a Clean Chroot.
https://wiki.archlinux.org/index.php/change_root

A chroot is basically a special directory on your computer which prevents applications, if run from inside that directory, from accessing files outside the directory. In many ways, a chroot is like installing another operating system inside your existing operating system.
https://help.ubuntu.com/community/BasicChroot


  • sudo is a root binary setuid, which executes root commands on behalf of authorized users and the users need to enter their own password to execute system command followed by ‘sudo‘.

https://www.tecmint.com/su-vs-sudo-and-how-to-configure-sudo-in-linux/


  • Sudo (sometimes considered as short for Super-user do) is a program designed to let system administrators allow some users to execute some commands as root (or another user).

Auditing/logging: when a sudo command is executed, the original username and the command are logged.
For the reasons above, switching to root using sudo -i (or sudo su) is usually deprecated because it cancels the above features.
https://wiki.debian.org/sudo

VXLAN

  • Virtual Extensible LAN (VXLAN) is a network virtualization technology that attempts to address the scalability problems associated with large cloud computing deployments.
It uses a VLAN-like encapsulation technique to encapsulate OSI layer 2 Ethernet frames within layer 4 UDP datagrams, using 4789 as the default IANA-assigned destination UDP port number.
    VXLAN endpoints, which terminate VXLAN tunnels and may be either virtual or physical switch ports, are known as VXLAN tunnel endpoints (VTEPs)
      VXLAN is an evolution of efforts to standardize on an overlay encapsulation protocol.
        VXLAN is an evolution of efforts to standardize on an overlay encapsulation protocol. It increases scalability up to 16 million logical networks and allows for layer 2 adjacency across IP networks. Multicast or unicast with head-end replication (HER) is used to flood broadcast, unknown unicast, and multicast (BUM) traffic.

            Open vSwitch is an example of a software-based virtual network switch that supports VXLAN overlay networks.
              https://en.wikipedia.org/wiki/Virtual_Extensible_LAN
              • VXLAN vs VLAN: A Quick Overview
              VXLAN is a network virtualization scheme that enables users to create a logical network for virtual machines (VMs) across different networks. That is to say, it allows you to create a layer 2 network on top of layer 3 through encapsulation. What to emphasize is that you could potentially create 16 million networks using VXLAN, compared to the 4096 VLANs. In this case, VXLAN technology enables network to support far more VLANs.
              VXLAN vs VLAN: Why Choose VXLAN Instead of VLAN?
              VXLAN allows you to create smaller layer 2 domains that are connected over a layer 3 network. Which eliminates the need to use Spanning Tree Protocol (STP) to converge the topology – but with a more robust routing protocols in the layer 3 network. Without STP, none of your links are blocked, so you can obtain full value from all the ports you purchased. VXLAN also enables you to load-balance the traffic to get the best use of your available bandwidth. These all makes sense to maximize data center performance.
              http://www.fiber-optic-transceiver-module.com/vxlan-vs-vlan-which-is-best-fit-for-cloud.html

              every VLAN has unique id
              this ID is added to frame
              12bit long,2^12,4096 VLANs

              each VxLAN has an identifier called VNI,
              VNI, VxLAN network identifier
              24bits long,2^24,16777216 segments
              Multitenant SDN allows customers to allocate their own VLANs
              VxLAN creates virtual networks on top of existing infrastructure, is called overlay technology
              infrastructure runs on underlay

              underlay network at layer3
              all ports are routed,no need trunking or spanning tree
              some sort of dynamic routing is used,Equal-cost multi-path routing (ECMP)
              ECMP's use of load-sharing and fastrecovery
              choices for underlay:OSPF,EIGRP,ISIS,BGP
              Open Shortest Path First (OSPF)
              Enhanced Interior Gateway Routing Protocol (EIGRP)
              Intermediate System to Intermediate System (ISIS)
              Border Gateway Protocol (BGP)

              VxLAN itself overlay network
              each VNI is a seperate virtual network that runs over the underlay
              VNI is called bridge domain

              to create virtual network, traffic is encapsulated with UDP and IP,when it reaches destination switch, it is decapsulated
              underlay can be changed without redesigning overlay

              VTEPs,encapsulation
              VTEP provides connection between overlay and underlay
              each VTEP has an IP address in underlay network and has one or more VNIs
              source and destination VTEPs create stateless tunnels to deliver traffic from one host to another host
              tunnel exists long enough to deliver VxLAN frame

              MPBGP is control lane protocol over VxLAN

                  VxLAN overlay feature advantages:
                    scale up to approx 16M segments
                      address and traffic isolation

                          why MPBGP?
                            risks for data center and cloud deployments:
                              limited scale
                                centralised
                                  admin dependent

                                      BGP EVPN control plane over VXLAN:What does it solve for VxLAN?
                                        Optimize/eliminate flooding of BUM traffic
                                          virtual machine mobility with optimal forwarding
                                            Decentralization of VTEPS
                                              Large scale multi-tenancy in control plane
                                                Route filtering and constrained route distribution
                                                  Ingress replication of multi-destination traffic
                                                    multicast free underlay


                                                    MP-BGP
                                                    MULTIPROTOCOL BGP
                                                    Multiprotocol Extensions for BGP (MBGP)
                                                    Multicast BGP
                                                    extension to Border Gateway Protocol (BGP) that allows different types of addresses (known as address families) to be distributed in parallel.
                                                    standard BGP supports only IPv4 unicast addresses
                                                    Multiprotocol BGP supports IPv4 and IPv6 addresses
                                                    Multiprotocol BGP supports unicast and multicast variants of each
                                                    Multiprotocol BGP allows information about the topology of IP multicast-capable routers to be exchanged separately from the topology of normal IPv4 unicast routers
                                                    Multiprotocol BGP allows a multicast routing topology different from the unicast routing topology.
                                                    Although MBGP enables the exchange of inter-domain multicast routing information, other protocols such as the Protocol Independent Multicast family are needed to build trees and forward multicast traffic.
                                                    As an enhancement of BGP-4, MP-BGP provides routing information for various protocols, such as IPv6 (BGP4+) and multicast:

                                                    Multiprotocol BGP is also widely deployed in case of MPLS L3 VPN, to exchange VPN labels learned for the routes from the customer sites over the MPLS network, in order to distinguish between different customer sites when the traffic from the other customer sites comes to the Provider Edge router (PE router) for routing.

                                                    leased line connections are expensive;
                                                    traditional router-based networks connect via dedicated point-to-point links.
                                                    leased line solution are replaced by VPN type solutions

                                                    VPN;
                                                    service provider provides layer2 connection between two sites

                                                    VPN models;
                                                    Overlay VPN;service provider does not participate, provides layer2 virtual connection between two endpoints, virtual point-to-point connection
                                                    peer-to-peer VPN;service provider participates in customer routing,


                                                    MPLS VPN
                                                    forward packets based on label instead of IP
                                                    combines overlay and peer-to-peer model VPN

                                                    virtual route forwarding(VRF)
                                                    Provider Edge Device in MPLS domain maintains routes in seperate VRF routing table for each customer
                                                    VPN is established between Provider Edge Devices, from one end to another end, VPN label is added



                                                    • Understanding VXLAN

                                                    Virtual extensible LANs (VXLANs) introduced an overlay scheme that expands the Layer 2 network address space from 4K to 16 million, largely solving the scaling issues seen in VLAN-based environments.
                                                    Network overlays are created by encapsulating traffic and tunneling the traffic over a physical network.
                                                    You can use a number of tunneling protocols in the data center to create network overlays—the most common protocol is VXLAN.
                                                    VXLAN tunneling protocol encapsulates Layer 2 Ethernet frames in Layer 3 UDP packets.
                                                    This encapsulation enables you to create virtual Layer 2 subnets or segments that can span physical Layer 3 networks.
                                                    https://www.juniper.net/documentation/en_US/junos/topics/concept/evpn-vxlan-data-plane-encapsulation.html


                                                    • Overlay networking (aka SDN overlay) is a method of using software to create layers of network abstraction that can be used to run multiple separate, discrete virtualized network layers on top of the physical network, often providing new applications or security benefits.

                                                    https://www.sdxcentral.com/networking/sdn/definitions/what-is-overlay-networking/


                                                    • In data centers, VXLAN is the most commonly used protocol to create overlay networks that sit on top of the physical network, enabling the use of a virtual network of switches, routers, firewalls, load balancers, and so on. 

                                                    https://www.juniper.net/us/en/products-services/what-is/vxlan/

                                                    Comparison: VXLAN vs NVGRE vs STT vs LISP - Overlay Network Technologies

                                                    VXLAN: Virtual Extensible LAN
                                                    OTV: Overlay Transport Virtualization
                                                    LISP: Locator/Identifier Separation Protocol
                                                    NVGRE: Network Virtualization Using Generic Routing Encapsulation
                                                    STT: Stateless Transport Tunneling

                                                    Apart from the underlay network(IP network), Network overlays are virtual networks of interconnected nodes that share an underlying physical network, allowing deployment of applications that require specific network topologies without the need to modify the underlying network.

                                                    In the case of network-based overlays, this function is implemented on the first switch (at the top of the rack). With the help of Ovelay networks you can achieve and provide scalable Layer II networks for a multitenant cloud that extends beyond 4000 VLANs. This capability is very important for private and public cloud hosted environments.

                                                    http://www.routexp.com/2017/06/comparison-vxlan-vs-nvgre-vs-stt-vs.html


                                                    • Geneve is a simple, flexible tunnel format designed for the overlay network case in a data center fabric, specifically when the underlay is IP — but probably applicable to just about any tunneling situation (other than the quasi-MPLS tunnel)

                                                    in the data networking world is the absolute plethora of tunneling technologies we have available. Going way back to the beginning, there was SNA, GRE, IP-in-IP, and a host of others. In the midterm was have MPLS (though some will argue this isn’t a tunneling protocol — but the point is it can be used as a tunneling encapsulation) and 802.1q, and then more recently VxLAN, LISP, NVGRE, and — yet again — a host of others.
                                                    https://packetpushers.net/geneve/


                                                    • What is GENEVE?

                                                    in the current age of large multi-tenant clouds. A new network virtualization standard has emerged: GENEVE (Generic Network Virtualization Encapsulation) which promises to address the perceived limitations of the earlier specifications and support all of the capabilities of VXLAN, NVGRE and STT. Many believe GENEVE could eventually replace these earlier formats entirely.
                                                    The stated goal of GENEVE is to define an encapsulation data format only. Unlike the earlier formats, it does not include any information or specification for the control plane
                                                    https://www.redhat.com/en/blog/what-geneve