【问题标题】:Is this a true error, or am I just misinterpreting what is happening?这是一个真正的错误,还是我只是误解了正在发生的事情?
【发布时间】:2019-08-31 01:24:17
【问题描述】:

我正在尝试在 Kali Linux 中的 Pycharm 中制作一个程序,该程序将按以下顺序:

  • 禁用界面
  • 运行airmon-ng check kill
  • 运行iwconfig interface mode monitor
  • 运行ifconfig interface up
  • 打印是否有效

我正在使用一些我用来为我正在学习的 Udemy 课程制作 MAC 地址更改器的代码,但我不确定它是否会使过程更快或更混乱。我想我明白了大部分,但我有点挂了。

在我运行它之后,它似乎已经工作了。 iwconfig 说它处于监视模式,ifconfig 说它已启动。但是,当它完成时,它会给我我编写的错误消息。真的是报错吗?

我尝试重新利用用于制作 MAC 地址转换器的代码以节省一些时间,并尝试在末尾编写 if is true 语句以测试监控模式是否开启。

monitor_mode 代码:

monitor_mode(options.interface)



...

def monitor_mode(interface):
    print("[+] Activating Monitor Mode for " + interface)

    subprocess.call(["ifconfig", interface, "down"])
    subprocess.call(["airmon-ng", "check", "kill"])
    subprocess.call(["iwconfig", interface, "mode", "monitor"])
    subprocess.call(["ifconfig", interface, "up"])


options = get_arguments()

monitor_mode(options.interface)

if monitor_mode is True:
    print("[+] Interface switched to monitor mode.")
else:
    print("[-] Error.")

mac_changer 原代码:

def change_mac(interface, 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"])

def get_current_mac(interface):
    ifconfig_result = subprocess.check_output(["ifconfig", interface])
    mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", ifconfig_result)

    if mac_address_search_result:
        return mac_address_search_result.group(0)
    else:
        print("[-] Could not read MAC address.")

options = get_arguments()

current_mac = get_current_mac(options.interface)
print("Current MAC = " + str(current_mac))

change_mac(options.interface, options.new_mac)

current_mac = get_current_mac(options.interface)
if current_mac == options.new_mac:
    print("[+] MAC successfully changed to " + current_mac)
else:
    print("[-] MAC unchanged.")

我希望我的 monitor_mode 程序关闭 wlan0,运行 airmon-ng check kill,通过 iwconfig 将 wlan0 开启监控模式,然后恢复 wlan0

相反,它只是这样做了,但它打印了我给它的错误消息,尽管没有其他任何东西表明它确实是一个失败。

【问题讨论】:

    标签: python python-2.7 terminal pycharm kali-linux


    【解决方案1】:

    您的代码中有两个问题:

    • 测试if monitor_mode is True 将始终返回False,因为monitor_mode 是一个函数,因此您将函数与True 进行比较

      李>
    • 相反,您应该比较 monitor_mode 的返回值,如下所示:

          if monitor_mode(options.interface):
              print("[+] Interface switched to monitor mode.")
          else:
              print("[-] Error.")
    

    但是,除非您将 monitor_mode 函数更改为实际 返回 一个有用的值来指示其成功或其他情况,否则这将不起作用......目前它 总是 返回一个 @ 987654328@值。

    【讨论】:

      猜你喜欢
      • 2013-02-22
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      相关资源
      最近更新 更多