Gettin’ hacked…

This server got hacked. It was used as a scanner for a couple days, attempting to break into other servers to test for vulnerabilities. I only discovered this because I attempted to access this server by the .onion domain that I have for it and it didn’t connect.

I’ve had a home server hacked before due to a user account with a I set up for my son with “an easy” password. I thought I learned that lesson. Apparently I did not with the server I have exposed to the interwebs.

Time to forensically breakdown the timeline of events.

Read More

Today I learned: command > script

Had to compare two files at work today. Actually, I had to compare one file to a series of files to see what data exists in both of them. This technically comes down to a LEFT JOIN where we only want left column data when it exists in the right column.

So, in writing a script in PHP it comes down to:

<?php
ini_set('MEMORY_LIMIT', '256M');
if (!file_exists($argv[1])) { die('file ' . $argv[1] . ' not found'); }
if (!file_exists($argv[2])) { die('file ' . $argv[2] . ' not found'); }
$fp = fopen($argv[1], 'rt');
$lines = [];
do {
  $line = trim(fgets($fp));
  if (strlen($line) > 0) {
    $lines[] = $line;
  }
} while (!feof($fp));
fclose($fp);
$fp = fopen($argv[2], 'rt');
do {
  $line = trim(fgets($fp));
  if (strlen($line) > 0) {
    if (in_array($line, $lines)) {
      echo "$line\n";
    }
  }
} while (!feof($fp));
fclose($fp);

This script, albeit working like a charm, takes a while with large amounts of records.

After some googling this script isn’t really necessary if you use grep correctly. You also gain the speed of an executable in one fell swoop.

$ grep -Fxf [file1] [file2]

Output is exactly the same.