Example #1
0
File: icmp.py Project: ufwt/dizzy
    def __init__(self, section_proxy):
        check_root("use the ICMP probe")

        self.target_host = section_proxy.get('target_host')
        self.timeout = section_proxy.getfloat('timeout', 1)
        self.pkg_size = section_proxy.getint('pkg_size', 64)
        self.retry = section_proxy.getint('retry', 2)
        self.socket = None
        self.is_open = False

        try:
            inet_aton(self.target_host)
            self.af = AF_INET
            self.proto = getprotobyname("icmp")
            echo = self.ICMP_ECHO
        except Exception as e:
            try:
                inet_pton(AF_INET6, self.target_host)
                self.af = AF_INET6
                self.proto = getprotobyname("ipv6-icmp")
                echo = self.ICMP6_ECHO
            except Exception as f:
                raise ProbeParseException("probe/icmp: unknown address family: %s: %s, %s" %
                                               (self.target_host, e, f))
        self.pid = getpid() & 0xFFFF
        self.header = pack("!BBHHH", echo, 0, 0, self.pid, 0)

        pad = list()
        for i in range(0x41, 0x41 + self.pkg_size):
            pad += [(i & 0xff)]
        self.data = bytearray(pad)

        checksum = csum_inet(self.header + self.data)
        self.header = self.header[0:2] + checksum + self.header[4:]
Example #2
0
File: pcap.py Project: ufwt/dizzy
 def __init__(self, config, filename):
     Thread.__init__(self)
     try:
         import pcapy
         self.pcap = pcapy
     except:
         print_dizzy(
             "No usable pcap library found. Be sure you have pcapy installed!"
         )
         print_dizzy("Pcap recording disabled!")
         self.pcap = None
         return
     self.interface = config.get("interface", "any")
     check_root("use the PCAP feature")
     print_dizzy("pcap/init: listening on interface '%s'." % self.interface,
                 VERBOSE_1)
     if not self.interface is "any":
         if not self.interface in self.pcap.findalldevs():
             print_dizzy(
                 "Device '%s' not found, recording on _all_ interfaces.")
             self.interface = "any"
     self.filter = config.get("filter", "")
     if not self.filter is "":
         print_dizzy("pcap/init: using bpf '%s'." % self.filter, VERBOSE_1)
     self.snaplen = config.getint("snaplen", 8192)
     self.promisc = config.getboolean("promisc", True)
     self.to_ms = config.getint("to_ms", 10)
     self.cooldown = config.getint("cooldown", 0)
     self.filename = filename
     self.is_open = False
Example #3
0
File: eth.py Project: ufwt/dizzy
    def __init__(self, section_proxy):
        check_root("use the ETH session")

        self.interface = section_proxy.get('target_interface')
        self.timeout = section_proxy.getfloat('timeout', 1)
        self.recv_buffer = section_proxy.getfloat('recv_buffer', 4096)
        self.auto_reopen = section_proxy.getboolean('auto_reopen', True)
        self.server_side = section_proxy.getboolean('server', False)
        self.read_first = self.server_side
        self.read_first = section_proxy.getboolean('read_first',
                                                   self.read_first)
        self.is_open = False
Example #4
0
File: tcp.py Project: mrmez/dizzy
    def __init__(self, section_proxy):
        self.target_host = section_proxy.get('target_host')
        self.target_port = section_proxy.getint('target_port')
        self.source_host = section_proxy.get('source_host', None)
        self.source_port = section_proxy.getint('source_port', None)
        if not self.source_host is None and self.source_port <= 1024:
            check_root("use a source port <= 1024")
        self.timeout = section_proxy.getfloat('timeout', 1)
        self.retry = section_proxy.getint('retry', 2)
        self.is_open = False
        self.socket = None

        try:
            inet_aton(self.target_host)
            self.af = AF_INET
        except Exception as e:
            try:
                inet_pton(AF_INET6, self.target_host)
                self.af = AF_INET6
            except Exception as f:
                raise ProbeParseException(
                    "probe/tcp: unknown address family: %s: %s, %s" %
                    (self.target_host, e, f))
        if not self.source_host is None:
            try:
                inet_aton(self.source_host)
            except Exception as e:
                try:
                    inet_pton(AF_INET6, self.source_host)
                except Exception as f:
                    raise ProbeParseException(
                        "probe/tcp: unknown address family: %s: %s, %s" %
                        (self.source_host, e, f))
                else:
                    if not self.af == AF_INET6:
                        raise ProbeParseException(
                            "probe/tcp: address family mismatch: %s - %s" %
                            (self.target_host, self.source_host))
            else:
                if not self.af == AF_INET:
                    raise ProbeParseException(
                        "probe/tcp: address family mismatch: %s - %s" %
                        (self.target_host, self.source_host))