Professional Documents
Culture Documents
StudyMaterial BNCSD601B
StudyMaterial BNCSD601B
Study Material
Vulnerability Analysis / Penetration Testing (BNCSD601B)
_____________________________________________________________________________________________
Module 1: 2
Module 2: 27
Module 3: 73
Module 4: 90
Module 5: 123
Module 6: 140
Module 7: 165
Module 8: 180
Installing Python:-
there are three ways to install the official Python distribution on Windows:
1. Microsoft Store package: The most straightforward installation method on Windows involves
installing from the Microsoft Store app. This is recommended for beginner Python users looking
for an easy-to-set-up interactive experience.
2. Full Installer: This approach involves downloading Python directly from the Python.org website.
This is recommended for intermediate and advanced developers who need more control during
the setup process.
3. Windows Subsystem for Linux (WSL): The WSL allows you to run a Linux environment directly
in Windows.
In this section, we’ll focus on only the first two options, which are the most popular installation methods
in a Windows environment.
The two official Python installers for Windows aren’t identical. The Microsoft Store package has some
important limitations.
The Microsoft Store package is an easily installable Python interpreter that is intended mainly for
interactive use, for example, by students.
The key takeaway here is that the Microsoft Store package is “intended mainly for interactive use.” That
is, the Microsoft Store package is designed to be used by students and people learning to use Python for
the first time.
In addition to targeting beginning Pythonistas, the Microsoft Store package has limitations that make it ill-
suited for a professional development environment. In particular, it does not have full write access to
shared locations such as TEMP or the registry.
If you’re new to Python and focused primarily on learning the language rather than building professional
software, then you should install from the Microsoft Store package. This offers the shortest and easiest
path to getting started with minimal hassle.
On the other hand, if you’re an experienced developer looking to develop professional software in a
Windows environment, then the official Python.org installer is the right choice. Your installation won’t be
limited by Microsoft Store policies.
You’ll likely see multiple versions that you can choose to install:
Select Python 3.8, or the highest version number you see available in the app, to open the installation
page.
Warning: Make sure that the Python application you’ve selected is created by the Python Software
Foundation.
The official Microsoft Store package will always be free, so if the application costs money, then it’s
the wrong application.
Alternatively, you can open PowerShell and type the following command:
C:\> python
If you don’t already have a version of Python on your system, then when you press Enter, the Microsoft
Store will automatically launch and take you to the latest version of Python in the store.
1. Click Get.
2. Wait for the application to download. When it’s finished downloading, the Get button will be
replaced with a button that says Install on my devices.
3. Click Install on my devices and select the devices on which you’d like to complete the installation.
4. Click Install Now and then OK to start the installation.
5. If the installation was successful, then you’ll see the message “This product is installed” at the top
of the Microsoft Store page.
Congratulations! You now have access to Python, including pip and IDLE!
1. Open a browser window and navigate to the Python.org Downloads page for Windows.
2. Under the “Python Releases for Windows” heading, click the link for the Latest Python 3 Release
- Python 3.x.x. As of this writing, the latest version was Python 3.8.4.
3. Scroll to the bottom and select either Windows x86-64 executable installer for 64-bit or Windows
x86 executable installer for 32-bit.
If you aren’t sure whether to select the 32-bit or the 64-bit installer, then you can expand the box below
to help you decide.
Once you’ve chosen and downloaded an installer, run it by double-clicking on the downloaded file. A
dialog box like the one below will appear:
1. The default install path is in the AppData/ directory of the current Windows user.
2. The Customize installation button can be used to customize the installation location and which
additional features get installed, including pip and IDLE.
3. The Install launcher for all users (recommended) checkbox is checked default. This means every
user on the machine will have access to the py.exe launcher. You can uncheck this box to restrict
Python to the current Windows user.
4. The Add Python 3.8 to PATH checkbox is unchecked by default. There are several reasons that
you might not want Python on PATH, so make sure you understand the implications before you
check this box.
The full installer gives you total control over the installation process.
Warning: If you don’t know what PATH is, then it’s highly recommended that you do not install with the
full installer. Use the Microsoft Store package instead.
Customize the installation to meet your needs using the options available on the dialog box. Then
click Install Now. That’s all there is to it!
Congratulations—you now have the latest version of Python 3 on your Windows machine!
About Python:-
Python is a high-level, general-purpose programming
language. Its design philosophy emphasizes code
readability with the use of significant indentation. Python is
dynamically typed and garbage-collected. It supports
multiple programming paradigms, including structured,
object-oriented and functional programming.
Exceptions. ...
File I/O.
Features of Python:-
Easy to Code. Python is a very high-level programming language, yet it is effortless to learn. ...
Easy to Read. ...
Free and Open-Source. ...
Robust Standard Library. ...
Interpreted. ...
Portable. ...
Object-Oriented and Procedure-Oriented. ...
Extensible.
Possible MCQs:-
Correct Answer
Answer Answer Answer Answer Number
Question
Number 1 Number 2 Number 3 Number 4 (Numeric eg:
1,2)
Who developed Python
Wick van Rasmus Guido van
Programming Niene Stom 3
Rossum Lerdorf Rossum
Language?
Which type of object-
structured functional all of the
Programming does oriented 4
programming programming mentioned
Python support? programming
Discover that "Is Python
case sensitive when machine none of the
No yes 2
dealing with dependent mentioned
identifiers?".
Which of the following is
the correct extension of .python .pl .py .p 3
the Python file?
Python code is Python code is
Python code is
Is Python code both compiled neither Python code is
only 1
compiled or interpreted? and compiled nor only compiled
interpreted
interpreted interpreted
What arithmetic
operators cannot be All of the
* + – 3
used with strings in mentioned
Python?
Short Questions:-
1. What are the different popular python IDEs?
2. What are the different methods we can use to install Python?
Long Questions:-
1. How to install Python in a Windows machine?
2. How to install Python in a Linux machine?
3. How to install any popular IDE like VS Code in Windows Machine?
4. Compare between Python2 and Python3.
MAC address is used by the Media Access Control (MAC) sublayer of the Data-Link
Layer. MAC Address is worldwide unique since millions of network devices exist and we
need to uniquely identify each.
MAC Address is a 12-digit hexadecimal number (6-Byte binary number), which is mostly
represented by Colon-Hexadecimal notation. The First 6-digits (say 00:40:96) of MAC
Address identifies the manufacturer, called OUI (Organizational Unique Identifier).
IEEE Registration Authority Committee assigns these MAC prefixes to its registered
vendors.
Here are some OUI of well-known manufacturers :
CC:46:D6 - Cisco
3C:5A:B4 - Google, Inc.
3C:D9:2B - Hewlett Packard
00:9A:CD - HUAWEI TECHNOLOGIES CO.,LTD
The rightmost six digits represent Network Interface Controller, which is assigned by
the manufacturer.
1. Unicast: A Unicast addressed frame is only sent out to the interface leading to a
specific NIC. If the LSB (least significant bit) of the first octet of an address is set to
zero, the frame is meant to reach only one receiving NIC. MAC Address of source
machine is always Unicast.
2. Multicast: The multicast address allows the source to send a frame to a group of
devices. In Layer-2 (Ethernet) Multicast address, LSB (least significant bit) of the
first octet of an address is set to one. IEEE has allocated the address block 01-80-
C2-xx-xx-xx (01-80-C2-00-00-00 to 01-80-C2-FF-FF-FF) for group addresses for
use by standard protocols.
Media Access Control address (MAC address) is a unique identifier assigned to most
network adapters or network interface cards (NICs) by the manufacturer for identification
and used in the Media Access Control protocol sub-layer.
An Ethernet MAC address is a 48-bit binary value expressed as 12 hexadecimal digits
(4 bits per hexadecimal digit). MAC addresses are in a flat structure and thus they are
not routable on the Internet. Serial interfaces do not use MAC addresses. It does NOT
contain a network and host portion with the address. It is used to deliver the frame to the
destination device.
Mac_changer.py
#! /usr/bin/env python
import subprocess
interface = input(”Enter interface name: ”)
newmac = input(”Enter new MAC address: ”)
Python Lists are just like dynamically sized arrays, declared in other languages (vector
in C++ and ArrayList in Java). In simple language, a list is a collection of things, enclosed
in [ ] and separated by commas.
The list is a sequence data type which is used to store the collection of
data. Tuples and String are other types of sequence data types.
List = [1, 2, 4, 4, 3, 3, 3, 6, 5]
print("\nList with the use of Numbers: ")
print(List)
A Set is an unordered collection data type that is iterable, mutable, and has no duplicate
elements.
Set are represented by { } (values enclosed in curly braces)
The major advantage of using a set, as opposed to a list, is that it has a highly optimized
method for checking whether a specific element is contained in the set. This is based on
a data structure known as a hash table. Since sets are unordered, we cannot access
items using indexes as we do in lists.
Dictionary in Python is a collection of keys values, used to store data values like a
map, which, unlike other data types which hold only a single value as an element.
Example of Dictionary in Python
Dictionary holds key:value pair. Key-Value is provided in the dictionary to make it
more optimized.
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print(Dict)
Number data types store numeric values. They are immutable data types, which means
that changing the value of a number data type results in a newly allocated object.
Different types of Number data types are :
int
float
complex
num = -8
# print the data type
print(type(num))
Float type
This is a real number with floating-point representation. It is specified by a decimal point.
Optionally, the character e or E followed by a positive or negative integer may be
appended to specify scientific notation. . Some examples of numbers that are
represented as floats are 0.5 and -7.823457.
They can be created directly by entering a number with a decimal point, or by using
operations such as division on integers. Extra zeros present at the number’s end are
ignored automatically.
num = 3/4
print(type(num))
Complex type
A complex number is a number that consists of the real and imaginary parts. For
example, 2 + 3j is a complex number where 2 is the real component, and 3 multiplied by
j is an imaginary part.
num = 6 + 9j
print(type(num))
String1 = '''Geeks
For
Life'''
print("\nCreating a multiline String: ")
print(String1)
Variables in Python:-
Python Variable is containers which store values. Python is not “statically typed”. We
do not need to declare variables before using them or declare their type. A variable is
created the moment we first assign a value to it. A Python variable is a name given to a
memory location. It is the basic unit of storage in a program.
Rules for creating variables in Python
A variable name must start with a letter or the underscore character.
A variable name cannot start with a number.
A variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ ).
Variable names are case-sensitive (name, Name and NAME are three different
variables).
The reserved words(keywords) cannot be used naming the variable.
# An integer assignment
age = 45
# A floating point
salary = 1456.8
# A string
name = "John"
print(age)
print(salary)
print(name)
def fun():
print("Welcome to GFG")
else:
print("i is greater than 15")
print("i'm in else Block")
print("i'm not in if and not in else Block")
i = 20
if (i == 10):
print("i is 10")
elif (i == 15):
print("i is 15")
elif (i == 20):
print("i is 20")
else:
print("i is not present")
The Algorithm designed are language-independent, i.e. they are just plain instructions
that can be implemented in any language, and yet the output will be the same, as
expected.
Types of Algorithms:
There are several types of algorithms available. Some important algorithms are:
1. Brute Force Algorithm: It is the simplest approach for a problem. A brute force
algorithm is the first approach that comes to finding when we see a problem.
2. Recursive Algorithm: A recursive algorithm is based on recursion. In this case, a
problem is broken into several sub-parts and called the same function again and again.
3. Backtracking Algorithm: The backtracking algorithm basically builds the solution
by searching among all possible solutions. Using this algorithm, we keep on building
the solution following criteria. Whenever a solution fails we trace back to the failure
point and build on the next solution and continue this process till we find the solution or
all possible solutions are looked after.
4. Searching Algorithm: Searching algorithms are the ones that are used for
searching elements or groups of elements from a particular data structure. They can be
of different types based on their approach or the data structure in which the element
should be found.
Here, There are 2 variables arr[], and x, where the arr[] is the variable part of n
elements and x is the fixed part. Hence S(P) = 1+n. So, the space complexity depends
on n(number of elements). Now, space depends on data types of given variables and
constant types and it will be multiplied accordingly.
import subprocess
def find_mac_address():
mac_regex = re.compile(r"(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})")
if mac_address:
return list(set(mac_address))
else:
mac_address_list = find_mac_address()
print(mac_address_list)
import re
import subprocess
def find_mac_address():
output = subprocess.check_output(["ipconfig", "/all"])
mac_regex = re.compile(r"(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})")
mac_address = re.search(mac_regex, output.decode())
if mac_address:
return mac_address.group()
else:
return "MAC address not found."
mac_address_list = find_mac_address()
print(mac_address_list)
Possible MCQs:-
All keywords in
None of the
Python are in Capitalized lower case UPPER CASE 4
mentioned
_________.
Which of the
following functions
can help us to find
sys.version(1) sys.version(0) sys.version() sys.version 4
the version of python
that we are currently
working on.
conversion of
The process of conversion of a
conversion of a byte stream conversion of a
pickling in Python Python object
a datatable into into Python list into a 1
includes hierarchy into
a list object datatable
____________. byte stream
hierarchy
What is the correct
output of the
following Python
56.236 56.23 56.00 56.24 4
expression if
x=56.236.
print("%.2f"%x).
What is the correct
output of the
following Python Error 6 4 3 3
function.
len(["hello",2, 4, 6])
Find the module in
the python standard
library that parses getarg getopt main Os 2
options received from
the command line.
To add a new
element to a list we
list1.addEnd(5) list1.addLast(5) list1.append(5) list1.add(5) 3
use which Python
command.
What is the maximum
possible length of an 79 characters 65 characters 32 characters None 4
identifier in Python.
Which of the
following is a Python {1, 2, 3} {} [1, 2, 3] (1, 2, 3) 4
tuple?
Find the correct
output of 9.0 6.0 3.0 None 1
print(math.pow(3, 2)).
On wireless networks
________ filtering is OUI IP NIC MAC 4
the security measure.
vulnerabilities in a
system.
Short Questions:-
Long Questions:-
1. What is a MAC address and what are its types?
The job of ARP is essentially to translate 32-bit addresses to 48-bit addresses and vice versa. This is
necessary because IP addresses in IP version 4 (IPv4) are 32 bits, but MAC addresses are 48 bits.
ARP works between Layers 2 and 3 of the Open Systems Interconnection model (OSI model). The
MAC address exists on Layer 2 of the OSI model, the data link layer. The IP address exists on Layer
3, the network layer.
ARP can also be used for IP over other LAN technologies, such as token ring, fiber distributed data
interface (FDDI) and IP over ATM.
When a new computer joins a LAN, it is assigned a unique IP address to use for identification and
communication. When an incoming packet destined for a host machine on a particular LAN arrives at
a gateway, the gateway asks the ARP program to find a MAC address that matches the IP address.
A table called the ARP cache maintains a record of each IP address and its corresponding MAC
address.
All operating systems in an IPv4 Ethernet network keep an ARP cache. Every time a host requests a
MAC address in order to send a packet to another host in the LAN, it checks its ARP cache to see if
the IP to MAC address translation already exists. If it does, then a new ARP request is unnecessary.
If the translation does not already exist, then the request for network addresses is sent and ARP is
performed.
ARP broadcasts a request packet to all the machines on the LAN and asks if any of the machines are
using that particular IP address. When a machine recognizes the IP address as its own, it sends a
reply so ARP can update the cache for future reference and proceed with the communication.
Host machines that don't know their own IP address can use the Reverse ARP (RARP) protocol for
discovery.
ARP cache size is limited and is periodically cleansed of all entries to free up space. Addresses tend
to stay in the cache for only a few minutes. Frequent updates enable other devices in the network to
see when a physical host changes their requested IP addresses. In the cleaning process, unused
entries are deleted along with any unsuccessful attempts to communicate with computers that are not
currently powered on.
Steps-
1. Create ARP request directed to broadcast MAC asking for IP
Two main parts-
Use ARP to ask who has the target IP
Set destination MAC to broadcast MAC
Lists are used to store multiple items in a single variable.Lists are one of 4 built -in data types in
Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different
qualities and usage.
List items are ordered, changeable, and allow duplicate values.List items are indexed, the first
item has index [0], the second item has index [1] etc.
When we say that lists are ordered, it means that the items have a defined order, and that order will
not change. If you add new items to a list, the new items will be placed at the end of the list.
The list is changeable, meaning that we can change, add, and remove items in a list after it has been
created. Since lists are indexed, lists can have items with the same value:
To determine how many items a list has, use the len() function:
From Python's perspective, lists are defined as objects with the data type 'list':
Dictionaries:-
These are used to store data values in key:value pairs. A dictionary is a collection which is ordered*,
changeable and do not allow duplicates. As of Python version 3.7, dictionaries are ordered. In Python
3.6 and earlier, dictionaries are unordered.
Dictionaries are written with curly brackets, and have keys and values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Dictionary items are ordered, changeable, and does not allow duplicates. Dictionary items are
presented in key:value pairs, and can be referred to by using the key name.
As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries
are unordered.
When we say that dictionaries are ordered, it means that the items have a defined order, and that
order will not change.
Unordered means that the items does not have a defined order, you cannot refer to an item by using
an index.
Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary
has been created.
thisdict = {
"brand": "Ford",
"electric": False,
"year": 1964,
"colors": ["red", "white", "blue"]
}
Nested Lists:-
Nested Dictionary: -
if type (d [ i ] ) in dict:
for k in d [ i ] :
print (k, ‘=’, d[i][k])
else:
print (i, ‘=’, d[i])
Output:-
Course
Fees
1
----------------
Course = Python
Fees = 20000
Course = Java Script
Fees = 15000
A network scanner is a software tool that scans the network for connected devices. It is also used for
diagnostic and investigative purposes to find and categorize what devices are running on a network.
This tool takes an IP address or a range of IP addresses as input and then scans each IP Addresses
sequentially and determines whether a device is present on that particular IP address or not. It scans
the network and returns an IP address and it’s corresponding MAC address if the device is present. A
Network Scanner uses ARP Request and Response to scan the entire network to find active devices
If it is still not clear what ARP is and how it works then refer to the images below.
In this function, we’ll have to do the following things to be able to scan the network:
Create an ARP Request.
Create an Ethernet Frame.
Place the ARP Request inside the Ethernet Frame.
Send the combined frame and receive responses.
Parse the responses and print the results.
What connects IP
Address Transmission
address to the File Transfer File Transfer
Resolution Control 1
Physical address of Protocol Protocol
Protocol Protocol
devices?
The ARP protocol
operates on which
Physical Data Link Network Transport 2
layer of the OSI
model?
Find in which year
ARP was defined
1982 1992 2002 2012 1
first time in Request
for Comment.
Select which of the
following RFC
RFC820 RFC822 RFC824 RFC826 4
number is used for
ARP.
Which of the
following list1 = list([1, all of the
list1 = list() list1 = [] 4
commands will 2, 3]) mentioned
create a list?
Find the output
[‘h’, ‘e’, ‘l’, ‘l’,
when we execute [‘hello’] [‘llo’] [‘olleh’] 1
‘o’]
list(“hello”).
Suppose list1 is [4,
2, 2, 4, 5, 2, 1, 0],
Which of the all of the
print(list1[2:]) print(list1[:2]) print(list1[:-2]) 4
following is correct mentioned
syntax for slicing
operation.
Suppose list1 is [2,
33, 222, 14, 25].
Error 2 25 None 3
Find what is list1[-
1].
Which of the d=
following d = {“john”:40, All of the
d = {} {40:”john”, 4
statements create a “peter”:45} mentioned
45:”peter”}
dictionary?
Suppose d =
{“john”:40,
“peter”:45}, to
d.delete(“john”: del
delete the entry for del d[“john”] 3
40) d.delete(“john”) d(“john”:40)
“john” what
command do we
use.
Short Questions:-
Long Questions:-
1. What is ARP spoofing ?