''' Syn flood program in python using raw sockets (Linux) Silver Moon ([email protected]) ''' import socket import sys import struct try: streams = Tuby # @UndefinedVariable except: from tuby.core import Streams from StringIO import StringIO streams = Streams() def checksum(msg): """checksum functions needed for calculation checksum""" s = 0 # loop taking 2 characters at a time for i in range(0, len(msg), 2): w = (ord(msg[i]) << 8) + (ord(msg[i + 1])) s = s + w s = (s >> 16) + (s & 0xffff) # s = s + (s >> 16); # complement and mask to 4 byte short s = ~s & 0xffff
import socket from struct import unpack import base64 import json """ from: http://www.binarytides.com/python-packet-sniffer-code-linux/ """ try: TUBY = TUBY # @UndefinedVariable except Exception: from tuby.core import Streams TUBY = Streams() class Packet(object): class Tcp(object): def __init__(self, packet): self.packet = packet self._preprocess() def _preprocess(self): version_ihl = self.packet.ip.iph[0] # version = version_ihl >> 4 ihl = version_ihl & 0xF iph_length = ihl * 4 # ttl = iph[5] # protocol = iph[6] # s_addr = socket.inet_ntoa(iph[8]) # d_addr = socket.inet_ntoa(iph[9]) tcp_header = self.packet.raw[iph_length:iph_length + 20]
try: TUBY = TUBY # @UndefinedVariable except Exception: from tuby.core import Streams TUBY = Streams() import platform import socket import sys import base64 import binascii ''' from: http://www.binarytides.com/python-packet-sniffer-code-linux/ # the public network interface HOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interface s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 0)) # Include IP headers s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packages s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) # receive a package print s.recvfrom(65565) # disabled promiscuous mode s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
try: TUBY = TUBY # @UndefinedVariable except Exception: from tuby.core import Streams TUBY = Streams() import platform import socket import sys import base64 import binascii """ from: http://www.binarytides.com/python-packet-sniffer-code-linux/ # the public network interface HOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interface s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 0)) # Include IP headers s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packages s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) # receive a package print s.recvfrom(65565)