Example #1
0
    def parse_postgres(self, raw):
        """Parse PostgreSQL packet.  psql is less insane."""
        raw = util.get_layer_bytes(str(raw))
        if len(raw) <= 1:
            return

        message_type = raw[0]
        if message_type == '70':
            # password message
            plen = parser_postgres.endian_int(raw[1:5])
            password = ''
            for i in xrange(plen - 5):
                password += raw[5 + i].decode('hex')
            self.log_msg('Password hash: %s' % password)
        elif message_type == '51':
            # simple query
            query = parser_postgres.parse_query(raw)
            self.log_msg('Query: %s' % query)
        elif message_type == '54':
            if self.dump_data:
                # query response
                (columns, rows) = parser_postgres.parse_response(raw)
                if not columns is None and not data is None:
                    pattern = re.compile('[\W_]+')
                    Query = namedtuple(
                        "Query", [pattern.sub('', x.name) for x in columns])
                    table = []
                    for row in rows:
                        row = Query._make(row)
                        table.append(row)
                    pptable(table)
        elif message_type == '58':
            self.log_msg('User quit.\n')
        elif message_type == '45':
            self.log_msg('Error: %s' % parser_postgres.parse_error(raw))
        elif message_type == '52':
            if not parser_postgres.database_exists(raw):
                self.log_msg('Invalid database.')
        elif message_type == '00':
            # startup/other
            if parser_postgres.is_ssl(raw):
                self.log_msg('SSL request!')
            else:
                startup = parser_postgres.parse_startup(raw)
                self.log_msg('Startup packet:')
                idx = 0
                while idx < len(startup) - 1:
                    self.log_msg('\t%s -> %s' %
                                 (startup[idx], startup[idx + 1]))
                    idx += 2
Example #2
0
    def parse_postgres(self, raw):
        """Parse PostgreSQL packet.  psql is less insane."""
        raw = util.get_layer_bytes(str(raw))
        if len(raw) <= 1:
            return

        message_type = raw[0]
        if message_type == '70':
            # password message
            plen = parser_postgres.endian_int(raw[1:5])
            password = ''
            for i in xrange(plen - 5):
                password += raw[5 + i].decode('hex')
            self.log_msg('Password hash: %s' % password)
        elif message_type == '51':
            # simple query
            query = parser_postgres.parse_query(raw)
            self.log_msg('Query: %s' % query)
        elif message_type == '54':
            if self.dump_data:
                # query response
                (columns, rows) = parser_postgres.parse_response(raw)
                if not columns is None and not data is None:
                    pattern = re.compile('[\W_]+')
                    Query = namedtuple("Query",
                                    [pattern.sub('', x.name) for x in columns])
                    table = []
                    for row in rows:
                        row = Query._make(row)
                        table.append(row)
                    pptable(table)
        elif message_type == '58':
            self.log_msg('User quit.\n')
        elif message_type == '45':
            self.log_msg('Error: %s' % parser_postgres.parse_error(raw))
        elif message_type == '52':
            if not parser_postgres.database_exists(raw):
                self.log_msg('Invalid database.')
        elif message_type == '00':
            # startup/other
            if parser_postgres.is_ssl(raw):
                self.log_msg('SSL request!')
            else:
                startup = parser_postgres.parse_startup(raw)
                self.log_msg('Startup packet:')
                idx = 0
                while idx < len(startup) - 1:
                    self.log_msg('\t%s -> %s' %
                                        (startup[idx], startup[idx + 1]))
                    idx += 2
Example #3
0
	def parse_postgres(self, raw):
		"""Parse PostgreSQL packet.  psql is less insane."""
		raw = util.get_layer_bytes(str(raw))
		if len(raw) <= 1:
			return

		message_type = raw[0]
		if message_type == '70':
			# password message
			plen = parser_postgres.endian_int(raw[1:5])
			password = ''
			for i in xrange(plen-5):
				password += raw[5+i].decode('hex')
			self.log_msg('Password hash: %s'%password)
		elif message_type == '51':
			# simple query
			query = parser_postgres.parse_query(raw)
			self.log_msg('Query: %s'%query)
		elif message_type == '54':
			# query response
			(columns, rows) = parser_postgres.parse_response(raw)
			self.log_msg(columns)
			for row in rows:
				self.log_msg(row)
		elif message_type == '58':
			self.log_msg('User quit.\n')
		elif message_type == '45':
			self.log_msg('Error: %s'%parser_postgres.parse_error(raw))
		elif message_type == '52':
			if not parser_postgres.database_exists(raw):
				self.log_msg('Invalid database.')
		elif message_type == '00':
			# startup/other
			if parser_postgres.is_ssl(raw):
				self.log_msg('SSL request!')
			else:
				startup = parser_postgres.parse_startup(raw)
				self.log_msg('Startup packet:')
				idx = 0
				while idx < len(startup)-1:	
					self.log_msg('\t%s -> %s'%(startup[idx], startup[idx+1]))
					idx += 2