我正在尝试在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"ww:ww:ww:ww:ww:ww", 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
。
相反,它只是这样做了,但它打印了我给它的错误消息,尽管没有其他关于它的迹象表明它确实是失败的。
代码中有两个问题:
-
测试
进行比较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
函数以实际返回指示其成功的有用值或以其他方式之前,这将不起作用......当前它始终返回一个False
值。