Perl spies on a sniffer

Secret Agent

Article from Issue 176/2015
Author(s):

Many Ubuntu users are blissfully unaware that the Zeitgeist daemon is shoulder surfing them and logging their desktop actions. Several Perl scripts can help sanitize the sniffer report and reveal interesting facts about a user's habits.

Precisely how does the Nautilus browser know which files an Ubuntu user edited recently to be able to display them in the Recent column? Figure 1, for example, lists two screenshots that I recently viewed with the Eye of Gnome (eog) photo viewer.

Figure 1: Recently viewed files in the Nautilus file browser.

Nautilus and Eye of Gnome are two totally different applications that do not exchange any data, but an unofficial helper named zeitgeist runs in the Ubuntu desktop's background, greedily absorbing information about what's going on with the numerous applications running on the desktop. If you are interested, you can type

ps aux | grep zeitgeist

to see the daemon running with your user ID in the process list. Gnome applications connect to the Zeitgeist daemon on D-Bus, and the daemon inquisitively logs any relevant transactions in its database, while providing this information in turn to other applications interested in it – for example, the Nautilus browser.

To store the desktop events, Zeitgeist uses a SQLite database, which other utilities or even a hand-crafted Perl sniffer can also read and evaluate. If you want to watch the daemon snapping up events that roll in from the desktop, you can type

zeitgeist-daemon -r --log-level=DEBUG

to launch the daemon in debug mode. The -r option actually stops the daemon running in the background and replaces it with one running in the foreground.

The Future Is Uncertain

Having said this, the Zeitgeist project on Launchpad [1] seems to have been dormant since 2013. Today, searches return critical comments from users concerned about data protection, who are frantically trying to kill off the daemon without crippling their Ubuntu desktop at the same time. Although the project might not have a rosy future, however, it is still worthwhile peeking behind the curtains to perform a critical analysis of the collected data.

Respecting Private Matters

Because logging actions on the desktop without so much as a by-your-leave can infringe on users' privacy, the Unity desktop lets users restrict Zeitgeist's collecting mania and even discard all the data collected thus far. In System Settings below the Security & Privacy entry, users can tame the daemon by disabling a number of checkboxes. Zeitgeist is then given a blacklist and ignores any events that come in from blocked applications.

Figure 2 shows that Zeitgeist can also be talked into avoiding logging actions that relate to music, movies, photos, chat logs, or documents. You can even press Clear Data to tell the daemon to delete permanently any data it has collected thus far. To see what exactly the Zeitgeist daemon collects, you can use the graphical zeitgeist-explorer from the package of the same name (Figure 3).

Figure 2: This dialog in the system settings below Security & Privacy determines which actions the Zeitgeist daemon logs.
Figure 3: The zeitgeist-explorer utility visualizes incoming events in real time.

On a newly installed Ubuntu, Zeitgeist will log anything it can get its hands on. However, not all applications are as verbose as Eye of Gnome. For example, if you want Zeitgeist to record any tracks that you play with Rhythmbox, you actually need to install the rhythmbox-plugin-zeitgeist Ubuntu package. For Chrome or Firefox, other plugins are available for users who want to track their own web activities.

Perl Investigates

The Perl scripts introduced in the following sections rummage through the data collection. For example, to discover which new photos the user last viewed, Listing 1 [2] reads the uri table in the SQLite activity.sqlite database below .local/share/zeitgeist in your home directory. The SQL SELECT * from uri query simply lists all the rows of data from the uri table in which Zeitgeist assigns index numbers to newly discovered paths or URLs.

Listing 1

urls-recent

01 #!/usr/local/bin/perl -w
02 use strict;
03 use DBD::SQLite;
04
05 my( $home ) = glob "~";
06 my $dbfile = "$home/.local/share/" .
07   "zeitgeist/activity.sqlite";
08 my $dbh = DBI->connect(
09   "dbi:SQLite:dbname=$dbfile", "", "" );
10
11 my $sth = $dbh->prepare(
12 "SELECT * from uri" );
13 $sth->execute();
14
15 while( my( $id, $uri ) =
16        $sth->fetchrow_array() ) {
17   print "$uri\n";
18 }

The CPAN DBD::SQLite module used in the listings for querying SQLite contains not just the Perl wrapper but also the C code for the SQLite project itself. After installing the sqlite3 Ubuntu package, you can type

sqlite3 activity.sqlite .schema

in the Zeitgeist database's directory to see which tables exist in the database. Later, you can look into the table contents with interactively submitted SQL commands.

Listing 1 uses the DBI module's prepare() method, with the loaded SQLite driver to prepare the SQL command, and then runs execute() against the statement handle that is returned to transfer this to the SQLite engine. As is typical in DBI, repeating the call to fetchrow_array() snaps up the rows of results returned by the database engine. Each of these rows contains (in the case of the uri table) two column values – id and value – which the script assigns to two Perl variables of the same name.

Figure 4 shows that Listing 1 not only returns paths to images but also strange-sounding URLs, like application://firefox.desktop, which are indicative of events in which the user called specific applications (e.g., the Firefox browser).

Figure 4: The Zeitgeist daemon stores all the recent URLs in a SQLite database.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Gran Canaria: GNOME Zeitgeist Tracks What You've Done

    "Where are the notes I took online while at the library Tuesday night?" A question such as this might be best answered by the likes of GNOME Zeitgeist.

  • Gnome Zeitgeist with New User Interface

    The tracker daemon Gnome Activity Journal called Zeitgeist has a new user interface.

  • First Developer Version of GNOME Activity Journal

    Following over a year's worth of work the GNOME Activity Journal now appears in its first developer version, 0.3.2. The Zeitgeist framework it uses assumes the same version number.

  • Perl: Daily Tip

    When tackling something complex, such as a foreign language or Vim commands, digesting small bits of knowledge might be more effective than consuming a super-sized meal of information. This month’s Perl column gives you a method of serving up knowledge snippets by email.

  • Perl: Log Chat Sessions

    The IRC (Internet Relay Chat) protocol lets you program bots as automatic helpers. In this month's column, we let a bot log a session and store the results in a database.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News

njobs Europe
What:
Where:
Country:
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia