<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
<channel>
<title>"ServermonitoringHQ Posts"</title>
<link>
http://servermonitoringhq.com/blog/rss
</link>
<description>"ServermonitoringHQ Posts"</description>
<item>
<title>
How to check if your server has been hacked
</title>
<link>
http://servermonitoringhq.com/blog/how_to_check_if_your_server_has_been_hacked
</link>
<description>
<p>I've split this article into compromise hacks (i.e. rootkit attacks) which are relatively easy to detect and application compromises which can be more subtle.</p>
<p>
<strong>UPDATE:</strong>
After a
<a href='http://www.webhostingtalk.com/showthread.php?t=1140630'>discussion</a>
about the article on WebHostingTalk I've incorporated a few great suggestions.
</p>
<br />
<h2>Root compromises.</h2>
<p>This means someone has full access to the system, here are the tell tale signs in order of most likely to give you a quick feel for what's going on.</p>
<h3>1. Have a look for system files that have changed recently</h3>
<p>This is the first thing I would do.</p>
<pre>find /etc /var -mtime -2</pre>
<p>The "-2" means 2 days, i.e. show me all files modified in the last 2 days.</p>
<p>Now if you haven't installed any new software on your server for a while then this command will run and produce very little output. For a server I investigated there were references to postfix. clearly someone had installed a mail server probably for sending spam.</p>
<h3>2. Run who</h3>
<pre>who  &#x000A;&#x000A;user1 pts/2        2012-03-28 13:38 (128.114.44.209)&#x000A;</pre>
<p>This should give you a list of users on the system, what you're looking for is users other than yourself especially root.</p>
<h3>3. History</h3>
<pre>history</pre>
<p>Login as root and run history, this will give you a list of recently run commands. If you're the only person who logs in as root you should have an idea if anything looks suspicious or not.</p>
<h3>4. Netstat</h3>
<p>It's a good idea at this point to see what processes are running on which ports.</p>
<pre>netstat --listen -A inet   &#x000A;&#x000A;tcp 0 0 *:64010 *:* LISTEN&#x000A;tcp 0 0 *:http-alt *:* LISTEN &#x000A;tcp 0 0 *:ssh *:* LISTEN &#x000A;tcp 0 0 *:https *:* LISTEN &#x000A;</pre>
<br />
<h2>Application Breaches</h2>
<p>An example of an application breach might be a shopping cart that allows file uploads these uploads can be executed as say PHP scripts (This happened with oscommerce). The attacker doesn't have root access but they can certainly use up resources.</p>
<h3>5. High load and Memory.</h3>
<p>Sudden spikes in memory and load usage are an indication of possible root breaches but sometimes the only indication an application has been breached.</p>
<p>If you're a ServerMonitoringHQ.com user then you'll receive notifications of CPU and Memory spikes. (Along with bandwidth and more).</p>
<p>You can use the following command to track load (CPU usage). Generally values over 1 indicate the CPU is getting used quite hard.</p>
<pre>cat /proc/loadavg&#x000A;&#x000A;0.04 0.35 0.26 1/83 27412  &#x000A;</pre>
<p>
The first column
<code>0.04</code>
is the number to look at
</p>
<h3>6. Top</h3>
<p>
The
<code>top</code>
command is a quickly way to see what processes are consuming resources.
</p>
<img src='http://4.bp.blogspot.com/_29yMocwFCms/ScWvwQ0PeBI/AAAAAAAAAKY/LPaU2AgemF4/s320/Picture+41.PNG' />
<h3>7. Bandwidth Spikes</h3>
<p>As with process and memory if you don't know what you normally consume it's difficult to tell if you get a spike or not.</p>
<pre>netstat -i &#x000A;Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR &#x000A;eth0 1500 0 2937582 0 0 0 3127979 0 0 0 BMRU &#x000A;lo 16436 0 531312 0 0 0 531312 0 0 0 LRU &#x000A;</pre>
<p>The larger numbers for TX and RX are bytes transferred (roughly), run this twice, a minute apart will give you an indication of bandwidth transfer per minute.</p>
<h3>And finally, good luck.</h3>
<p>We've all been there, best of luck getting your server up and running again.</p>

</description>
<guid>
http://servermonitoringhq.com/blog/how_to_check_if_your_server_has_been_hacked
</guid>
</item>
<item>
<title>
How to quickly stress test a web server
</title>
<link>
http://servermonitoringhq.com/blog/how_to_quickly_stress_test_a_web_server
</link>
<description>
<p>
The
<a href='http://curl.haxx.se/docs/manpage.html'>Curl</a>
syntax allows you to specify sequences and sets of URL's.
Say for example we're going to run a load stress test against Google
we can run...
</p>
<pre>curl -s "http://google.com?[1-1000]"</pre>
<p>
This will make 1000 calls to google i.e.
</p>
<pre>http://google.com?1  &#x000A;http://google.com?2  &#x000A;http://google.com?3 &#x000A;\... &#x000A;http://google.com?1000&#x000A;</pre>
<p>
So say you want to stress test your web application and it won't complain if
it's fed an extra parameter, 10,000 calls could be done something like.
</p>
<pre>curl -s "http://yourappp.com/your_page_to_test.php?[1-10000]"</pre>
<h3>Multiple Pages</h3>
<p>
Easy just add each page to the command line.
</p>
<pre>curl -s "http://yourapp.com/page1.php?[1-1000]" "http://yourappp.com/page2.php?[1-1000]"</pre>
<p>Or even...</p>
<pre>curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]"</pre>
<h3>Timing</h3>
<p>
Using the
<a href='http://unixhelp.ed.ac.uk/CGI/man-cgi?time'>time</a>
command we can get a view on our performance
</p>
<pre>time curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]"  &#x000A;&#x000A;real 0m0.606s &#x000A;user 0m0.009s &#x000A;sys 0m0.008s &#x000A;</pre>
<h3>Simulating consecutive users</h3>
<p>
OK, this is great for sending a whole bunch of calls one after the other but
what about simultaneous calls.  For this we can place the Curl calls in a
script and set them running in the background.  i.e. my_stress_test.sh
</p>
<pre>curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!" &#x000A;curl -s "http://yourapp.com/page{1, 2}.php?[1-1000]" &amp;&#x000A;pidlist="$pidlist $!"  &#x000A;&#x000A;for job in $pidlist do &#x000A;  echo $job     &#x000A;  wait $job || let "FAIL+=1" &#x000A;done  &#x000A;&#x000A;if [ "$FAIL" == "0" ]; then &#x000A;  echo "YAY!" &#x000A;else &#x000A;  echo "FAIL! ($FAIL)" &#x000A;fi&#x000A;</pre>
<p>
Then run
<code>time my_stress_test.sh</code>
</p>
<h3>
Caveats
</h3>
<p>
This does not simulate user behaviour exactly as the browser is not only
downloading the page but all attached images, javascripts, stylesheet etc.
You could simulate this too by adding the URL's to the url command.
</p>

</description>
<guid>
http://servermonitoringhq.com/blog/how_to_quickly_stress_test_a_web_server
</guid>
</item>
<item>
<title>
How to keep a job running in Linux
</title>
<link>
http://servermonitoringhq.com/blog/how_to_keep_a_job_running_in_linux
</link>
<description>
<p>There are many ways to keep a process running on linux but I haven't seen any that are as easy to implement as the script below.</p>
<p>
Basically the script does a
<code>ps ax</code>
and then a
<code>grep</code>
for your process. If it's not running it will re-start the process.
</p>
<p>
You install the script into your crontab i.e.
<code>crontab -e</code>
</p>
<p>As a bonus this mechanism will re-start your process after a re-boot.</p>
<h3>Edit your crontab</h3>
<p>
Cut and paste the following code into your crontab.
</p>
<pre>*/5 * * * * /home/path_to_the_script/make-run.sh</pre>
<p>
Make sure the cron entry is pointing to where your make-run.sh is located.
</p>
<h3>The Bash script</h3>
<pre>#!/bin/bash &#x000A;# make-run.sh &#x000A;# make sure a process is always running.  &#x000A;# Add the following to the crontab (i.e. crontab -e)&#x000A;# */5 * * * * /home/path_to_make_run/make-run.sh&#x000A;&#x000A;process=servermonitoringhq &#x000A;makerun="/home/path_to_the_job_you_want_running/runjob.sh"  &#x000A;&#x000A;if ps ax | grep -v grep | grep $process &gt; /dev/null         &#x000A;then                 &#x000A;  exit         &#x000A;else         &#x000A;  $makerun &amp;&#x000A;fi &#x000A;</pre>
<p>
Test the script on it's own first to make sure it starts your job.
</p>

</description>
<guid>
http://servermonitoringhq.com/blog/how_to_keep_a_job_running_in_linux
</guid>
</item>
<item>
<title>
The Ultimate Web Based IDE
</title>
<link>
http://servermonitoringhq.com/blog/the_ultimate_web_based_ide
</link>
<description>
<div class='kicker'>
<p>
For those pressed for time the ultimate
<strong>online web IDE</strong>
is a combination of
<a href='http://code.google.com/p/shellinabox/'>Shellinabox</a>
,
<a href='http://en.wikipedia.org/wiki/GNU_Screen'>GNU Screen</a>
and
<a href='http://en.wikipedia.org/wiki/Vim_%28text_editor%29'>Vim</a>
.
</p>
<p>
If you've got a bit more time read on, find out why a solution for quick fixes has turned into to my favourite way to code.
</p>
</div>
<p>
<img alt="shellinabox" height="587" src="/assets/blog/shellinabox.png" width="650" />
</p>
<h2>A basic development iteration</h2>
<p>
I'm usually developing the following repeatedly through development/maintenace of a Ruby on Rails application.
</p>
<ol>
<li>Have 1 tab open in firefox with shellinabox and make file edits using Vim.</li>
<li>Have another open tab in firefox with my application running and test the changes.</li>
<li>Repeat the first 2 steps until the fix is ready.</li>
<li>Run the unit tests</li>
<li>If all is OK commit changes to git.</li>
<li>Push changes to production which in my case is Heroku.</li>
</ol>
<p>
Using Vim, screen and shellinabox I can run through this cycle quickly. After a while I realised that coding through the browser was no slower than coding in an IDE.
</p>
<p>
I also like the idea of being able to pick up from where I left off whilst moving from one computer to another.
</p>
<p>
I now code exclusively in VIM through shellinabox.
</p>
<h3>Setting up the IDE</h3>
Install shellinabox. I'm on debian so I used
<a href='http://code.google.com/p/shellinabox/source/browse/trunk/INSTALL.Debian'>
Install shellinaox on debian.
</a>
I then point a subdomain to the shellinabox localhost url and port.
<br />
<br />
<script src='https://gist.github.com/864001.js?file=gistfile1.txt'></script>
Install screen - sudo apt-get install screen

</description>
<guid>
http://servermonitoringhq.com/blog/the_ultimate_web_based_ide
</guid>
</item>
<item>
<title>
Welcome To ServerMonitoringHQ
</title>
<link>
http://servermonitoringhq.com/blog/welcome_to_servermonitoringhq
</link>
<description>
<div class='kicker'>
<p>After 18months development I'm proud to announce ServerMonitoringHQ to the world. A hosted software as a service tool for monitoring servers.</p>
</div>
<h2>Why did I create ServerMonitoringHQ.</h2>
<p><span class='drop-cap'>A</span>fter running
<a href='http://status2k.com'>Status2K.com</a>
(a PHP script for server monitoring) for a few months I ran into a few issues. Mainly that it's hard to maintain and spot errors with a script running on someone else's servers.  And also that it's fustrasting to see copies of your script pirated on numerous file sharing sites.
</p>
<p>
So I wanted to create a hosted server monitoring and statistics solution. I looked at the other hosted solutions and most seem to concentrate on uptime, i.e. pinging servers or loading web pages. There are a few that gather statistics internally e.g. you install an agent on each of your servers. I decided to have an agent-less approach. So ServerMonitoringHQHQ can gather server statistics over SSH with nothing to install on your server. For those that don't want to give out SSH information you can also use the ServerMonitoringHQ agent script. The script gives a nice realtime web based statistics output. See the
<a href='http://servermonitoringhq.com/agent/'>ServerMonitoringHQ Agent</a>
</p>
<h2>About Me</h2>
<p>
I've been programming professionally since 1994 mainly for investment banks in London. I started out doing C and C++ for satellite communications companies before progressing onto Java. I installed Linux for the first time in 1996 and have been using a mixture and Windows and Linux on the server side throughout my career.
</p>
<p>
I've had numerous side projects throughout the years but ServerMonitoringHQ is the most viable and I'm going to spend a lot of time marketing this site and hopefully making it the best monitoring solution out there.
</p>
<h2>Technology</h2>
<p>
ServerMonitoringHQ is a
<a href='http://rubyonrails.org/'>Ruby on Rails</a>
application. After building sites in Java and PHP I've found Rails to be the most productive platform currently available.
</p>
<p>
The ServerMonitoringHQ Agent is a PHP application. PHP I believe is the most widely available scripting language on Linux so hopefully most people should find installation of the script trivial.
</p>
<p>
The site is hosted at
<a href='http://heroku.com'>Heroku</a>
which provides me with the ability to scale the site if required quite quickly. I actually have 4 applications installed at heroku to support this site.
</p>
<ol>
<li>This blog which is a basic rack application where I edit the posts by hand coding HAML pages with Vim.</li>
<li>
The application itself, i.e. all the screens and data collection.
<a href='http://servermonitoringhq.com'>ServerMonitoringHQ.com</a>
</li>
<li>
<a href='https://github.com/blog/542-introducing-resque'>Resque</a>
A queue for background jobs with a nice front end with live statistics.
</li>
<li>
A customised version of
<a href='http://fatfreecrm.com'>Fat Free CRM</a>
with which I handle all customer interaction and which I'll extend to provide
a TenderApp style support channel.
</li>
</ol>
<h2>Credits</h2>
<p>
I'd like to give credit to the guys over at the
<a href='http://www.micropreneur.com'>Micropreneur Academy</a>
the information from there has shaped a lot of what you see here.
</p>

</description>
<guid>
http://servermonitoringhq.com/blog/welcome_to_servermonitoringhq
</guid>
</item>
</channel>
</rss>
