Archive for March, 2010

31
Mar

Looking Into “Obfuscated PuTTy”

I did a diff between the files in obfuscated-openssh versus those in it’s daddy openssh-5.2p1 and found that once you get past the ssh_config options and a few others, it boils down to a few functions that could be easily (???) hacked into PuTTy.

So I just might give it a try.

The problem is, I have a 13 year old Windows C compiler (Microsoft VC++ 5.0, which I paid $200 for way back in 1997) and it can’t handle the source code of the newer PuTTy versions, so I’m sort of stuck with hacking away at PuTTy 0.57 (the current version is 0.60).

I’m torn between calling it “PoTTy” (“o” for “obfuscated”, of course) or “PuTZy” (“Z” for the command line option for obfuscation in th *ix version).

“PoTTy” has a certain appeal, but I like “PuTZy” better.

30
Mar

obfuscated-openssh In Production

Today I took down my old ssh server and replaced it with my oossh server.  The payoff is shown below.  It’s the end of an era.  This is the very last of these alerts anyone is ever going to see on any IPS/IDS between me and HinkyNet…

This is going to work out nicely.

29
Mar

Trouble In Proxy List Land

I ran across this thread today and I had to chuckle a little bit.

In it, one proxy lister whines about another proxy lister ripping off his proxy lists.

Well, get over it.

They all do it.

I do it.

And I admit I do it!  Always have, always will.

Every proxy list everywhere has all the same (bad) information in it.  The problem is, and always has been, finding the working proxies buried inside all these worthless, copy-catted proxy lists.

29
Mar

obfuscated-openssh Proxy FIX

Sorry, but I don’t know how to make patch/diff files so I’m going to walk you through it. It’s very simple.

Copy this code…

if(options.obfuscate_handshake) {
   if(options.obfuscate_keyword)
      obfuscate_set_keyword(options.obfuscate_keyword);
packet_enable_obfuscation();
}

Now, edit sshconnect.c and search for the comment “Indicate OK return” (without the quotes). This will be in the ssh_proxy_connect function. Paste the code directly above this comment, save, close, and build.

That’s it! He just forgot to put the obfuscation check in that function. If you look at the ssh_connect function, this same code is right at the end. I imagine he never even tested it through a proxy. Why bother if you can just “get out” on port 22 (or whatever)? Only losers use proxies, right?.

I’d write the author and let him know the problem, but he seems like a busy guy and it’s been my experience that when people get an e-mail from some clown named “Hinky Dink”, they usually delete it.

Wouldn’t you?

29
Mar

obfuscated-openssh BUGZ!!!!

Just my luck.

I spent the last four hours hunting down a bug in obfuscated-openssh that prevented it from working properly WITH PROXIES!!!!

But since I’m a Fucking Genius I nailed it.  And I wouldn’t call it a “bug” per se.  It’s more of an omission on the author’s part.  An oopsie, so to speak.

I will post the fix after I’ve done some more testing and when I can get some free time.

28
Mar

Not A Clear Bit In The Bunch

For testing I installed oossh on my Sony Vaio CentOS 5.4 laptop (sorry, neither Debian nor Ubuntu would run on this damned thing without hanging – some sort of funky ACPI issue that CentOS rolls right over).  I decided to replace the distro version of ssh completely and run oossh in its place.  Not a bad decision.  Compiled correctly, it’s a drag’n'drop replacement.

I put an ObfuscatedPort on TCP 4144 and tried connecting from Cygwin, with Wireshark running (on Windows) to capture everything.  Looking at the capture, it worked exactly as advertised.

Very, very nice.

This is the beginning of a beautiful relationship.

28
Mar

oossh Deployment

I have taken to calling obfusctaed-openssh “oossh” for short, mostly because I’ve been installing it in parallel with the default distribution in /usr/local/oossh.  So far I’ve completed a pair of Cygwin installs and four Linux installs.

One Linux install was particularly vexing.  At work I have a nine year old, very broken Debian “sarge” box – kernel 2.4.26 with iptables 1.3.3 – that continues to crank despite all odds.  Currently it has an uptime of 346 days – the longest uptime of any Linux box I run.  It has such a stellar record because it’s a Genuine Incredible Pain In The Ass to reboot (both turn-of-the-century IDE drives are throwing S.M.A.R.T. errors – “Press F1 to continue” – and almost everything in /etc/init.d dies and has to be started manually after a boot).

This thing has been a thorn in my side for five years.  It was originally authorized by my manager (and CISO) in 2001.  That particular Bozo got his ass fired in 2004 and every subsequent manager has shit his or her pants over the very existence of this box since then (until recently we were an extremely Windows-centric shop).  Unfortunately for them, this box performs Mission Critical Monitoring – designed and implemented by Yours Truly, thank you – that no one else has been able (or cares) to duplicate.  So it has been grudgingly allowed to exist for all these years.  Whenever I ask to get it replaced it inevitably causes a Management Shitstorm, so I’ve learned to keep my mouth shut about it.

They don’t care that it’s been dying for five years.  They want it to die.  I don’t even pretend to understand this attitude (truthfully, after all this time I do have a replacement ready to go when sarge finally dies).

And I’ve tried to kill it.  I broke “apt” during a disastrous  upgrade in 2005.  It hasn’t been patched since, but I’ve managed to keep it off the radar of no less than three vulnerability assessments in the last five years.  The box is basically invisible except for the service it performs.

So it was no surprise oossh balked at sarge’s ancient version of OpenSSL (0.9.8b) when I tried to install it.  I downloaded 0.9.8n – all of four days old as of today - configured, typed ‘make’, and held my breath.

And the old dog did not let me down.  I pointed oossh at the shiny new SSL install and it compiled happily.

That is what I love about Linux (although it’s basically a love/hate relationship).  You just can’t keep it down.

28
Mar

obfuscated-openssh

If you’re in any environment where packet inspection is going on, your ssh sessions are 99.9% secure. That leftover 0.1% can be a problem. It’s the initial ssh handshake between your client and your server, sent over the wire in screaming clear text. Even the most brain-dead IDS can pick it up and out you to the Network Nazis (I know because in real life I am a Network Nazi).

What you need is obfuscated-openssh, a modified version of OpenSSH 5.2  The current version of OpenSSH as of this writing is 5.4, but I haven’t found any issues with this older version.  Luckily OpenSSH.org doesn’t report any security issues, but as we all know that could change tomorrow.

Plus, the obfuscation code itself could be insecure or buggy, so caveat haxor.

Get (git) it.  You need it.  If you don’t need it now, you will need it in the future.  The Network Nazis are watching.

Before you install it, make backup copies of all the keys and configuration files in /etc/ssh, just in case.

Configure (you may need the ‘–with-pam’ option to make it work exactly like your distro’s default version of OpenSSH) and run ‘make install’.  Then restart sshd.  At your leisure read the docs, decide which ports you want to use for obfuscation, and make arrangements (USB thumb drive, whatever) to get the code into the clients you need to protect.

Your client is Windows?  PuTTy’s not going to hack it.

Got Cygwin?  You’re in luck!  Both the client and server compile under Cygwin 1.71 if you have all the development prerequisites (I had to remove the ‘–with-pam’ option but after that it compiled on the first shot).  It compiles so well I wouldn’t be surprised if there isn’t a Cyqwin package for it already, but I haven’t checked.

I plan on using this everywhere, with a single non-obfuscated port for emergencies.

I’ll let you know how it pans out.  I’ve been looking for something like this for a long time.

27
Mar

Changing The SSH Port Without Changing It

For years, on security forums and mailing lists, if you ever dared to suggest changing SSH’s default port (TCP 22) the “security by obscurity” crowd would come out of the woodwork and nail your ass to the Cross of Righteousness for having the unmitigated gall to even dare utter such heretical nonsense.

Unfortunately for these dogmatic True Believers, changing the ssh daemon’s default listening port is such an incredibly effective method for avoiding ssh scans and brute force password attacks that it’s starting to show up in HOWTO security articles as a method for hardening your system.

For example, see this article at Linux Magazine.

But the Port 22 Crowd will not leave well enough alone.  Although they haven’t abandoned the “security by obscurity” mantra completely, they’re now using the following argument with increasing frequency:

NEVER CHANGE YOUR SSH PORT! If an exploit comes out that can crash SSH locally, a local unprivileged user on your system could crash SSH and start their own daemon on the SSH port > 1024 and capture your usernames and passwords. If you want SSH on a different port, do this with firewall rules.

Note that ALL CAPS is required when raising this alarm.

Also note that if you require users to connect with SSH in the first place, it’s not going to do them a helluva lot of good to crash SSH.  If you have users who actually sit down at the keyboard of the physical system, that’s another problem entirely.  Why bother with crashing SSH when they can slip a bootable CD into the tray and bounce the box?

And of course if you choose a port other than 22 but less than 1024 you can avoid this issue completely.

However, “changing the port with firewall rules” struck me as a novel idea (maybe I’m just stupid but it never occurred to me before) and set me to wondering how you would do such a thing, since I’ve always taking the easy way out by changing or adding ports in sshd_config.

So I sat down with iptables and experimented a bit.  I came up with the following method.  If everything you have is behind NAT, the problem can be reduced to simple port forwarding.  If not, there are a few hoops you need to jump through.  Be advised the iptables rules presented below assume you have a blank set of rules.  Just copying and running them against an existing set of rules probably won’t work.

First, set SSHD back to the default port 22.  Next, figure out what port or ports you want to do SSH over.  We’re going to use 44, 88, and 8188 here.

Now we take care of the Hypothetical Evil Unprivileged User by not accepting anything over those ports in the first place.  This is only effective for port 8188 but we’ll do all three ports for the sake of completeness:

#~iptables -t filter -A INPUT -p tcp -m multiport --dports 44,88,8188 -j REJECT --reject-with tcp-reset

Then, pick a number between 1 and 4294967295.  This will be the value of the iptables “mark” we use for ssh.  I’ll use 0×2200 (8704), just because it’s ssh-ish, but any positive integer in that range will do.  We’re going to tell iptables to reject anything without this mark coming into port 22.

#~iptables -t filter -A INPUT -p tcp -m tcp --dport 22 -m connmark ! --mark 0×2200 -j REJECT --reject-with tcp-reset

I would prefer to DROP these packets rather than REJECT them, but more on that later.

Now we’ll tell iptables what ports we will accept for ssh.

#~iptables -t filter -A FORWARD -p tcp -m multiport --dports 44,88,8188 -j ACCEPT

In the “mangle” table we slap our mark on these packets.

#~iptables -t mangle -A PREROUTING -p tcp -m multiport --dports 44,88,8188 -j CONNMARK --set-mark 0×2200

Finally, in the “nat” table we tell iptables to send the marked packets back to port 22.

#~iptables -t nat -A PREROUTING -p tcp -m multiport --dports 44,88,8188 -j REDIRECT --to-ports 22

The packets go back to the INPUT rule and, since they’re marked correctly, are sent to the SSHD process listening on port 22.

We have done exactly what was recommended, i.e. we have indeed changed the default ssh port with firewall rules alone (and without NAT).  And yet, ssh still listens on port 22!

I must admit this appeals to me on a number of levels, not the least of which is that it has all the hallmarks of a slick little hack.  Secondly, it definitely takes a load off of the ssh daemon since it’s listening on one port instead of three (in reality I have ssh listening on seven ports).

However, this is done at the expense of complexity, which has yet another group of True Believers who are fond of chanting “COMPLEXITY IS THE ENEMY OF SECURITY” at the slightest provocation.  This is another religion I have never bought into (it may be the same group since increasing complexity generally tends to increase obscurity).

Well, fuck them, you can’t please everyone.

Besides, I use the most bizarre, complex combination of port forwarding and routing you’d ever want to see.  Most days I have a hard time understanding it myself.  It keeps me sharp.

I am almost 100% certain this wouldn’t please a “real” firewall administrator.  They’re mostly overpaid Certified Cisco Clowns anyway.  It would never even occur to them to actually use iptables.

But what we have done in essence is put all our trust in iptables working “just right”.  And we’re betting the next time there’s an update to the netfilter core code (or the kernel) everything will still work.

I’ve been around iptables/netfilter far too long to ever bet on that.  Sorry, fellas, “once bitten, twice shy” and all that.

Then there’s the TCP reset thing.  Can it be bypassed?  Web filtering appliances that use span ports and two-way TCP resets work fine when everyone “plays by the rules of TCP/IP” (actual statement from Web filter appliance vendor Sophos), but the Bad Guys don’t usually play by the rules.

The alternative, DROP-ing the packet, lets anyone scanning our system with tools like nmap know with absolute certainty that SSHD is listening on port 22 since it will show up as “filtered”.  This makes TCP resets the lesser of two evils, but it’s still evil.

In the end analysis, isn’t sending a reset from an “open” port just another instance of “security by obscurity”?

Not that I care, that was a purely rhetorical question.

And what about attacks against iptables connection marking (CONNMARK) itself?  Do they even exist?  Am I opening myself up to an unknown exploit vector? Do I have to take additional measures to avoid spoofing or brute forcing or some other method (fragmented/crafted packets, maybe) to get around my firewall rules?

Even though we followed this fellow’s advice, there are too many open questions and it appears that just changing the port in sshd_config is still a simple and effective countermeasure.  It’s worked for me for over ten years.  I have escaped all 0day SSHD vulnerabilities for over a decade and no one ever tries to brute force passwords on my box.  It doesn’t happen because port 22 isn’t open.

Simple.  Effective.

duh!

So I feel compelled to shout out my own advice:

ALWAYS CHANGE YOUR SSH PORT!!!

27
Mar

I Hate WordPress/Chrome/GoDaddy

I haven’t figured out which one it is yet, so I figure I might as well hate them all equally.

I just spent the last two hours putting the finishing touches on a masterful look at ssh security, hit “Publish”, and was greeted with a blank white page.

I went back into WP and found my masterpiece hadn’t been saved.  And of course, hitting the “back” button did nothing.  Maybe I should be pissed at Chrome.  Whatever the fuck happened, apparently I was typing into a black hole.

Never trust this pile of shit.  Before hitting that “Publish” button, copy everything into an application you can trust, like FUCKING NOTEPAD, and make a backup.

UPDATE: A REASON TO HATE WORDPRESS

I dunno, maybe it’s this brain-dead theme.

Anyway, I discovered that you can’t use a double dash (--) here.  You have to use the html code “--”.

Who knew?

Fine.  I can handle that.

However, when you re-edit the page, or simply switch from “HTML” edit mode to “Visual” edit mode they turn back into “real” double dashes and you have to re-edit the page and put the html code back in.

FWIW, I took my SSH dissertation and copied it to my BlogSpot blog (from my FUCKING NOTEPAD BACKUP) and the double-dash problem wasn’t an issue. The side-scrolling boxes were too narrow (vertically) but that was easily fixed.

Score one for BlogSpot.

UPDATE: SPOKE TOO SOON!

The side-scrollers were all messed up in Firefox on BlogSpot, but I fixed that, too. Then I discovered that they were never too narrow in the first place. There was a line break that both IE and Chrome just ignored.