I am studying the capabilities of Artificial Intelligence to improve the National Security and Cyber Security. For performing my first test and examen, I am using A.I for growth hacking.
Growth hacking is a process of rapid experimentation across marketing channels and product development to identify the most effective, efficient ways to grow a business.
This new area is directly connected to mass surveillance domain. I am exploring this new field of security so much controverted but really interesting. My first step is the creation of a social botnet on twitter, capable of gathering data about the #cybersecurity tag. So here is a quick tutorial on how to create a TwitterBot.
A Twitterbot is a program that integrates with the Twitter platform, automatically posting, retweeting, liking, or following other users.
My article is referred to the Digital Ocean one. The quotes come from there.
STEP 1: The account.
I create a new account on twitter, just in case it will end to be banned for botting.
It is important to exercise care when creating Twitterbots, as not only are harassment and spamming not OK, but they will cause your Twitterbot’s account to be suspended for violating Twitter’s Terms of Service.
I used a new address email and new phone number to be able to activate the “widget” option in the Twitter settings. It will be needed to use the Twitter API in our program.
We need know to create or app. Digital Ocean did a really good article on how to create your Twitter app. Follow the link or create yours if you know how to do it.
STEP 2: The host.
You setup your twitter account, you have your app. You need now a decent environment to run your bot. First thing, you should use a Linux or Unix based host. Your host needs to be connected and online 24 hours a day.
I am using a dedicated VPS for hosting my bots. It’s accessible from everywhere.
STEP 3: The bot.
Here is my code of my TwitterBot. It is able to retweet, follow and like if certain conditions are present:
- The tweet contains #cybersecurity
- The tweet is not a retweet
- The user has less than 1000 followers
- The tweet doesn’t contain “RT”
- The language is English
Bellow the code of the main code:
import tweepy import tweepy import time # Import our Twitter credentials from credentials.py from conf import consumer_key, consumer_secret, access_token, access_token_secret # Access and authorize our Twitter credentials from credentials.py auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) # For loop to iterate over tweets with #cybersecurity, limit to 10 try: for tweet in tweepy.Cursor(api.search,q='#cybersecurity',lang = "en", include_rts=False).items(10): try: followers = tweet.user.followers_count if followers < 1000 : if "RT" not in tweet.text and not tweet.retweeted: print('Tweet by: @%s' % tweet.user.screen_name) print('Followed by: ~%s' % tweet.user.followers_count) # Favorite the tweet tweet.favorite() # Retweet tweet.retweet() print('Favorited and retweet the tweet') # Follow the user who tweeted tweet.user.follow() print('Followed the user') # Add a timeout for not spamming and alerting twitter. time.sleep(180) except Exception as e: print e.message except tweepy.error.TweepError as e: print e except Exception as e: print e
And below the sample for adding your twitter credentials:
consumer_key = '' consumer_secret = '' access_token = '' access_token_secret = ''
STEP 4: The result.
A few days later, I had 28 followers. I noticed I can convert 10% of the people I am following on followers and without doing any human interaction. It’s really interesting. I also received an email from Twitter telling my account has been probably hacked.
I reset the password and the bot is still running for probably few more days.