Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "Ruby"

From NetSec
Jump to: navigation, search
Line 1: Line 1:
 
'''Ruby''' is an [[interpreted languages|interpreted language]], dynamically, reflective, semi-Functional and Object Orientated scripting language written in [[C]]. Ruby is said to be semi-Functional because it supports hire-order functions (aka lambdas) and closures (aka blocks). Ruby was created by [http://en.wikipedia.org/wiki/Yukihiro_Matsumoto Yukihiro "Matz" Matsumoto] and was first released in 1995.
 
'''Ruby''' is an [[interpreted languages|interpreted language]], dynamically, reflective, semi-Functional and Object Orientated scripting language written in [[C]]. Ruby is said to be semi-Functional because it supports hire-order functions (aka lambdas) and closures (aka blocks). Ruby was created by [http://en.wikipedia.org/wiki/Yukihiro_Matsumoto Yukihiro "Matz" Matsumoto] and was first released in 1995.
  
Matz's goal was to combine powerful features from various other [[programming]] languages, and create a [[programming language]] maximized for developer happiness; as opposed to computational efficiency. Ruby's Object Model mirrors that of Smalltalk, the syntax shares some similarities with [[Bash]], [[Perl]], [[Python]], and the scoping rules for closures was taken from [[LISP]].  
+
Matz's goal was to combine powerful features from various other [[programming]] languages, and create a [[programming language]] maximized for developer happiness; as opposed to computational efficiency. Ruby's Object Model mirrors that of Smalltalk, the syntax shares some similarities with [[Bash]], [[Perl]], [[Python]], and the scoping rules for closures was taken from [[LISP]].
 
+
 
+
= External Resources =
+
* Terse syntax, with some similarities to Perl or Bash
+
* Non-whitespace sensitive
+
* [http://en.wikipedia.org/wiki/Duck_typing Duck Typing]
+
* [http://en.wikipedia.org/wiki/Operator_overloading Operator Overloading]
+
* [http://en.wikipedia.org/wiki/Higher-order_function Higher-order functions] (aka lambdas)
+
* [http://en.wikipedia.org/wiki/Anonymous_function Anonymous functions] (aka closures or blocks)
+
* [http://en.wikipedia.org/wiki/Currying Currying]
+
* Fully Object Orientated. Everything is an Object, even primitives (<kbd>0x42.chr # => "A"</kbd>)
+
* Every statement has a return value
+
* Method-calls as messages
+
* Multiple inheritence via Modules (aka Mixins)
+
* [http://en.wikipedia.org/wiki/Metaclass Metaclasses]
+
* <kbd>if</kbd>, <kbd>elsif</kbd>, <kbd>else</kbd>, <kbd>unless</kbd>, <kbd>case</kbd>, <kbd>break</kbd>, <kbd>continue</kbd>, <kbd>retry</kbd>, <kbd>return</kbd>, <kbd>for ... in</kbd>, <kbd>while</kbd>, <kbd>until</kbd>, <kbd>begin</kbd>, <kbd>ensure</kbd>, <kbd>raise</kbd>/<kbd>rescue</kbd>, <kbd>throw</kbd>/<kbd>catch</kbd> statements.
+
* In-line Regular Expressions (<kbd>"hello world" =~ /[a-z0-9]+/</kbd>)
+
* [http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection]
+
* [http://en.wikipedia.org/wiki/Metaprogramming Meta-programming]
+
* Open Classes (aka [http://en.wikipedia.org/wiki/Monkey_patch Monkey Patching])
+
* <kbd>method_missing</kbd>/<kbd>const_missing</kbd> methods
+
* [http://en.wikipedia.org/wiki/Continuation Continuations] (aka Fibers)
+
* Fully featured standard library
+
 
+
{{immediate|content}}
+
 
+
==Learning==
+
 
+
There are free ebooks and websites which teach you how to program in Ruby:
+
 
+
* [http://tryruby.org/ TryRuby] in your browser!
+
* [http://www.humblelittlerubybook.com/ The Humble Little Ruby Book]
+
* [http://ruby-doc.org/docs/ProgrammingRuby/ Programming in Ruby (1.8): The Pragmatic Programmer's Guide]
+
* [http://ruby.bastardsbook.com/ The Bastards Book of Ruby]
+
* [http://rubylearning.com/ Learning Ruby] (blog)
+
 
+
Of course, there are many other commercial books and websites on Ruby:
+
 
+
* [http://www.amazon.com/gp/product/1934356085/ref=as_li_tf_tl?ie=UTF8&tag=redditrrubyco-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1934356085 Programming Ruby 1.9: The Pragmatic Programmers’ Guide]
+
* [http://www.amazon.com/gp/product/0596516177/ref=as_li_tf_tl?ie=UTF8&tag=redditrrubyco-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0596516177 The Ruby Programming Language]
+
* [http://www.amazon.com/gp/product/1933988657/ref=as_li_qf_sp_asin_tl?ie=UTF8&tag=redditrrubyco-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1933988657 Well Grounded Rubyist]
+
* [http://www.amazon.com/gp/product/0321584104/ref=as_li_tf_tl?ie=UTF8&tag=redditrrubyco-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0321584104 Eloquent Ruby]
+
* [https://cooperpress.com/rubyreloaded Ruby Reloaded (online course)]
+
* [https://rubyoffrails.com/ Ruby Off Rails (online course)]
+
 
+
==Installing==
+
 
+
All Linux distributions provide packages for Ruby, and other Ruby development tools:
+
 
+
Debian / Ubuntu:
+
 
+
<pre>sudo apt-get install ruby1.9.1-full</pre>
+
 
+
RedHat / Fedora:
+
 
+
<pre>sudo apt-get install ruby ruby-dev irb rubygems</pre>
+
 
+
Mac OS X systems ship with an older version of Ruby already installed, however you will want to use the latest version (current 1.9.3). The easiest way to install Ruby on a *nix platform, which does not provide an recent version of Ruby, is with the [https://rvm.io/ Ruby Version Manager (RVM)]. RVM is a set of bash scripts which can download, compile, install and update Ruby all within one's home directory.
+
 
+
<pre>curl -L https://get.rvm.io | bash -s stable --ruby</pre>
+
 
+
==Alternate Implementations==
+
 
+
The primary implementation of Ruby is known as MRI (Matz Ruby Implementation) or CRuby. However, like any other programming language, Ruby also has many alternate implementations.
+
 
+
* [http://jruby.org/ JRuby]: Ruby implemented on the Java Virtual Machine (JVM). It may be slow to startup, but once running JRuby is extremely performant. Consider using JRuby for highly parallized/threaded programs.
+
* [http://rubini.us Rubinius]: Ruby implemented on [http://llvm.org/ LLVM]. Rubinius has a small core of C++ that uses LLVM to interpret, compile and run Ruby code. The majority of Rubinius is actually written in Ruby, which makes the source-code extremely readable.
+
* [http://macruby.org/ MacRuby]: Ruby implemented on LLVM and Objective C. MacRuby can interface to any Mac OS X system library.
+
* [http://www.ironruby.net/ IronRuby]: Ruby implemented ontop of the Microsoft .NET Dynamic Language Runtime (DLR).
+
* [https://github.com/mruby/mruby/ MRuby]: A custom C implementation of Ruby, designed for embedded systems. MRuby seeks to compete with Lua.
+
* [http://www.rubymotion.com/ Ruby Motion]: Uses MacRuby to compile Ruby to Objective C iOS apps.
+
* [http://ruboto.org/ Ruboto]: JRuby optimized for the Android platform.
+
 
+
==Development Tools==
+
 
+
<kbd>ruby</kbd> is the Ruby interpreter.
+
 
+
<pre>$ ruby my_script.rb
+
$ ruby -Ilib bin/my_util</pre>
+
 
+
<kbd>irb</kbd> is the Ruby interactive console, similar to <kbd>python</kbd> or <kbd>perlconsole</kbd>. IRB also supports tab-completion, which can be enabled by adding <kbd>require 'irb/completion'</kbd> to your <kbd>~/.irbrc1</kbd> file.
+
 
+
<pre>$ irb
+
>> RUBY_VERSION
+
=> "1.9.3"</pre>
+
 
+
<kbd>gem</kbd>, or better known as RubyGems, is the package manager for Ruby. RubyGems allows you to install Ruby libraries, or Gems, from [https://rubygems.org/ RubyGems.org]. Installed Gems can be loaded with the <kbd>require</kbd> method:
+
 
+
<pre>$ gem install foo-bar
+
$ irb
+
>> require 'foo/bar'
+
=> true</pre>
+
 
+
<kbd>ri</kbd> is a Ruby Documentation indexing tool. RI allows you to quickly looking documentation for Ruby methods, from the command line:
+
 
+
<pre>$ ri Array#pack</pre>
+
 
+
<kbd>rake</kbd> is like Make, but for Ruby. Rake is used by Ruby projects to automate various tasks, such as testing, building or installing the project.
+
 
+
<pre>$ rake build</pre>
+
 
+
[http://gembundler.com/ Bundler] is a RubyGem that allows projects to lock-down their dependencies. Bundler is commonly used by developers to automatically install dependencies for a project (<kbd>bundle install</kbd>) or to generate new projects (<kbd>bundle gem foo</kbd>).
+
 
+
[http://rspec.info/ RSpec] is a popular testing framework for Ruby. When a project grows beyond one file/Class/Module, it's generally a good idea to write tests for your code, to ensure nothing breaks.
+
 
+
==Useful Libraries==
+
 
+
For a complete listing of popular RubyGems by category, please see the [https://www.ruby-toolbox.com/ Ruby Toolbox].
+
 
+
===Console===
+
 
+
* [https://github.com/janlelis/irbtools irbtools]: Pimp out your IRB.
+
* [https://github.com/cldwalker/ripl Ripl]: Mimimal alternative to IRB, with tons of [http://rubygems.org/search?utf8=%E2%9C%93&query=ripl- plugins].
+
* [http://pryrepl.org/ Pry]: Powerful alternative to IRB.
+
 
+
===Database===
+
 
+
* [http://sequel.rubyforge.org/ Sequel]: A SQL library for Ruby. Supports SQLite3, MySQL and Postgres.
+
* [http://datamapper.org/ DataMapper]: An Object Relational Mapper (ORM). Supports SQLite3, MySQL, Postgres, Oracle, MSSQL, HSQL, MongoDB, Redis.
+
* [http://ar.rubyonrails.org/ ActiveRecord]: The Object Relational Mapper (ORM) of Ruby on Rails.
+
* [http://mongomapper.com/ MongoMapper]: An Object Relational Mapper (ORM) for the [http://www.mongodb.org/ MongoDB].
+
 
+
===Binary===
+
 
+
* [https://github.com/ffi/ffi#readme FFI]: Foreign Function Interface for Ruby. Allows you to write bindings to C libraries, entirely in Ruby.
+
* [http://metafuzz.rubyforge.org/binstruct/ BinStruct]: Binary Structures.
+
* [https://github.com/emonti/rstruct RStruct]: Yet another Ruby Binary Structure library.
+
* [https://github.com/sophsec/ffi-udis86#readme ffi-udis86]: Ruby FFI bindings to the [http://udis86.sourceforge.net/ udis86] dissassembler.
+
 
+
===Exploitation===
+
 
+
* [https://github.com/hammackj/rex REX]: Various Exploitation helper methods, extracted from Metasploit.
+
* [https://github.com/emonti/rbkb Ruby BlackBag (rbkb)]: Ruby BlackBag. Misc ruby-based pen-testing/reversing tools. Inspired by Matasano BlackBag.
+
* [https://github.com/tduehr/ragweed Ragweed]: scriptable Win32/Linux/OSX debugger written in Ruby.
+
* [https://github.com/struct/Nerve Nerve]: a cross platform hit tracer built on Ragweed.
+
* [http://ronin-ruby.github.com/ Ronin]: A Ruby platform for vulnerability research and exploit development. Ronin allows for the rapid development and distribution of code, Exploits, Payloads, Scanners, etc, via Repositories. Provides a customized Ruby Console, built-in Database and many useful classes, modules, methods, libraries.
+
 
+
===Network===
+
 
+
* [https://github.com/todb/packetfu packetfu]: A library for reading a writing packets to an interface or to a libpcap-formatted file.
+
* [http://rubyeventmachine.com/ EventMachine]: Evented IO for Ruby.
+
* [https://github.com/igrigorik/em-proxy em-proxy]: EventMachine TCP proxy.
+
* [http://rubygems.org/gems/net-dns net-dns]: DNS client library for Ruby.
+
* [http://rubygems.org/gems/whois whois]: Whois client for Ruby.
+
 
+
===Scanners / Spiders===
+
 
+
* [https://github.com/sophsec/ruby-nmap#readme ruby-nmap]: Automate nmap from Ruby.
+
* [https://github.com/postmodern/spidr#readme Spidr]: A versatile Web Spider. Spidr is designed to be fast and easy to use.
+
* [http://anemone.rubyforge.org/ Anemone]: A multi-threaded Web Spider, supporting various backend databases.
+
* [http://arachni-scanner.com/ Arachni]: Fully featured Web Vulnerability scanner.
+
 
+
===Web===
+
 
+
* [http://nokogiri.org/ Nokogiri]: A fast XML/HTML parser built ontop of libxml. Supports XPath and CSS-path searching of documents.
+
* [http://mechanize.rubyforge.org/ Mechanize]: Automated head-less browser.
+
* [https://github.com/archiloque/rest-client RestClient]: A simple HTTP client library.
+
* [https://github.com/postmodern/gscraper#readme GScraper]: Web-scraping interface to Google Search.
+
* [https://github.com/emonti/buby Buby]: JRuby bindings to [http://www.portswigger.net/burp/proxy.html Burp].
+
* [http://sinatrarb.org/ Sinatra]: A minimal library for creating web applications.
+
 
+
==Resources==
+
 
+
* [irc://irc.freenode.net/#ruby-lang #ruby-lang on irc.freenode.net]
+
* [http://reddit.com/r/ruby /r/ruby]: A sub-reddit for news and questions about Ruby.
+
* [https://github.com/ GitHub]: where the majority of Ruby projects are hosted and developers collaborate.
+
* [https://rubygems.org RubyGems.org]: repository for all Ruby libraries)
+
* [https://www.ruby-toolbox.com/ Ruby Toolbox]: Groups popular RubyGems by category.
+
* [http://rubydoc.info/ RubyDoc]: Hosts documentation for Ruby [http://rubydoc.info/stdlib/core core], [http://rubydoc.info/stdlib/ stdlib] and all [http://rubydoc.info/gems/ RubyGems].
+
 
+
===References===
+
 
+
* [http://guides.rubygems.org/make-your-own-gem/ Make your own gem]: Basic guide on publishing your first RubyGem.
+
* [http://gitref.org/ GitRef]: Reference to Git, the Distributed Version Control System (DVCS) prefered by Rubyists.
+
* [https://github.com/styleguide/ruby/ Ruby Style Guide]: The defacto Ruby style-guide.
+
 
+
===Talks===
+
 
+
* [http://blip.tv/rupy-strongly-dynamic-conference/yehuda-katz-tradeoffs-and-choices-why-ruby-isn-t-python-5726460 Why Ruby isn't Python]
+
* [http://chargen.matasano.com/chargen/2009/8/30/ruby-for-pentesters-blackhat-09.html Ruby for Pentesters] [http://www.blackhat.com/presentations/bh-usa-09/TRACY/BHUSA09-Tracy-RubyPentesters-PAPER.pdf [paper]] [http://www.blackhat.com/presentations/bh-usa-09/TRACY/BHUSA09-Tracy-RubyPentesters-SLIDES.pdf [slides]]
+
* [http://dontstuffbeansupyournose.com/2011/04/27/greyhat-ruby-source-boston/ Greyhat Ruby]
+

Revision as of 17:22, 12 August 2012

Ruby is an interpreted language, dynamically, reflective, semi-Functional and Object Orientated scripting language written in C. Ruby is said to be semi-Functional because it supports hire-order functions (aka lambdas) and closures (aka blocks). Ruby was created by Yukihiro "Matz" Matsumoto and was first released in 1995.

Matz's goal was to combine powerful features from various other programming languages, and create a programming language maximized for developer happiness; as opposed to computational efficiency. Ruby's Object Model mirrors that of Smalltalk, the syntax shares some similarities with Bash, Perl, Python, and the scoping rules for closures was taken from LISP.