Introduction I used to use PDFSam to do PDF file merging when submitting my claims which consist of many receipts and claim application form which are all in PDF format, however since I know python an easier and free way to do PDF merging is to use the PyPDF2 module. Credits go to the PyPDF2 … Continue reading python – Merge PDF files
Category: Python
Python scripting for anything interesting…
hackthebox – Shocker
Enumeration I am using my own bash script to do a more efficient nmap scan. Here's the simple bash script: #!/bin/bash if [ $# -eq 0 ]; then echo "Usage: $0 <target_ip> <output_file>" else ports=$(nmap -T4 --min-rate=1000 -p- $1|grep -e ^[0-9]|cut -d "/" -f 1| tr '\n' ','|sed 's/,$//') nmap -sC -sV -p $ports -vvv … Continue reading hackthebox – Shocker
Simple terminal in python
Suppose you are pentesting a web app and you have found a file upload vulnerability and have successfully uploaded a php file that has this content: <?php echo shell_exec($_GET['cmd']); ?> Everytime you need to execute command to find out more about the system that hosts that web app you may need to do something like … Continue reading Simple terminal in python
python – Generating RSA key pairs with pycryptodome module
Thank you for the creator of pycryptodome module, this module has made RSA key pair easy. This recipe presents a function for generating private and public key pair. from Crypto.PublicKey import RSA # pycryptodome def rsa_key_gen(bits=2048, privatekey_path=RSA_PRIVATE_KEY, pubkey_path=RSA_PUBLIC_KEY): private_key = RSA.generate(bits) with open(privatekey_path, "wb") as privkey_file: privkey_file.write(private_key.export_key()) with open(pubkey_path, "wb") as pubkey_file: pubkey_file.write(private_key.publickey().export_key())
[python]Simple syslog server with socketserver module
The code of syslog server can be found here. The syslog server is simple because it only collects logs from syslog client, I have not tested with multiple clients yet, which I think may need threading. The logs are saved to log file and also display on the console. This demo uses a cisco switch … Continue reading [python]Simple syslog server with socketserver module
[python]Creating vlans on multiple switches
Introduction The entire script demo can be found here. The script reads from an excel sheet named as "vlans.xlsx" and extracts the information, the information is then converted into vlan commands with a jinja2 template, the script is able to send to multiple switches by using threading, on each thread a new Switch instance is … Continue reading [python]Creating vlans on multiple switches
[python]Netmask to inverse mask
Cisco IOS uses inverse mask in access control list and router network command, only Cisco uses inverse mask instead of actual netmask. Suppose if the mask is 255.255.255.240, then the inverse mask is 0.0.0.15, another example is 255.255.240.0 then the inverse mask is 0.0.15.255, if you are handling cisco acl with python then there will … Continue reading [python]Netmask to inverse mask
[python] Convert IPv4 subnet mask to CIDR representation
Take an example of this subnet mask 255.255.255.240 which CIDR representation is 28. These are the methods to convert to CIDR representation without using any module. Split the netmask by dots, so that each octet is in a list.For each item in the list, use bin function to get the binary representation of each octet, … Continue reading [python] Convert IPv4 subnet mask to CIDR representation
[python]Test connection with socket module
This is the code snippet that checks if a specific port is listening on the target server or not, if the port could not be reached and does not exist the socket module throws a timeout exception or ConnectionRefusedError. from socket import socket, timeout as _timeout, AF_INET, SOCK_STREAM ERRORS = TimeoutError, ConnectionRefusedError, _timeout def has_service(address, … Continue reading [python]Test connection with socket module
[python]Record router information with mongodb
Introduction This is a lab demonstration on how to record cisco router's information to mongo database. Mongo database is very easy to learn for new developers who understand the json structure because the structure to insert data into the database is very json-like this is very easy to learn without knowing SQL syntax. I am … Continue reading [python]Record router information with mongodb