(String | Fixnum).ordinalize method

January 5th, 2012

I’ve been including ActiveRecord for awhile simply to use a couple of it’s non-database functions so I decided it was time to write a couple simple snippets that I could use instead; saving my programs the dependency and memory overhead  of ActiveRecord.

The most useful, to those beyond myself, is probably the extending of the Ruby’s String and Fixnum classes to include ActiveRecord’s ‘ordinalize’ function. For those not familiar, it will take a String or Fixnum and return a string of the number in the following format:

1 => 1st, 2 => 2nd, 3 => 3rd, 10 => 10th, etc…

Example usage:

puts 5.ordinalize
=> 5th

For easy copy/paste, you can grab a gist of my code from my Github

Installing Ettercap 0.7.3 on OS X Lion

August 12th, 2011

The saga of my moving from OS X Snow Leopard to OS X Lion continued today as I was recompiling my myriad of MITM software packages for use on Lion. Almost everything, including my own custom software, went smoothly except Ettercap 0.7.3. I have documented my fix below for my future reference and to hopefully save someone else the four hours it took me to get everything rolling.

step 1: configure file fix.

Upon initial ./configure the following halts everything:

checking for library containing pthread_create... none required
checking whether gcc accepts -pthread... no
configure: WARNING: ***************************
configure: WARNING: * PTHREAD ARE REQUIRED !! *
configure: WARNING: ***************************

This was unexpected to say the least as my other apps didn’t seem to have any problems including pthreads. After a couple hours of wasting my life trying to figure out the problem I finally tracked it down to the Ettercap configure file itself. Simply swap out MACOSX for DARWIN on the following line (line # 28246):

ORIGINAL:

elif test "$OS" != "MACOSX" -a "$OS" != "WINDOWS"; then

FIXED

elif test "$OS" != "DARWIN" -a "$OS" != "WINDOWS"; then

step 2: libnet inclusion.

Earlier in the day I had to install libnet for one of my custom libraries, but you will also need it for Ettercap or you will get something similar to:

checking for libnet... no
configure: error: libnet >= 1.1.2.1 not found

To solve this, install libnet from http://sourceforge.net/projects/libnet-dev/ and the next time you run Ettercap’s configure file pass it the following option:

-with-libnet=/usr/local/

step 3: Seriously, another error?!? Bloody hell.

n file included from wdg.c:23:
./wdg.h:189: error: expected specifier-qualifier-list before ‘u_char’
./wdg.h:304: error: expected ‘)’ before ‘pair’
./wdg.h:305: error: expected declaration specifiers or ‘...’ before ‘u_char’
./wdg.h:312: error: expected ‘)’ before ‘pair’
wdg.c:81: error: expected ‘)’ before ‘pair’
wdg.c:82: error: expected declaration specifiers or ‘...’ before ‘u_char’
wdg.c:83: error: expected ‘)’ before ‘pair’


Okay, the problem here is that type ‘u_char’ is not defined in the standard C spec. On most systems there is a sys/types.h header located at /usr/include/sys/types.h. To instruct gcc to include it, pass the following to configure:

CFLAGS="-include /usr/include/sys/types.h"

step 4: A libiconv mess…

To avoid the following error during make:

Undefined symbols for architecture x86_64:
"_libiconv_open", referenced from:
_set_utf8_encoding in etterlog-ec_format.o
_utf8_format in etterlog-ec_format.o
"_libiconv_close", referenced from:
_set_utf8_encoding in etterlog-ec_format.o
_utf8_format in etterlog-ec_format.o
"_libiconv", referenced from:
_utf8_format in etterlog-ec_format.o
ld: symbol(s) not found for architecture x86_64

Install a fresh version of the iconv library to /usr/local/. Note that we are installing the 1.11 version not the latest 1.13.1 version because the 1.11 version is compatible with the iconv that ships with OS X Lion (as of the writing of this blog post on 08/12/2011). The quick and easy:

curl -O http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz
tar -zxvf libiconv-1.11.tar.gz cd libiconv-1.11
./configure
make
sudo make install

Additionally, we will need to tell gcc to link to our fresh version at /usr/lib/local/ and not the /usr/lib version that ships with OS X via:

CFLAGS="-lc /usr/local/lib/libiconv.2.dylib"

step 5: No ettercap GUI for me, please… I’ll admit it, I’m an old hacker.

I feel comfortable and in control when in terminal windows. Simply put, every GUI except the iPhone’s iOS I find overwhelming and confusing. I’m sure those who began using computers post-internet feel differently, but I’m a creation of the 80′s who has been living in prompts since the age of 4. I believe in GUI’s only if they actually make you more productive for the task, such as OS X’s Expose which is absolutely brilliant for swapping between terminal windows ;) I say that entire rant to give reason to why I did not figure out how to install the gtk+ libraries for the ettercap gui. To avoid the following:

checking for pkg-config... /usr/local/bin/pkg-config
checking for GTK_CFLAGS...
checking for GTK_LIBS...
configure: error: Package requirements
(gtk+-2.0 >= 2.0.0 pango >= 1.0
atk >= 1.0) were not met. Consider
adjusting the PKG_CONFIG_PATH environment
variable if you installed software in a
non-standard prefix.

Instruct configure to make for text mode only by using the following option:

-disable-gtk

6: libpcre (optional)  

If you have installed the pcre library and want to expand the functionality of ettercap, you will need to manually specify it’s location via configure option:

-with-libpcre=/usr/local/include

7: Finally, putting it all together.

You now should be able to compile without errors:

make clean
./configure LDFLAGS="$LDFLAGS -pthreads" \
-with-libnet=/usr/local/ -disable-gtk \
CFLAGS="-include /usr/include/sys/types.h -lc /usr/local/lib/libiconv.2.dylib" \
-with-libpcre=/usr/local/include
make
make check
sudo make install

8: Config reminder

Lastly, don’t forget that for SSL MITM on OS X you’ll need to run the following bash script beforehand using sudo:

#!/bin/sh
# redir_command_on:
if [ -a "/tmp/osx_ipfw_rules" ]; then
ipfw -q add `head -n 1 osx_ipfw_rules` fwd 127.0.0.1,$1 tcp from any to any $2 in via $3
else
ipfw add fwd 127.0.0.1,$1 tcp from any to any $2 in via $3 | cut -d " " -f 1 >> /tmp/osx_ipfw_rules
fi

and the following after you’re done using Ettercap:

#!/bin/sh
# redir_command_off
if [ -a "/tmp/osx_ipfw_rules" ]; then
ipfw -q delete `head -n 1 /tmp/osx_ipfw_rules`
rm -f /tmp/osx_ipfw_rules
fi

Both of these scripts and more important details can be found in the Ethercap config file at:

/usr/local/etc/etter.conf

Hopefully this can save someone else from going through the 28000+ lines of the configuration file, and don’t forget it’s always bad karma to use tools against anyone who helped you install them. Happy Janus attacking :)

—————–
now playing: Antonio Pinto – Lord of War

Installing nginx on OS X Lion

August 4th, 2011

If you try to install nginx on OS X Lion you’ll likely end up with the following errors during configuration or makefile:

cc1: warnings being treated as errors
src/core/ngx_crypt.c: In function ‘ngx_crypt_apr1’:
src/core/ngx_crypt.c:76: warning: ‘MD5_Init’ is deprecated (declared
at /usr/include/openssl/md5.h:113)
src/core/ngx_crypt.c:77: warning: ‘MD5_Update’ is deprecated
(declared at /usr/include/openssl/md5.h:114)
....

For some god-forsaken reason, Apple decided to depreciate many of the more basic openssl functions in Xcode’s version of GCC. Rather than dwell on why they did not stop to consider all of the software this is going to break, you can simply solve the problem by passing the following option to configure:

--with-cc-opt="-Wno-deprecated-declarations"

For example:

make clean

./configure --with-cc-opt="-Wno-deprecated-declarations" --with-http_ssl_module

make

sudo make install

( Additionally, you may need to add

/usr/local/nginx/sbin 

to your $PATH in ~/.profile )

—————–
now playing: Faithless – God is a DJ

Mac OS X service to toggle hidden file visibility in Finder

April 9th, 2011

(for the impatient my github code link)

I recently became fed up with having to jump into a shell every time I wanted to toggle whether hidden files were visible or not in Mac OS X Finder. So today I sat down and made a Mac OS X service for Finder that toggles the Finder bundle’s setting including a dialog that pops up confirming you want to run the service.

=== Installation ===

Download the code from my github account

Install as a Mac OS X service by moving the downloaded “Toggle Hidden File Visibility.workflow” folder to:

[your home directory]/Library/Services/Toggle Hidden File Visibility.workflow

NOTE: Remember a .workflow file looks like a folder on github, but Mac OS X treats it as a bundled file.

==== Usage ====

When in a Finder window, go to the top menu and select:

Finder => Services => Toggle Hidden File Visibility

NOTE: If you’re in a ‘Open file’ dialog you will need to use the following keyboard shortcut instead (it’s built into OS X):

Command + Shift + .