Monday, December 29, 2008
Checking Password Policies in Linux
Thursday, December 18, 2008
NTFS for MAC OS X
Sometimes if you have an external drive that's NTFS formated and it's not disconnected properly from Windows, it'll come up with this message while trying to mount it in Mac OS X
$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/disk1s1': Operation not supported
Mount is denied because NTFS is marked to be in use. Choose one action:
Choice 1: If you have Windows then disconnect the external devices by
clicking on the 'Safely Remove Hardware' icon in the Windows
taskbar then shutdown Windows cleanly.
Choice 2: If you don't have Windows then you can use the 'force' option for
your own responsibility. For example type on the command line:
mount -t ntfs-3g /dev/disk1s1 /Volumes/WD Passport -o force
Or add the option to the relevant row in the /etc/fstab file:
/dev/disk1s1 /Volumes/WD Passport ntfs-3g defaults,force 0 0
Solution
I just had to force it to mount, and then umount it in Terminal. After unplugging and plugging the drive back in, everything works like it did before:
$>sudo mkdir /Volumes/WD\ Passport
$>sudo /usr/local/bin/ntfs-3g /dev/disk1s1 /Volumes/WD\ Passport -o force
$>sudo umount /Volumes/WD\ Passport
Taken from
http://www.elctech.com/projects/troubles-mounting-ntfs-external-drive-on-mac-os-x
Tuesday, December 16, 2008
Windows Admin Tricks
Sunday, November 30, 2008
Forensics: Filesystem Mount
Saturday, November 29, 2008
DD to image a drive
The following steps show you how to use dd and MD5 to create, restore, and verify forensically sound disk images:
First, we start by creating an MD5 checksum of a disk. To do this, first log in as root, and open a command prompt. Create the MD5 checksom for the disk to be duplicated using the following:
md5sum /dev/fd0 > /tmp/original-md5
This command creates the MD5 checksum of the device, /dev/fd0, and outputs the result to a file named /tmp/ original-md5.
View the checksum with cat /tmp/original-md5.
Now, create an image file of the disk.
Use dd to create a binary copy of the disk:
*Remember to unmount the disk before using dd.
dd if=/dev/fd0 of=/tmp/disk.img bs=1k
The if=/dev/fd0 parameter directs dd to use the device /dev/fd0 as the input file. The of=/tmp/disk.img parameter tells dd to output the data to a file named /tmp/disk.img. The bs=1k tells dd to use a block size of 1024 or 1KB.
Next, we'll use MD5 to verify the accuracy of the image file. First, create the MD5 checksum for the image file with the following:
md5sum /tmp/disk.img > /tmp/image-md5
Compare the checksums of the original disk and the image file using the following:
cat /tmp/*md5
The cat command displays the contents of files that end with md5. Note that the checksums are identical.
Next, you'll restore the image file to a blank disk.
Use dd to copy the image file to the disk:
dd if=/tmp/disk.img of=/dev/fd0 bs= 1k
This command reverses the flow of the data, whereas the command in step 2 created the image file.
Create the checksum for the duplicate disk:
md5sum /dev/fd0 > /tmp/duplicate-md5
Now, use cat to verify the accuracy of the duplicate disk by comparing the checksums of all three versions:
cat /tmp/*md5
Test MD5 against an altered image file. Do this by first adding a single byte of data to the image file:
echo x >> /tmp/disk.img
Then, create a new checksum for the image file:
md5sum /tmp/disk.img > /tmp/corrupt-md5
Finally, compare the checksums for each step of this exercise:
cat /tmp/*md5
Note how a difference of only 1 byte causes the MD5 to change drastically. This demonstrates the value of using and checking the MD5 signatures of files when downloading them from the Internet.
*Taken from http://www.informit.com/articles/article.aspx?p=27203&seqNum=3
Saturday, November 22, 2008
Computer Privacy Annoyances (Dan Tynan)
Friday, September 12, 2008
MS SQL
DECLARE @AuthorID char(11)
DECLARE c1 CURSOR READ_ONLY
FOR
SELECT au_id
FROM authors
OPEN c1
FETCH NEXT FROM c1
INTO @AuthorID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @AuthorID
FETCH NEXT FROM c1
INTO @AuthorID
END
CLOSE c1
DEALLOCATE c1
Select "insert name,age,address value('" & vname &... & "')"
Sunday, September 7, 2008
Linux Run Levels
By Joshua Erdman
Digital Foundation, inc.
Linux has 7 different run levels (or operating modes):
rc0.d - System Halted
rc1.d - Single User Mode
rc2.d - Single User Mode with Networking
rc3.d - Multi-User Mode - boot up in text mode
rc4.d - Not yet Defined
rc5.d - Multi-User Mode - boot up in X Windows
rc6.d - Shutdown & Reboot
Each mode has it's own list of settings for what services to start and what services to shutdown. Not only does this list contain what is supposed to be running, but also what order each service should be started in - a feature many Linux lovers like to point out that Windows lacks..
chkconfig - will list all the registered services and display thier status at each different run level.
Most of the time when your server boots up it will start in runlevel 3 or 5 depending on what it is set to. This setting can be found in the file /etc/inittab
If you ever want to change what mode your server defaults to on bootup, just edit that file, but NEVER change it to runlevel 6 or 0. This will cause your server to shutdown on bootup or if you set it to runlevel 6 it will continuously reboot. I guess this could make a great prank on a friend's workstation.
RC.D Directory Explanation
In the folder: /etc/rc.d are all the run level folders starting from rc1.d to rc6.d and including init.d
It is in each of these rc#.d folders where the service run settings are kept. If you change directory into /etc/rc.d/rc3.d all the files that start with a capital S are the services that will start at this runlevel. All the files that start with a K are the services that will be killed at that runlevel.
The reason why services that are not supposed to run are still listed is because it is popular to switch a server from one run level to another instead of just booting into the needed run level. That way you can take your server offline (single user mode) and then apply a patch or do a file restore.
Let's take a closer look at these files that are inside the rc#.d folders. Notice that they are symbolic links to the script file located in /etc/rc.d/init.d This makes things very easy. All the commands to start, stop, or reload a service are handled by these scripts. So when a server is to go into a specific run level it can find the correct script and knows whether to start it based on its name and link path.
*we can easily change root password by running in single user mode
Boot Linux into single-user mode
Reboot the machine.
Press the ESC key while GRUB is loading to enter the menu.
If there is a 'recovery mode' option, select it and press 'b' to boot into single user mode.
Otherwise, the default boot configuration should be selected. Press 'e' to edit it.
Highlight the line that begins with 'kernel'. Press 'e' again to edit this line.
At the end of the line, add an additional parameter: 'single'. Hit return to make the change and press 'b' to boot.
Change the admin password
The system should load into single user mode and you'll be left at the command line automatically logged in as root. Type 'passwd' to change the root password or 'passwd someuser' to change the password for your "someuser" admin account.
Tuesday, July 1, 2008
Wednesday, June 25, 2008
Virtual Hosts on Apache2
Example of content of the /etc/apache2/sites-available/www.example.com
#
# Example.com (/etc/apache2/sites-available/www.example.com)
#
ServerAdmin webmaster@example.com
ServerName www.example.com
ServerAlias example.com
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/www/www.example.com/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.example.com/cgi-bin/
Options +ExecCGI
# Logfiles
ErrorLog /home/www/www.example.com/logs/error.log
CustomLog /home/www/www.example.com/logs/access.log combined
Lastly, run (sudo) a2ensite www.example.com
Restart Apache2 and test out the URL.
#ref: http://www.debian-administration.org/articles/412
Wednesday, June 18, 2008
FTP and SFTP
sudo apt-get install proftpd gproftpd
*gproftpd is the GUI module for proftpd
Configure the default ftp directory through
sudo gedit /etc/proftpd/proftpd.conf
This is basically the configuration file for proftpd. Reminder to check tie user login to their home directory if need be.
To enable anonymous / general login, need to setup a generic ftp login for all users of the system. *anonymous login does NOT require password. We can also the read and write permission for each directory in this file.
sudo /etc/init.d/proftpd restart
Access Control List for FTP
/etc/ftpusers
/etc/ftphosts
/etc/ftpaccess
*ftphosts -> can use ip domain range or *.domainname.com
Enhanced security. Since authentication protocol for FTP is in plaintext, we should enable TLS/SSH login through SFTP to encrypt username and passsword for ftp logins.
Reference
http://ubuntuforums.org/showthread.php?p=429783
Boot script sequence
1) /etc/lilo.conf
2) /etc/inittab
3) /etc
Boot sequence in Red Hat
boot/grub stuff
/etc/inittab
/etc/rc.sysinit script
/etc/init.d stuff ->rc0,rc1,rc2,rc3,etc..
/etc/rc.d/rc.local
Runlevel | Scripts Directory (Red Hat/Fedora Core) | State |
---|---|---|
0 | /etc/rc.d/rc0.d/ | shutdown/halt system |
1 | /etc/rc.d/rc1.d/ | Single user mode |
2 | /etc/rc.d/rc2.d/ | Multiuser with no network services exported |
3 | /etc/rc.d/rc3.d/ | Default text/console only start. Full multiuser |
4 | /etc/rc.d/rc4.d/ | Reserved for local use. Also X-windows (Slackware/BSD) |
5 | /etc/rc.d/rc5.d/ | XDM X-windows GUI mode (Redhat/System V) |
6 | /etc/rc.d/rc6.d/ | Reboot |
s or S | Single user/Maintenance mode (Slackware) | |
M | Multiuser mode (Slackware) |
After the runlevel script is done, the kernel will execute scripts in one of the following directories.
- /etc/rc.d/init.d/ (Red Hat/Fedora )
- /etc/init.d/ (S.u.s.e.)
- /etc/init.d/ (Ubuntu / Debian)
Adding a script to the /etc/rc.d/rc#.d/ directory with either an S or K prefix, adds the script to the boot or shutdown process. The scripts are run in numerical order. S20abc is run before S30xyz. The extensibility to the boot and shutdown procedures of the operating system is one of the strengths of UNIX. The orderly sequential initiation of processes can be coordinated for dependent processes. The orderly shutdown of processes is often required of complex programs such as databases. This is how it is done. Individual processes may be monitored, shutdown and started at any time using these scripts. i.e. /etc/rc.d/rc2.d/httpd start. The modifiers start, stop or status may be used.
The start/stop/status scripts actually reside in the directory:
- /etc/rc.d/init.d/ (Red Hat/Fedora)
- /etc/init.d/ (S.u.s.e. and Ubuntu / Debian)
The rc.local script is the last system script to be executed. This is equivalent to autoexec.bat in windows. This is where most of the customised commands/scripts are located.
Meaning, /etc/init.d is the central depository of all scripts.
Files in rc?.d are symbolic links to /etc/init.d.
Eg if runlevel 3 is selected, scripts in /etc/rc3.d which are symbolic links to scripts in /etc/init.d are executed.
Tuesday, June 17, 2008
Cron Jobs
1) Uncomment the #cron line in /etc/syslog.conf to enable cron logging
2) Restart sysklogd : sudo /etc/init.d/sysklogd restart
3) Add cron jobs through crontab -e
4) Restart cron : sudo /etct/init.d/cron restart
To disable email notification, redirect the output to /dev/null
0 3 * * * /root/backup.sh >/dev/null 2>&1
Special strings to substitute * * * * *
Special string | Meaning |
@reboot | Run once, at startup. |
@yearly | Run once a year, "0 0 1 1 *". |
@annually | (same as @yearly) |
@monthly | Run once a month, "0 0 1 * *". |
@weekly | Run once a week, "0 0 * * 0". |
@daily | Run once a day, "0 0 * * *". |
@midnight | (same as @daily) |
@hourly | Run once an hour, "0 * * * *". |
User crontabs are saved in
/var/spool/cron
*Cron status reporting
Set up Evolution to read mails sent by cron.
Create a new account and select "local delivery mails" from the dropdown box. This will enable Evolution to receive mails sent to /var/mail/
*cron commands are also logged in auth.log
Alternative to cron jobs
If a particular task needs to be schedule to be run once or a few times, an alternative solution would be to use the "at" command. This command basically allows the user to schedule a job at any particular time. Eg to send out an email at 4am next week.
at -f /home/user/atcommand -m now + 7 days
The f options tells the at command to run the content of a file (which is in a script format situated at /home/user/atcommand). The -m options will tell the system to send out an email (which contains the output of the command) to notify the user once the job is done and now + 7 days indicates that this job will be executed 7 days from now.
*make sure that there's either /etc/at.deny or /etc/at.allow file in your system. Else, onyl the root will be able to use the at command. These are basically ACL for at command.
You can query all at command jobs using atq and remove the jobs using atrm
Anacron for systems that are not up and running 24/7.
For each job, Anacron checks whether this job has been executed in the last n days, where n is the period specified for that job. If not, Anacron runs the job's shell command, after waiting for the number of minutes specified as the delay parameter.
After the command exits, Anacron records the date in a special timestamp file for that job, so it can know when to execute it again. Only the date is used for the time calculations. The hour is not used.
When there are no more jobs to be run, Anacron exits.
Only root can schedule anacron jobs. A way to enable other users to do so is by creating an anacron group and enable write permission for this group on /var/spool/anacron (where job timestamps are stored)
# run-parts /etc/cron.daily
"run-crons" executes all the scripts in the /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly, and /etc/cron.weekly directories.
*used to find files in directory that is messy, file criteria is *junk*
find /tmp -name '*junk*' -exec ls -l {} \;
To force anacron to be executed hourly, put a script which consist of the following in /etc/cron.hourly
/usr/sbin/anacron -s
Sunday, June 15, 2008
Installing PHP5
1) Start by selecting and installing your modules through the synaptic package manager.
OR by command line
sudo apt-get install php5 mysql phpmyadmin
*please install PHP5.gd is you intend to use drupal
2) To enable PHP5, sudo a2enmod PHP5 and restart apache2
3) Test whether php pages are parsed by entering http://localhost/ and click on phpadmin
4) If cannot access that page (greeted by save php or phtml page as) , then you need to edit /etc/apache2/apache2.conf
look for the line AddType ****
and add in "AddType application/x-httpd-php .php .phtml"
5) Restart apache2 and you should be able to access the phpmyadmin page
Unable to start in Linux GUI
1) At the GUI login , press Ctrl + Alt + F1 to login in terminal
2) Use df -h to check hard disk utilization information
3) Try deleting files in /home which you know can be deleted.
4) Try deleting files in /tmp
5) mount a USB drive and move some of your files in /home to the USB drive and delete them from the system.
Installing Apache 2 in Ubuntu Feisty
*Apache modules are reported not to work with Apache2 modules.
1) To uninstall Apache
sudo apt-get remove apache
*alternatively, this can be done through sypnatic package module
2) Update apt-get's package list
sudo apt-get update (to subscribe to updated packages)
3) Install Apache2
sudo apt-get install apache2
4) The system should print out a message saying that apache2 is running. To test,
type http://localhost/ in a browser. You should be able to see the apache-default folder.
5) If step 4 fails, check /etc/default/apache2
ensure that NO_START = 0 to enable apache2 to start at port 80.
It could be that NO_START = 1 if apache was installed in your system and prevented Apache2 from starting at port 80.
6) Restart apache2
sudo /etc/init.d/apache2 restart
* commands to clean up source codes / downloaded files which are no longer in used
sudo dpkg --purge apache apache2
Installation of Ubuntu in Vmware Fusion
5) Enter the following commands:
cd vmware-tools-distrib
./vmware-install.pl
*The default answers are all suitable - but the process takes out your network connection.
./vmware-config-tools.pl.
6) When prompted to enter password when executing sudo commands, enter the admin's (usually the first user registered in Ubuntu) password and NOT the root password.
7) Root password can be set in System / Administration / Users and Groups in the GUI.