pam_captcha, release 1.0
Posted Mon, 30 Jan 2006
I also put pam_captcha on one of my servers to see what happens. I use SSH keys so I'll never see the captcha stuff. I'm interested to see what kinds of brute force attempts get thwarted.
I also put pam_captcha on one of my servers to see what happens. I use SSH keys so I'll never see the captcha stuff. I'm interested to see what kinds of brute force attempts get thwarted.
Our defensive strategy this year was some trivial security through obscurity combined with some very clever hardening. Using FreeBSD on all of our machines, we ran all of our services on one machine leaving the remaining 3 machines for attacking and forensics.
All services ran inside a single jail. The creation of the jail was done mostly with rsync to copy the freebsd base system. Inside this jail, we ran sshd, ftpd (via inetd), sendmail, popd, and apache. The jail had several mechanisms to limit malicious user activity. These include pseudo-quotas, login.conf user limits, etc.
web_ip="10.10.102.97" mail_ip="10.10.102.143" ftp_ip="10.10.102.34" ssh_ip="10.10.102.178" # Redirect real-service ports first rdr inet proto tcp to $web_ip port 80 -> 192.168.1.1 port 80 rdr inet proto tcp to $mail_ip port 25 -> 192.168.1.1 port 25 rdr inet proto tcp to $mail_ip port 110 -> 192.168.1.1 port 110 rdr inet proto tcp to $ftp_ip port 21 -> 192.168.1.1 port 21 rdr inet proto tcp to $ftp_ip port 20 -> 192.168.1.1 port 20 # The REAL ssh "server" rdr inet proto tcp to $ssh_ip port 31975 -> 192.168.1.1 port 29 # Pretend everything else is ssh rdr inet proto tcp port 1:49152 -> 192.168.1.1 port 22 # Make everything pingable, too rdr inet proto icmp -> 192.168.1.1You'll notice the "real ssh server" is directed to 192.168.1.1 port 29. We'll cover sshd next and why this is important.
ListenAddress 0.0.0.0:22 ListenAddress 0.0.0.0:29
arpd -d 10.10.102.0/24So now anyone who tries to touch our network will get a response from any ip they hit. This is similar to a honeyd or labrea approach, but better. Labrea can successfully tarpit people who don't know how to tell real hosts from fake ones, but you can almost always easily determine labrea tarpitted (faked) hosts from real ones. Another solution might have involed honeyd, but I wanted a real, usable service. Since the only damage I felt anyone could incur would be from the shell, I wanted to keep users busy by baiting them with working ssh services that they simply didn't have real shells on.
Now, SPARSA's rules stated that no arp poisoning was allowed. I don't consider this arp poisoning because I could easily accomplish the same thing arpd supplied with this one-liner, and without true spoofing:
jot 253 1 | xapply -fv 'ifconfig em0 alias 10.102.1.%1 netmask 0xffffffff' -It's not spoofing if I actually have all of the IPs on the network, now is it?
PORT=`echo "$SSH_CONNECTION"|awk '{print $4}'`
trap - INT
if [ "$PORT" -eq 22 ]; then
sl -laF
cat /root/mario
sleep 3
else
/bin/tcsh -l
fi
This script was called 'happyshell' and each team's account had this shell. The
script looks at SSH_CONNECTION for the port they sshed into the machine with. If
it's 22 (the "fake" server), then they get some useless output printed to their
screen, and it quits. If they hit the real server, it gives them tcsh. Very
simple. If you want to know what '/root/mario' contained, check it out here:
mario ascii picture
If you attempted to login via ssh to any IP:PORT other than 10.10.102.178:31975 you would get a message that would annoy you instead of a shell. Perfect, but you could still write a script to attempt to login and find the real ssh server, so we needed something else to slow you down.
We initially thought a 10 second sleep delay would be sufficient, but as we discussed it further we realized we could ask the authenticating user questions to verify that they were human. The technical term for this kind of challenge-response authenticator is "captcha" - read about captchas on wikipedia.
I spent a few hours the weekend before the competition (last weekend) to write pam_captcha. There are currently 3 kinds of captchas. The first is a identifying a random string that's been run through figlet, turning it into text-ascii art. The second captcha is a simple math problem also run through figlet; users must solve this math problem to continue. The third captcha has no real practical uses, but for the context of the competition would be both annoying to users and hilarious for me. It involves users performing physical activities, such as stealing a competitor's hat, or singing a song. Verification was done by a human who then alerts the computer that this person is a human. I called this 3rd captcha "Dance Dance Authentication" or DDA.
I had to turn off DDA after the first 2 hours due to complaints. This was fine becuase I only wrote it for humor's sake. The other two captchas stayed enabled throughout the competition.
Outside of this competition, pam_captcha will prevent or atleast deter script kiddies from bruteforcing login attempts via ssh. So if you're interested in preventing this, then go ahead and use it. It works in Linux and FreeBSD.
During the 5-hour setup period of the competition, I installed the primary services on our system and finished some last minute testing before the attack-and-defend section began. 15 minutes before the end of the setup period, we were ready to go. 3 machines left to perform attacks and forensics, 1 to do services. So far so good, right?
Yep. Several teams attempted to find our ssh server and gave up after about 10 login attempts and moved on to easier targets (other teams). No one bothered attacking via web, ftp, or mail. Our series of tricks tied to our SSH server worked extremely well until around 6pm (1 hour left in the competition) everyone got their collective panties in a bunch and demanded that I stop being so tricksy. The rules for the competition did not cover what ports you had to run your services on, so naturally I protested. Finally, after about 20 minutes of hearing people bitch and moan, I updated the firewall rules to direct port 22 on the "real" ssh server to the actual ssh server (192.168.1.1:29, remember?). Only 3 (out of 6) teams attempted to login after that. Two teams attempted to fill fill the file system and failed. Another team attempted to starve CPU, but every team's default nice level was 19, making it only run when nothing else needed to do so.
The inode exhaustion attempts had a somewhat funny side-effect. The one-liner I used to do this was this:
while :; do a=$(($a+1)); touch $a $a$a $RANDOM $RANDOM$RANDOM $RANDOM$a; doneI just wanted to create lots and lots of files. I did this typically in my homedir or /tmp on another team's ssh server. After running for a significant amount of time, running ls in the directory became quite sluggish as it read all of the files. At one point, I had created well over 300000 files in /tmp. The team affected finally noticed this and tried to do "rm *" which inevitably failed with an error of "Too many arguments" - even attempting to do "rm 1*" failed due to too many arguments. Wonderful! Eventually they figured it out and ran 'find /tmp | xargs rm' - but this machine was also running X11 which had sockets in /tmp. They got blown away and X crashed. Whoops ;)
Beyond that, I ran multiple resource starvation attacks (that can be easily prevented) on several teams multiple times.
We insisted we be given back points for Nagios' false positives on our downtime, but we were turned away. Other teams complained about Nagios falsely reporting downtime and were awarded points back for false downtime. That's nice. It's good that the judges were fair to all teams.
No other teams were able to take down our services. Nagios, at random times, would determine that one (usually random) of our services were offline. Every time this happened, we verified all of our services and they were indeed online. Thusly, there was only about 60 seconds where any of our services were down during the entire competition. Other teams had critical failures during the competition and were also attacked and taken offline by other teams. Therefore, we had almost 100% availability, other teams were not so lucky. The only point in the competition where you can lose points is for downtime beyond 2 minutes, or so the rules state. You gain points by attacking others and partaking in the SPARSA challenge and the forensics challenge.
Long story short, we did OK with the forensics and OK on the sparsa challenge, but not great.
I'm not angry that we didn't win (or place, for that matter). I'm angry with the behavior of the members of SPARSA who made up random, unsubstantiated rules on the spot for no reason and applied them to some teams and not others. Many of them were entirely unprofessional and down-right rude and arrogant.
Dan, a friend of mine on another team, overheard several of the judges talking about my team and how they should just dock an arbitrary amount of points from us. What kind of crap is that? We paid $40 to attend this competition to get treated like this? I'm considering lobbying for a refund. We'll see. I'm extremely annoyed that there are student organizations seemingly bent around supporting their own arrogant members. If you're at RIT and are looking to join SPARSA, don't. Join CSH instead. We suck less.
At any rate, the competition itself was pretty fun if nothing else than for demonstrating pam_captcha and the better-than-labrea tarpitting-with-real-services tricks. I feel that we should've been given style points for unique solutions so hiding services and for pam_captcha. Style points weren't in the rules, but style should certainly not cause anger. Instead, The SPARSA judges just got angry. Feature? Hate the game, not the player.
Oh well... I'm done with student organizations in May (graduation!).
I'll put up a project page later.
Yay :)
document.getElementById() to look for elements
the way Prototype does. Bypassing that limitation, you can successfully query
XML documents and even subdocuments of HTML or XML. This is fantastic.
Today's magic was a demo I wrote to pull my rss feed via XMLHttpRequest (AJAX)
and very simply pull the data I wanted to use out of the XML document object
returned.
The gist of the magic of jQuery revolves around the $() function.
This function is generations ahead of what the Prototype $()
function provides.
The magic is here, in the XMLHttpRequest onreadystatechange function
// For each 'item' element in the RSS document, alert() out the title.
var entries = $("item",xml.responseXML).each(
function() {
var title = $(this).find("title").text();
alert("Title: " + title);
}
The actual demo is quite impressive, I think. I can query through a complex XML
document in only a few lines of code. Select the data you want, use it, go
about your life. So simple!
View the RSS-to-HTML jQuery Demo
pref("toolkit.defaultChromeURI",
"chrome://applicationName/content/startPage.xul");
I didn't want to write a full XUL application. I wanted to use my existing HTML/JavaScript-based web kiosk pages. So, what do I use?
pref("toolkit.defaultChromeURI",
"http://www.csh.rit.edu/~psionic/projects/kioskweb/demo/");
Start XULRunner, and a window pops up with my webpage in it. Fantastic!
I haven't had a chance to test XULRunner on the touchscreen system yet, but seeing as how it lacks much of the code that makes firefox slightly bulky I'm hoping it will startup and run much faster. We'll see soon!
If you're looking to write a web-based application that uses XUL or even simply HTML+JavaScript, give XULRunner a look.