Belkin? Rtkit?

While attempting to remotely debug a linux machine today, I was first encountering a strange problem. Any process that took more than about 1/2 second to complete, would freeze. top, ps, lsmod, tail -f, the list goes on. For example, trying to run dmesg and display it’s output would freeze, but dmesg into a file, and it would complete!

After much digging, I eventually found that rtkit (rtkit-daemon) is constantly trying to make pulseaudio operate at realtime. In reality, we don’t need our audio to operate in realtime as most modern computers can keep up with video playback just fine. For the few people we actually want near real time audio (say, people recording multitrack stuff), then they can enable it themselves. Disabling rtkit (actually, uninstalling it as it appears to be started in dbus stuff), seems to have solved that problem.

The next problem was a strange DNS response. A dns request through the Belkin modem, to this server (purewhite.id.au) would return 10.45.41.175 instead of 175.41.45.10. I know what reverse DNS is, but this is reverse IP! Belkin is returning the ip in reverse!! (Or backwards if you desire). A quick check reveals that this relatively new modem, hasn’t got any new firmware for it (and it’s firmware is over 1 year old). Apparently, someone else had this problem and belkin told them to just hard code the ip’s in your hosts file for the hosts that are being returned wrong! I believe it was also a Belkin modem that would return strange results when you did an AAAA request (ipv6).
So if you have a Belkin, maybe force your computer to use your ISP’s DNS servers directly, rather than the routers. (Or take it back to the shop, because after all, it is faulty)

Nginx, PHP-FPM, WordPress, Super Cache

So recently I’ve been exploring the alternative world of Nginx instead of Apache, and PHP-FPM instead of mod_php. There are plenty of tutorials on the net for getting all of this setup, however not that many are up to date anymore for the Super Cache stuff. Hopefully what I present here will be a more up to date config, that is also mostly secure compare to a good number of ones on the net (to do with passing non PHP files to the php interpreter).

Firstly, my Nginx config for this very blog.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server {
  server_name www.tim.purewhite.id.au;
  rewrite ^/(.*) http://tim.purewhite.id.au/$1 permanent;
}
 
server {
	server_name tim.purewhite.id.au static.tim.purewhite.id.au;
	root /home/tim/domains/tim.purewhite.id.au/public_html;
 
	access_log /var/log/nginx/tim.purewhite.id.au_access_log;
	access_log  /var/log/nginx/default.access.log host_combined;
	#access_log  /var/log/nginx/uri.log host_combined_uri;
	error_log /var/log/nginx/tim.purewhite.id.au_error_log;
 
	index index.php;
 
	location / {
 
		if ($http_cookie ~ "comment_author_|wordpress|wp-postpass_") {
			rewrite ^/(.*) /loggedin$1 last;
		}
		try_files $uri
		/wordpress/wp-content/cache/supercache/$http_host/$uri/index.html
		$uri/
		 /index.php;
	}
 
	location /loggedin {
		internal;
		rewrite ^/loggedin(.*) /$1 break;
		try_files $uri $uri/ /index.php;
	}
 
 
	location ^~ /code {
	        proxy_set_header Host $host;
	        proxy_set_header X-Forwarded-Server $host;
	        proxy_set_header X-Forwarded-Host $host;
	        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:8080/code/;
	}
 
	location ~* \.(ico|css|js|gif|jpe?g|png)$ {
		expires 1w;
		break;
	}
 
 
 
	fastcgi_intercept_errors off;
 
	location ~ \.php {
		try_files $uri =404;
		include fastcgi_params;
		fastcgi_pass   127.0.0.1:9002;
	}
 
	include drop;
}

The first thing to notice is line 1-4. This simply redirects everyone from www.tim.purewhite.id.au to tim.purewhite.id.au. Simple as that.

Next we define the server and the root document path. Still very standard. Then we define access logs, for various reason I’m logging to more than one place, but that’ll change once everything is finished.

Line 15 is boring, we just define the “index index.php” so that if you access a directory it will load index.php or give you a 404 (which it won’t because of things further down).

Now for the fun. Lines 19-21. These catch a logged in user and send them on an internal redirect down to lines 28-32. This is so we don’t serve cached content to logged in users. That little snippit is thanks to a post at http://permalink.gmane.org/gmane.comp.web.nginx.english/15664.

However, there was a problem in the rest of the code. Thanks to a post at http://wordpress.org/support/topic/lack-of-nginx-support-from-wp-super-cache I realised we needed to test if the cache was being used or not. So I added the extra logging and discovered it wasn’t. I quickly worked out what the problem was. The code at lines 22 – 25 had the middle 2 lines swapped around. So “$uri/” was before the supercache line. What this mean was that it would try if the $uri was a directory, and to load a directory it would try index.php (due to the index line) and so would end up loading wordpress through index.php. However, if we try the supercache line first, we find the cache file and so don’t need to load indexes.

And just like that, magic, it works! We use supercache files for normal users, and if a cache file doesn’t exist, we load wordpress like normal!

I’m also looking at how we run Nginx and PHP-FPM. I have heard of a few ways, one being that root runs a Nginx as user nginx or nobody, and each user runs their own Nginx which we proxy to from the main one. (And users run their own PHP-FPM as well). This sounds like a lot of work, very complicated, but yes, it gives you absolute security as only the user can access his web docs and scripts, and everything runs as that user. No one else’s php process can load your config file to discover your database passwords.

Another way of running it is with Nginx as a nginx/nobody/www-data user, and each user run their own php-fpm but give the nginx/nobody/www-data user read only access to the web directory. If done correctly, this can actually be very secure. First, (as root) you chgrp all the files and directories in the users doc root (htdocs, www, public_html etc) to the user nginx will run as. Ideally, you also only allow them read access (so `chmod g+rX,g-w -R public_html` will give them access to read, but not write). You then set the gid bit on the directory; `chmod g+s public_html` (and do this for any directories that already exist underneath). Now any files the user creates underneath the public_html dir will be readable to the nginx user, so nginx can serve static files. Now running php-fpm as each user (I use php-fpm with a pool per user), the php process can read all the files that user can, so only the users own php process can read their config files with the password in it! And it also means that files you upload (i.e. wordpress media files) will be owned by the user, not by www-data or what ever the web user is. This is SO much better than Apache and mod_php, and easier than suExec with mod_php.

Once I have more of my domains moved to Nginx, I’ll do a report on memory and cpu usage.

Munin cgi graph timing out

A problem that has given lots of people problems, caused me issues yesterday. I have munin using munin-cgi-graph to create the graphs on demand due to me not often viewing the graphs. A few days ago I had a server issue that caused apache to lock up (I think a process ran away with my RAM which caused swapping and apache to lock up.) Once I apache running again, I wanted to check the munin graphs to see what the system looked like during the lockup (which killed a number of processes due to out of memory conditions). However, the graphs wouldn’t generate and the cgi was timing out without sending any data.

Timeout waiting for output from CGI script /usr/lib/cgi-bin/munin-cgi-graph
Premature end of script headers: munin-cgi-graph

I’m not alone ether. http://wiki.kartbuilding.net/index.php/Further_issues_upgrading_to_Lenny#munin_with_cgi and http://forum.linode.com/viewtopic.php?t=5171%3E both had issues. More googling still didn’t find an answer so I tried to debug the perl cgi. After using CPAN to get Devel:Trace installed, I discovered the cgi was sitting waiting for a semaphore flag that it uses to ensure no more than a certain number of munin-graphs are running at once. This is great, except when a crash has caused this semaphore to be stuck at the maximum so no more munin-graph processes get started ever!

There are 2 solutions. The first is simple, reboot. The second is also simple, clear the semaphore flags manually. ipcs is the command to show the flags and ipcrm is the command for removing the semaphores. Check the man pages for information on the correct syntax.

Day 13

I think today is Day 13.

So finally I’ve had a chance to sit down and nut this out. First things first, getting hello world to run on the iPhone. Finally I worked out how to self sign a certificate, and get Xcode to build it, then using a custom script I found on the net, sign the code so the iPhone will run it. Yay! Hello World runs on the iPhone!

Next step. Get a GPS app running on the iPhone. After following a pretty good tutorial from http://www.vellios.com/2010/08/16/core-location-gps-tutorial/ I finally got a GPS test app running. (After making some changes so it would run on iOS 3.1). However, this is the end of the good news. So far, as I suspected, the iPhone 3GS isn’t performing well on the GPS. Accuracy of 1km isn’t good enough, that can be achieved with just network location! We need down to about 10m. I’m thinking maybe I will need to upgrade to a newer iOS to see if it’s an issue with the hardware or the software. However I want this app to run on iOS 3.1, so am hesitant to do any upgrades.

The last of the good news is that the Objective-C is starting to make some sense to me, and I’ll now work on learning the major differences, and some more subtle ones, between Objective-C, C++ and C.

Day 6

So not much has happened over the weekend due to it being very busy. Today the mini-DVI to HDMI adapter arrived, so I could finally “dock” the Macbook at my desk. After “docking” it with my monitor, keyboard and mouse, it suddenly feels less like a laptop and more like a desktop! More screen realestate is a big bonus. But being able to just pick it up, pull out a few cables and take it with me, tether it to my mobile via wifi and work on the go, just makes such a difference to having a separate desktop and laptop!

As I already used a password manager under Linux, I wanted an application that was compatible with my existing password database. Thankfully, Password Gorilla runs on OS X, and all the other platforms, and reads the same password database as pwsafe does. So while I was out today, I finally migrated a number of machine passwords into a secure “safe”. The GUI is rather nice on the Mac, so I may considering using it under Linux too.

I’ve also installed Qumana which will allow me to blog without using a browser. This is something I did many moons ago, and so thought I’d try it again for this Project as it assists in making me use the Mac for the whole time, rather than using interfaces/apps/things that I am already comfortable with.

As I have a few uni assignments due this week, I probably won’t spend much time working on the project. And unfortunately, at least for one of the assignments, I will have to use my Linux machine to complete it due to some tools that aren’t available for Mac. I have contemplated installing Linux on the Mac, but for now figure that the time spent doing that is better spent on the assignments.

Interestingly, while setting in a shopping centre working today, some random walked past and said something like “Mac’s are nice aren’t they?” So for all those who want people to stop and talk to you, get a Mac!

I think I have gotten this Mac to the point that it’s now very usable for me. I’ve installed enough apps to get me going, and I’m forcing myself to learn all the Mac shortcuts. Now I’ll use it for all my Assignments this week as much as possible, and I think by the end of the week, I’ll probably be using my Linux machine via VNC on my Mac!

Powered by Qumana

Day 3

I’ve decided to blog this journey of learning and challenge. I am developing a mobile app, initially for iOS and eventually for Android. I have given myself an initial 60 days to get it done, 60 days from getting the equipment.

Being an iOS app, I required an Apple Mac computer to run the required development tools. Tuesday afternoon an iPhone 3GS and a MacBook arrived, curtsey of a friend of Jun’s. First thing I needed to do was download the Lion update, so I could run XCode 4.1. This started Tuesday evening and was finished by Wednesday morning (Day 1). I then prepared a USB Drive to boot the installer from, and went and purchased a new laptop HDD to upgrade the MacBook. By lunch time I’d fitted the new 500Gb HDD and the OS X Lion install was finished. Now started the 6-8hr download of XCode. Meanwhile I spent some time getting aquainted with this MacBook and OS X. No, I’m not converted like some people have been asking, however it probably will be my main computer for the next 60 odd days.

Yesterday (day 2) I wrote a Hello World app in XCode for iOS. It was copied straight from a tutorial on the net, and I quickly discovered that Apple wants $99 from me to be able to even test it on my iPhone! Come on Apple, you already get the money for the MacBook, the iPhone, and now you want more money just so we can test apps on our OWN devices!?!? Eventually we’ll need to fork out this money so we can sign our apps and put them on the App Store. For now though, I think I’ll just jailbreak for testing purposes.
I’ve continued getting acquainted with the MacBook. It now runs Firefox and Thunderbird, iCal is 2 way syncing my calendar. Clementine has become my music player (iTunes, no thanks), LibreOffice is installed. TextWrangler may become my other code editor if it is good enough. Dropbox is setup for syncing between my MacBook and certain folders on my main computer. So far, it’s been nice using this computer, however it’s certainly not better than similar hardware running Linux. For a start, it took me a long time to get network shares with our NAS working well, even though it supports AFP. Eventually it was easier to just setup NFS. I’m getting used to all the keyboard shortcuts, which once learned certainly speed up some navigation. Annoyingly, there have been some things where a keyboard doesn’t work and you have to use a mouse.

Regarding code, it looks like I’ll probably use Git for the SCM as its built in to XCode.

Thats all for Day 3 so far. I need to get some uni work done and we have a busy weekend. I look forward to next week when I’ll have to make this iPhone run my apps!

Gmail account hacked :(

For someone that prides himself on security, it is rather embarrassing to get hacked. I currently don’t know how they got in, or exactly what they have done. I have changed my passwords and security questions though.

So far, I know that my account was accessed from Poland (194.181.62.13) with last access at 8:49 am today. It only appears to have been accessed via a browser, and there don’t seem to be any extra filters (forwarding) setup. I do know that it appears everyone in my address book has been sent a link, although the link I can see that was sent (thanks to a bounce back) doesn’t appear to work. They also deleted everything from my sent box and trash, which is probably what annoys me the most. I don’t know if anything else has been deleted.

The most likely method they got in by was from an attack on another site, that revealed my password from when I used the same password in more than one place. As I no longer do this, I’ve been slowly changing my passwords to all be unique, however I should have changed my gmail one along time ago.

So 2 morals to this story. Even security conscience people can get hacked. And backup your data from the cloud if you wish to avoid loosing anything. I’m now in the process of setting up version controlled backups of my gmail data.

Google+ (Google’s Social Network)

By now you should have heard about Google+. You may have some idea of what it is, or you may have none, so hopefully I can answer some of your questions and help you get started.

Firstly, Google+ is Google’s latest entry into social networking. Already it looks much better than Buzz or Wave. What I like about it already is that the interface is clean and simple, and most importantly it is very easy to control your privacy settings. Now Facebook does have a similar feature, but it is extremely difficult to use.

Circles. You simple assign your “friends” to different circles, they can be in more than one. Then, you can share a post/photo/video etc with different circles, individual people, or the public. (There is also an extended circles which I believe shares it with people in your circles, and people in their circles). Want to let the world know about your new baby, simply post it public! (Like twitter). Want to post how you are having a dodgy day but only want your friends to know, and not your boss, just post it to your friends circle and make sure you boss is in your work circle. Want to share some good news with family and few close friends, post it to your family circle and then add the extra friends in as well!
Circles make it very simple to control who see’s what on your Google+ profile. Given the security scares of facebook stalkers and the like, it’s good to know you have total control over who see’s what.

Currently there are no Google+ games or apps. However for me that’s a bonus. I’m sick of all these status updates of “I just completed level 235 of bubble popping game….” and lots of other meaningless things like that. I don’t mind people playing games, but I don’t want to hear about it! What Google+ offers you out of the box though, is an amazing tool for social network communications that will allow you to easily keep in contact with people from all areas of your life, without getting cluttered down in the mechanisms of the communications. Huddles allow you to create a group of people for discussing something, like a group assignment, complete with group video chat (which arrived before Facebook announce the Skype Video partnership).

I’m hoping that you have read this far and are at least interested in trying Google+. For many people, until all your friends are there, you aren’t going to move. In fact, unless you are sick of the bloat of facebook, you probably have very little incentive to move unless you have privacy concerns with facebook. However I urge to to consider this, someone has to take the first steps so that others will follow. And if you need a good reason to take those first steps, I believe the privacy issues of facebook should be enough for anyone to think twice about facebook. And, if Google+ does flop, or you want to run away from it, all the stuff you put on it is yours, there is a nice easy way to download all your photos and other things on Google+ so you aren’t locked in!

 

Now here is the hard part, Google+ is still currently invite only as it’s still in it’s “trial” stages while they work out bugs. So below is a form that you can put your name and email address in, and a short note if you desire, and I’ll invite you to Google+. Due to the demand for invites, there are 2 things we do to try and get you in. First we send you an invite, then we share a post with you. You’ll get 2 emails, try the invite one first, which should have a red button to “Learn more about Google+” which will hopefully take you to the signin page to create your profile. If that fails, the second email will have a link to “View or Comment on Blah Blahs Post”. This link will also hopefully take you to a page where you can fill out your public profile and then sign in to Google+.
Both methods work at different times, so if it doesn’t work for you immediately, please wait an hour and try again.

 

I promise to not do anything with your email address other than invite you to Google+. Please be patient as I need to manually invite each person unless I can work out some way to automate this. I am happy to invite people I don’t know, however please don’t be offended if you don’t end up in my circles.

(Form removed as invites no longer needed)

Mt Gox Passwords Leaked

For the second time in a week, I’ve heard of a websites user database being leaked. In the first case it was from a site I’ve never used. The second though was a site I signed up to a few months back.
One of the biggest problems with this leaked database is that the hashing function used isn’t that strong when the hacker has rainbow tables to use to crack the database.
The first side effect of this for me was to go and change some of my passwords as a precautionary measure. The second side effect, and the more annoying one, is that I used a private email address for this particular account instead of using one of my “junk” gmail addresses. So now my private email address is in the hands of every hacker who is trying to crack that database. And already we are receiving “spam” to those addresses in that database. Most of it so far is users ether letting you know the Mt Gox database has been hacked, or users/owners of other Bitcoin exchanges sending you “advertising” so you’ll come start using their exchange. I’ve email gotten an email advertising online storage from a company that accepts Bitcoins as payments. And they haven’t bothered to try and keep the email addresses slightly private, 1500 other people also have my address, and I have theirs, as no Bcc was used. (Of course, spam filtering will quickly filter that particular email out).
Interested to see how bad the compromise was, and if it’ll affect me, I’ve also downloaded the user database now. A quick look shows that my password is hashed with the less secure method and a quick bit of code later I can confirm the password I used to make that hash. Luckily for me, I use pwdhash to generate a unique password for each site I use. This means that an attacker who has cracked my hashed password in the Mt Gox password, still only has a password that can be used for one site, Mt Gox. If they had enough time and power, then maybe they could work backwards and eventually find the password I used to generate my pwdhash passwords, but by the time they did this, I’d have changed all those passwords anyway.
Having only been using pwdhashing for a little while now, it was good to discover that it has already protected me from an attack. A number of user who had simple passwords that have been cracked already, have also had other accounts attacked as they used the same password in multiple places.

 

An interesting side note is how much the Mt Gox Bitcoin exchange has grown in a very short space of time. A discussion taking place in a forum noted that your position in the database is related to when you signed up. Working from knowing when you signed up shows how many people signed up after you. It seems to have had exponential growth in the last few weeks, which is good for Bitcoin in general, but bad once you realise how this will look to all those new users. Looking at my position in the database, I can see I was a very early adopter.

 

Drupal Upgrades

Drupal upgrades have not been easy, and they should be easy. You look at wordpress, one click and the upgrade is done! Plugins, themes and core can all be upgraded from in the browser.

Drupal upgrades are traditionally backup, move all files out, extract new fresh files, move selected files back. Now there is an easier way! Patch files from http://fuerstnet.de/en/drupal-upgrade-easier allow you to backup, and then inplace upgrade the Drupal core files! No nasty moving things around that is almost guaranteed to break something because you forgot to move something back.

I still look forward to the day when Drupal upgrades are as easy as WordPress. Until then, I have a good enough method!