• Python Ethical Hacking


    MAC ADDRESS

    • Media Access Control
      • Permanent
      • Physical
      • Unique
    • Assigned by manufacturer

    WHY CHANGE THE MAC ADDRESS

    1.Increase anonymity

    2.Impersonate other devices

    3.Bypass filters

     

    Change the MAC Address manually.

    ifconfig
    
    ifconfig eth0 down
    
    ifconfig eth0 hw ether 00:11:22:33:44:55
    
    ifconfig eth0 up
    
    ifconfig

    MAC_CHANGER USING A PYTHON MODULE TO EXECUTE SYSTEM COMMANDS

    • The subprocess module contains a number of functions.
    • These functions allow us to execute system commands.
    • Commands depend on the OS which executes the script.

    Refer to the Python Documentation: https://docs.python.org/3/library/subprocess.html

    Simple sample:

    #!/usr/bin/env python
    
    import subprocess
    
    subprocess.call("ifconfig", shell=True)

    The Python script to change the MAC Address:

    #!/usr/bin/env python
    
    import subprocess
    
    subprocess.call("ifconfig eth0 down", shell=True)
    subprocess.call("ifconfig eth0 hw ether 00:11:22:33:44:66", shell=True)
    subprocess.call("ifconfig eth0 up", shell=True)

     It works.

    The updated Python script to change the MAC address using variables.

    #!/usr/bin/env python
    
    import subprocess
    
    interface = "eth0"
    new_mac = "00:11:22:33:44:77"
    
    print("[+] Changing MAC address for " + interface + " to " + new_mac)
    
    subprocess.call("ifconfig " + interface + " down", shell=True)
    subprocess.call("ifconfig " + interface + " hw ether " + new_mac, shell=True)
    subprocess.call("ifconfig " + interface + " up", shell=True)

    Run the script successfully.

    The updated Python script using the user's input.

    #!/usr/bin/env python
    
    import subprocess
    
    interface = input("interface > ")
    new_mac = input("new MAC > ")
    
    print("[+] Changing MAC address for " + interface + " to " + new_mac)
    
    subprocess.call("ifconfig " + interface + " down", shell=True)
    subprocess.call("ifconfig " + interface + " hw ether " + new_mac, shell=True)
    subprocess.call("ifconfig " + interface + " up", shell=True)

     Run the new scripts successfully.

    Enhance the security of the Python script by changing the use of the call function.

    #!/usr/bin/env python
    
    import subprocess
    
    interface = raw_input("interface > ")
    new_mac = raw_input("new MAC > ")
    
    print("[+] Changing MAC address for " + interface + " to " + new_mac)
    
    subprocess.call(["ifconfig", interface, "down"])
    subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
    subprocess.call(["ifconfig", interface, "up"])

     Run the script successfully and more secure.

    Update the Python script to handle command-line arguments.

    Use the module Parser: https://docs.python.org/2/library/optparse.html

    #!/usr/bin/env python
    
    import subprocess
    import optparse
    
    parser = optparse.OptionParser()
    
    parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
    
    parser.parse_args()
    
    interface = raw_input("interface > ")
    new_mac = raw_input("new MAC > ")
    
    print("[+] Changing MAC address for " + interface + " to " + new_mac)
    
    subprocess.call(["ifconfig", interface, "down"])
    subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
    subprocess.call(["ifconfig", interface, "up"])

    Initializing the variables based on the command arguments.

    #!/usr/bin/env python
    
    import subprocess
    import optparse
    
    parser = optparse.OptionParser()
    
    parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
    parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")
    
    (options, arguments) = parser.parse_args()
    
    interface = options.interface
    new_mac = options.new_mac
    
    print("[+] Changing MAC address for " + interface + " to " + new_mac)
    
    subprocess.call(["ifconfig", interface, "down"])
    subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
    subprocess.call(["ifconfig", interface, "up"])

    Execute the following commands.

    python mac_changer.py --interface eth0 --mac 00:11:22:33:44:55
    
    or 
    
    python mac_changer.py -i eth0 -m 00:11:22:33:44:55

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    Linux中怎么通过PID号找到对应的进程名及所在目录
    MYSQL 1093 之You can't specify target table for update in FROM clause解决办法
    Spring注解@Resource和@Autowired区别对比
    Java数据类型和MySql数据类型对应一览
    java高分局之jstat命令使用(转)
    为python安装matplotlib模块
    Python中的文件IO操作(读写文件、追加文件)
    Python 3语法小记(九) 异常 Exception
    SpringBoot下的Job定时任务
    linux的top命令参数详解
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/11333651.html
Copyright © 2020-2023  润新知