コード例 #1
0
 def poke(self):
     question = DNS(rd=1, qd=DNSQR(qname='twitter.com'))
     if self.sniffer:
         packet = IP(dst=self.dst, src=self.src, id=self.ttl, ttl=self.ttl) / UDP(
             sport=self.sport) / question
         networking.send(packet)
         self.report['PACKETS'].append(('QUESTION', packet))
     else:
         self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
         atexit.register(self.udp_socket.close)
         self.udp_socket.settimeout(0)
         self.udp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
         self.udp_socket.bind((self.src, self.sport))
         self.udp_socket.sendto(str(question), (self.dst, self.dport))
コード例 #2
0
ファイル: tcp_rst_probe.py プロジェクト: xyz12810/qiang
 def send_syn(self):
     if self.sniffer:
         packet = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 1,
                     ttl=64 if self.waits_for_syn_ack else self.ttl) / \
                  TCP(sport=self.sport, dport=self.dport, flags='S', seq=0)
         networking.send(packet)
         self.report['PACKETS'].append(('SYN', packet))
         if self.waits_for_syn_ack:
             self.wait_for_syn_ack()
     else:
         self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         atexit.register(networking.immediately_close_tcp_socket_so_sport_can_be_reused, self.tcp_socket)
         self.tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.tcp_socket.settimeout(2)
         self.tcp_socket.bind((self.src, self.sport)) # if sport change the route going through might change
         self.tcp_socket.connect((self.dst, self.dport))
コード例 #3
0
ファイル: tcp_rst_probe.py プロジェクト: xyz12810/qiang
    def send_offending_payload(self):
        if self.sniffer:

            packet = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 2, ttl=self.ttl) / \
                     TCP(sport=self.sport, dport=self.dport, flags='A',
                         seq=1, ack=self.report['SYN_ACK?'] or 100) / self.get_offending_payload()
            networking.send(packet)
            self.report['PACKETS'].append(('OFFENDING_PAYLOAD', packet))
        else:
            self.tcp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
            try:
                self.tcp_socket.send(self.get_offending_payload())
            except socket.error as e:
                if ERROR_CONNECTION_RESET == e[0]:
                    self.report['RST_AFTER_SYN?'] = True
                else:
                    raise
コード例 #4
0
    def poke(self):
        # question = DNS(rd=1, qd=DNSQR(qname='www.gov.cn'))

        if self.sniffer:
            # We send 5000 packets
            packets = []
            print "Building packets..."
            progress = ProgressBar()
            for i in progress(range(0, MAX_PACKETS)):
                packet = IP(src=self.src, dst=self.dst, id=self.ttl * 5 + i, ttl=self.ttl) / UDP(
                    sport=self.sport, dport=self.dport) / (''.join([random.choice(string.printable) for _ in range(1470)]))
                packets.append(packet)
            print "Send them!"
            # A simple throttler
            time_start = datetime.now()
            
            def millisec_passed():
                n = datetime.now() - time_start
                return (n.seconds * 1000 + n.microseconds / 1000.0)

            bytes_sent = 0
            i = 0
            progress = ProgressBar(maxval=MAX_PACKETS).start()
            while i < MAX_PACKETS:
                if bytes_sent / (millisec_passed() / 1000.0) > self.bandwidth:
                    continue
                packet = packets[i]
                networking.send(packet)
                self.report['PACKETS'].append(('PACKET_%d' % i, packet))
                i += 1
                bytes_sent += len(packet)
                progress.update(i)
            progress.finish()
        else:
            self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
            atexit.register(self.udp_socket.close)
            self.udp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
            self.udp_socket.settimeout(0)
            self.udp_socket.bind((self.src, self.sport)) # if sport change the route going through might change
            self.udp_socket.sendto(str(question), (self.dst, self.dport))
コード例 #5
0
 def poke(self):
     question = DNS(rd=1, qd=DNSQR(qname='www.gov.cn'))
     if self.sniffer:
         packet1 = IP(
             src=self.src, dst=self.dst, id=self.ttl * 10 + 1,
             ttl=self.ttl) / UDP(sport=self.sport,
                                 dport=self.dport) / question
         networking.send(packet1)
         self.report['PACKETS'].append(('PACKET_1', packet1))
         if not self.one_packet_only:
             packet2 = IP(src=self.src,
                          dst=self.dst,
                          id=self.ttl * 10 + 2,
                          ttl=self.ttl) / UDP(sport=self.sport,
                                              dport=self.dport) / question
             networking.send(packet2)
             self.report['PACKETS'].append(('PACKET_2', packet2))
             packet3 = IP(src=self.src,
                          dst=self.dst,
                          id=self.ttl * 10 + 3,
                          ttl=self.ttl) / UDP(sport=self.sport,
                                              dport=self.dport) / question
             networking.send(packet3)
             self.report['PACKETS'].append(('PACKET_3', packet3))
     else:
         self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                         socket.IPPROTO_UDP)
         atexit.register(self.udp_socket.close)
         self.udp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
         self.udp_socket.settimeout(0)
         self.udp_socket.bind(
             (self.src, self.sport
              ))  # if sport change the route going through might change
         self.udp_socket.sendto(str(question), (self.dst, self.dport))
コード例 #6
0
ファイル: tcp_packet_drop_probe.py プロジェクト: 11liju/qiang
 def poke(self):
     if self.sniffer:
         packet1 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 1, ttl=self.ttl) / TCP(
             sport=self.sport, dport=self.dport, flags='S', seq=0)
         networking.send(packet1)
         self.report['PACKETS'].append(('PACKET_1', packet1))
         if not self.one_packet_only:
             packet2 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 2, ttl=self.ttl) / TCP(
                 sport=self.sport, dport=self.dport, flags='S', seq=0)
             networking.send(packet2)
             self.report['PACKETS'].append(('PACKET_2', packet2))
             packet3 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 3, ttl=self.ttl) / TCP(
                 sport=self.sport, dport=self.dport, flags='S', seq=0)
             networking.send(packet3)
             self.report['PACKETS'].append(('PACKET_3', packet3))
     else:
         self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         atexit.register(networking.immediately_close_tcp_socket_so_sport_can_be_reused, self.tcp_socket)
         self.tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.tcp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
         self.tcp_socket.settimeout(2)
         self.tcp_socket.bind((self.src, self.sport)) # if sport change the route going through might change
         try:
             self.tcp_socket.connect((self.dst, self.dport))
             self.report['SYN_ACK?'] = True
         except socket.timeout:
             pass
コード例 #7
0
 def poke(self):
     if self.sniffer:
         packet1 = IP(
             src=self.src, dst=self.dst, id=self.ttl * 10 + 1,
             ttl=self.ttl) / TCP(
                 sport=self.sport, dport=self.dport, flags='S', seq=0)
         networking.send(packet1)
         self.report['PACKETS'].append(('PACKET_1', packet1))
         if not self.one_packet_only:
             packet2 = IP(
                 src=self.src,
                 dst=self.dst,
                 id=self.ttl * 10 + 2,
                 ttl=self.ttl) / TCP(
                     sport=self.sport, dport=self.dport, flags='S', seq=0)
             networking.send(packet2)
             self.report['PACKETS'].append(('PACKET_2', packet2))
             packet3 = IP(
                 src=self.src,
                 dst=self.dst,
                 id=self.ttl * 10 + 3,
                 ttl=self.ttl) / TCP(
                     sport=self.sport, dport=self.dport, flags='S', seq=0)
             networking.send(packet3)
             self.report['PACKETS'].append(('PACKET_3', packet3))
     else:
         self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         atexit.register(
             networking.immediately_close_tcp_socket_so_sport_can_be_reused,
             self.tcp_socket)
         self.tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                                    1)
         self.tcp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
         self.tcp_socket.settimeout(2)
         self.tcp_socket.bind(
             (self.src, self.sport
              ))  # if sport change the route going through might change
         try:
             self.tcp_socket.connect((self.dst, self.dport))
             self.report['SYN_ACK?'] = True
         except socket.timeout:
             pass
コード例 #8
0
ファイル: udp_packet_drop_probe.py プロジェクト: 11liju/qiang
 def poke(self):
     question = DNS(rd=1, qd=DNSQR(qname='www.gov.cn'))
     if self.sniffer:
         packet1 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 1, ttl=self.ttl) / UDP(
             sport=self.sport, dport=self.dport) / question
         networking.send(packet1)
         self.report['PACKETS'].append(('PACKET_1', packet1))
         if not self.one_packet_only:
             packet2 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 2, ttl=self.ttl) / UDP(
                 sport=self.sport, dport=self.dport) / question
             networking.send(packet2)
             self.report['PACKETS'].append(('PACKET_2', packet2))
             packet3 = IP(src=self.src, dst=self.dst, id=self.ttl * 10 + 3, ttl=self.ttl) / UDP(
                 sport=self.sport, dport=self.dport) / question
             networking.send(packet3)
             self.report['PACKETS'].append(('PACKET_3', packet3))
     else:
         self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
         atexit.register(self.udp_socket.close)
         self.udp_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, self.ttl)
         self.udp_socket.settimeout(0)
         self.udp_socket.bind((self.src, self.sport)) # if sport change the route going through might change
         self.udp_socket.sendto(str(question), (self.dst, self.dport))