Samstag, 26. Oktober 2013

Custom Viewer

With release 0.9.17 watobo introduced a new viewer pane. This custom viewer gives you full control of how the output should look like. It enables you to parse the response (extract, format, decode, …) and display only the relevant parts by using the power of ruby – an example will follow shortly.
The custom viewer is available in the main window’s response viewer as well as in the manual request editor response - the latter we use for this tutorial.
Here’s the place we’re talking about:


Example

Our example function takes two parameters ‘char’ and ‘count’. The JSON response contains the parameter ‘answer’, which looks based64 encoded:


For decoding, select the base64 string, right-click and send it to watobo’s transcoder …

and finally decode it. But it still doesn't look human readable:




There's no well known magic-byte, but because of the two parameters ‘char’ and ‘count’ … bla … bla … bla … I know that the response is deflated with zlib ;)
Let’s proof it in irb:
>> require 'zlib'
>> require 'base64'
>> Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate Base64.decode64("Cw+HAQA=")
WWWWWWWWWW


This looks much better!

Cool, but it is not very comfortable if you have to copy-paste this string for each single response. So this is the time for the custom viewer.To automate this process (extract, decode and finally inflate) we only have to write a small handler. This handler consists of a ruby-lambda which receives the response object as an argument.

The very handler skeleton looks like this:
lambda{|response|
}


Because the return value of the handler function will be displayed,  it is a good choice to return a string.


The final code should look like this:

lambda{|response|
  h = JSON.parse(response.body.to_s)
  bin = Base64.decode64(h[‚answer‘])
  Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate bin
}


Now, save it and go on with the custom viewer:


You should see the red sign "No handler!". Press ‘add’ and select our freshly created handler file.
The sign should have been turned green, saying "Handler ready!"

*DRUMS_PLEASE* … press “SEND” … et voilà!



The viewer shows only the extracted, decoded and finally inflated value.

If you like it, please spread the word!

[as]





Montag, 18. März 2013

Installing FX/Ruby on (Kali) Linux

As most of the common linux distribution also Kali Linux has its own ruby package. But using these pre-built packages is often a pain in the ... ahm ... not the best choice, especially if you need to compile your own modules. From my experiences with Ruby on linux, I recommend to use RVM (Ruby Version Manager) for installing Ruby. This little tutorial will show you how to install (FX)Ruby on Kali Linux.

I assume you're using Kali Linux as an unprivileged user (not/never root!). If not, it's not my problem ;)
If running as root you should create an unprivileged user with the following commands:
adduser -m -s /bin/bash -G sudo "your_username"
passwd "your_username" [now enter your super-secure-password]

Now logout 'root' and login as your new user

Note: The following steps are meant to be executed as an unprivileged user!
Otherwise RVM will install itself as a multi-user-environment which will not work for this tutorial.

1. Install Additional Packages

These packages are necessary to compile fox-toolkit, fxscintilla and opengl which are essential for fxruby.
for pkg in bash curl git patch bzip2 build-essential openssl libreadline6 libreadline6-dev git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev libx11-dev libxcursor-dev libxext-dev libxrandr-dev libxft2-dev freeglut3-dev libjpeg-turbo8-dev libjpeg8-dev libjpeg-dev zlib1g-dev libbz2-dev libpng12-dev libtiff4-dev;
do
sudo apt-get -y install $pkg
done
# ftp://ftp.fox-toolkit.org/pub/fox-1.6.47.tar.gz
# Download and compile fox-toolkit
# version 1.6.44 works
# version 1.7.x is incompatible with fxruby
# http://www.fox-toolkit.org/
wget http://ftp.fox-toolkit.org/pub/fox-1.6.47.tar.gz
tar xzvf fox-1.6.47.tar.gz
cd fox-1.6.47
./configure
make
sudo make install
cd ..

# Download and compile fxscintilla
wget http://download.savannah.gnu.org/releases/fxscintilla/fxscintilla-2.28.0.tar.gz
tar xzvf fxscintilla-2.28.0.tar.gz
cd fxscintilla-2.28.0
./configure
make
sudo make install
cd ..


Now it's time to lay back and get a coffee ...

2. Install RVM

Installing RVM is very straight forward. More details can be found here.
znow@hotdog:~$curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
znow@hotdog:~$source "$HOME/.rvm/scripts/rvm"

3. Integrate RVM Into Gnome Terminal

Before we continue with installing Ruby we should make our bash running as a login-shell. If you want to learn more about how to integrate RVM into Gnome, I recommend this article.
So, first check "Run command as login shell" option under Terminal->Edit->Profile Preferences|<-title data-blogger-escaped-and="" data-blogger-escaped-command-="">

Next, we have to edit ~/.bash_profile to make it look like this:
source "$HOME/.profile"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

4. Install Ruby

In case you want to use WATOBO you should install Ruby 1.9.3. No lower version and no higher! Open a new terminal and type:
znow@hotdog:~$rvm install 1.9.3
Now it's time to lay back and get a 2nd coffee ....

Re-check your ruby path which should point into your home directory:
znow@hotdog:~$ which ruby
/home/znow/.rvm/rubies/ruby-1.9.3-p392/bin/ruby

5. Install FXRuby and more ...

Now everything should be fine and you can continue installing gems you like, like fxruby, opengl, ...
znow@hotdog:~$ gem install fxruby
Fetching: fxruby-1.6.26.gem (100%)
Building native extensions. This could take a while...
Successfully installed fxruby-1.6.26
1 gem installed
Installing ri documentation for fxruby-1.6.26...
Installing RDoc documentation for fxruby-1.6.26...
znow@hotdog:~$ ruby -e "require 'fox16'; puts Fox.fxversion"
1.6.47
znow@hotdog:~$

Installer

You can download the installer shell script [here]

[as]