Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[c] Facebook spreader filter_list
Author
Message
[c] Facebook spreader #1
This program will login to Facebook with the provided username/password, extract the friends list, then message them all.

Requires: curl, and gumbo.

Code:
#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& from, const string& to ) {
   size_t first = str.find(from);
   size_t last = str.find(to);
   return( str.substr ( first+from.size(),last-first-to.size()));
}

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; titbang; 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.clear();
}

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;
}
(This post was last modified: 08-15-2017, 05:40 AM by titbang.)

[+] 1 user Likes titbang's post
Reply

RE: [c] Facebook Spreader #2
Nice.

Did you code this yourself?
[Image: AD83g1A.png]

Reply

RE: [c] Facebook Spreader #3
Very nice, actually I want make a one in Java.
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: [c] Facebook Spreader #4
@mothered Yeah it's an older sample of mine.

@Mr.Kurd Doing it in Java should be quite easy. Check out Jsoup if you haven't already.

Reply

RE: [c] Facebook Spreader #5
(07-18-2017, 09:38 PM)titbang Wrote: @mothered Yeah it's an older sample of mine.

@Mr.Kurd Doing it in Java should be quite easy. Check out Jsoup if you haven't already.

I have background with Jsoup but it want need any Api or any Lib?!
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: [c] Facebook Spreader #6
LOL, with Java I would use Selenium to automate that stuff.

Reply

RE: [c] Facebook Spreader #7
(07-18-2017, 09:38 PM)titbang Wrote: @mothered Yeah it's an older sample of mine.

Good work.

It's nice to see you've put the time and effort to code It yourself.
[Image: AD83g1A.png]

Reply

RE: [c] Facebook Spreader #8
It looks like a good step in the right direction for automation, but that's definitely C++. C doesn't have objects, e.g. vectors or strings.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: [c] Facebook Spreader #9
(07-20-2017, 06:17 PM)Inori Wrote: It looks like a good step in the right direction for automation, but that's definitely C++. C doesn't have objects, e.g. vectors or strings.

I have this bad tendency of mixing C and C++.
(This post was last modified: 08-11-2017, 04:14 AM by titbang.)

Reply

RE: [c] Facebook Spreader #10
(07-20-2017, 02:26 PM)BORW3 Wrote: LOL, with Java I would use Selenium to automate that stuff.

Quote:me too but using python3 ; (import selenium and call web.driver)

Reply







Users browsing this thread: 2 Guest(s)