Linux Showdown Day #6 Solution — The Final Showdown

by Dusty Jones


The Final Showdown

On day 6 we launched the Final Showdown. To get into this round, you had to finish in the top 15 in any of the previous days. This scenario had 2 seemingly simple task. The first was to rename a directory of e-reader files to a new naming convention, the second was to update the naming convention in the database. There were many ways to do these tasks, we saw for .. do loops in bash, awk scripts, at least one person installed php and scripted a solution. Only seven contestants finished the tasks correctly. The previous day's winners are mostly listed as DNF. Almost all issues encountered in this Final Showdown were the result of improper naming convention. Our grader script required strict adherence to the naming standards. In the rush to finish first, most participants misread the naming guidelines.

"thenaterator" held the number one spot on the leaderboard for most of the final day, only to be surpassed later in the day by "ubergeek03" who took the top spot with a time of 6 Minutes 52 seconds. DiablQ came in second place a mere second later at 6 Minutes 53 seconds.

Originally, I planed to solve this challenge with the perl rename command followed by a search and replace in the database. Most Linux distros include the perl rename command, but CentOS does not. Instead, we can use the included rename command to do the same in two steps. First, change book to e-book, then tackle the extension, we will use this same two-step technique on the database rows.

rename book e-book *.azw
rename .azw .tt *azw

Now rename the database to match, using the same two-step technique: base name, then extension.

mysql -u root -p******
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ereader |
| mysql |
| test |
+--------------------+
4 rows in set (0.04 sec)

mysql> use ereader;
Database changed

mysql> show tables;
+-------------------+
| Tables_in_ereader |
+-------------------+
| books |
+-------------------+
1 row in set (0.00 sec)

mysql> describe books;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| book | varchar(32) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> update books set book = replace(book, 'book', 'e-book');
mysql> update books set book = replace(book, '.azw', '.tt');

Thanks for following along with the SXSW Linux Showdown, we had a great deal of fun hosting this challenge. We hope to get the next round of challenges out to you soon.


Linux Showdown Day #5 Solution

by Dusty Jones


Day five's scenario tests your ability to use LVM to extend the primary partition onto an unallocated 200MB block in order to keep your job.  "jrenkin",  day two's winner, returned to the top spot with the respectable time of 89 seconds.

df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 20641404 1334240 18258648 7% /
tmpfs 250716 0 250716 0% /dev/shm
/dev/mapper/vg0-lv0_photos
99150 5664 88366 7% /var/www/photos

We want to extend the /dev/mapper/vg0-lv0_photos to use all unallocated space available. Before we can work on the partition we must unmount it. 

umount /var/www/photos

Now, we can go to work resizing the partition. We can use the command lvextend for this. lvextend requires a size, that is passed with -L484M.

lvextend
Please specify either size or extents but not both.
Run `lvextend --help' for more information.
lvextend /dev/mapper/vg0-lv0_photos -L484M

We've extended the partition and now need to resize the logical volume to make use of it, resize2fs requires the a file check before running, so lets run e2fsck on /dev/mapper/vg0-lv0_photos first.

resize2fs /dev/mapper/vg0-lv0_photos
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/vg0-lv0_photos' first.

e2fsck -f /dev/mapper/vg0-lv0_photos
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg0-lv0_photos: 14/25688 files (0.0% non-contiguous), 8914/102400 blocks

resize2fs /dev/mapper/vg0-lv0_photos

Re-mount /var/www/photos and run df to verify your work.

mount /var/www/photos/

df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 20641404 1334248 18258640 7% /
tmpfs 250716 0 250716 0% /dev/shm
/dev/mapper/vg0-lv0_photos
480399 6423 449196 2% /var/www/photos

Linux Showdown Day #4 Solution

by Dusty Jones


In day four, an intruder has installed a backdoor and is serving illegal programs from your server. You've got 20 minutes to remove the warez and close the backdoor. Day four's winner, who coincendentally won the first TrueAbility challenge in October, is a total linux badass kalemeow. Her time of 1 minute and 47 seconds secured her first place berth.

You can start the search for unauthorized users in /etc/passwd, the system database of users.

cat /etc/passwd
root:x:0:0:root:/root:/usr/local/bin/sudosh
...
p0wn3d:x:500:0::/home/p0wn3d:/bin/bash

The last entry <b>p0wn3d</b> looks interesting. You could try to delete the user with userdel.

userdel p0wn3d
userdel: user p0wn3d is currently logged in

Unfortunately the unauthorized user is still logged in, you will need to find any processes owned by the p0wn3d user.

ps auxwww
...
apache 13204 0.0 1.0 251848 5160 ? S 18:15 0:00 /usr/sbin/httpd
p0wn3d 13206 0.0 0.3 37008 1648 ? S 18:15 0:00 /usr/bin/ncat -e /bin/bash -l -p 3306 -t -k
root 13949 0.0 0.7 97864 3864 ? Ss 18:34 0:00 sshd: root@pts/0
...

Kill p0wn3d's 113206 process and delete the user.

kill -9 13206
userdel p0wn3d

Now remove the warez directory, frustratingly named -system, causing rm to treat it as a command line option.

cd /var/www/sxsw.maptheevent.com/
ls
index.php -system
rm -rf -system
rm: invalid option -- 's'
Try `rm ./-system' to remove the file `-system'.
Try `rm --help' for more information.

rm -rf ./system # or rm -rf -system
Comment

Linux Showdown Day #3 Solution

by Dusty Jones


Re-Election Pressure

The mayor is about to announce his re-election campaign--in twenty minutes--but his WordPress site isn't working. Now your job is on the line. Fix the site or find a new job. This scenario requires you to install a basic WordPress site.

My former colleague, a skilled break-fixer, Wade Minter took first place with a time of 2:54 minutes.

We left the files you need in /root/wpmigration. There is an archive file of the previous WordPress install, and a database dump. Extract the files from the archive to gain access to the previous WordPress installation.

cd /root/wpmigration
tar -zxf wordpress_site.tar.gz

The scenario provided the MySQL root user's password, along with the WordPress user's desired credentials. A quick mysql client command will setup access.

Create the WordPress database and configure access credentials using the scenario provided information.

mysql -u root -p ********
create database wpdatabase;
grant all on wpdatabase.* to 'wpadmin'@'localhost' identified by 'wppass';
flush privileges;
use wpdatabase;
source /root/wpmigration/wpdatabase.sql

Look at /etc/httpd/conf.d/blog.rivercityco.conf to determine document root, then copy the extracted files to the document root.

cat /etc/httpd/conf.d/blog.rivercityco.conf
<VirtualHost *:80>
ServerAdmin webmaster@rivercityco.net
ServerName blog.rivercityco.net
DocumentRoot /var/www/html/
DirectoryIndex index.php
</VirtualHost>
cp -r /root/wpmigration/wordpress_site/wordpress/ /var/www/html/

Restart Apache, and use wget, curl, or lynx to check your work.

service httpd restart
curl http://blog.rivercityco.net
...
<title>Mayor, Lee Leffingwell Blog | Building a Great Austin</title>
...