Internet Bots for Fun & No Profit

BSides Winnipeg 2013 Talk

Kyle Geske

He Who Presents

3350514518_8ca9143bbd_b

Kyle Geske

  • Hardware/Firmware Engineer Turned Web Developer
  • Instructor at Red River College
    (Ruby/Rails, PHP, HTML/CSS, Philosophy of Time Travel)
  • Artist - Shared studio space with my dad @ Artspace

V-World Avatars

  • Twitter, Flickr, Pinboard, Github, Gmail, Etc: stungeye
  • Web: stungeye.com
  • AKA: Walter S. Glutton

Foucault's Pendulum

Italian_cover_foucault

I first encountered the Pendulum 20 years ago. It contained code, really big words, and European history that I knew nothing about.

   1  10  REM anagrams
   2  20  INPUT L$(1),L$(2),L$(3),L$(4)
   3  30  PRINT
   4  40  FOR I1=1 TO 4
   5  50  FOR I2=1 TO 4
   6  60  IF I2=I1 THEN 130
   7  70  FOR I3=1 TO 4
   8  80  IF I3=I1 THEN 120
   9  90  IF I3=I2 THEN 120
  10  100 LET I4=10-(I1+I2+I3)
  11  110 LPRINT L$(I1);L$(I2);L$(I3);L$(I4)
  12  120 NEXT I3
  13  130 NEXT I2
  14  140 NEXT I1
  15  150 END

It took me 18 years to finish this book.

Abulafia

Abraham_abulafia
  • Abulafia is the name of a computer in the book Foucault’s pendulum.

  • Named after Abraham Abulafia, religious philosopher of the 1200s and the founder of the school of “Prophetic Kabbalah”.

  • The characters use Abulafia to invent their own conspiracy theory by writing a program that makes connections between random bits of text they provide.

    • The Templars have something to do with everything

    • Minnie Mouse is Mickey Mouse’s fiancee

    • What follows is not true

Abotlafia

Capture
  • Abotlafia is my version of this fictional computer.

  • Abotlafia makes the connections the inspire The Plan.

  • Abotlafia makes random connection between tweet-sized sentences from the book Foucault’s pendulum.

  • Abotlafia has over 480 followers…

  • … and a Klout score of 44.

Summon the Bots

Pull out your mobile devices and tweet a few of these phrases:


These phrases summon bots written using the Ruby library Chatterbot.

Written by Colin Mitchell.

Building Bots with Ruby & Chatterbot

Make a Twitter Account

First thing you’ll need to do is create an account for your bot on Twitter. That’s the easy part.

Install Chatterbot


   1  gem install chatterbot

Run the Generator

Chatterbot comes with a script named chatterbot-register which:

Ruby

Ruby_makes_me_happy

The code in this talk will be in the Ruby language. If you don’t know Ruby just pretend it’s pseudo-code. ;)

Numbers Station Bot

Sprach-morse-generator
   1  require 'chatterbot/dsl'
   2  
   3  loop do
   4  
   5    tweet rand(1000000..99000000).to_s
   6  
   7    sleep 300
   8  
   9  end

The Twitter bot equivalent of a Numbers Station.

BSidesReminder

Reminder

I built the @bsidesreminder bot to ensure that I wouldn’t procrastinate writing this talk. Every day at 11am this bot would tell me how many days it was until BSides Winnipeg 2013.

BSidesReminder

   1  require 'date'
   2  
   3  BSIDES_WINNIPEG_2013_DATE = Date.parse('November 16 2013')
   4  days_until_bsides = (BSIDES_WINNIPEG_2013_DATE - Date.today).to_i
   5  
   6  exit  if days_until_bsides < 0 
   7  
   8  require 'chatterbot/dsl'
   9  
  10  tweet_text = "@stungeye You are presenting @BSidesWpg "
  11  
  12  if days_until_bsides.zero?
  13    tweet_text += "today!"
  14  elsif days_until_bsides == 1
  15    tweet_text += "tomorrow."
  16  else
  17    tweet_text += "in #{days_until_bsides} days."
  18  end
  19  
  20  tweet tweet_text

Echo Bot

Echo
   1  require 'chatterbot/dsl'
   2  
   3  replies do |tweet|
   4  
   5    user = tweet_user(tweet)
   6  
   7    echo = tweet.text.gsub(/@echoes_bot/, user)  
   8  
   9    reply echo, tweet
  10  
  11  end

Try sending a tweet to @echoes_bot. This bot will echo back to you anything you send to it.

Lucky Librarian - @finditplease

Lucky_librarian

Send @finditplease a topic you wish to research.

Lucky Librarian - @finditplease

   1  require 'chatterbot/dsl'
   2  require 'google-search'
   3  require 'cgi'
   4  
   5  NO_RESULTS_FOUND = 'Ever so sorry; I found no websites that reference: '
   6  
   7  replies do |user_tweet|
   8    user_who_tweeted = tweet_user(user_tweet)
   9    
  10    google_query = user_tweet.text.gsub(/[#\@]\w+\b/,'').strip
  11    
  12    feeling_lucky = Google::Search::Web.new(:query => google_query).first
  13  
  14    response_tweet = user_who_tweeted + " "
  15  
  16    if feeling_lucky.nil?
  17      response_tweet += NO_RESULTS_FOUND + google_query 
  18    else
  19      response_tweet += CGI.unescapeHTML(feeling_lucky.title)
  20    end
  21      
  22    response_tweet += " " + feeling_lucky.uri  unless feeling_lucky.nil?
  23  
  24    reply response_tweet, user_tweet
  25  end

Rhyme Librarian

Rhyme_profile

@redlibrarian: And if you’re fresh out of library school and need to learn *the job* as well…

@rhyemelibrarian: See, for example, under L.

Send @rhymelibrarian a tweet and it will reply with a sentences that rhymes with yours.

Rhyme Librarian

Tough_shit

@redlibrarian: @stungeye Dude is @rhymelibrarian yours? If not, I’m blocking it.

@rhymelibrarian: If you can’t figure it out yourself, tough shit.

Rhyme Librarian

   1  DB = Sequel.connect("mysql2://#{DB_USER}:#{DB_PASSWORD}@localhost/stungeye")
   2  wordnik = WordnikParty.new(WORDNIK_KEY)
   3  
   4  replies do |user_tweet|
   5  
   6    user_name = tweet_user(user_tweet)
   7    tweet_text = user_tweet.text.gsub(/[#\@]\w+\b/,'').gsub(/\W+$/,'')
   8    last_word = tweet_text.split(' ').last.downcase
   9  
  10    unless last_word.include?('http')
  11      rhymes = wordnik.rhymes_with(last_word, 100)
  12      possible_sentences = find_sentences(rhymes, user_name)
  13  
  14      unless possible_sentences.size.zero?
  15        selected_sentence = possible_sentences.sample
  16        DB[:rhymesentences]
  17          .where(:id => selected_sentence[:id])
  18          .update(:tweeted => true)
  19  
  20        reply "#{user_name} #{selected_sentence[:words]}", user_tweet
  21      end
  22    end
  23  end

The rhymesentences table contains sentences from The Communist Manifesto, The Wealth of Nations, and Alice in Wonderland.

The find_sentences method is interacts with this database table to find sentences that end in the possible rhymes found by the Wordnik API.

Wonder Sparks

Wonder

Why do I do this? Why create Twitter bots?

As humans I believe we are contractually obligated to inspire each other.

“What are wonder sparks, you may ask? Well that’s the best part… The answer is: anything. Anything that will stimulate the sense of wonder of your fellow man.

Paint pictures on the sides of garbage cans, plant trees in strange urban locations, leave poems on the tables in the lunch room, or ponder strange philosophical concepts with the other people in the checkout line at the grocery store.”

– Me, in 2003.

Since then I’ve added “Write weird-ass Twitter bots” to this list.

Abotlafia

Besides_bsides

@abotlafia: Besides, we had the logic of facts on our side.

@xorrbit: .@abotlafia BSides: We have the logic of facts on our side. #newslogan

@abotlafia: @xorrbit There’s no difference between you and me.

They Understand the Plan

They_know

Reading Cats

Literarycat

For 10 minutes last night I hijacked Abulafia’s tweets and had him do search for and retweet pictures of cats reading. He was averaging about 10 to 20 literary cat retweets a minute.

meow-reader.tumblr.com

Reading Cats

Cats

@roseandsigil: .@abotlafia, my go-to for Eco bibliomancy, has turned into a machine for retweeting pictures of cats reading.

@abotlafia: To this Abraham Abulafia dedicated his life, while your Saint Thomas was toiling to find god with his five paths.

On the Internet...

On_the_internet_nobody_knows_you_re_a_dog

…nobody knows your a bot either.

Learn That Praise

Jav1

Not Understanding U

Jav3

Who is Robert Fludd?

Jav4

Ask U Shall Receive

Jav5

Reverse Turing Test

Turing

One might say this user failed the Reverse Turing Test. But it’s all too easy to mistake a bot for a human… we want to believe!

Easy to Anthropomorphize

Followers

an·thro·po·mor·phize

transitive verb

to attribute human form or personality to

intransitive verb

to attribute human form or personality to things not human

Benefit of the Doubt

Fooled

Bot Detection

Detecting

Are you sure that all your followers on Twitter are human? How about everyone you follow?

Academic Research: Detecting Automation of Twitter Accounts: Are You a Human, Bot, or Cyborg?

Thank You - Source Available

The Ruby source for my BSides bots is available on GitHub:

github.com/stungeye/Bsides-Bots

An early version of Abotlafia:

github.com/stungeye/abotlafia

The ChatterBot Library I used:

github.com/muffinista/chatterbot/

My bots mentioned in this talk: