Perl tip: URL Decode and Encode 
Here's a quick perl tip on how to URL Decode and Encode:

To encode a string to be placed in a URL:

$string =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;

To decode a URL-encoded string:

$string =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;


[ add comment ] ( 6113 views )   |  permalink
Bash Pitfalls 
Found this great Wiki on Bash Pitfalls today which should help avoid common bash scripting errors.

[ add comment ] ( 255 views )   |  permalink
Upgrading firmware on a Linksys WRT54GS to DD-WRT 
Recently I upgraded my old linksys WRT54GS from the Linksys suppled firmware to the spiffy DD-WRT linux-based distribution so I could more effectively troubleshoot problems with my pain-in-the-ass cable modem service. Since Linksys has gotten purchased by a certain networking giant, each subsequent hardware revision of the WRT54G/WRT54GS series has gotten smaller and smaller amounts of RAM and Flash. The most plausible reason for crippling these $40-$50 dollar routers is that with an alternate firmware like DD-WRT, suddenly these cheap boxes are capable of much greater functionality like Quality-of-Service (QoS) bandwidth management, policy routing, IPv6 support, wireless captive portal, login access via SSH/telnet, third party packages, and much more. In other words, they might be able to start cannibalizing the revenue stream from their more expensive big brothers.

Luckily, the router I had was WRT54GS revision v1.1 which has a whopping 32M of RAM and 8M of flash which can run the DD-WRT standard distribution. Make sure to very carefully check the supported devices list to make sure your router is supported before you start, so you don't brick your router!!

Before beginning, make sure to review the DD-WRT Installation Wiki.

Upgrading to the DD-WRT Standard distribution dd-wrt.v23_sp2_standard.zip
was a two step process. When you unzip the zipfile, pay special attention to the file labeled 'hwsupport.txt' as it may contain special instructions for your hardware. In my case it stated:

3.) Linksys WRT54G/GS (any version) flashing notes:
---------------------------------------------------
-For upgrading from the original Linksys firmware, please use the generic mini version (dd-wrt.vXX_mini_generic.bin) and flash
it from the web GUI interface. After this first flashing you can change to any other distribution, if you want.
-For flashing via the web GUI interface, always use the included 'generic' binaries. The other Linksys router specific binarie
s are only meant for tftp upgrades.

This meant I had to go back and download the Mini distribution dd-wrt.v23_sp2_mini.zip
from the website and flash that first. The flashing process was uneventful, brought up the web interface from the standard linksys distribution and selected the mini distribution above. Flashing took a minute or two, and then rebooted into the DD-WRT mini distribution. The default login is root with a password of admin.

Initially the web interface would not come up although I could ping the router which caused me some fear I had bricked it. However after disconnecting the power cable while holding the reset button (See also DD-WRT Reset and Reboot ) did the trick and I was able to bring up the web interface.

Then I was able to select the standard DD-WRT distribution and using the same web process to upgrade. After the last reboot I was able to login to my new more capable router!

I've been having some fun playing with SNMP, Macupd, rflow, SSH, the flash filesystem (jffs2), and other items which will be subject of future blog entries. Happy hacking!

[ add comment ] ( 294 views )   |  permalink
Brute force HTTP Basic authentication with authforce 
Authforce is a very fast tool for brute forcing HTTP Basic Authentication protected URLs. In HTTP Basic authentication the username and password is Base64 encoded and passed along with the HTTP headers from the client to the HTTP server. This means that the credentials are passed over the network in plaintext and is vulnerable to eavesdropping by an attacker. Despite this weakness, it is still quite widely used - for example access to the default Tomcat manager page is protected by HTTP Basic by default.

When a client requests a HTTP Basic-protected resource, the web server will challenge with a HTTP 401 Authorization Required (See www.w3.org's page for a listing of all HTTP codes) which causes a username/password dialog to pop up in your browser. Now you've identified the target URL for authforce to run against.

Authforce needs a list of usernames, a list of passwords, and target URL to work. Here's an example:

authforce --verbose --beep --logfile=aftest --username-file=users --password-file=words http://192.168.1.100/tmp

authforce will show you the current username and password being tried in realtime. If it gets a match you will see something like this:

match [goonda:mysecretpass]

Note that authforce will work against both http and https URLs, however you will need to add the --no-ssl-fail option if the site uses self-signed certificates. Happy Hacking!

[ add comment ] ( 165 views )   |  permalink
Setup an SSL tunnel with stunnel 3.x 
Stunnel is a very handy utility for wrapping virtually any service in SSL. In a pentesting perspective its especially handy if you want to use a tool which only speaks HTTP (e.g. a perl LWP script which you are too lazy to make speak SSL, or want to make manual HTTP requests adhoc ;). We can setup a tunnel to our target SSL webserver, and have it bind to a local port we can use for access. NOTE: This only applies to stunnel version 3.x, 4.x uses an stunnel.conf file instead of command line switches.

For example, if our target webserver is called example.foo.com, with a webserver running SSL on port 443, we would run the following command to bind to a local high port e.g. 10666. If you attempted to bind to a local port below 1024, you would have to run this command as root:

stunnel -d localhost:10666 -c -r example.foo.com:443

To confirm that its working, first check the log (usually /var/log/messages, but /var/log/daemon.log on my system).

Mar 7 20:20:32 localhost stunnel[22933]: Using 'example.foo.com.10666' as tcpwrapper service name
Mar 7 20:20:32 localhost stunnel[22933]: stunnel 3.26 on i486-pc-linux-gnu PTHREAD+LIBWRAP with OpenSSL 0.
9.8c 05 Sep 2006
Mar 7 20:20:32 localhost stunnel[22934]: FD_SETSIZE=1024, file ulimit=1024 -> 500 clients allowed

So now our stunnel daemon process is listening on localhost, port 10666, ready to service our requests! Lets try it out by doing a simple HEAD request on the target webserver:

user@host# nc localhost 10666
HEAD / HTTP/1.0

HTTP/1.1 403 Forbidden
Date: Sat, 08 Mar 2008 01:12:44 GMT
Server: Apache
Connection: close
Content-Type: text/html; charset=iso-8859-1

Excellent! I have also run password crackers like hydra through stunnel without problems, so it can take a beating. Happy Hacking!

[ add comment ] ( 275 views )   |  permalink

| 1 | 2 | 3 | Next> Last>>