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]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] 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

[python]Delete many by objectid using pymongo

I have multiple duplicated entries, I think this is the problem with NoSQL type of database, although easy to use it has no normalization method like the relational type database. So my mongo database have duplicated like this: These are the duplicates when I accidentally run the script multiple times with the same device info. … Continue reading [python]Delete many by objectid using pymongo