Learning to read the Metasploit Framework source code

by Security Dude


On Saturday I spent the day with the Ladies Learning Code’s “Intro to Ruby” workshop in Vancouver.  We learned the syntax of Ruby.  We built a small program that mimicked Twitter.  We would post a comment and our little program would determine if the Tweet was suitable to post. If it was within the 140 character limit, it printed out to our screen.  Simple. It taught us about variable assignment, lists, arrays, conditionals and loops.

I was amazed by all the ladies and the dedication in the room. Before we knew it, everyone was clicking away at their keyboards, and you could see the smiles on each of the participants faces as they realized how much fun programming was. I was having fun! You could feel the energy. I’m lucky to have witnessed the emergence of a bunch of new Rubyists. The experience was awesome!

Today, I thought it was important to spend some time reviewing the material and building on the yesterday’s lesson. I’m going to review classes in Ruby.  Here’s an example I made up that I feel builds on objects IRL.

class Newspaper
 attr_accessor :price, :size, :publisher, :political, :independant
end
GlobeAndMail = Newspaper.new
VancouverSun = Newspaper.new
TheProvince = Newspaper.new
TheGeorgiaStrait = Newspaper.new
The24 = Newspaper.new
Courier = Newspaper.new

GlobeAndMail.price = 1.00
VancouverSun.price = 0.75
TheProvince.price = 0.75
TheGeorgiaStrait.price = 0
The24.price = 0
Courier.price = 0

papers = [GlobeAndMail, VancouverSun, TheProvince, TheGeorgiaStrait, The24, Courier,]

And here is a mockup of a Ticket Machine class that takes the price of a ticket when initialized. The object has a few methods to add money to your balance and determine if you have enough money to pay for the ticket.  Here’s the code. In the last screenshot, I’m now having success reading Metasploit code.  Awesome day filled with aha moments!

class TicketMachine
 attr_accessor :balance, :price

 def initialize(priceOfTicket)
   @price = priceOfTicket
   @balance = 0
 end

 def print
   if @balance >= @price
     puts "Here is your ticket"
     @balance = 0
     return @price
   elsif @balance < @price
     puts "put more money. balance =", @balance
   end
 end

 def add(value)
   @balance = @balance + value
 end
end

Advertisements