Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search Sqlite Database - All Tables and Columns

Is there a library or open source utility available to search all the tables and columns of an Sqlite database? The only input would be the name of the sqlite DB file.

I am trying to write a forensics tool and want to search sqlite files for a specific string.

like image 914
ST-User Avatar asked Nov 22 '12 14:11

ST-User


People also ask

How can I see all tables in SQLite database?

If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.

How can I see all tables in a database?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.


2 Answers

I know this is late to the party, but I had a similar issue but since it was inside of a docker image I had no access to python, so I solved it like so:

for X in $(sqlite3 database.db .tables) ; do sqlite3 database.db "SELECT * FROM $X;" | grep >/dev/null 'STRING I WANT' && echo $X; done

This will iterate through all tables in a database file and perform a select all operation which I then grep for the string. If it finds the string, it prints the table, and from there I can simply use sqlite3 to find out how it was used.

Figured it might be helpful to other who cannot use python.

like image 145
MrWorf Avatar answered Nov 07 '22 00:11

MrWorf


Just dump the db and search it.

% sqlite3 file_name .dump | grep 'my_search_string'

You could instead pipe through less, and then use / to search:

% sqlite3 file_name .dump | less

like image 44
Chris Rees Avatar answered Nov 06 '22 23:11

Chris Rees