Hacked by Li


A tranche of daily Http: requests to my server, a peculiar block of chinese addresses and other IPs in my apache conf blacklist. These guys are fucking relentless.


Perl script scraping the Apache error logs and poking them into mysql using DBI:
#!/usr/local/bin/perl

##################################################
# Require DBI; Check caps of 'mysql' in your distro
##################################################
use DBI;
use DBD::MYSql;

##################################################
# PERL MODULES WE WILL BE USING
##################################################
$user      = "dbuser";
$pw        = "dbpassword";
$dsn       = "DBI:mysql:hitlist:localhost:3306";

##################################################
# PERL DBI:sql CONNECT
##################################################
$connect = DBI->connect( $dsn, $user, $pw )
  or die "Unable to connect: $DBI::errstr\n";

##################################################
# insert a beginning record in DB
##################################################
$query        = "INSERT INTO hits (date,hits) VALUES ('2011-09-18','0')";
$query_handle = $connect->prepare($query);
$query_handle->execute();

##################################################
# Hash Char Month to Numeric
##################################################
my %month = (
			  'Jan' => '01',
			  'Feb' => '02',
			  'Mar' => '03',
			  'Apr' => '04',
			  'May' => '05',
			  'Jun' => '06',
			  'Jul' => '07',
			  'Aug' => '08',
			  'Sep' => '09',
			  'Oct' => '10',
			  'Nov' => '11',
			  'Dec' => '12',
);

##################################################
# define some variables to control looping
##################################################
$hitcount    = 0;
$yesterday   = undef;
$lastlogdate = undef;
$today       = undef;

##################################################
# Fetch last log date and hits from Mysql DB
##################################################
$query        = "SELECT * FROM hits ORDER BY id DESC LIMIT 1";
$query_handle = $connect->prepare($query);
$query_handle->execute();
$query_handle->bind_columns( \$id, \$lastlogdate, \$lastlogdatehits );
$query_handle->fetch();

open( MYFILE, '/home/attila/error.log.1' );
while ()
{
	$longdate   = substr( "$_",      5, 20 );
	$word_month = substr( $longdate, 0, 3 );
	$number_month = $month{$word_month};          #Hash to mysql DATETIME
	$day          = substr( $longdate, 4, 2 );
	$year         = substr( $longdate, 16, 4 );
	$time         = substr( "$_", 12, 8 );
	$datetime = ( $year . "-" . $number_month . "-" . $day . " " . $time );
	$today    = ( $year . "-" . $number_month . "-" . $day );

	if ( "$_" =~ m/denied/ )
	{
		$hitcount = $hitcount + 1;
		if ( $today eq $lastlogdate )
		{
			$query =
"UPDATE hits SET hits = ($hitcount+$lastlogdatehits) WHERE id = $id";
			$query_handle = $connect->prepare($query);
			$query_handle->execute();
		}
	}
}
close(MYFILE);
$count    = 0;
$hitcount = 0;
$newday   = 0;
open( MYFILE, '/home/attila/error.log.1' );
while ()
{
	$count        = $count + 1;
	$longdate     = substr( "$_", 5, 20 );
	$word_month   = substr( $longdate, 0, 3 );
	$number_month = $month{$word_month};          #Hash to mysql DATETIME
	$day          = substr( $longdate, 4, 2 );
	$year         = substr( $longdate, 16, 4 );
	$time         = substr( "$_", 12, 8 );
	$datetime = ( $year . "-" . $number_month . "-" . $day . " " . $time );
	$today    = ( $year . "-" . $number_month . "-" . $day );

	if ( $today ne $lastlogdate )
	{

		if ( ( $today ne $yesterday ) and ( $newday == 1 ) )
		{

			$query =
			  "INSERT INTO hits (date,hits) VALUES ('$yesterday','$hitcount')";
			$query_handle = $connect->prepare($query);
			$query_handle->execute();
			$hitcount = 0;
			if ( "$_" =~ m/denied/ )
			{
				$hitcount = 1;
			}

		} else
		{
			$newday = 1;
			if ( "$_" =~ m/denied/ )
			{
				$hitcount = $hitcount + 1;
			}
		}

	}
	$yesterday = $today;
}
$query        = "INSERT INTO hits (date,hits) VALUES ('$today','$hitcount')";
$query_handle = $connect->prepare($query);
$query_handle->execute();
close(MYFILE);

PHP rendering the chart using the JPGraph Libraries
    require_once ('/usr/share/jpgraph/jpgraph.php');
    require_once ('/usr/share/jpgraph/jpgraph_line.php');
    
    // Make a MySQL Connection
    mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    mysql_select_db("hitlist") or die(mysql_error());
    
    $datay1 = array();
    //$query = "SELECT * FROM hitlist";
    $result = mysql_query("SELECT * FROM hits") or die(mysql_error());
    while($row = mysql_fetch_array( $result )) {
    	$datay1[] = $row['hits'];
    }
    
    // Setup the graph
    $graph = new Graph(600,500);
    $graph->SetScale("textlin");
    $graph->img->SetAntiAliasing(false);
    $graph->title->Set('Filled Y-grid');
    $graph->SetBox(false);
    $graph->img->SetAntiAliasing();
    $graph->xgrid->Show();
    $graph->xgrid->SetLineStyle("solid");
    //$graph->xaxis->SetTickLabels(array('A','B','C','D'));
    $graph->xgrid->SetColor('#E3E3E3');
    
    // Create the first line
    $p1 = new LinePlot($datay1);
    $graph->Add($p1);
    $p1->SetColor("#6495ED");
    $p1->SetLegend('Line 1');
    
    // Output line
    $graph->Stroke();
teaserpic: 
James Horvath Gooey Website
James Horvath Gooey Oooey