Wednesday, January 7, 2009
Securing an LAMP server ... intro
This is the layout of the system:
First of course there is OS hardening. I mention it since I've noticed that it isn't done by everyone. It is an Ubuntu server and google was my friend :). There are tons of info out there.
All ports except port 80 will be closed towards the Internet and port 80 will be connected to the web server by using NAT. On the web server the only ports open are HTTPS and SSH.
The server has a firewall and 3 rules:
1. Close every port
2. Allow the HTTPS traffic from the internal network and the Internet
3. Allow SSH trafic from the internal network and the Internet.
I am not happy with the last one, I will change it so that only the admin has access from his laptop but right now it is not my primary concern.
In my next post about securing the a LAMP, I'll be talking about the apache web server. Meanwhile if you have any suggestions or questions just give me a reaction.
Wednesday, December 31, 2008
Happy New Year ! ... hang on a second
It is only matter of a couple of hours here in Brussels. Yesterday they said on the Belgian news that worldwide the atomic clocks will be stopped for one second at midnight since the earth is slowing down.
So before you jump up and shout Happy New Year take a second for yourself. You've deserved it :).
Happy New Year folks!
Tuesday, December 9, 2008
Netstumbling WiFi APs
I've found 1228 WiFi connections of which were 349 wide open with no form of protection. I looked at netstumbler and it picked up more signals each time I approached the center of a town. It is probably correct to say that there are more chances to find concentrations of networks in towncenters but I have to tell you as well that you drive slower so the laptop had more time to pickup signals.
In the 1228 WiFi connections there were 8 peer-to-peer connections of only 1 had a form of protection. There were 2 hpsetup, this is usually an SSID for an HP printer. One other peer-to-peer was also a printer according to the SSID.
The majority of connections were either 11 Mbps or 54 Mbps. (The maximum my card does is 54 Mbps). The brands I encountered were 3Com, Apple, bbox2 (Belgacom), Belkin, D-link, Hercules, Philips, Linksys, Mobistar, Netgear, Sagem, Thomson, Sweex, Topcom, US Robotics, ZyXel, Nokia.
Wednesday, December 3, 2008
Lessons learned ... clustering SQL 2005 on a Windows 2008 (x64) cluster
The first problem I had was getting to know Win2008. I know according to Microsoft that everything has improved but the challenge for us professionals is to keep up with the fact that some things don't have the same name or are completely on a different location. So I lost quite some valuable time on calling around asking a Windows system engineer with the questions "where can I find ..." and "How do I do ...". Yes, I felt like a complete idiot.
First I had to set up the MSDTC cluster resource, in Win2008 there is a wizard for that. I used it and it worked fine.
Then I had to add my clustered disks ... formatting took like eternity. No I 'm kidding but it took a while and was very impatient to go on.
Once all that was done I organised the cluster resources and started the SQL Server install. It went as planned. I ticked the box to tell it was a cluster install and continued on my quest.
The first error message I got was this one

It is actually the full-text search service that is down and it is simply solved by installing SQL 2005 SP2. After clicking ok I ran into a next error.

It is stupid but I needed to install Visual Studio 2005 SP1 (I only found x86) to solve this one. I think this happens because the SQL Server Managament Studio is written in 32-bit and I was working on x64. I know in Windows 2003 this is no issue but appearently on Windows 2008 it becomes one.
After fixing this I installed SQL 2005 SP2 and that has a problem on its own. I noticed that I was not able to make maintenance plans. I got these nice screenshots:



This is what happend: for some reason, don't ask me why it seems that the resource database had trouble to update in SP2. SP2 appearently changed some things ...
If you run in to this, you can verify the version of your resource databases with this query:
When I ran that query It answered me 9.00.1399 which is the RTM version (RTM is how it is shipped the first day your version is sold). Okay, that was usefull info but how to solve this was a mystery to me. I crused around on the information high way and found out that all it took wat to manually run the queries that are located in the "sysdbupg" script. This script can be found in "C:\Program Files\Microsoft SQL Server\
The last issue i had was an issue with database mail. Luckely for me there are nice people who blog and at Jean-Pierre Paradis' Blog I found what I was looking for. I got an activation failure.
I just copied Jean-Pierre's solution and it worked. I repeat it here if for some reason you would not be able to get to his blog.
First create the text file DataBaseMail90.exe.config in the \MSSQL\Binn folder of your SQL Instance (ex: \Program Files\Microsoft SQL Server\MSSQL.1\MSSQLSERVER\MSSQL\Binn). with the following content :

GO
INSERT INTO [msdb].[dbo].[sysmail_configuration]
(
[paramname]
,[paramvalue]
,[description]
)
VALUES
(
N'ReadFromConfigurationFile'
,N'1'
,N'Send mail from mail server in configuration file'
);
Then I replaced this stored procedure:
GO
/****** Object: StoredProcedure [dbo].[sp_sysmail_activate] Script Date: 12/01/2008 15:41:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
-- sp_sysmail_activate : Starts the DatabaseMail process if it isn't already running
--
ALTER PROCEDURE [dbo].[sp_sysmail_activate]
AS
BEGIN
DECLARE @mailDbName sysname
DECLARE @mailDbId INT
DECLARE @mailEngineLifeMin INT
DECLARE @loggingLevel nvarchar(256)
DECLARE @loggingLevelInt int
DECLARE @parameter_value nvarchar(256)
DECLARE @localmessage nvarchar(max)
DECLARE @rc INT
EXEC @rc = msdb.dbo.sysmail_help_configure_value_sp @parameter_name = N'DatabaseMailExeMinimumLifeTime',
@parameter_value = @parameter_value OUTPUT
IF(@rc <> 0)
RETURN (1)
--ConvertToInt will return the default if @parameter_value is null or config value can't be converted
--Setting max exe lifetime is 1 week (604800 secs). Can't see a reason for it to ever run longer that this
SET @mailEngineLifeMin = dbo.ConvertToInt(@parameter_value, 604800, 600)
--Try and get the optional logging level for the DatabaseMail process
EXEC msdb.dbo.sysmail_help_configure_value_sp @parameter_name = N'LoggingLevel',
@parameter_value = @loggingLevel OUTPUT
--Convert logging level into string value for passing into XP
SET @loggingLevelInt = dbo.ConvertToInt(@loggingLevel, 3, 2)
IF @loggingLevelInt = 1
SET @loggingLevel = 'Normal'
ELSE IF @loggingLevelInt = 3
SET @loggingLevel = 'Verbose'
ELSE -- default
SET @loggingLevel = 'Extended'
SET @mailDbName = DB_NAME()
SET @mailDbId = DB_ID()
EXEC @rc = master..xp_sysmail_activate @mailDbId, @mailDbName, @mailEngineLifeMin, @loggingLevel
IF(@rc <> 0)
BEGIN
SET @localmessage = FORMATMESSAGE(14637)
exec msdb.dbo.sysmail_logmailevent_sp @event_type=3, @description=@localmessage
END
ELSE
BEGIN
SET @localmessage = FORMATMESSAGE(14638)
exec msdb.dbo.sysmail_logmailevent_sp @event_type=0, @description=@localmessage
END
RETURN @rc
END
with this one
USE [msdb]
GO
/****** Object: StoredProcedure [dbo].[sp_sysmail_activate] Script Date: 08/13/2008 11:59:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- sp_sysmail_activate : Starts the DatabaseMail process if it isn't already running
--
ALTER PROCEDURE [dbo].[sp_sysmail_activate]
AS
BEGIN
DECLARE @mailDbName sysname
DECLARE @mailDbId INT
DECLARE @mailEngineLifeMin INT
DECLARE @loggingLevel nvarchar(256)
DECLARE @loggingLevelInt int
DECLARE @parameter_value nvarchar(256)
DECLARE @localmessage nvarchar(max)
DECLARE @readFromConfigFile INT
DECLARE @rc INT
SET NOCOUNT ON
EXEC sp_executesql @statement = N'RECEIVE TOP(0) * FROM msdb.dbo.ExternalMailQueue'
EXEC @rc = msdb.dbo.sysmail_help_configure_value_sp @parameter_name = N'DatabaseMailExeMinimumLifeTime',
@parameter_value = @parameter_value OUTPUT
IF(@rc <> 0)
RETURN (1)
--ConvertToInt will return the default if @parameter_value is null or config value can't be converted
--Setting max exe lifetime is 1 week (604800 secs). Can't see a reason for it to ever run longer that this
SET @mailEngineLifeMin = dbo.ConvertToInt(@parameter_value, 604800, 600)
EXEC msdb.dbo.sysmail_help_configure_value_sp @parameter_name = N'ReadFromConfigurationFile',
@parameter_value = @parameter_value OUTPUT
--Try to read the optional read from configuration file:
SET @readFromConfigFile = dbo.ConvertToInt(@parameter_value, 1, 0)
--Try and get the optional logging level for the DatabaseMail process
EXEC msdb.dbo.sysmail_help_configure_value_sp @parameter_name = N'LoggingLevel',
@parameter_value = @loggingLevel OUTPUT
--Convert logging level into string value for passing into XP
SET @loggingLevelInt = dbo.ConvertToInt(@loggingLevel, 3, 2)
IF @loggingLevelInt = 1
SET @loggingLevel = 'Normal'
ELSE IF @loggingLevelInt = 3
SET @loggingLevel = 'Verbose'
ELSE -- default
SET @loggingLevel = 'Extended'
SET @mailDbName = DB_NAME()
SET @mailDbId = DB_ID()
EXEC @rc = master..xp_sysmail_activate @mailDbId, @mailDbName, @readFromConfigFile,
@mailEngineLifeMin, @loggingLevel
IF(@rc <> 0)
BEGIN
SET @localmessage = FORMATMESSAGE(14637)
exec msdb.dbo.sysmail_logmailevent_sp @event_type=3, @description=@localmessage
END
ELSE
BEGIN
SET @localmessage = FORMATMESSAGE(14638)
exec msdb.dbo.sysmail_logmailevent_sp @event_type=0, @description=@localmessage
END
RETURN @rc
END
Start the procedure with the follwing SQL command :
Finally that was the last issue I had. Thanks to everybody who helped me, like always in our business it is a matter of looking at a problem with as many as possible.
Saturday, November 29, 2008
Mounting usb-drives with a NTFS lock on it.
First you make a directory on which you will mount the disk. For people new to linux this is just a simple directory to which you will attach the disk.
Open yourself a shell prompt and type the following:
mkdir ~/mydisk
This will make your directory in your home directory.
The type the following:
mount -t ntfs-3g /dev/sdg1 ~/mydisk -o force
This will mount the disk presented at the device /dev/sdg1 and attach it to the folder ~/mydisk. For people new to linux I recommend to do some further reading about devices.
My system answers me with :
$LogFile indicates unclean shutdown (0, 0)
WARNING: Forced mount, reset $LogFile.
And I find the disk mounted under ~/mydisk
FOSDEM 2009 and HAR2009
Fosdem is according to their website a free and non-commercial event organized by the community, for the community. Its goal is to provide Free and Open Source developers a place to meet. (http://www.fosdem.org/2009/). Fosdem will take place the 7th and 8th of February 2009 in Brussels. There are every year people comming from all over the world. One of the things I like is the open idea. If you want to talk to somebody and exchange ideas, you just walk up to that person and start a conversation. If you go back to the previous years you'll see that they managed to get some important speakers in the open source community.
HAR is totally something else. HAR's website is http://har2009.org/. It is an international technology & security conference. It will take place in August 2009 from the 13th till 16th near Vierhouten, NL. It is something like Rock Wechter but for people who are into technology and security.
I plan to go to fosdem to a couple of talks and I would like to go to HAR if it is possible.
Enter at own risk ... don't go eat there!
The name of the place is KAZI Surprise and it is located at the Chaussée de Wavre 46 in 1050 Brussels. We asked what the day special was it was goat with saka-saka or tilapia (fish) with fried bananas. We ordered the fish.
The fish had an odd tasted, clearly it was not fresh. Everybody knows that all fresh fish has a taste that is distinguishable from the not so fresh one.
Luckely in the hours that followed the experience my colleague and me didn't get the signs of food poison (although our stomachs were making some noises). I spoke to a doctor that evening and he told me that you would see the effect of food poisoning within the 4 hours.
I filed a complaint at the Federal Agency for Food Safety.
So my dear blog readers, don't go out to eat there.