コード例 #1
0
 def stop(self):
     if not self.is_running:
         logWarn("is not running",
                 verbose=self.is_verbose,
                 TAG=self.TAG_NAME)
         return
     self.is_running = False
     logOk("Stopped", verbose=self.is_verbose, TAG=self.TAG_NAME)
コード例 #2
0
ファイル: sender.py プロジェクト: SigPloit/gtp_v2_attacks
    def run(self):
        self.is_running = True

        logNormal("--: Acting as SENDER :--",
                  verbose=self.is_verbose,
                  TAG=self.TAG_NAME)

        if self.is_running and self.sock is not None:
            ''' Prepare the messages to send '''

            logNormal("Preparing GTP messages",
                      verbose=self.is_verbose,
                      TAG=self.TAG_NAME)
            mdatas = []
            if self.messages is not None and len(self.messages) > 0:
                count = 0
                for m in self.messages:
                    logNormal("preparing msg #%d - type %d" %
                              (count, m.get_msg_type()),
                              verbose=self.is_verbose,
                              TAG=self.TAG_NAME)
                    mdatas.append(m.get_message())
                    count += 1
            tot_count = len(mdatas)
            logOk("Prepared %d GTP messages" % (tot_count),
                  verbose=self.is_verbose,
                  TAG=self.TAG_NAME)

            curr_count = 1

            for num, data in enumerate(mdatas):
                logNormal("Sending message (#%d of %d)..." %
                          (curr_count, tot_count),
                          verbose=self.is_verbose,
                          TAG=self.TAG_NAME)
                for ip in self.peers:
                    try:
                        ip_str = ip.strNormal()

                        msg_info = {'reply': 0}
                        msg_type = self.messages[num].get_msg_type()
                        if msg_type == 32 or msg_type == 34:
                            msg_info['local_teid'] = self.messages[
                                num].get_fteid()

                        if not message_queue.has_key(ip_str) or \
                            not message_queue[ip_str].has_key(msg_type):
                            message_queue[ip_str] = {}
                            message_queue[ip_str][msg_type] = [msg_info]
                        else:
                            message_queue[ip_str][msg_type].append(msg_info)

                        sent_bytes = self.sock.sendto(data,
                                                      (ip_str, self.gtp_port))

                        if sent_bytes is not None and sent_bytes > 0:
                            info_msg = "Bytes sent to %s %d" % (ip_str,
                                                                sent_bytes)
                        else:
                            info_msg = "NO bytes sent to %s" % (ip_str)
                        logNormal(info_msg,
                                  verbose=self.is_verbose,
                                  TAG=self.TAG_NAME)
                    except timeout, e:
                        logErr("%s TIMEOUT_ERROR" % (ip_str),
                               TAG=self.TAG_NAME)
                        pass
                    except error, e:
                        if e.errno == errno.ECONNREFUSED:
                            logErr("%s CONNECTION_REFUSED" % (ip_str),
                                   TAG=self.TAG_NAME)
                        elif e.errno == errno.EBADFD:
                            logErr("%s BAD_FILE_DESCRIPTOR_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                            break
                        elif e.errno == errno.EPIPE:
                            logErr("%s BROKEN_PIPE_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                            break
                        elif e.errno == errno.ECONNRESET:
                            logErr("%s CONNECTION_RESET_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                        else:
                            logErr("%s UNKNOWN_ERROR: %s" % (ip_str, e),
                                   TAG=self.TAG_NAME)
                            break
                        pass
                    except Exception, e:
                        logErr("%s GENERIC ERROR : reason %s" % (ip_str, e),
                               TAG=self.TAG_NAME)
                        break
コード例 #3
0
ファイル: sender.py プロジェクト: SigPloit/gtp_v2_attacks
                            logErr("%s UNKNOWN_ERROR: %s" % (ip_str, e),
                                   TAG=self.TAG_NAME)
                            break
                        pass
                    except Exception, e:
                        logErr("%s GENERIC ERROR : reason %s" % (ip_str, e),
                               TAG=self.TAG_NAME)
                        break
                curr_count += 1
                time.sleep(self.msg_freq)

            if self.start_time is not None:
                stop_time = time.time()
                hours, rem = divmod(stop_time - self.start_time, 3600)
                minutes, seconds = divmod(rem, 60)
                logOk("Elapsed time: {:0>2}:{:0>2}:{:05.4f}".format(
                    int(hours), int(minutes), seconds),
                      verbose=self.is_verbose,
                      TAG=self.TAG_NAME)

    ##
    ## @brief      Stops the execution of the thread
    ##
    ## @param      self  refers to the class itself
    ##
    def stop(self):
        if not self.is_running:
            return
        self.is_running = False
        logOk("Stopped", verbose=self.is_verbose, TAG=self.TAG_NAME)
コード例 #4
0
ファイル: listener.py プロジェクト: gavz/SigPloit
    def run(self):
        self.is_running = True
        count = 0
        while self.sock is not None and self.is_running:
            try:
                data, addr = self.sock.recvfrom(1024)
                if len(data) > 8:
                    (flags, resp_msg_type, length,
                     sequence_or_teid) = struct.unpack("!BBHL", data[:8])
                    version = flags & 0xF0
                    if version != 0x40 and version != 0x10:
                        logWarn("Unsupported GTP version %02x" % (version),
                                verbose=self.is_verbose,
                                TAG=self.TAG_NAME)
                        continue
                    if not message_queue.has_key(addr[0]):
                        logWarn("Unmanaged IP %s" % (addr[0]),
                                verbose=self.is_verbose,
                                TAG=self.TAG_NAME)
                        continue
                    req_msg_type = GTPResponse2Request[resp_msg_type]

                    if not message_queue[addr[0]].has_key(req_msg_type):
                        logWarn("Unsolicited response msg %d" %
                                (resp_msg_type),
                                verbose=self.is_verbose,
                                TAG=self.TAG_NAME)
                        continue

                    logOk("Received response to sent msg %s from ip %s" %
                          (GTPmessageTypeStr[req_msg_type], addr[0]),
                          verbose=self.is_verbose,
                          TAG=self.TAG_NAME)
                    if req_msg_type == GTPmessageTypeDigit["echo-request"]:
                        message_queue[addr[0]][req_msg_type][0]['reply'] = 1
                    else:
                        for elem in message_queue[addr[0]][req_msg_type]:
                            if elem.has_key('local_teid') and \
                                elem['local_teid'] ==  sequence_or_teid :
                                elem['reply'] = 1
                                elem['remote_teid'] = self.__getFTEID(
                                    data[12:])
                                break
                count += 1
                logNormal("RECEIVED #%d messages" % (count),
                          verbose=self.is_verbose,
                          TAG=self.TAG_NAME)
            except timeout, e:
                if addr[0]:
                    logErr("%s TIMEOUT_ERROR" % (addr[0]), TAG=self.TAG_NAME)
                else:
                    logErr("TIMEOUT_ERROR", TAG=self.TAG_NAME)
                pass
            except error, e:
                if e.errno == errno.EBADFD:
                    if addr[0]:
                        logErr("%s BAD_FILE_DESCRIPTOR_ERROR" % (addr[0]),
                               TAG=self.TAG_NAME)
                    else:
                        logErr("BAD_FILE_DESCRIPTOR_ERROR", TAG=self.TAG_NAME)
                    break
                elif e.errno == errno.EPIPE:
                    if addr[0]:
                        logErr("%s BROKEN_PIPE_ERROR" % (addr[0]),
                               TAG=self.TAG_NAME)
                    else:
                        logErr("BROKEN_PIPE_ERROR", TAG=self.TAG_NAME)
                    break
                else:
                    logErr("UNKNOWN ERROR: %s" % (e), TAG=self.TAG_NAME)
                    break
コード例 #5
0
ファイル: sender.py プロジェクト: t-bonds/sigploit_3
    def run(self):
        self.is_running = True

        logNormal("--: Acting as SENDER :--",
                  verbose=self.is_verbose,
                  TAG=self.TAG_NAME)

        if self.is_running and self.sock is not None:
            ''' Prepare the messages to send '''

            logNormal("Preparing GTP messages",
                      verbose=self.is_verbose,
                      TAG=self.TAG_NAME)
            mdatas = []
            if self.messages is not None and len(self.messages) > 0:
                count = 0
                for m in self.messages:
                    logNormal("preparing msg #%d - type %d" %
                              (count, m.get_msg_type()),
                              verbose=self.is_verbose,
                              TAG=self.TAG_NAME)
                    mdatas.append(m.get_message())
                    count += 1
            tot_count = len(mdatas)
            logOk("Prepared %d GTP messages" % (tot_count),
                  verbose=self.is_verbose,
                  TAG=self.TAG_NAME)

            curr_count = 1

            for num, data in enumerate(mdatas):
                logNormal("Sending message (#%d of %d)..." %
                          (curr_count, tot_count),
                          verbose=self.is_verbose,
                          TAG=self.TAG_NAME)
                for ip in self.peers:
                    try:
                        ip_str = ip.strNormal()

                        msg_info = {'reply': 0}
                        msg_type = self.messages[num].get_msg_type()
                        if msg_type == 32 or msg_type == 34:
                            msg_info['local_teid'] = self.messages[
                                num].get_fteid()

                        if ip_str not in message_queue or \
                            msg_type not in message_queue[ip_str]:
                            message_queue[ip_str] = {}
                            message_queue[ip_str][msg_type] = [msg_info]
                        else:
                            message_queue[ip_str][msg_type].append(msg_info)

                        sent_bytes = self.sock.sendto(data,
                                                      (ip_str, self.gtp_port))

                        if sent_bytes is not None and sent_bytes > 0:
                            info_msg = "Bytes sent to %s %d" % (ip_str,
                                                                sent_bytes)
                        else:
                            info_msg = "NO bytes sent to %s" % (ip_str)
                        logNormal(info_msg,
                                  verbose=self.is_verbose,
                                  TAG=self.TAG_NAME)
                    except timeout as e:
                        logErr("%s TIMEOUT_ERROR" % (ip_str),
                               TAG=self.TAG_NAME)
                        pass
                    except error as e:
                        if e.errno == errno.ECONNREFUSED:
                            logErr("%s CONNECTION_REFUSED" % (ip_str),
                                   TAG=self.TAG_NAME)
                        elif e.errno == errno.EBADFD:
                            logErr("%s BAD_FILE_DESCRIPTOR_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                            break
                        elif e.errno == errno.EPIPE:
                            logErr("%s BROKEN_PIPE_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                            break
                        elif e.errno == errno.ECONNRESET:
                            logErr("%s CONNECTION_RESET_ERROR" % (ip_str),
                                   TAG=self.TAG_NAME)
                        else:
                            logErr("%s UNKNOWN_ERROR: %s" % (ip_str, e),
                                   TAG=self.TAG_NAME)
                            break
                        pass
                    except Exception as e:
                        logErr("%s GENERIC ERROR : reason %s" % (ip_str, e),
                               TAG=self.TAG_NAME)
                        break
                curr_count += 1
                time.sleep(self.msg_freq)

            if self.start_time is not None:
                stop_time = time.time()
                hours, rem = divmod(stop_time - self.start_time, 3600)
                minutes, seconds = divmod(rem, 60)
                logOk("Elapsed time: {:0>2}:{:0>2}:{:05.4f}".format(
                    int(hours), int(minutes), seconds),
                      verbose=self.is_verbose,
                      TAG=self.TAG_NAME)