Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 55 guests and 1 member online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Web Applicationsarrow w3af - cookies
EH-Net
May 19, 2013, 03:52:35 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: w3af - cookies  (Read 15003 times)
0 Members and 1 Guest are viewing this topic.
Ketchup
Hero Member
*****
Offline Offline

Posts: 1021



View Profile
« on: April 28, 2009, 10:52:39 PM »

I can't seem to figure out how to get w3af to import a session cookie for a particular URL I am trying to scan.   It's asking for a Mozilla compatible cookiejar filename.   I am not sure exactly what that is.  FF3 uses SQLite for it's cookie database.   I tried that but it didn't work.   Does anyone know what it wants?

Logged

~~~~~~~~~~~~~~
Ketchup
jimbob
Guest
« Reply #1 on: April 29, 2009, 05:41:47 AM »

I think you've kinda answered your own question. I believe it looking for the cookie file used by Firefox >= 2.x. This I believe was a plaintext, whitespace-delimited file. I guess someone could write a script to dump the SQLite database in FireFox >= 3 into the old format... there's a weekend project for someone.

Jimbob
Logged
jimbob
Guest
« Reply #2 on: April 29, 2009, 07:16:44 AM »

OK, I couldn't resist the challenge, my C skills need some sharpening and I've never used sqlite. Here's a short program to extract the cookie information from the sqlite3 database used my Firefox 3 into the old format.

I've tested this on Cygwin but there is no reason why it should not compile on another platform so long as the sqlite3 libraries and headers are installed. I compiled it with the following command:

gcc -Wall -g -o cookiejar cookiejar.c  -lsqlite3

Regards,
Jimbob

Code:
#include <stdlib.h>
#include <stdio.h>
#include <sqlite3.h>

/*
  These are the columns in the moz_cookies table
  id = used internall my Firefox?
  name = some_name
  value = some_value
  host = .ethicalhacker.net
  path = /
  expiry = 1304073154
  lastAccessed = 1241001154890625
  isSecure = 0
  isHttpOnly = 0

  The Firefox 2.x cookie file format is...
  Domain       Domain scope?  Path  Secure  Expires     Name      Value
  .example.com TRUE           /     FALSE   1143149359  login_id  123456
*/

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
  printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
    argv[0],                            // host or domain name
    *argv[0] == '.' ? "TRUE" : "FALSE", // Domain accessible if host starts with a '.'
    argv[1],                            // path
    *argv[2] == '1' ? "TRUE" : "FALSE", // SSL only?
    argv[3],                            // Expiry
    argv[4],                            // Cookie name
    argv[5] ? argv[5] : "NULL"          // Cookie value
  );

  return 0;
}

int main(int argc, char **argv){
  sqlite3 *db;
  char *zErrMsg = 0;
  char *sql = "select host,path,isSecure,expiry,name,value from moz_cookies";
  int rc;

  if( argc!=2 ){
    fprintf(stderr, "Usage: %s DATABASE\n", argv[0]);
    exit(1);
  }

  //TODO: Stat the file first

  // Open the database, exit on failure
  rc = sqlite3_open(argv[1], &db);
  if( rc ){
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(1);
  }

  rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
  if( rc!=SQLITE_OK ){
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  }

  // Close the database
  sqlite3_close(db);
  return 0;
}
Logged
Ketchup
Hero Member
*****
Offline Offline

Posts: 1021



View Profile
« Reply #3 on: April 29, 2009, 11:04:33 AM »

Wow, thanks jimbob!    I thought I had a project to do this weekend Smiley   Thank you very much again!   I am pretty comfortable with C/C++, so I can tweak if necessary.  Have I said thanks? Smiley
Logged

~~~~~~~~~~~~~~
Ketchup
jimbob
Guest
« Reply #4 on: April 29, 2009, 03:56:41 PM »

No problem at all. I fixed it up to compile with Visual C++, which is a first for me. I generally don't do any windows programming outside cygwin/vi/gcc so I've also gained from this exercise.

References
http://www.sqlite.org/quickstart.html
http://kb.mozillazine.org/Cookies

Jimbob
« Last Edit: April 29, 2009, 03:58:34 PM by jimbob » Logged
Ketchup
Hero Member
*****
Offline Offline

Posts: 1021



View Profile
« Reply #5 on: April 29, 2009, 04:55:21 PM »

I tested it and it worked like a charm.   The only thing I had to add was a comment line at the top of the cookies file:

#Netscape Cookie File

VC++ is actually pretty nifty in terms of debugging and IDE options.  I also like the MFC classes, especially the later editions when they took security a bit more seriously.   They really have come a long way from strcmp(tinystr, hugestr) days.   

I've started using SQLite in the last 6 months or so.   It's a pretty cool portable database system.   The only compatible alternative I know is MS Access, and that's a mess.   SQLite is not terribly fast on inserts, but it really does the trick when you need something portable.

Thanks again!
Logged

~~~~~~~~~~~~~~
Ketchup
jimbob
Guest
« Reply #6 on: May 01, 2009, 02:43:05 AM »

I shall have to spend some more time learning VC++, it's a useful skill. I'll add the leading comment to my source and publish it somewhere. I know there are other tools out there that read the cookie SQLite database but I'm a command line ki d of guy and I like output I can pipe.

I imagine Berkeley DB to be the closest to SQLite in terms of embedded database but I like SQLite on the basis that I already know SQL. I can see this too being useful :-)

Jimbob
Logged
ethicalhack3r
Full Member
***
Offline Offline

Posts: 139


View Profile WWW
« Reply #7 on: January 12, 2010, 02:36:44 PM »

Sorry to bring up an old topic and thanks for the great script!

For some reason the cookies of a couple of sites I'm testing are not stored in the same place as other cookies. The only difference that I can see from the sites I'm testing and others is that the sites I'm testing are HTTPS. I tried logging into other HTTPS sites and they do seem to be saved into the same sqlite database.

I thought it may have been a problem with the script, however after openning the sqlite database and inspecting the data, the cookies were not there.

The location of my cookies.sqlite file:
/home/user/.mozilla/firefox/apj29vu2.default/cookies.sqlite

Does Firefox save HTTPS cookies in a different location? Is there something else going on here?

Thanks in advance.  Grin

P.S. Firefox 3.0.15 / BackTrack4 Final
Logged
Ketchup
Hero Member
*****
Offline Offline

Posts: 1021



View Profile
« Reply #8 on: January 14, 2010, 04:33:01 PM »

I am not sure why you are not seeing the cookies.   I am not an expert on cookies, but could they be expiring (session cookies)? 

I also use wget to write the cookiejar file sometimes.   Perhaps it will help you here:

Code:
wget --save-cookies cookiefile --post-data "login info goes here" -O URL > /dev/null
Logged

~~~~~~~~~~~~~~
Ketchup
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.065 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.