zueducator

Online education for all on health, science, technology, business and management...

ad3

Wednesday, July 6, 2022

Role of Python in Cyber Security

 Role of Python in Cyber Security

Introduction

This article is specifically designed to discuss and learn about the role and importance of cyber security systems in our daily life as well as the application and role of Python in making the cyber security system robust, secure, and programmer-friendly.


Some important terminologies associated/related with cyber security systems and Python are:

Programming language

·      Programming language refers to a kind of computer language generally used in computer programming to implement algorithms.

·       Programming languages are used to write all computer programs and computer software.

·       Some useful programming languages that can be applied in cyber security are C, C++, C#, Javascript, Java, Ruby, and Python.

Ransomware

·       Ransomware refers to a type of malware that prevents or limits users from accessing their system, either by locking the system’s screen or locking the user’s file, or threatening to publish the victim’s personal data until a ransom is paid.

·       Some advanced malware uses a technique called cryptoviral extortion.

Embezzlement

·       Embezzlement refers to the theft or misappropriation of funds placed in one’s trust or belonging to one’s employer.

·       Embezzlement is a form of white-collar crime in which a person or entity intentionally misappropriates the assets entrusted to them.

·       Embezzlement simply means the stealing of money entrusted to one’s care.

·       Theft of currency is the most common form of embezzlement.

Phishing



·       Phishing attacks refer to the practice of sending fraudulent communications that appear to come from a reputable source.

·       Phishing is usually done to steal sensitive data like credit card and login information or to install malware on the victim’s machine.

·       Phishing is usually done through email.

Host discovery

·      Host discovery refers to the process of enumeration of live hosts.

·       Host discovery on your network is the first step to any vulnerability assessment.

·       Host discovery scan is launched to see what hosts are on your network, and associated information such as IP address, FQDN, OS, and open ports. After finding the hosts, hackers can choose what hosts they want to target in a specific vulnerability scan.

Privilege escalation

·       Privilege escalation refers to a type of network attack used to gain unauthorized access to systems within a security perimeter.

·       In this case, hackers start finding weak points in an organization’s defenses and gaining access to a system.

Evasion

·       In network security, evasion refers to bypassing an information security defense in order to deliver an exploit, attack, or another form of malware to a target network or system, without detection.

·       Evasion attacks are done at test time, in which the attacker aims to manipulate the input data to produce an error in the machine learning system.

·       Evasion attacks do not alter the behavior of the system but exploit its blind spots and weaknesses to produce the desired errors.

·       Some typical evasion techniques are password-protected compressed, and PGP encrypted files.

Persistence in cyber security

·       Persistence in cyber security refers to discreetly maintaining long-term access to systems despite disruptions such as restarts or changed credentials.

·       Persistence includes access and configuration to maintain the initial foothold of the systems.

Hacker

·        Hacker refers to a person who uses his abilities to gain unauthorized access to systems or networks in order to commit crimes.

·       Computer hacking activities include password cracking using a password cracking algorithm to gain access to a computer system, stealing your money and opening a credit card and bank account in your name, ruining your credit, requesting new personal identification numbers or additional credit cards, and make purchases without your consent.

Malware


·        Malware is also called malicious software.

·       Malware refers to any software intentionally designed to cause disruption to a computer, server, client computer, or computer network, leak private information, gain unauthorized access to information or systems, deprive user’s access to information, or which unknowingly interfere with the user’s computer security and privacy.

·       Malware is made available in the form of a file or code, typically delivered over a network, that infects, explores, steals, or conducts virtually any behavior an attacker wants.

·       Malware includes viruses, spyware, ransomware, adware, worm, Trojans, bots or botnets, rootkits, malvertising, and keyloggers.

Malware analysis

·       Malware analysis refers to the study or process of determining the functionality, origin, and potential impact of a given malware sample such as a virus, worm, Trojan horse, bots, rootkits, or backdoor.

·       Malware analysis helps to detect, examine, identify, and understand the nature of cyber threats and also helps to mitigate the potential threat.

·       Malware analysis is done regularly to analyze a suspicious file to check whether it is legitimate or malicious.

Cyber security

·       Cyber security is also known as information technology security or electronic information security.

·       Cyber security refers to the protection of internet-connected systems such as hardware, software, and data from cyber threats.

·       Cyber security framework’s major functions are to identify, protect, detect, respond, and recover.

Some important and major roles of cyber security systems in computing are:

·       Cyber security aims to protect the confidentiality, integrity, and availability of computer systems, networks, and data, against cyber attacks or unauthorized access.

·       Cyber security is generally used to protect the privacy of data and hardware that handles, stores, and transmits the data.

·       Cyber security protects the devices like smartphones, laptops, tablets, data, servers, network computers, and the services we access- both online and at work from malicious attack, theft, or damage.

·       Cyber security system protects sensitive data, personally identifiable information (PII), protected health information (PHI), personal information, intellectual property, data, and governmental and industry information system.

·       Cyber security system is usually used by individuals and enterprises to protect against unauthorized access to data centers and other computerized systems.

·       Cyber security system helps to protect all organizational assets from both external and internal threats as well as disruptions caused due to natural disasters.

Benefits of Cyber security system

·       Cyber security system provides data protection from unauthorized access, sensitive data loss or deletion.

·       Cyber security system prevents financial fraud and embezzlement.

·       Cyber security system prevents fraud through financial transactions like wire transfers and craigslist.

·       Cyber security system prevents intellectual property and cyber espionage.

·       Cyber security system protects against malware and ransomware attacks.

·       Cyber security system protects data from ID theft.

·       Cyber security system prevents damage to hardware.

·       Cyber security system helps to improve customer confidence in the computer system.

Python


·       Python refers to a high-level, interpreted, interactive, and object-oriented scripting language.

·       Python uses simple English keywords frequently and focuses less on punctuations.

·       Python is interpreted. Python is processed at runtime by the interpreter. You do not need to compile your program before executing it.

·       Python is interactive. A user can interact with the interpreter directly to write the programs using the Python prompt.

·       Python is an incredibly powerful object-oriented language. The language can be extended by adding new modules, even if they have been compiled in C and C++.

Benefits of learning Python

·       Python is remarkably easy to learn.

·       Python is easy to read. There is no need to be a skilled programmer.

·       Python makes use of an elegant syntax.

·       Python can be used to develop prototypes because it is easy to work with and read.

·       Most automation, data mining, and big data platforms rely on Python. This is because it is the ideal language to work with for general-purpose tasks.

·       Python powers Django, a complete and open source web application framework. Frameworks –like Ruby on Rails- can be used to simplify the development process.

·       Python is widely used by a number of big companies like Google, Pinterest, Instagram, Disney, Yahoo, Nokia, and IBM.

Main features of Python

·       Python has built-in-high level data types: strings, lists, dictionaries, etc.

·       Python has the usual control structures: if, if-else, if-else if, while, for, etc.

·       Multiple levels of organizational structure: functions, classes, modules, and packages. For instance, Python standard library.

·       In Python, source code is compiled to byte code without a separate compile step.

·       Python provides a consistent way to use objects.

·       Python is good for both small and large tasks.

·       Python uses indentation to show block structure.

·       Python is a scripting language and is suitable for embedding and for writing small unstructured scripts.

·       Python comes with the standard Python library, offering integrated support for a variety of common programming tasks like syncing with web servers, searching through text, and modifying files.

·       Python can be embedded into an application, which will provide a programmable interface for users of that app.

·       Python can be extended by adding new modules, even if they have been compiled in C or C++. Extension modules and extension types can be written by hand. There are also tools that help with this. For instance, SWIG, Sip, and Pyrex.

·       Cython enables us to generate C code from Python and “easily” create wrappers for C/C++ functions.

·       Jython is a version of Python that “plays” well with JAVA.

·       Python is compatible with OS‘s like Windows, Linux, Mac OS, and many brands of Unix, OS/2. Also, Python uses a similar interface on each one of those platforms, which means you can jump between them easily if necessary.

·       Python is used for software development at companies and organizations such as Google, Yahoo, CERN Industrial Light, Magic, and NASA.

Python for cyber security

·       Python is an extremely useful programming language for cyber security.

·       Cyber security professionals can learn Python quickly as Python has a short learning curve.

·       Python is good for those who have a limited programming background.

·       Python provides cyber security tools like cyber security analysis or penetration testing tools in its extensive standard library.

·       Cyber security professionals often use Python to build scripts and tools to prevent security breaches.

·       Python libraries are also used for code-cracking, decoding, network scanning, and even network attacks.

·       In cyber security, Python is used heavily in malware analysis, host discovery, the sending, and decoding of packets accessing servers, port scanning, network scanning, performing penetration testing tasks, and analyzing cyber threats.

·       For malware analysis, NLTK, Numpy, and Pandas are the most widely used Python libraries.

·       The Scikit library is widely used for implementing machine learning in cyber security operations.

Some important terminologies frequently used in Python are as under:

IDE (Integrated Development Environment)

·       An IDE includes an editor, debuggers, interpreter and other programming aids in one comprehensive program.

·       Some commercial IDE include Microsoft Visual Studio 2010, the Eclipse Foundation’s Eclipse IDE, Apple’s Xcode, and IDLE is a very simple IDE for Python.

IDLE

IDLE is a very simple Python IDE available for Windows, Linux, and Mac OS.

Interpreter

An interpreter translates the source code into the target machine language.

Compiler

A compiler translates the source code to the target code.

Debuggers

A debugger allows the programmer to simultaneously run a program and see which source code line is currently being executed. Debuggers are valuable for locating errors (also called bugs) and repairing programs that contain errors.

Profilers

A profiler is used to evaluate a program’s performance. A profiler indicates how many times a portion of a program is executed during a particular run and how long that portion takes to execute.

Dynamic

·       Types are bound to values, not to variables.

·       Python values are inspectable.

·       Strongly typed at runtime, not compile-time objects (values) have a type, but variables do not.

·       Function and method look-up is done at run time.

·       There is an interactive interpreter.

Editor

An editor allows the programmer to enter the program source code and save it to files.

Source code

Source code refers to any higher-level language code.

Target code

Target code refers to the interpreted machine language code.

Statement

A statement is a command that the interpreter executes.

Datatypes

·       Datatypes are the classification or categorization of data items.

·       Datatypes represent a kind of value that determines what operations can be performed on that data.

Some Python built-in datatypes used in this book are:

·       Text type                  str

·       Numeric types             int, float, complex

·       Sequence types          list, tuple, range

·       Set types                  set

·       Datatypes in Python also include classes and variables.

·       Every value in Python has a datatype.

Python numbers

·       Integers, floating-point numbers, and complex numbers fall under Python numbers.

·       Python numbers are defined as int, float, and complex numbers.

Python strings

Python strings refer to a sequence of Unicode characters. We can use single quotes or double quotes to represent strings. Multiline strings can be denoted using triple quotes, ‘  ’ ’ or “  ”  ”.

Python string literals

·       String literals in Python are surrounded by either single quotation marks or double quotation marks. For example, print(“welcome”) or  print(‘welcome’).

·       Strings in Python are arrays of bytes representing Unicode characters.

·       A single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.

Python list

·       Python list refers to an ordered sequence of items.

·       Python list is one of the most used data types in Python and is very flexible.

·       All the items in a Python list do not need to be of the same type.

Declaring Python list

·       Items separated by commas are enclosed within brackets [ ]. For example, a=[1, 2.2, ‘Python’]. We can use the slicing operator [ ] to extract an item or a range of items from a list.

·       Index starts from 0 in Python.    

·       Python lists are mutable, meaning, the value of elements of a list can be altered.

Python tuple

·       Python tuple refers to an ordered sequence of items whose elements are immutable. Python tuples once created cannot be modified.

·       Python tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.

·       Python tuples are defined within parenthesis () where items are separated by commas.

Python set

·       Python set refers to an unordered collection of unique items.

·       Python set is defined by values separated by a comma inside braces { }. Items in a set are not ordered.

·       Python set has unique values.

·       A Python set eliminates duplicates.

·       In the case of Python set, indexing has no meaning.

Iteration

Iteration repeats the execution of a sequence of code.

Python loop

Python supports only two primitive loops while loop and for a loop.

While loop

Using a while loop, we can execute a set of statements as long as a condition is true.

For loop

·       A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

·       With the for loop, we can execute a set of statements, once for each item in a list, tuple, set, etc.

Basic syntax is

for <variable-name> in <array-name>:

print(<variable-name>)

Python array

Python array refers to a special variable, which can hold more than one value at a time of the same datatype. For example,  fruit =[“Apple”,”Banana”,”Orange”]

Python class

·       A class can define specific sets of characteristics that are shared by all objects of that class.

·       Classes describe objects.

·       In Python, all classes have a function called –init-(), which is always executed when the class is being initiated.

·       We use the –init-() function to assign values to object properties or other operations that are necessary to do when the object is being created.

Syntax to declare a class in Python

class <class-name>:

pass

variable-name=value

           or

class MyFirstclass:

pass

·       A programmer should use four spaces for indentation.

·       Python constructs, indentation is used to delimit the classes, rather than braces or brackets.

·       The class definition starts with the “class” keyword. This is followed by a name (user-defined or of your choice) identifying the class and is terminated with a colon.  

·       The “pass” keyword is used on the second line to indicate that no further action needs to be taken.       

Python object

·       An object is a collection of data with associated behaviors.

·       Objects are instances of classes that can be associated with each other.

·       An object instance is a specific object with its own set of data and behaviors.

·       Almost everything in Python is an object, with its properties and methods.

Syntax to declare an object

Object-name=class-name()

print(object-name.variable-name)

Python function

·       Python function is a group of related statements that perform a specific task.

·       Python functions help to break our program into smaller and modular chunks.

·       A Python function avoids repetition and makes code reusable.

·       The simplest function accepts no parameters and returns no value to the caller. The def keyword introduces a function definition.

Syntax to declare a function is:

def function-name(parameters):

“”” doctring”””

Statement(s)

Syntax to call a function in Python

function-name (‘value’)

To call a function we simply type the function name with appropriate parameters.

Python method

·       Python methods refer to the behaviors that can be performed on a specific class of objects.

·       A method in Python is formatted identically to a function. It starts with the keyword “def” followed by a space and the name of the method. This is followed by a set of parenthesis containing the parameter list and terminated with a colon.

·       Python methods can also accept parameters and return values.

·       All methods have one required argument. This argument is conventionally named “self”. The “self” argument to a method is simply a reference to the object that the method is being invoked on.

Parameters

Parameters to a method are a list of objects that need to be passed into the method that is being called (the objects that are passed in from the calling object are usually referred to as arguments).

Module

A module is a collection of Python code that can be used in other programs.

from math import sqrt

from math import sqrt makes the sqrt function available for use in the program. The math module has many other mathematical functions. These include trigonometric, logarithmic, hyperbolic and other mathematical functions.

from math import *

The * symbol represents “everything”. This statement makes all the code in the math module available to the program. If a program needs to use many different functions from the math module, some programmers use this approach.

Python functions

·       Python functions include print(), input(), eval(), int(),float(), range() and type().

sqrt ( )

·       Python has a function in its standard library named sqrt(). The square root function accepts one numeric (integer or floating-point) value and produces a floating-point result.

·       The sqrt() function is part of a separate module.

print ( )

·       The print ( ) function prints the specified message (string or any other object) to the screen or other standard output device.

·       The print() function displays text in the console window. It does not compute and return a value to the client.

·       Empty print () function prints an empty line. It will leave a blank line in the output.

Python casting

·       Python casting is done to specify a type on to a variable.

·       Casting in Python is done using the constructor function.

int() constructor function

int() constructs an integer number from an integer literal, a float literal (by rounding down to the previous whole number) literal.

float() constructor function

float() constructs a float number from an integer literal, a float literal.

str()constructor function

str() constructs a string from a wide variety of data types, including strings, integer literals, and float literals.

type() function

·       type() function is used to get the datatype of any object.

·       type() function is used to know which class a variable or a value belongs to.

instance()

instance() function is used to check if an object belongs to a particular class.

The range ( ) function

·       The range ( ) function is used to loop through a set of code a specified number of times.

·       The range ( ) function defaults to 0 as a starting value.

·       The range ( ) function defaults to increment the sequence by 1. However, it is possible to specify the increment value by adding a third parameter range (2, 30, 3).

·       It is possible to specify the starting value by adding parameter range (2, 6) which means values from 2 to 6 but not including 6.

len() method

The len() method is used to return the length of an array( the number of elements in an array). For example, p=len(array-name)

append( ) method

append( ) method is used to add an element to an array. The basic syntax is array-name. append(“<element-names>”)

pop() method

pop()method is used to remove an element from an array. Basic syntax is array-name.pop(index). For example, fruit.pop(1). This deletes the second element of the fruit array.

remove() method

·       remove()method is used to remove an element from an array. Basic syntax is array-name.remove(“<element-name>”). For example, fruit.remove(“apple”)

·       The remove() method only removes the first occurrence of the specified value.

insert () method

insert()method is used to add an element at the specified position. Basic syntax is inert(<position index>, <”element-name”> ). For example, insert (2,”apple”).

reverse() method

reverse() method is used to reverse the order of the list.

sort() method

sort()method is used to sort the list.


Simple Python programs

Programs based on Python string

1.  Program to display a character constant.

Print(‘a’)           #output statement

Output:

a


2. Program to display a string constant.

print(“Apple”)      #output statement

Output:

Apple


3. Program to display more than one string in a single line without using variable.

Print(“Apple”,”Orange”,”Papaya”)

Output:

Apple   orange   papaya


4. Program to display different types of string using variables.

A=’A’          #Initialization statement

print(a)              #output statement

b=”Apple”

print(b)

c=”Welcome to python”

print(c)            #output statement

Output:

A

Apple

Welcome to Python


5. Program to display different data belonging to different datatypes.

print("welcome to python")

print("This is 2018")

print(5+10)

a=5          #Initialization statement

b=10

print("Sum=",a+b)

c=10.55             #Initialization statement

e=3.5          

d=int(c)         #type casting

print("d=",d)

print(c+e)        #output statement

Output:

Welcome to python

This is 2018

15

Sum=15

d=10

14.05


6. Program to display more than one string using variables.

S1=”apple”         #Initialization statement

s2= “orange”

print(s1, s2)

print(“Strings are:”, s1, “,”,s2)

Output:

apple   orange

Strings are: apple, orange


7. Program to display strings using curly braces{}.

print("I love {0} and {1}".format('ab','bc'))

print("I love {1} and {0}".format('ab','bc'))

Output:

I love ab and  bc      

I love bc  and  ab


8. Program to display a string using input() built -in-function.

a=input("Enter your name:")

print("Name:",a)

Output:

Enter your name: Apple

Apple


9. Program to input any name and display it.

a=input("Enter first name:")

b=input("Enter last name:")

print("Name:",a,b)

Output:

Enter first name: Tom

Enter last name: Paddy

Name: Tom paddy


10. Program to display a string using function with argument.

def f1(a):     #function declaration

 print (a)

f1(a="Apple")       #calling function

Output:

Apple


11. Program to display strings using variable number of arguments.

def f1(*argv):       #function declaration

 for arg in argv:     # for loop

  print (arg)

f1("Apple", "Orange", "Papaya")     

Output:

Apple

Orange

Papaya


12. Program to display a string using condition.

a=1        #Initialization statement

if a==1:       #conditional statement

 print(" Good")

else:

 print("Bad")     #output statement

Output:

Good


13. Program to display a string using multiple condition.

a=1       #Initialization statement

if a==1:          #conditional statement

 print("very good")

elif a==2:

 print("good")

elif a==3:       #conditional statement

 print("satisfactory")   #output statement

else:

 print("poor")        #output statement

Output:

Very good


14. Program to enter any character and display grade accordingly.

a=input("Enter A,B,C,-------:")

if a=='A':        #conditional statement

 print("Good")

elif a=='B':

 print("Satisfactory")

else:

 print("Bad")         #output statement

Output:

Enter A,B,C,-------: B

Satisfactory


15. Program to display list members using for loop.

fruit=['Apple','Guava','Orange']

for a in fruit:           #for loop

 print(a)            #output statement

Output:

Apple

Guava

Orange


16. Program to display strings using Python list.

app=['Banana','Apple','Papaya']      #array

for ap in app:          #for loop declaration

 print(ap)           #output statement

Output:

Banana

Apple

Papaya


17. Program to concatenate any two strings.

print("Enter first name:")

x=input()

print("Enter second name:")

y=input()

print("HELLO,"+x+’ ’+y)      #output statement

Output:

Enter first name:

Steve

Enter second name:

Orange

HELLO, Steve Orange


18. Program to display the indexed member of a string.

a='welcome to Python'

print("a[4]=",a[4])      #for character position

print("a[6:11]=",a[6:11])

Output:

a[4]= o

a[6:11]= e to


19. Program to display a string using function.

def apple3():      #class declaration

  print("apple")

apple3() #calling function 

Output:

apple


20. Program to display a string using default argument.

def apple(name, msg="Good morning"):

 print ("Hello",name+','+msg)

apple("John")

Output:

Hello, John Good morning


21. Program to display strings using arbitrary arguments.

def fruit(*names):     #function declaration

 for a in names:

  print(a)

def person(*names): #function declaration

 for a in names:

  print("Hello",a)

fruit("apple","orange","papaya")

person("Paul","John","Tony")

Output:

apple

orange

papaya

Hello Paul

Hello John

Hello Tony


22. Program to display different strings using different methods.

fruits=["apple","banana","orange"]

x=fruits[0]

y=fruits[1]

print(x)

print(y)

print(fruits[2])

fruits.append("papaya")

print (fruits)

fruits.remove("banana")

print (fruits)

fruits.pop(1)

print (fruits)

fruits .append("cherry")

fruits.append("guava")

print (fruits)

fruits.sort()

print (fruits)

fruits.insert(2,"pineapple")

print (fruits)

fruits.sort()

print (fruits)

fruits.reverse()

print (fruits)

Output:

apple

banana

orange

[‘apple’,’ banana’,’ orange’, ‘papaya’]

[‘apple’, ‘orange’, ’papaya’]

[‘apple‘, ‘papaya’]

[‘apple’, ‘papaya’, ’cherry’, ’guava’]

[‘apple’, ’cherry’, ’guava’, ‘papaya’]

[‘apple’, ’cherry’, ’pineapple’, ’guava’, ‘papaya’]

[‘apple’, ’cherry’, ’guava’, ‘papaya’, ’pineapple’]

[‘pineapple’, ‘papaya’, ’guava’, ’cherry’ ,‘apple’]


 


No comments:

Post a Comment