October 22, 2019 Python Security Programming Part 1
“The single biggest existential threat that’s out there, I think, is cyber. “ – Michael Mullen
This article will introduce the basics of Python security programming. The reader will learn how to implement Python network and security related scenarios and use cases.
Cybersecurity was discovered through a research project. It evolved through the creation of a virus. Charley Kline, who was a student of UCLA Professor Leonard Kleinrock, came up with an electronic message to Bill Duvall, who was a programmer. The first message was “login”. This was the first step in the world of messaging and communication. Robert Thomas, a researcher from BBN Technologies, came up with the first computer virus in 1970. The program was called creeper. It was able to move across the network leaving a trail of its path. It was outputting the message “I am the creeper: catch me if you can”.
In the new digital era, our privacy is vulnerable. In the networked world in which we live, we interact with computers and servers daily. The sensitive data which resides on the servers is related to financial data, personal information and intellectual property. Cyber attacks can result in privacy issues. Cybersecurity helps secure the information and save the data on the servers.
Enterprises are investing in securing their information from cyber attacks. Cybersecurity is related to people, processes and products related to technology. The technology helps in reducing threats and vulnerabilities, and aids in recovery, resiliency and responding to incidents.
Cybersecurity technology protects the networked systems from cyber attacks. The word cyber is related to systems, servers, network and data. Security is about securing the systems, network, application and information.
The code below shows a Python networking and security implementation. In this implementation, we look at the basic samples where Python is used for security.
- You need to set up Python3.5 to run the code samples below. You can download from this link.
os module has the features to use related to operating system. The features related to paths, folders and os commands are shown in the example below.
The code snippet below shows the os name and path joining methods of os.
path = os.path.join('bhagvan','python_scripts')
get current working directory method of os is shown below code snippet.
dir = os.getcwd()
The change directory method of os is shown in the code snippet below.
chdir = os.chdir('/Users/bhagvan.kommadi/desktop/topcoder/')
The make dirs method of os is shown in the code snippet below.
newdir = os.makedirs('/Users/bhagvan.kommadi/desktop/topcoder/blog/test')
The clear command is executed by using system method of os is shown in the code snippet below.
sys = os.system('clear')
The ipconfig ifcount command is executed by using system method of os is shown in the code snippet below.
sys1 = os.system('ipconfig ifcount')
The features related to files which are shown in the example below are opening, reading and writing files.
file = open('/Users/bhagvan.kommadi/desktop/topcoder/blog/test/check.txt')
readTxt = file.read()
newFile = open('/Users/bhagvan.kommadi/desktop/topcoder/blog/test/newfile.txt', 'w')
newFile.write('This is the first line')
Instructions for Running the Code
#running the os and file python code