Wednesday, August 24, 2011

Grokking CSVs Easier in STDOUT

#!/usr/bin/env ruby
require 'rainbow' # To make things a bit more readable
require 'csv' # using just split won't work cause of \n in some fields

if ARGV[0].nil?
 puts "#{$0} <csv_file>"
 exit
end
i = 0
headers = []
header_index = 0
CSV.foreach(ARGV[0], :quote_char => '"', :col_sep =>',', :row_sep =>:auto) do |line|
 line.each do |column|
   if i == 0
     headers.push(column)
   end
   if i % 2 == 0
     puts headers[header_index].upcase
     puts "#{column}\n"
   else
     puts headers[header_index].upcase.inverse
     puts "#{column}\n".inverse
   end
   header_index += 1
 end
 header_index = 0
 i += 1
end

Tuesday, August 2, 2011

Enabling Remote X11 Forwarding Over SSH Despite IPv6 Bug

Run ps -ef | grep X on your X client (the remote box) and your X server (in this case, you local machine in which you intend to have the GUI application displayed)

Your output SHOULD look very similar to this:
/usr/bin/X :0 vt07 -nolisten tcp

It is perfectly acceptable that the -nolisten tcp is enabled and running on both the X client and X server

/etc/ssh/ssh_config (Your local machine i.e. your ssh client)
Host *
ForwardAgent no
ForwardX11 yes
ForwardX11Trusted no

/etc/ssh/sshd_config (Your sshd server i.e. your remote ssh server)
X11Forwarding yes
X11DisplayOffset 10

Try running xclock.  At this point, I was getting:

Error: Can't find display

And running:

echo $DISPLAY

resulted in nothing.

If you experience similar issues, you've configured the options in /etc/ssh/ssh_config & /etc/ssh/sshd_config, and get the following error when authenticating with your ssh server (evident on sshd server by running tail -f /var/log/auth.log):

error: Failed to allocate internet-domain X11 display socket.

Then ensure the following is configured within /etc/ssh/sshd_config:

AddressFamily inet

Restart your sshd server:

/etc/init.d/sshd restart

Exit your shell by hitting CTRL+d

Re-authenticate:

ssh -X <user>@<host>

echo $DISPLAY

and you should see:

localhost:10.0

Run xlock and viola!  Awesomeness.  Cheers!

Monday, August 1, 2011

Converting IPv4 Addresses into Memory Addresses

This is helpful when you're writing your own Metasploit modules with custom shellcode:

#!/usr/bin/env ruby
# Enjoy ;)
ip = ARGV[0]
if ip.split(".").count == 4
  print "0x"
  ip.split(".").reverse.each do |octet|
    print "%02x" % octet.to_i
  end
  print "\n"
else
  puts "Invalid IPv4 Address"
end