Libcurl is a great library that supports a variety of protocols and allows simple scripting of activities. It can be used for all sorts of things like testing applications, automation, screen-scraping, etc.
It is capable of handling certs and cookies and is a great library to use when pentesting web apps. If you plan on doing some web application pentesting then you should get to know cURL. There is a command line "curl" you can use, but I have been using it with command-line PHP lately. PHP is very simple, and is super-easy to build into web apps (becuase that's why it exists in the first place).
I plan to post some more curl stuff in the future for various purposes, but below is a simple example of using PHP and the cURL library. If you are not familiar with cURL, it can help get you started.
Enjoy,
-Curt
------------ Code Starts Below This Line ------------
#!/usr/bin/php<?php
#
# Facebook Stalker
# fbstalker.php
#
# Wanna keep up with which of your "friends" logs into facebook, and when, and for how long?
# Then look no further. This primitive little php script will keep an eye on your buddies and
# write to a log file every X seconds to let you know who was logged into facebook at that time.
#
# At the moment, changing things like the check interval, logfile name, and other variables
# must be done manually by editing this script. I don't plan on making the script pretty,
# elegant, or more user friendly because I already feel creepy enough..
#
# TO USE:
#
# just type "fbstalker.php" and hit enter.
#
# The script will prompt you for your facebook username(email address) and password
#
#
# You'll need the php command line package (php-cli) installed to use it.
#
// Read the email addr from the command line
echo "Email Address: ";
$line = trim(fgets(STDIN));
$username=$line;
// Read the password from the command line
echo "Password: ";
$line = trim(fgets(STDIN));
$pw = $line;
// Open the log file
$outfile = fopen("fb.log", "w");
// Do the following forever
while ( 1 == 1 )
{
// Initialize our curl session
$curl = curl_init();
// Tell curl we want to send POST requests to the server
curl_setopt($curl, CURLOPT_POST, 1);
// Tell curl we don't care about the server certificate
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , 0);
// Tell curl we want to tell the server we are an Internet Explorer browser
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16 Paros/3.2.13");
// Tell curl we want to write cookes to a local file nameed "facebookcookies"
curl_setopt($curl, CURLOPT_COOKIEJAR , "facebookcookies");
// Tell curl we want to capture header information sent to us from the server
curl_setopt($curl, CURLOPT_HEADER, 1);
// Tell curl that we want the server responses to be sent to a local variable
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Tell curl that we want to follow all redirects that we may receive from the server
curl_setopt($curl, CURLOPT_FOLLOWLOCATION , 1);
// Set the login URL
curl_setopt($curl, CURLOPT_URL,"https://login.facebook.com/login.php");
// Set the input parameters (with our uname and passwd)
$userloginfields = "set_as_homepage=&challenge=6e24c1edb23c1e5c5b7d24c17063ef41&md5pass=1&noerror=1&email=" . $username . "&pass=" . $pw . "&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84";
curl_setopt($curl, CURLOPT_POSTFIELDS, $userloginfields);
// Send the request
$result = curl_exec ($curl);
// Facebook userid information is sent back in the header. Find it and set a local variable.
$idpos = strpos($result, "c_user");
$endidpos = strpos($result, ";", $idpos);
$userid = substr($result, $idpos + 2, $endidpos - $idpos -2 );
// Set the "see who is online" URL
curl_setopt($curl, CURLOPT_URL,"http://www.facebook.com/ajax/presence/update.php");
// Set the input parameters
$usercheckfields = $userid . "¬if_latest=1219371952¬if_latest_read=1219371952¬ifications=1&popped_out=false&&force_render=true&buddy_list=1&post_form_id=194be832599f4c1dcef71bb3a83a9f3d";
curl_setopt($curl, CURLOPT_POSTFIELDS, $usercheckfields);
// Send the request
$result = curl_exec ($curl);
// Log out of facebook. (we want to minimize the chances of someone spying on us...)
curl_setopt($curl, CURLOPT_URL,"http://www.facebook.com/logout.php?js");
curl_setopt($curl, CURLOPT_POSTFIELDS, "confirm=1&post_form_id=194be832599f4c1dcef71bb3a83a9f3d");
// Send the request
curl_exec ($curl);
// Close our curl session
curl_close($curl);
// Now parse the results to figure out who is logged in
$whoson = $result;
$startpos = 0;
$namepos = 1;
while ( $namepos )
{
$namepos = strpos($whoson, "name\":", $startpos);
if ( $namepos )
{
$endpos = strpos($whoson, "name\":", $namepos + 6);
if ( ! $endpos )
$endpos = strlen($whoson);
$startpos = $namepos;
$match = substr($whoson, $startpos+7, $endpos - $startpos );
$who = substr($match, 0, (strpos($match, "\"")));
if ( ! strpos ($who, "common.js" ) )
{
// Don't show and users matching "urt Stap" or "orge Bush" because we don't care about them
if ( ( ! strpos ($who, "urt Stap" )) && ( ! strpos ($who, "orge Bush" )) )
{
$date = date("F j, Y, g:i a");
// Show the results in the term window
printf( $date . " : " . $who . "\n");
// Write the results to the log file
fwrite ($outfile, $date . " : " . $who . "\n");
}
}
$startpos = $endpos;
}
} // End the "parse usernames from results" loop
// Wait for a spell, and then do the whole thing again
sleep (120);
} // end main while loop (1=1)
// Close the file (code will never get here... just being inconsistently thorough
fclose ( $outfile);
?>

December 24, 2009 - 7:21pm
Old post but script just hangs for me ...