Jump to content
Aerosol

[C] Facebook Mass Messenger

Recommended Posts

Posted (edited)

Login to account with provided username/password, extract friends list, send messages to them all.

Requires: curl, and gumbo.

Enjoy.

#include <stdio.h>
#include <curl/curl.h>
#include <iostream>
#include <cstring>
#include <vector>

#include "gumbo.h"

using namespace std;

CURL *curl;
CURLcode res;

string data;
string fb_dtsg;

vector<string> friends;

struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_httppost *msgform=NULL;
struct curl_httppost *msglast=NULL;

static size_t curl_write( void *ptr, size_t size, size_t nmemb, void *stream) {
data.append( (char*)ptr, size*nmemb );
return size*nmemb;
};

string replace_all(string str, const string& from, const string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
return str;
}

string string_between( string str, const string& delim1, const string& delim2 ) {
unsigned first = str.find(delim1);
unsigned last = str.find(delim2);
string out = str.substr (first,last-first);
return out;
}

int curl_check_cookie_response( )
{
struct curl_slist *cookies;
struct curl_slist *nc;
int i;
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
if (res == CURLE_OK) {
nc = cookies, i = 1;
while (nc) {
if(strstr( nc->data, "c_user") != NULL )
return 0;
nc = nc->next;
i++;
}
}
curl_slist_free_all(cookies);
return 1;
}

int authenticate_details( const char* email, const char* password )
{
curl_easy_setopt(curl, CURLOPT_URL, "https://m.facebook.com/login.php" );
curl_easy_setopt( curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; sludg3; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0");
curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 2L );
curl_easy_setopt( curl, CURLOPT_VERBOSE, 0 );
curl_easy_setopt( curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt( curl, CURLOPT_COOKIEJAR, "cookies.txt" );
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "email", CURLFORM_COPYCONTENTS, email, CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "pass", CURLFORM_COPYCONTENTS, password, CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, curl_write );
if( curl_easy_perform(curl) == CURLE_OK ) {
return 0;
}
return 1;
}

void gumbo_parse_friend_data( GumboNode* node )
{
GumboAttribute* url;
if (node->type != GUMBO_NODE_ELEMENT) {
return;
}
if (node->v.element.tag == GUMBO_TAG_A &&
(url = gumbo_get_attribute(&node->v.element.attributes, "href"))) {
if( strstr( url->value, "?uid=" ) != NULL ) {
data = string_between( url->value, "=", "&" );
data = replace_all( data, "=", "");
friends.push_back( data );
}
}
GumboVector* children = &node->v.element.children;
for (unsigned int i = 0; i < children->length; ++i) {
gumbo_parse_friend_data(static_cast<GumboNode*>(children->data[i]));
}
}

void gumbo_parse_session_id ( GumboNode* node ) {

GumboAttribute* inputName; GumboAttribute* inputValue;
if (node->type != GUMBO_NODE_ELEMENT) {
return;
}
if (node->v.element.tag == GUMBO_TAG_INPUT ) {
inputName = gumbo_get_attribute( &node->v.element.attributes, "name" );
inputValue = gumbo_get_attribute( &node->v.element.attributes, "value" );
if( inputValue != NULL && inputName != NULL) {
std::string val( inputName->value );
std::size_t match = val.find( "fb_dtsg" );
if( match == 0 ) {
fb_dtsg = inputValue->value;
}
}
}
GumboVector* children = &node->v.element.children;
for (unsigned int i = 0; i < children->length; ++i) {
gumbo_parse_session_id(static_cast<GumboNode*>(children->data[i]) );
}
}

int grab_friends_list_data( )
{
curl_easy_setopt(curl, CURLOPT_URL, "https://m.facebook.com/friends/center/friends" );
if( curl_easy_perform(curl) == CURLE_OK ) {
GumboOutput* output = gumbo_parse(data.c_str());
gumbo_parse_friend_data( output->root);
return 0;
}
return 1;
}

int grab_friend_session( string friend_id )
{
char url[512];
snprintf( url, sizeof( url ), "https://m.facebook.com/messages/thread/%s", friend_id.c_str() );
curl_easy_setopt( curl, CURLOPT_URL, url );
if( curl_easy_perform(curl) == CURLE_OK ) {
GumboOutput* output = gumbo_parse(data.c_str());
gumbo_parse_session_id( output->root);
return 0;
}
return 1;
}

int send_message_to_friend( string friend_id, string message )
{
char field[ 32 ], value[ 32 ];
snprintf( field, sizeof( field ), "ids[%s]", friend_id.c_str() );
snprintf( value, sizeof( value ), "%s", friend_id.c_str() );
curl_easy_setopt( curl, CURLOPT_URL, "https://m.facebook.com/messages/send/?icm=1" );
curl_formadd(&msgform, &msglast, "fb_dtsg", CURLFORM_COPYCONTENTS, fb_dtsg.c_str(), CURLFORM_END);
curl_formadd(&msgform, &msglast, CURLFORM_COPYNAME, field, CURLFORM_COPYCONTENTS, value, CURLFORM_END);
curl_formadd(&msgform, &msglast, CURLFORM_COPYNAME, "body", CURLFORM_COPYCONTENTS, message.c_str(), CURLFORM_END);
curl_easy_setopt( curl, CURLOPT_HTTPPOST, msgform );
if( curl_easy_perform(curl) == CURLE_OK ) {
return 0;
}
return 1;
}


void cleanup( ) {
data = "";
}

int main( int argc, char *argv[] ) {

curl = curl_easy_init();

if(curl) {

if( authenticate_details( "message@allyourfriends.com", "thepassword" ) == 0 ) {

if( curl_check_cookie_response() == 0 )
{
printf("We are logged in.");

if( grab_friends_list_data() == 0 )
{
for(vector<int>::size_type i = 0; i != friends.size(); i++)
{
printf( "Sending message to friend ID: %s\r\n", friends[i].c_str() );

if( grab_friend_session( friends[i].c_str() ) == 0 ) {
send_message_to_friend( friends[i].c_str(), "hi");
}
}
}
}
else {
printf("Failed to login.");
}
}
}

return 0;
}

P.S://

Nu l-am testat!

Credit's to: sludg3@tf

@kNigHt done.

Edited by Aerosol
Posted
Thanks for sharing, dar vezi ca librariile sunt obligatorii.

dupa trimiterea a aproximativ 200 mesaje contul va fi restrictionat din pacate !

personal folosesc FaceBook Blaster Pro 11, insa chiar si cu acesta ce ofera posibilitatea de a trimite aleator mesajul si intervalul de timp nu am reusit sa trimit mai mult de 500 mesaje de pe un cont !

Posted

Putin nu e de ajuns, presupun ca verifica ceva gen : numar de mesaje trimise /perioada de timp, daca nu ceva mai avansat cu frecventa litere/cuvinte in mesaje si si vreun coeficent de coincidenta... (statistica si probabilitati)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...