giovedì 24 ottobre 2013

How To :Read FireFox Cookies

E' dura da ammettere ma nell un ottica "del grande tutto" siamo tracciatati e guradati fin nell'intimo..

Mi Nonno l'ha detto fin da quando ha capito che cosa era interent ( e non ha mai fatto in tempo ad usarlo ) "chell'internet lì a l'è un meste undue tutch san quel che te fè"
trad ( dal milanese ) internet è un qualcosa dove tutti sanno quello che fai

Morale da buon curioso mi sono domandato come verificare ( ad esempio su FireFox ) quanti e quali Cookies ho.

Per prima cosa scopro che utilizza sqlLite, per cui il primo step se non lo avete e quello di scaricavi le librerie per la gestione di sqlLite che trovate a questo link:

http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

Dopo il setup si può partire con: New Windows Application ( X86 se avete scaricato slq lite 32 bit )

Aggiungente un bottone o un menu,
Aggiungete una DataGrid...

E poi "Copia e Incolla... "



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;

namespace CookiesReader
{
    public partial class frmMain : Form
    {

       
        private DataTable dt = null;
        

        public frmMain()
        {
            InitializeComponent();
        }

        private void mnuRead_Click(object sender, EventArgs e)
        {

            GetFireFoxCookie(getFireFoxDBLite());

            if (dt != null)
            {
                dvgDetails.DataSource = dt;
            }

        }

        private void GetFireFoxCookie(string source)
        {
            if (source == "") { return; }

            using (var conn = new SQLiteConnection("Data Source=" + source))
            {
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from moz_cookies order by baseDomain";

                    dt = new DataTable();
                    SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);

                    conn.Open();
                    sda.Fill(dt);
                }
            }
        }


        private string getFireFoxDBLite()
        {
            string x = Environment.GetFolderPath(
                 Environment.SpecialFolder.ApplicationData);

            x += @"\Mozilla\Firefox\Profiles\";

            DirectoryInfo di = new DirectoryInfo(x);
            DirectoryInfo[] dir = di.GetDirectories("*.default");

            if (dir.Length != 1) { return ""; }

            x += dir[0].Name + @"\" + "cookies.sqlite";

            if (!File.Exists(x)) { return ""; }

            return x;
        }
    }
}


Quindi unbel run .. e mani nei capelli !!

Nessun commento: