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

Difference between revisions of "Ruby"

From NetSec
Jump to: navigation, search
Line 17: Line 17:
 
Many times a hacker has stopped to ask how a character is represented in ascii, possibly for alphanumeric shellcode. Rather than having to resort to wikipedia, why not throw together a script? We'll call it asciispeek.rb
 
Many times a hacker has stopped to ask how a character is represented in ascii, possibly for alphanumeric shellcode. Rather than having to resort to wikipedia, why not throw together a script? We'll call it asciispeek.rb
  
#!/usr/bin/ruby
+
{{code|text=<source lang="ruby">
  
def asciispeek(x)
+
#!/usr/bin/ruby
x.each_byte do |c|
+
 
 +
  def asciispeek(x)
 +
  x.each_byte do |c|
 
     puts c.to_s(2)
 
     puts c.to_s(2)
 
end
 
end
Line 26: Line 28:
  
 
asciispeek(ARGV.join(' ').to_s)
 
asciispeek(ARGV.join(' ').to_s)
 +
</source>}
  
 
This script takes the arguments from the shell (ARGV) and joins them into one string. The act of joining removes the whitespace between them, so we add it back in, and then convert it to a string. The result is then passed to our function. Our function calls an enumerable method of the string class, each_byte, which gets at the byte representation of the character. We then pipe it into a block which converts it into a base 2 number and then prints it. A simple edit could make this spit out the hex representation, or the octal. This is a good example of the idea of reusing code. By encapsulating the actual actions into a function, we can copy this function into a class or script that we make in the future.  
 
This script takes the arguments from the shell (ARGV) and joins them into one string. The act of joining removes the whitespace between them, so we add it back in, and then convert it to a string. The result is then passed to our function. Our function calls an enumerable method of the string class, each_byte, which gets at the byte representation of the character. We then pipe it into a block which converts it into a base 2 number and then prints it. A simple edit could make this spit out the hex representation, or the octal. This is a good example of the idea of reusing code. By encapsulating the actual actions into a function, we can copy this function into a class or script that we make in the future.  

Revision as of 02:11, 24 June 2012

Ruby is one of many interpreted languages written in C used in Linux systems for command line tools and serving web applications. Ruby on Rails is an object-oriented MVC framework written in ruby served by WEBRICK and mongrel on Linux systems.

RPU0j.png This article needs immediate attention, and is in desperate need of content.

Development Environment

ruby cli

irb

gem

Your first application

Variables and data types

Boolean Logic

Loops

User Input

User-Defined Functions

Security

Examples of Useful Programs

Many times a hacker has stopped to ask how a character is represented in ascii, possibly for alphanumeric shellcode. Rather than having to resort to wikipedia, why not throw together a script? We'll call it asciispeek.rb

{{code|text=
 
 
 #!/usr/bin/ruby
 
  def asciispeek(x)
  	x.each_byte do |c|
    		puts c.to_s(2)
	end
end
 
asciispeek(ARGV.join(' ').to_s)
 
}

This script takes the arguments from the shell (ARGV) and joins them into one string. The act of joining removes the whitespace between them, so we add it back in, and then convert it to a string. The result is then passed to our function. Our function calls an enumerable method of the string class, each_byte, which gets at the byte representation of the character. We then pipe it into a block which converts it into a base 2 number and then prints it. A simple edit could make this spit out the hex representation, or the octal. This is a good example of the idea of reusing code. By encapsulating the actual actions into a function, we can copy this function into a class or script that we make in the future.

Ruby is part of a series on programming.
<center>
</center>