我正在尝试在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
。
相反,它只是这样,但它打印了我给它的错误信息,但没有其他任何关于它表明它确实是一个失败。
您的代码中有两个问题:
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
值。