LINUX.ORG.RU
ФорумAdmin

Для тех у кого не работает Kerio Client под Linux

 ,


1

1

Всем привет! Для тех у кого не работает Kerio Client на Linux и другие костыли не помогают, предлагаю свое решение на Python c использованием Scapy:

import scapy.all as scapy
import subprocess
import optparse
import re
import time 


def run_kerio():
    subprocess.call([r"/etc/init.d/kerio-kvc", r"restart"])


def get_current_address(iface):
    ifconfig_result = subprocess.check_output (["ifconfig", iface])
    ip_search_result = re.search(r"((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}", str(ifconfig_result))
    mac_search_result = re.search(r"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})", str(ifconfig_result))
    if not ip_search_result:
        print ("[-] Could not read IP address")
        return {"IP": None, "Ether": None}    
    if not mac_search_result:
        print ("[-] Could not read MAC address")
    else:
        return {"IP": ip_search_result.group(0), "Ether": mac_search_result.group(0)}
    

def get_arguments():
    parser=optparse.OptionParser()
    parser.add_option("-i", "--interface", dest="iface", help="Interface to change its MAC address (Default: kvnet).")
    (options, arguments) = parser.parse_args()
    if not options.iface:
        print ("[!] Interface not specified. Used default: kvnet")
        options.iface = "kvnet"
    return options 
        

def change_mac (iface, ether):
    if ether != None:
        print ("[+] Change MAC address for inerface: " + iface + ", [Ether]: " + ether)
        subprocess.call(["ip", "link", "set", iface, "address", ether])
    else:
        print ("[-] Change MAC Error: No searched [Ether]: " + ether)
  
    
def check_changed_mac(iface,mac):
    current_address = get_current_address(iface)
    if mac == current_address.get('Ether') :
        print ("[-] MAC address hes not changed")
        return False
    else: 
        print ("[+] MAC address was sucessfully changed! \nCurrent [Ether]:" + current_address.get('Ether'))
        return True


def run_sniff(interface,address_ip):
    
    packet_53=scapy.sniff(iface=interface, filter="src port 53 and ip dst " + address_ip, count=1)
    if address_ip in packet_53[0]["IP"].dst:
        return (packet_53[0]["Ether"].dst)
    else:
        return None
    

def main ():
    run_kerio()
    time.sleep(8)
    options = get_arguments()
    current_address = get_current_address(options.iface)
    last_ether = current_address.get('Ether')
    sniff_ether = run_sniff(options.iface,current_address.get('IP'))
    if last_ether == sniff_ether:
        print("[-] Dont searched new MAC address: Sniff response [Ether]: " + sniff_ether)
        main()
    else:        
        change_mac(options.iface,sniff_ether)
        check_changed_mac(options.iface, last_ether)   
                
                
if __name__ == '__main__':
    main()

P.S.: Не судите строго, я не программист)) Пишу по необходимости, когда иных подходящих решений не нахожу.