Submitted by atomicrabbit
This restriction stops remote shared folders from being added to Network Places whenever you open a document in the shared folder.
Disabling this option can speed up network browsing as well as keep the My Network Places folder clean.
0 = track shares
1 = disable tracking
» Example Registry Tweak
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecentDocsNetHood"=dword:00000001
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoRecentDocsNetHood"=dword:00000001
Reference: http://unattended.msfn.org/unattended.xp/view/registry/90/SESSID=05901bb54208da41953351329d097d80/
Disable NetBios (Windows) And Increase Security - Increase your computer security
Disable NetBIOS
Increase your security
If NetBIOS is enabled
Your Files and Folders , Work Group-name , Computer name , Loging- name will be shared in Internet
in Windows 2000
1- open Windows Explorer
2- Right click on My Network places and select properties
3- Click Internet protocol TCP/IP and select properties
4- Click on Advanced and then WINS
5- Select Disable NetBIOS over TCP/IP and click ok
6- Restart your computer
If Windows displays “This connection has an empty … " message, ignore it
Reference: http://www.astahost.com/info.php/Disable-Netbios-Windows-Increase-Security_t8863.html
Disable automatic share and print discovery in Windows XP
Windows XP automatically searches the network for shares and printers upon connecting to the network. This is probably useful in a SOHO or home network but not the enterprise. To disable XP automatic discovery:
* In Explorer, click Tools
* Click Folder Options
* Click the View tab,
* Uncheck Automatically Search for Network Folders and Printers in Advanced settings list.
It is important to disable this setting in Windows XP because it is the basis of a seriouse security flaw in XP. When you click My Network Places, your logon password may be transmitted automatically to numerous unspecified computers on the LAN. Windows XP tries to acquire the shared resources list of all computers on the LAN. At that time, the users local logon password is used when the password for the shared resource is not known. Your PC transmits the LMhash version of you password.
If there are NT4.0 or any other pre-Windows 2000 PCs on the LAN, XP will transmit your password to the pre-Windows 2000 PCs during its share and print search. It transmits the LM hash which is significantly weaker than XP or Windows 2000 hashes. In order to protect the LM hash, XP has a registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\NoLMHash which if set to 1 will prevent XP or Windows 2000 from generating the LM hash. pwdump will not be able to acquire the LM hash, which is a good thing.
Saddly, NoLMHash does not affect LM authentication. Even if NoLMHash has been set, XP will still transmit the LM hash to a NT4.0 machine when My Network Places is clicked.
http://www.windowsnetworking.com/nt/xp/atips/atips23.shtml
Monday, October 19, 2009
Friday, October 16, 2009
Find the largest top 10 files and directories
List files newer than 1 days
#find . -mtime -1 -ls
find files older than 1 year and get the total disk usage of those files
#nice find / -type f -mtime +365 |xargs du -hs
http://www.computing.net/answers/unix/list-files-newer-than-10-days/4440.html
Sometime it is necessary to find out what file(s) or directories is eating up all disk space. Further it may be necessary to find out it at particular location such as /tmp or /var or /home etc.
There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files:
Output:
If you want more human readable output try:
# du -ks /var | sort -n -r | head -n 10
Where,
#find . -mtime -1 -ls
find files older than 1 year and get the total disk usage of those files
#nice find / -type f -mtime +365 |xargs du -hs
http://www.computing.net/answers/unix/list-files-newer-than-10-days/4440.html
Sometime it is necessary to find out what file(s) or directories is eating up all disk space. Further it may be necessary to find out it at particular location such as /tmp or /var or /home etc.
There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files:
- du : Estimate file space usage
- sort : Sort lines of text files or given input data
- head : Output the first part of files i.e. to display first 10 largest file
# du -a /var | sort -n -r | head -n 10Output:
1008372 /var 313236 /var/www 253964 /var/log 192544 /var/lib 152628 /var/spool 152508 /var/spool/squid 136524 /var/spool/squid/00 95736 /var/log/mrtg.log 74688 /var/log/squid 62544 /var/cache
If you want more human readable output try:
# du -ks /var | sort -n -r | head -n 10
Where,
- -a : Include all files, not just directories (du command)
- -h : Human readable format
- -n : Numeric sort (sort command)
- -r : Reverse the result of comparisons (sort command)
- -n 10 : Display 10 largest file. If you want 20 largest file replace 10 with 20. (head command)
REFERENCE
http://www.cyberciti.biz/faq/how-do-i-find-the-largest-filesdirectories-on-a-linuxunixbsd-filesystem/
Tuesday, October 13, 2009
cgi 500 Internal Server Error
Category:
Perl
— SkyHi @ Tuesday, October 13, 2009
..and how to fix it.
When running a Perl CGI script, you may see the "Internal Server Error" message in your browser. The message will usually also say something like "please check the server's error-log for more information." You should do that -- the message printed to the error log will often tell you exactly what the problem is. The Apache error log, for example, is often located at /var/log/apache/error_log or /var/log/apache2/error_log (or sometimes "error.log").
If you don't have access to the error log, the next simplest thing to do is to make a copy of the script, then open the original and delete all of its contents, and add just these 3 lines to the file:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "testing...\n";
(Note: if the server is a Windows system, then replace the first line above with either #!perl or #!c:\path\to\perl.exe.)
Now try to access the page in your browser again. If it works (you see "testing..." as its output) then you know that your server is at least configured properly for running Perl CGI scripts. If it doesn't work, then that may mean the problem is in the server configuration, rather than with your CGI script. (For example, are you sure you actually have Perl installed? Virtually all UNIX/Linux/OS X servers do, but Windows servers usually need to have it installed manually, from a package like ActivePerl.)
Assuming your server is configured properly for running CGI scripts, your problem may be one of these common causes for the Internal Server Error:
Problems outside the script:
1. Directory permissions: your cgi-bin directory should be chmodded as 0755, not 0777. Similarly if your script is at .../cgi-bin/foo/bar.cgi, the foo directory must not be world-writable (0777). This is because many servers will refuse to execute CGI scripts within world-writable directories, as a security precaution.
2. File permissions: your CGI script itself must also be 0755 and not 0777, for the same reasons.
3. Transfer modes: if you are using FTP to transfer the CGI script to your server, then your FTP client is probably set to AUTO transfer mode; that is, it will try to figure out whether to use BINARY or ASCII mode without asking you. But depending on whether your CGI script came from a Windows or UNIX system, and whether it's going to a Windows or UNIX system, you may need to manually set your FTP client to use either ASCII or BINARY mode before transferring your CGI script. Try one and then the other.
4. Line endings: the cause of the transfer-mode problem is actually another problem in itself: different types of Operating Systems (namely, Windows vs. UNIX/Linux/everything) use different character codes to represent line-endings. If your server is a UNIX server, but you're editing your CGI script on a Windows computer with a text-editor that doesn't use UNIX-style line-endings, it'll cause problems. Applications like GoLive and Dreamweaver sometimes get this wrong. Even built-in editors can't agree: WordPad (not Word) seems to get it right while Notepad messes it up. So try opening & saving your CGI script in a different text editor and uploading it to the server again.
Problems within the script:
1. The shebang line: the first line of a CGI script must contain the path to the Perl binary on the server. On most UNIX servers this is just #!/usr/bin/perl or sometimes #!/usr/local/bin/perl and you can always run the command "which perl" to find out for sure. On Windows servers, you can sometimes get away with just using #!perl but you may need to specify the full path like #!c:\path\to\perl.exe.
2. Actual script errors: it's always possible that there's simply an error in the Perl code itself. If you're having trouble with a script you purchased from Encodable Industries, this is unlikely since many other people have bought the same exact script and are running it just fine.
Related Problems
1. Another common problem with CGI scripts is the premature end of script headers error.
Reference: http://encodable.com/internal_server_error/
When running a Perl CGI script, you may see the "Internal Server Error" message in your browser. The message will usually also say something like "please check the server's error-log for more information." You should do that -- the message printed to the error log will often tell you exactly what the problem is. The Apache error log, for example, is often located at /var/log/apache/error_log or /var/log/apache2/error_log (or sometimes "error.log").
If you don't have access to the error log, the next simplest thing to do is to make a copy of the script, then open the original and delete all of its contents, and add just these 3 lines to the file:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print "testing...\n";
(Note: if the server is a Windows system, then replace the first line above with either #!perl or #!c:\path\to\perl.exe.)
Now try to access the page in your browser again. If it works (you see "testing..." as its output) then you know that your server is at least configured properly for running Perl CGI scripts. If it doesn't work, then that may mean the problem is in the server configuration, rather than with your CGI script. (For example, are you sure you actually have Perl installed? Virtually all UNIX/Linux/OS X servers do, but Windows servers usually need to have it installed manually, from a package like ActivePerl.)
Assuming your server is configured properly for running CGI scripts, your problem may be one of these common causes for the Internal Server Error:
Problems outside the script:
1. Directory permissions: your cgi-bin directory should be chmodded as 0755, not 0777. Similarly if your script is at .../cgi-bin/foo/bar.cgi, the foo directory must not be world-writable (0777). This is because many servers will refuse to execute CGI scripts within world-writable directories, as a security precaution.
2. File permissions: your CGI script itself must also be 0755 and not 0777, for the same reasons.
3. Transfer modes: if you are using FTP to transfer the CGI script to your server, then your FTP client is probably set to AUTO transfer mode; that is, it will try to figure out whether to use BINARY or ASCII mode without asking you. But depending on whether your CGI script came from a Windows or UNIX system, and whether it's going to a Windows or UNIX system, you may need to manually set your FTP client to use either ASCII or BINARY mode before transferring your CGI script. Try one and then the other.
4. Line endings: the cause of the transfer-mode problem is actually another problem in itself: different types of Operating Systems (namely, Windows vs. UNIX/Linux/everything) use different character codes to represent line-endings. If your server is a UNIX server, but you're editing your CGI script on a Windows computer with a text-editor that doesn't use UNIX-style line-endings, it'll cause problems. Applications like GoLive and Dreamweaver sometimes get this wrong. Even built-in editors can't agree: WordPad (not Word) seems to get it right while Notepad messes it up. So try opening & saving your CGI script in a different text editor and uploading it to the server again.
Problems within the script:
1. The shebang line: the first line of a CGI script must contain the path to the Perl binary on the server. On most UNIX servers this is just #!/usr/bin/perl or sometimes #!/usr/local/bin/perl and you can always run the command "which perl" to find out for sure. On Windows servers, you can sometimes get away with just using #!perl but you may need to specify the full path like #!c:\path\to\perl.exe.
2. Actual script errors: it's always possible that there's simply an error in the Perl code itself. If you're having trouble with a script you purchased from Encodable Industries, this is unlikely since many other people have bought the same exact script and are running it just fine.
Related Problems
1. Another common problem with CGI scripts is the premature end of script headers error.
Reference: http://encodable.com/internal_server_error/
.htaccess mod_rewrite to direct non-www to www
Category:
Apache,
mod_rewrite,
SEO
— SkyHi @ Tuesday, October 13, 2009
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^dreamincode.(.*)
RewriteRule ^(.*)$ http://www.dreamincode.net/$1 [R=301,L]
Reference: http://www.dreamincode.net/code/snippet1126.htm
RewriteEngine on
RewriteCond %{HTTP_HOST} ^dreamincode.(.*)
RewriteRule ^(.*)$ http://www.dreamincode.net/$1 [R=301,L]
Reference: http://www.dreamincode.net/code/snippet1126.htm
Friday, October 9, 2009
Removing a passphrase from an SSL Key
Category:
Apache
— SkyHi @ Friday, October 09, 2009
Removing a passphrase from an SSL Key
Friday, October 12th, 2007
The typical process for creating an SSL certificate is as follows:
# openssl genrsa -des3 -out www.key 1024
At this point it is asking for a PASS PHRASE (which I will describe how to remove):
Enter pass phrase for www.key:
# openssl req -new -key www.key -out www.csr
Next, you will typically send the www.csr file to your registrar. In turn, you should receive a key.
From a security standpoint utilizing a passphrase, is a good thing, but from a practical standpoint not very useful.
For instance, what happens when your server reboots/crashes at 3am? Or better, what happens in 6 months when you reboot your machine, and you don’t remember the password? Well, one thing is for sure, your web server will not be online.
I suggest removal of the passphrase, you can follow the process below:
Always backup the original key before first to make sure no mistakes occur:
# cp www.key www.key.orig
Then unencrypt the key with openssl. You’ll need the passphrase for the decryption process:
# openssl rsa -in www.key -out new.key
Now copy the new.key to the www.key file and you’re done. Next time you restart the web server, it should not prompt you for the passphrase.
Reference: http://www.mnxsolutions.com/blog/apache/removing-a-passphrase-from-an-ssl-key.html
Friday, October 12th, 2007
The typical process for creating an SSL certificate is as follows:
# openssl genrsa -des3 -out www.key 1024
At this point it is asking for a PASS PHRASE (which I will describe how to remove):
Enter pass phrase for www.key:
# openssl req -new -key www.key -out www.csr
Next, you will typically send the www.csr file to your registrar. In turn, you should receive a key.
From a security standpoint utilizing a passphrase, is a good thing, but from a practical standpoint not very useful.
For instance, what happens when your server reboots/crashes at 3am? Or better, what happens in 6 months when you reboot your machine, and you don’t remember the password? Well, one thing is for sure, your web server will not be online.
I suggest removal of the passphrase, you can follow the process below:
Always backup the original key before first to make sure no mistakes occur:
# cp www.key www.key.orig
Then unencrypt the key with openssl. You’ll need the passphrase for the decryption process:
# openssl rsa -in www.key -out new.key
Now copy the new.key to the www.key file and you’re done. Next time you restart the web server, it should not prompt you for the passphrase.
Reference: http://www.mnxsolutions.com/blog/apache/removing-a-passphrase-from-an-ssl-key.html
Tuesday, September 29, 2009
LVM Single Drive to LVM RAID 1 Mirror MigrationLVM Single Drive to LVM RAID 1 Mirror Migration
Category:
LVM
— SkyHi @ Tuesday, September 29, 2009
Steps to migrate a running machine using LVM on a single drive to mirrored drives on Linux RAID 1 (mirror) and LVM. Keep the machine online while data is migrated across the LVM too!
This document was written based on a How-to article for Debian Etch (see references for original article). This version was tested using CentOS 5.3. It may work for other versions of CentOS and Linux using LVM on a single drive.
In my example the main drive is /dev/sda where /dev/sda1 is a ext3 /boot partition and /dev/sda2 is a our LVM PV. Our new hard drive is /dev/sdb and is the same model and size as /dev/sda. LVM naming may be different and I have outlined steps to get PV, VG, and LV names of your specific system setup.
Remember to BACKUP YOUR DATA! I make no guarantees this will work and you should have all data backed up off of BOTH drives used in this tutorial to an external source that is disconnected from the machine when starting this tutorial.
Insert a second drive
This step will vary between systems. In short, you need to put the new drive into the machine that will be part of the RAID mirror. The drive should be identical in size as the current one and if possible, the same model.
Throughout this document the new drive will be referenced as /dev/sdb.
2.
Print current partition layout for reference
We will need the current partition layout of /dev/sda (our original drive with LVM partition). Our example has only 2 partitions. /dev/sda1 (the boot partition) and /dev/sda2 (the LVM partition).
Print the current layout with the following command
# fdisk -l /dev/sda
3.
Partition the second drive
We now need to partition the second drive identical to the first drive. Use the starting cylinder and last cylinder of the first drive partition layout to ensure the second drive is the same.
Partition the new drive with the following command:
# fdisk /dev/sdb
a. Press 'n' to create a new partition
b. Press 'p' for primary partition
c. Press '1' to create the first primary partition (this step might be automatically completed as there are no partitioins yet)
d. Press '1' to start it at the first cylinder
e. Type in the number of the last cylinder for the original /dev/sda1 partition, in our example it is '13'
f. Type in 't' to set the partition type
g. Type in the partition number
h. Type in 'fd' for Linux RAID type
i. Perform sub-steps a-h for the second primary partition
j. Type in 'w' to write the changes
4.
Compare the partition layout between the two drives
We should now have /dev/sdb partitioned with 2 Linux RAID partitions the same size as the /dev/sda partitions (which are likely not Linux RAID type, this is OK). Verify the partition sizes line up:
# fdisk -l
Our example system now outputs:
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1044 8281507+ 8e Linux LVM
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 13 104391 fd Linux raid autodetect
/dev/sdb2 14 1044 8281507+ fd Linux raid autodetect
5.
Create our new RAID mirror devices
Zero the superblock in case the new drive happened to be part of a linux software RAID before:
# mdadm --zero-superblock /dev/sdb1
# mdadm --zero-superblock /dev/sdb2
Create the new RAID devices:
# mdadm --create /dev/md0 --verbose --level=1 --raid-devices=2 missing /dev/sdb1
# mdadm --create /dev/md1 --verbose --level=1 --raid-devices=2 missing /dev/sdb2
We use the word 'missing' in place of the first drive as we will add the drive to the array after we confirm the machine can boot and all the data is on array (which will currently only have 1 drive, the newly added /dev/sdb).
6.
Build the /etc/mdadm.conf
There may already be a mdadm.conf in which case you may only need to add the arrays with the mdadm --examine line. In our example we did not have any /etc/mdadm.conf and needed to build one by hand.
The following commands will build a simple /etc/mdadm.conf that sends notifications to root (our example machine also has root aliased to an external email address).
# echo "DEVICE partitions" >> /etc/mdadm.conf
# echo "MAILADDR root" >> /etc/mdadm.conf
# mdadm --examine --scan >> /etc/mdadm.conf
7.
Format the new RAID boot partition
We can now format the RAID partition that will be used in place of our boot partition on /dev/sda1. In our example system the original partition is ext3 mounted as /boot.
Setup using command:
# mkfs.ext3 /dev/md0
8.
Mount and build the new boot partition
We need to copy over the existing boot partition to the new RAID device:
# mkdir /mnt/boot
# mount /dev/md0 /mnt/boot
# cp -dpRx /boot/* /mnt/boot/
# umount /mnt/boot
9.
Mount new boot partition in place of old
We will now unmount the current /boot partition and mount our new /dev/md0 device in place of it to prepare for making a new initrd image.
# umount /boot
# mount /dev/md0 /boot
10.
Build new initrd image
Now build a new initrd image that contains the dm-mirror and other raid modules to be safe (without these the boot will fail not recognizing the new /boot).
# mv /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bak
# mkinitrd -v /boot/initrd-$(uname -r).img $(uname -r)
11.
Install grub on both drives
Install grub on both physical drives MBR and edit /etc/fstab to reflect our new boot partition /dev/md0
# grub-install /dev/sda
# grub-install /dev/sdb
If grub-install complains about not able to find /dev/sdb or that it is not part of the BIOS drives then you may need to use the --recheck switch
# grub-install --recheck /dev/sdb
# grub-install --recheck /dev/sda
12.
Edit /etc/fstab to reflect new /boot location
Edit the /etc/fstab file to replace LABEL=/boot with /dev/md0. Your new /boot partition line should look something like:
/dev/md0 /boot ext3 defaults 1 2
13.
Time for the first reboot!
Now, reboot the system to get it up and running on the new boot partition and off of /dev/sda1. This will confirm that we can safely change the /dev/sda1 partition ID to Linux RAID type and then add the partition to the md0 mirror.
# reboot
14.
Take a breather... Verify /boot is mounted using the RAID device
You are about half way done. Hopefully everything is up and running after your first reboot.
Check the mount command to verify that /boot is using the new /dev/md0 device:
# mount
If it is then you can are set to continue... after a short break of course.
15.
Change first drive /dev/sda1 to Linux RAID type
Modify the old /boot device (/dev/sda1) to be Linux RAID type. This will prepare it so it can be added to our RAID device /dev/md0 (which our new /boot is using).
# fdisk /dev/sda
a. Type in 't' to set the partition type
b. Type in the partition number (1)
c. Type in 'fd' for Linux RAID type
d. Type in 'w' to write the changes and exit fdisk
16.
Add /dev/sda1 to /dev/md0 mirror
Add the /dev/sda1 partition to the /dev/md0 mirror and remove the old label
# e2label /dev/sda1 ""
# mdadm --add /dev/md0 /dev/sda1
17.
Wait for the /dev/md0 mirror to rebuild
Watch the /proc/mdstat output to make sure the syncing of the newly completed /dev/md0 device finishes before continuing.
# watch cat /proc/mdstat
Once it is complete you may continue. Since the /boot partition is usually only a couple hundred megabytes this usually completes very quickly.
18.
Create new LVM physical volume
Create a new LVM PV on the second raid device. We will use this new PV to extend the current LVM volume group to.
# pvcreate -v /dev/md1
19.
Extend volume group to new PV
Use command `vgs` to show the name of the LVM VG. In our example it is VolGroup00.
Run the following command replacing VolGroup00 with the actual name of your volume group. You may have to do this step for each VG if you have multiple:
# vgextend -v VolGroup00 /dev/md1
20.
Move logical volume to new PV
Use `pvdisplay` to verify the VG is now using both drives:
# pvdisplay
Now we can move the LV to the new PV:
Use`lvs` to get the LV names (you will need to move all) then run the following command for both (replacing LogVolXX with your LV names):
# pvmove -v /dev/sda2 /dev/md1
Wait a while.... It will output % done every 15 seconds.
Depending on the size of your original drive this may take an hour or more. It is now copying everything from the first drive to the second drive while keeping the machine online.
21.
Remove the VG from the old PV
Once all the data is finished moving we want to 'reduce' the volume groups to only use the new physical volume and then remove the old physical volume so it cna no longer be used for LVM.
# vgreduce -v VolGroup00 /dev/sda2
# pvremove /dev/sda2
22.
Build new initrd image (again)
Built new initrd image again. This was needed on our example system to keep from throwing a kernel panic at boot. We are being safe by doing this step again.
# mv /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bak
# mkinitrd -v /boot/initrd-$(uname -r).img $(uname -r)
23.
Install grub on both drives (again)
Double check that grub is installed correctly.
Somewhere between the Step 10 reboot and Step 24 reboot grub became corrupted (froze with only 'GRUB' on screen and no indicator) so I had to reinstall grub again on each drive to be safe. The fix was to install grub the traditional way using the grub commands root (hd0,1) and setup (hd0) and then the same for hd1.
# grub-install --recheck /dev/sdb
# grub-install --recheck /dev/sda
24.
Reboot again!
Reboot the machine again:
# reboot
Everything come back up OK? Great, we are almost done!
25.
Change first drive /dev/sda2 to Linux RAID type
Change the old LVM partiton to Linux RAID type:
# fdisk /dev/sda
a. t
b. 2
c. fd
d. w
Verify the partition type is now Linux RAID:
# fdisk -l
26.
Add /dev/sda2 to /dev/md1 mirror
We are now ready to add the old /dev/sda2 LVM partition to the /dev/md1 RAID device:
# mdadm --add /dev/md1 /dev/sda2
27.
Wait for the /dev/md1 mirror to rebuild
Watch the /proc/mdstat output to make sure the syncing of the newly completed /dev/md1 device finishes before rebooting.
# watch cat /proc/mdstat
28.
Last reboot!
Reboot the machine once more to verify that everything is working correctly:
# reboot
Is the machine back up and running? No data loss?
Wonderful! You have just completed migrating your single drive machine to a two drive Linux RAID mirror.
Conclusion
While it is always best to create RAID setups and the time of install there may be a desire to have RAID after the fact when the original installer was not required, did not have the hardware (only 1 drive available), or didn't have the know how.
In a pinch, this may help to bring a production system some drive redundancy. I hope you found this tutorial helpful!
Reference: http://community.spiceworks.com/how_to/show/340
This document was written based on a How-to article for Debian Etch (see references for original article). This version was tested using CentOS 5.3. It may work for other versions of CentOS and Linux using LVM on a single drive.
In my example the main drive is /dev/sda where /dev/sda1 is a ext3 /boot partition and /dev/sda2 is a our LVM PV. Our new hard drive is /dev/sdb and is the same model and size as /dev/sda. LVM naming may be different and I have outlined steps to get PV, VG, and LV names of your specific system setup.
Remember to BACKUP YOUR DATA! I make no guarantees this will work and you should have all data backed up off of BOTH drives used in this tutorial to an external source that is disconnected from the machine when starting this tutorial.
Insert a second drive
This step will vary between systems. In short, you need to put the new drive into the machine that will be part of the RAID mirror. The drive should be identical in size as the current one and if possible, the same model.
Throughout this document the new drive will be referenced as /dev/sdb.
2.
Print current partition layout for reference
We will need the current partition layout of /dev/sda (our original drive with LVM partition). Our example has only 2 partitions. /dev/sda1 (the boot partition) and /dev/sda2 (the LVM partition).
Print the current layout with the following command
# fdisk -l /dev/sda
3.
Partition the second drive
We now need to partition the second drive identical to the first drive. Use the starting cylinder and last cylinder of the first drive partition layout to ensure the second drive is the same.
Partition the new drive with the following command:
# fdisk /dev/sdb
a. Press 'n' to create a new partition
b. Press 'p' for primary partition
c. Press '1' to create the first primary partition (this step might be automatically completed as there are no partitioins yet)
d. Press '1' to start it at the first cylinder
e. Type in the number of the last cylinder for the original /dev/sda1 partition, in our example it is '13'
f. Type in 't' to set the partition type
g. Type in the partition number
h. Type in 'fd' for Linux RAID type
i. Perform sub-steps a-h for the second primary partition
j. Type in 'w' to write the changes
4.
Compare the partition layout between the two drives
We should now have /dev/sdb partitioned with 2 Linux RAID partitions the same size as the /dev/sda partitions (which are likely not Linux RAID type, this is OK). Verify the partition sizes line up:
# fdisk -l
Our example system now outputs:
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1044 8281507+ 8e Linux LVM
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 13 104391 fd Linux raid autodetect
/dev/sdb2 14 1044 8281507+ fd Linux raid autodetect
5.
Create our new RAID mirror devices
Zero the superblock in case the new drive happened to be part of a linux software RAID before:
# mdadm --zero-superblock /dev/sdb1
# mdadm --zero-superblock /dev/sdb2
Create the new RAID devices:
# mdadm --create /dev/md0 --verbose --level=1 --raid-devices=2 missing /dev/sdb1
# mdadm --create /dev/md1 --verbose --level=1 --raid-devices=2 missing /dev/sdb2
We use the word 'missing' in place of the first drive as we will add the drive to the array after we confirm the machine can boot and all the data is on array (which will currently only have 1 drive, the newly added /dev/sdb).
6.
Build the /etc/mdadm.conf
There may already be a mdadm.conf in which case you may only need to add the arrays with the mdadm --examine line. In our example we did not have any /etc/mdadm.conf and needed to build one by hand.
The following commands will build a simple /etc/mdadm.conf that sends notifications to root (our example machine also has root aliased to an external email address).
# echo "DEVICE partitions" >> /etc/mdadm.conf
# echo "MAILADDR root" >> /etc/mdadm.conf
# mdadm --examine --scan >> /etc/mdadm.conf
7.
Format the new RAID boot partition
We can now format the RAID partition that will be used in place of our boot partition on /dev/sda1. In our example system the original partition is ext3 mounted as /boot.
Setup using command:
# mkfs.ext3 /dev/md0
8.
Mount and build the new boot partition
We need to copy over the existing boot partition to the new RAID device:
# mkdir /mnt/boot
# mount /dev/md0 /mnt/boot
# cp -dpRx /boot/* /mnt/boot/
# umount /mnt/boot
9.
Mount new boot partition in place of old
We will now unmount the current /boot partition and mount our new /dev/md0 device in place of it to prepare for making a new initrd image.
# umount /boot
# mount /dev/md0 /boot
10.
Build new initrd image
Now build a new initrd image that contains the dm-mirror and other raid modules to be safe (without these the boot will fail not recognizing the new /boot).
# mv /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bak
# mkinitrd -v /boot/initrd-$(uname -r).img $(uname -r)
11.
Install grub on both drives
Install grub on both physical drives MBR and edit /etc/fstab to reflect our new boot partition /dev/md0
# grub-install /dev/sda
# grub-install /dev/sdb
If grub-install complains about not able to find /dev/sdb or that it is not part of the BIOS drives then you may need to use the --recheck switch
# grub-install --recheck /dev/sdb
# grub-install --recheck /dev/sda
12.
Edit /etc/fstab to reflect new /boot location
Edit the /etc/fstab file to replace LABEL=/boot with /dev/md0. Your new /boot partition line should look something like:
/dev/md0 /boot ext3 defaults 1 2
13.
Time for the first reboot!
Now, reboot the system to get it up and running on the new boot partition and off of /dev/sda1. This will confirm that we can safely change the /dev/sda1 partition ID to Linux RAID type and then add the partition to the md0 mirror.
# reboot
14.
Take a breather... Verify /boot is mounted using the RAID device
You are about half way done. Hopefully everything is up and running after your first reboot.
Check the mount command to verify that /boot is using the new /dev/md0 device:
# mount
If it is then you can are set to continue... after a short break of course.
15.
Change first drive /dev/sda1 to Linux RAID type
Modify the old /boot device (/dev/sda1) to be Linux RAID type. This will prepare it so it can be added to our RAID device /dev/md0 (which our new /boot is using).
# fdisk /dev/sda
a. Type in 't' to set the partition type
b. Type in the partition number (1)
c. Type in 'fd' for Linux RAID type
d. Type in 'w' to write the changes and exit fdisk
16.
Add /dev/sda1 to /dev/md0 mirror
Add the /dev/sda1 partition to the /dev/md0 mirror and remove the old label
# e2label /dev/sda1 ""
# mdadm --add /dev/md0 /dev/sda1
17.
Wait for the /dev/md0 mirror to rebuild
Watch the /proc/mdstat output to make sure the syncing of the newly completed /dev/md0 device finishes before continuing.
# watch cat /proc/mdstat
Once it is complete you may continue. Since the /boot partition is usually only a couple hundred megabytes this usually completes very quickly.
18.
Create new LVM physical volume
Create a new LVM PV on the second raid device. We will use this new PV to extend the current LVM volume group to.
# pvcreate -v /dev/md1
19.
Extend volume group to new PV
Use command `vgs` to show the name of the LVM VG. In our example it is VolGroup00.
Run the following command replacing VolGroup00 with the actual name of your volume group. You may have to do this step for each VG if you have multiple:
# vgextend -v VolGroup00 /dev/md1
20.
Move logical volume to new PV
Use `pvdisplay` to verify the VG is now using both drives:
# pvdisplay
Now we can move the LV to the new PV:
Use`lvs` to get the LV names (you will need to move all) then run the following command for both (replacing LogVolXX with your LV names):
# pvmove -v /dev/sda2 /dev/md1
Wait a while.... It will output % done every 15 seconds.
Depending on the size of your original drive this may take an hour or more. It is now copying everything from the first drive to the second drive while keeping the machine online.
21.
Remove the VG from the old PV
Once all the data is finished moving we want to 'reduce' the volume groups to only use the new physical volume and then remove the old physical volume so it cna no longer be used for LVM.
# vgreduce -v VolGroup00 /dev/sda2
# pvremove /dev/sda2
22.
Build new initrd image (again)
Built new initrd image again. This was needed on our example system to keep from throwing a kernel panic at boot. We are being safe by doing this step again.
# mv /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bak
# mkinitrd -v /boot/initrd-$(uname -r).img $(uname -r)
23.
Install grub on both drives (again)
Double check that grub is installed correctly.
Somewhere between the Step 10 reboot and Step 24 reboot grub became corrupted (froze with only 'GRUB' on screen and no indicator) so I had to reinstall grub again on each drive to be safe. The fix was to install grub the traditional way using the grub commands root (hd0,1) and setup (hd0) and then the same for hd1.
# grub-install --recheck /dev/sdb
# grub-install --recheck /dev/sda
24.
Reboot again!
Reboot the machine again:
# reboot
Everything come back up OK? Great, we are almost done!
25.
Change first drive /dev/sda2 to Linux RAID type
Change the old LVM partiton to Linux RAID type:
# fdisk /dev/sda
a. t
b. 2
c. fd
d. w
Verify the partition type is now Linux RAID:
# fdisk -l
26.
Add /dev/sda2 to /dev/md1 mirror
We are now ready to add the old /dev/sda2 LVM partition to the /dev/md1 RAID device:
# mdadm --add /dev/md1 /dev/sda2
27.
Wait for the /dev/md1 mirror to rebuild
Watch the /proc/mdstat output to make sure the syncing of the newly completed /dev/md1 device finishes before rebooting.
# watch cat /proc/mdstat
28.
Last reboot!
Reboot the machine once more to verify that everything is working correctly:
# reboot
Is the machine back up and running? No data loss?
Wonderful! You have just completed migrating your single drive machine to a two drive Linux RAID mirror.
Conclusion
While it is always best to create RAID setups and the time of install there may be a desire to have RAID after the fact when the original installer was not required, did not have the hardware (only 1 drive available), or didn't have the know how.
In a pinch, this may help to bring a production system some drive redundancy. I hope you found this tutorial helpful!
Reference: http://community.spiceworks.com/how_to/show/340
Malecious Random JavaScript Rootkit
Category:
Hack
— SkyHi @ Tuesday, September 29, 2009
Malecious Random JavaScript Rootkit
(Adapted from http://www.cpanel.net/security/notes/random_js_toolkit.html )
BugTargeted Systems
A Linux server virus has recently been reported targeting multiple platforms such as: RedHat Enterprise, Centos v4.x/v5.x, and Fedora Core v5/v6. This Rootkit is not believed to be specific to any one control panel and/or Php application(s). Unfortunately, there are still many unknown details. We are actively researching the entry point to this exploit to pinpoint the methods used to gain access in order to stop this Rootkit from infecting servers in the future. It's a very time and energy consuming process as the primary Rootkit is designed to be hidden within the system which proves to be challenging even to Level I engineers.
Affected Binary Packages
It has been established that this Rootkit requires super user privileges. The initial entry point has not been confirmed yet. When a hacker gains shell access, the Rootkit is installed. Frequently-compromised binaries include:
/sbin/ifconfig
/sbin/fsck
/sbin/route
/bin/basename
/bin/cat
/bin/mount
/bin/touch
The Rootkit renames these system binary packages by adding a random set of characters at the end of the file name. Additionally, a 0 byte file with a different set of random characters is created based upon the target binary package's name.
For example:
/sbin/routewWmVTnBL6szkobbNZ9Iz
/sbin/routeGnAxnt168fMJAxHiru22
These files are hidden on the live filesystem of an affected system. In order to view these files, the system must be rebooted to a safe environment such as a system rescue CD.
How a Rootkit works
1. Once the Rootkit is successfully installed, the server will sit idle until rebooted. During a server reboot, the system initialization scripts will call the infected binaries.
2. When executed, the infected binary packages use /dev/mem as a pathway to the Kernel , and then attach to several system calls within the running Kernel. This results in hidden files, broken binary packages, and random JavaScript code being seen by web visitors.
3. When the system is fully online in an infected state, the Kernel will begin serving a JavaScript payload to random web requests/visits. This occurs outside of Apache and will not be seen in any of the Apache logs. The JavaScript injection will look like:
The JavaScript file is dynamically created and will have a random five character filename. This JavaScript will begin exploiting several known vulnerabilities within Windows, QuickTime and Yahoo Messenger on the web visitor's PC. Keep in mind that the JavaScript is not served on every request. It is injected into a small percentage of requests at random.
How do I know my server has been infected with this JS Rootkit ?
If you feel your server is being compromised, you can run the tests below to confirm.
The easiest test is to attempt to create a directory with a numerical name such as:
mkdir 123test
If your system returns the following error:
[root\@server ~]# mkdir 1
mkdir: cannot create directory `1': No such file or directory
Your system has been compromised.
This is not always true in older variants of a Rootkit . To make sure that your server is not compromised, run the following command for 3-5 minutes in order to sniff packets:
tcpdump -nAs 2048 src port 80 | grep "[a-zA-Z]\{5\}\.js'"
If your server is infected, the system will return the following result:
root@server log]# tcpdump -nAs 2048 src port 80 | grep "[a-zA-Z]\{5\}\.js'"
tcpdump: verbose output suppressed, use -v or -vv for full protocol
decode
listening on eth0, link-type EN10MB (Ethernet), capture size 2048 bytes
1311 packets captured
2627 packets received by filter
0 packets dropped by kernel
Additional detection methods require an in-depth knowledge of Kernel debugging.
Solution
It is possible to remove this Rootkit by booting the server into a safe environment and moving the previous binary back in place. In this case, /sbin/routewWmVTnBL6szkobbNZ9Iz is the original binary. You can confirm this by looking at the size of the file. One will be 0 bytes and the other will be relatively significant in size. We suggest copying these binaries from a trusted and clean server.
Keep in mind that this is a root compromise. Until the point of entry is determined and closed, the server can continue to be compromised without proper security practices in place. We highly recommended that you do the following:
1. Contact your datacenter, NOC, or a qualified administrator to have the system fully checked and recovered.
2. Secure and harden your server.
3. Change any root passwords that have been previously used.
4. DO NOT give shell or jailshell access to ANYONE.
5. Update your server’s applications and services to the latest release, especially security patches and monitor the server closely for any unsuspected activity.
June 26th, 2008: Read the Latest findings about the Random JavaScript Rootkit
Click here if you wish to protect your server against IFrame JS code with "ServerTune IFrame Shield"
More information about Kernel Rootkits (To view this page, your browser must support in-line frames.)
Reference: http://servertune.com/kbase/entry/258/
(Adapted from http://www.cpanel.net/security/notes/random_js_toolkit.html )
BugTargeted Systems
A Linux server virus has recently been reported targeting multiple platforms such as: RedHat Enterprise, Centos v4.x/v5.x, and Fedora Core v5/v6. This Rootkit is not believed to be specific to any one control panel and/or Php application(s). Unfortunately, there are still many unknown details. We are actively researching the entry point to this exploit to pinpoint the methods used to gain access in order to stop this Rootkit from infecting servers in the future. It's a very time and energy consuming process as the primary Rootkit is designed to be hidden within the system which proves to be challenging even to Level I engineers.
Affected Binary Packages
It has been established that this Rootkit requires super user privileges. The initial entry point has not been confirmed yet. When a hacker gains shell access, the Rootkit is installed. Frequently-compromised binaries include:
/sbin/ifconfig
/sbin/fsck
/sbin/route
/bin/basename
/bin/cat
/bin/mount
/bin/touch
The Rootkit renames these system binary packages by adding a random set of characters at the end of the file name. Additionally, a 0 byte file with a different set of random characters is created based upon the target binary package's name.
For example:
/sbin/routewWmVTnBL6szkobbNZ9Iz
/sbin/routeGnAxnt168fMJAxHiru22
These files are hidden on the live filesystem of an affected system. In order to view these files, the system must be rebooted to a safe environment such as a system rescue CD.
How a Rootkit works
1. Once the Rootkit is successfully installed, the server will sit idle until rebooted. During a server reboot, the system initialization scripts will call the infected binaries.
2. When executed, the infected binary packages use /dev/mem as a pathway to the Kernel , and then attach to several system calls within the running Kernel. This results in hidden files, broken binary packages, and random JavaScript code being seen by web visitors.
3. When the system is fully online in an infected state, the Kernel will begin serving a JavaScript payload to random web requests/visits. This occurs outside of Apache and will not be seen in any of the Apache logs. The JavaScript injection will look like:
The JavaScript file is dynamically created and will have a random five character filename. This JavaScript will begin exploiting several known vulnerabilities within Windows, QuickTime and Yahoo Messenger on the web visitor's PC. Keep in mind that the JavaScript is not served on every request. It is injected into a small percentage of requests at random.
How do I know my server has been infected with this JS Rootkit ?
If you feel your server is being compromised, you can run the tests below to confirm.
The easiest test is to attempt to create a directory with a numerical name such as:
mkdir 123test
If your system returns the following error:
[root\@server ~]# mkdir 1
mkdir: cannot create directory `1': No such file or directory
Your system has been compromised.
This is not always true in older variants of a Rootkit . To make sure that your server is not compromised, run the following command for 3-5 minutes in order to sniff packets:
tcpdump -nAs 2048 src port 80 | grep "[a-zA-Z]\{5\}\.js'"
If your server is infected, the system will return the following result:
root@server log]# tcpdump -nAs 2048 src port 80 | grep "[a-zA-Z]\{5\}\.js'"
tcpdump: verbose output suppressed, use -v or -vv for full protocol
decode
listening on eth0, link-type EN10MB (Ethernet), capture size 2048 bytes
1311 packets captured
2627 packets received by filter
0 packets dropped by kernel
Additional detection methods require an in-depth knowledge of Kernel debugging.
Solution
It is possible to remove this Rootkit by booting the server into a safe environment and moving the previous binary back in place. In this case, /sbin/routewWmVTnBL6szkobbNZ9Iz is the original binary. You can confirm this by looking at the size of the file. One will be 0 bytes and the other will be relatively significant in size. We suggest copying these binaries from a trusted and clean server.
Keep in mind that this is a root compromise. Until the point of entry is determined and closed, the server can continue to be compromised without proper security practices in place. We highly recommended that you do the following:
1. Contact your datacenter, NOC, or a qualified administrator to have the system fully checked and recovered.
2. Secure and harden your server.
3. Change any root passwords that have been previously used.
4. DO NOT give shell or jailshell access to ANYONE.
5. Update your server’s applications and services to the latest release, especially security patches and monitor the server closely for any unsuspected activity.
June 26th, 2008: Read the Latest findings about the Random JavaScript Rootkit
Click here if you wish to protect your server against IFrame JS code with "ServerTune IFrame Shield"
More information about Kernel Rootkits (To view this page, your browser must support in-line frames.)
Reference: http://servertune.com/kbase/entry/258/
Subscribe to:
Posts (Atom)
