Python programming for cybersecurity
Overview
AS we know Python is a powerful programming language because it’s very easy. It’s a benefit for beginners, but also for experienced programmers. This easiness and better code readability allows the programmer to create very complex programs easily, and the better code readability translates into better and faster debugging of the program. Due to which, the programmer can create the final program much easily and much faster than in other languages.
You can go in the field of Science and Data Analytics (numpy, scipy module), Gaming (pygame module- althought you can make only small 2D games, but very easily), Web Development (Django), Android development (kiwi module), AI, Cybersecurity and IOT.
It’s not only a powerful and popular, language, it’s the language in demand. Companies require more and more Python develops, due to the rise in the field of AI and Internet of things (IOT), and Python has the support for it.
Use Python in cybersecurity
Any of the following can be performed in python without using any other third-party tool:
- Port Scanning.
- Web scraping.
- Network monitoring.
- Malware analysis.
…And many other implementations related to security application.
Port scanning
Using Nmap module allow us to scan network ports for A-Z here is an example below provide a sample code to generate a Port Scanner. It will work for both the web application as well as remote Host.
Web scraping
Imagine you have to pull a large amount of data from websites and you want to do it as quickly as possible. How would you do it without manually going to each website and getting the data? Well, python in the answer! by utilize BeautifulSoup and requests modules we can get HTML & XML files.
Network monitoring
Python is one of the widely used languages for writing the special scripts for packet capturing, classification and machine learning. It should be mentioned that a great deal of network monitoring and logging software has been developed in python. shinken and Zenoss are popular tools used for monitoring the network data collection, hosts, alerts and messaging and include lots of active and passive monitoring methods. That are based on Python.
Malware analysis
There are many python-based malware analysis tools you can use today.
Below are just a few that I find helpful for static file analysis:
-AnalyzePE -Pyew -Pescanner
These tools produce useful output and serve as excellent starting points for absorb python. By simply viewing the source code and performing research as necessary, you can understand from what the authors wrote and modify the code to serve your own purpose. Let’s read in a file for testing. We’ll use an emotet sample.
· Step one
# pip install pefile
· Step two
Run python in the terminal and type the following command below:
The get_imphash() method worked as expected, providing the file’s import table hash. You can explore this module by viewing its help information.
Type help(pefile). Below is an excerpt of the output.
In addition to an introduction of the module, we see a description of classes contained within the module. Scrolling down provides information about each class.
You may also revisit the pefile library documentation to explore additional static characteristics worth including in this spreadsheet. With more detail, this document could help you triage and prioritize samples for analysis. I leave these tasks to you for further exploration.
Remember... practice make perfect !
I have a collection of tools in my github It will lead you to a plethora of tools and utilities built exclusively in python.
conclusion
Programming has become essential to cyber security. IT security professional must efficiently write applications and scripts; often on short notice. The Python language provides unmatched ease, flexibility, and functionality for both new and experienced coders. It has emerged as a top choice for cyber security professionals because it lessens development effort and the coder’s learning curve.
Hackers, penetration testers, and other security experts need a language library that provides the entire spectrum of features to create powerful and often novel programs. Python comes with modules to support Web activities such as parsing HTTP and XML and building clients. Django and other open-source Web frameworks are available from developers favoring the rapid application development methodology. Third-party modules offer robust features, such as optimized calculation handling, that make Python an increasingly solid language for data applications.
Python’s simple and clean structure, modular design, and extensive library make it ideal for security applications. Cyber experts rely on the capability to rapidly code programs and the feature set to implement new strategies and techniques. No other language offers as powerful a combination, and Python stands as the must-know language for the serious security professional.
Resources
- https://realpython.com/beautiful-soup-web-scraper-python/
- https://github.com/thearrival/
- M. Wahal, T. Choudhury and M. Arora, "Intrusion Detection System in Python," 2018 8th International Conference on Cloud Computing, Data Science & Engineering (Confluence), Noida, 2018, pp. 348-353, doi: 10.1109/CONFLUENCE.2018.8442909.
- https://www.andreafortuna.org/2019/09/25/pepper-a-python-script-to-perform-malware-static-analysis-on-portable-executable-format/
- Google.com
Application Security | DevSecOps | Vulnerability Management | CISSP | CEH | ISO 27001 LA
4 年Password brute forcing, Fuzzing, process automation etc also included.