LAMP on debian (ubuntu mint etc) One line install
![]()
Installing a LAMP stack on deb has never been easier!
sudo tasksel install lamp-server

Speed up apt-get with axel and apt-fast.
Web Upd8 has a nice article on a bash script by Matt Parnell that uses axel to increase the speed of apt-get updates. Basically, install axel then use this script instead of apt-get:
#!/bin/sh #apt-fast by Matt Parnell http://www.mattparnell.com , this thing is FOSS #please feel free to suggest improvements to admin@mattparnell.com # Use this just like apt-get for faster package downloading. Make sure to have axel installed #If the first user entered variable string contains apt-get, and the second string entered is either install or dist-upgrade if echo "$1" | grep -q "[upgrade]" || echo "$2" | grep -q "[install]" || echo "$2" | grep -q "[dist-upgrade]"; then echo "Working..."; #Go into the directory apt-get normally puts downloaded packages cd /var/cache/apt/archives/; #Have apt-get print the information, including the URI's to the packages apt-get -y --print-uris $1 $2 $3 $4 > debs.list; #Strip out the URI's, and download the packages with Axel for speediness egrep -o -e "(ht|f)tp://[^\']+" debs.list | xargs -l1 axel -a; #Perform the user's reqested action via apt-get apt-get -y $1 $2 $3 $4; echo "Done! Make sure and check to see that the packages all were installed properly. If a package is erred, run sudo apt-get autoclean and try installing it again without the use of this script."; elif echo "$1" | grep -q "[*]"; then apt-get $1; else echo "Sorry, but you appear to be entering invalid options. You must use apt-get and one of apt-get's options in order to use this script."; fi

BASH case insensitive path checking. (effificently)
I needed to check some paths for files. I have a script that calls a copy function on some files that were previously mounted on a case insensitve system. I couldn't find anything, so instead of using `find -i` which would be a resource hog i wrote this: -
#!/bin/bash
old_IFS=$IFS
if ! [ -a $1 ]; then
trypath=""
path=""
IFS=$'/'
for i in $1; do
trypath=$path$i"/"
if [[ -a $trypath ]]; then
path=$trypath
else
ipath=`ls "$path" | grep -i $i`
path=$path$ipath"/"
fi
done
echo "$path"
else
echo "exists"
fi
IFS=$old_IFS
Spamassasin sa-learn automatic from exchange mailbox
I needed a script to auto bayes learn spam, there were a couple out there, but all old, and none of them did imaps, which is what exchange needs. So herre you go:
#!/usr/bin/perl
#
# 20081006
# from flipsidereality.com
#
# script to pull spam and ham from exchange by imaps, push it through sa-learn, and then delete it from the exchange server.
use Mail::IMAPClient;
use IO::Socket::SSL;
my $debug=0;
my $salearn;
# Define our server and credentials here
my $username = 'XXXXXX';
my $password = 'xxxxxxxx';
my $server = 'imaps.mail.server';
my $spam_folder = 'bySPAM';
my $ham_folder = 'byFALSE_POSITIVE';
my $amavis_user = 'amavis'; # User to run sa-learn in the context of,
# Open an SSL session to the IMAP server
# Handles the SSL setup, and gives us back a socket
my $ssl=new IO::Socket::SSL("$server:imaps");
die ("Error connecting - $@") unless defined $ssl;
$ssl->autoflush(1);
# Initialise the IMAP object
# Annoyingly, when giving it a Socket, it won't do the initial IMAP
# welcome stuff, so we have to do that ourselves a little later on
my $imap=Mail::IMAPClient->new(
Socket => $ssl,
Debug => $debug,
User => $username,
Password => $password,
Peek => 0
);
# Tell Mail::IMAPClient we're connected
$imap->State(Mail::IMAPClient::Connected);
# Get the IMAP Server to the point of accepting a login prompt
# Basically, we skip over the welcome messages until at the OK stage
my ($code, $output) = ("","");
until ( $code ) {
$output = $imap->_read_line or return undef;
for my $o (@$output) {
$imap->_debug("Connect: Received this from readline: ".join("/",@$o)."\n");
$imap->_record($imap->Count,$o); # $o is a ref
next unless $o->[Mail::IMAPClient::TYPE] eq "OUTPUT";
($code) = $o->[Mail::IMAPClient::DATA] =~ /^\*\s+(OK|BAD|NO)/i ;
}
}
# Did we get an OK welcome back?
if ($code =~ /BYE|NO /) {
$imap->State("Unconnected");
die "IMAP server disconnected";
}
# Now, have Mail::IMAPClient send the login for us
$imap->login;
if (!defined($imap)) { die "IMAP Login Failed"; }
# If debugging, print out the total counts for each mailbox
if ($debug) {
my $spamcount = $imap->message_count($spam_folder);
print ">>> ", $spamcount, " $spam_folder to process <<<\n";
my $nonspamcount = $imap->message_count($ham_folder);
print ">>> ", $nonspamcount, " $ham_folder to process <<<\n" if $debug;
}
# Process the spam mailbox
$imap->select($spam_folder);
my @msgs = $imap->search("ALL");
for (my $i=0;$i <= $#msgs; $i++)
{
# I put it into a file for processing, doing it into a perl var & piping through sa-learn just didn't seem to work
$imap->message_to_file("/tmp/salearn",$msgs[$i]);
# execute sa-learn w/data
if ($debug) { $salearn = `su $amavis_user -c '/usr/bin/sa-learn -D --no-sync --showdots --spam /tmp/salearn'`; }
else { $salearn = `su $amavis_user -c '/usr/bin/sa-learn --no-sync --showdots --spam /tmp/salearn'`; }
print "-------\nSpam: ",$salearn,"\n-------\n" if $debug;
# delete processed message
$imap->delete_message($msgs[$i]);
unlink("/tmp/salearn");
}
$imap->expunge();
$imap->close();
# Process the not-spam mailbox
$imap->select($ham_folder);
my @msgs = $imap->search("ALL");
for (my $i=0;$i <= $#msgs; $i++)
{
$imap->message_to_file("/tmp/salearn",$msgs[$i]);
# execute sa-learn w/data
if ($debug) { $salearn = `su $amavis_user -c '/usr/bin/sa-learn -D --no-sync --showdots --ham /tmp/salearn'`; }
else { $salearn = `su $amavis_user -c '/usr/bin/sa-learn --no-sync --showdots --ham /tmp/salearn'`; }
print "-------\nNotSpam: ",$salearn,"\n-------\n" if $debug;
# delete processed message
$imap->delete_message($msgs[$i]);
unlink("/tmp/salearn");
}
$imap->expunge();
$imap->close();
$imap->logout();
# integrate learned stuff, but only if there was something to integrate.
if ("$salearn" =~ m/Learned/gi )
{
my $sarebuild = `su $amavis_user -c '/usr/bin/sa-learn --sync'`;
print "-------\nSync: ",$sarebuild,"\n-------\n" if $debug;
}
Recursive unrar unzip perl script
It's a bit hacky, but it works.
#!/usr/bin/perl
use File::Find;
use File::Spec;
if (@ARGV[0] eq '')
{
print "useage: $0 foldername\n";
}
else
{
print "Exctacting for folder ". $ARGV[0] ."\n";
find ( \&extract_dir , @ARGV[0]);
print (++$n,": $_\n") foreach (@elist) ;
}
exit;
sub extract_dir
{
next if -d $_;
next if /^\./;
my $ff = $File::Find::name;
# deal with RAR files
unrar($_,$ff);
#deal with ZIP files
if ($ff =~ /\.zip$/i )
{
print "unzip $ff";
system ('unzip','-qq', "$_");
if ($? != 0)
{
push (@elist, $ff);
}
else
{
print "\nrm -f $ff\n";
system ('rm', '-f', $_);
}
}
}
sub unrar
# takes filename, full filename
{
if ($_[0] =~ /\.rar$/i)
{
if ($_[0] =~ /\.part[0-9]+?\.rar$/i)
{
if ($_[0] =~ /\.part[0]+?1\.rar$/i)
{
print "unrar x $_[1] \n";
system ('unrar','x','-y','-inul', "$_[0]");
if ($? != 0)
{
push (@elist, "$_[1]");
}
else
{
my $todel = $_[0];
$todel =~ s/\.part[0]+?1\.rar$/\.part*\.rar/g ;
print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
system ("find ./ -name \"$todel\" -exec rm {} \\\;");
}
}
}
else
{
print "unrar x $_[1] \n";
system ('unrar','x','-y','-inul', "$_[0]");
if ($? != 0)
{
push (@elist, "$_[1]");
}
else
{
my $todel = $_[0];
$todel =~ s/\.rar$/\.r*/g ;
print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
system ("find ./ -name \"$todel\" -exec rm {} \\\;");
}
}
}
}
Silent remove windows search 3 script
OK, so we got hit with the windows search wsus thing, M$ have said sorry, but dont offer a way to rid yourselves of the thing, so here it is:
' Filename: remove_win_search.vbs
' Date: 29 Oct 2007
' Desc: Removes windows search 3 as installed by default by WSUS (KB917013)
Dim fso
Dim objWSHShell
set fso = Wscript.CreateObject("Scripting.FileSystemObject")
if fso.FileExists("c:\windows\$NtUninstallKB917013$\spuninst\spuninst.exe") then
Set objWSHShell = WScript.CreateObject("WScript.Shell")
objWSHShell.Run "c:\windows\$NtUninstallKB917013$\spuninst\spuninst.exe /q /norestart", 0, true
end if
PHP Tor Wrapper
Shamelessly stolen from 0x000000.com. This PHP
function creates a socket connection through Tor and is able to make a
perfect HTTP request that goes through the Tor network. Usually people
use Firefox with FoxyProxy or the Torbutton, but sometimes you'll need
scripts that can access other sites through the Tor router, and this is
a PHP script that does just that. Pretty simple, but effective.
What you need further:
- Install Tor and Privoxy bundle.
- Have PHP, like the WAMP server.
That's it, plug it into your exploits or test scripts and you can call
all your scripts through the Tor router now, and thereby be a little
safer instead of using bad proxies.
<?phpfunction tor_wrapper($url){
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
# Tor address & port
$tor = '127.0.0.1:9050';
# set a timeout.
$timeout = '300';
$ack = curl_init();
curl_setopt ($ack, CURLOPT_PROXY, $tor);
curl_setopt ($ack, CURLOPT_URL, $url);
curl_setopt ($ack, CURLOPT_HEADER, 1);
curl_setopt ($ack, CURLOPT_USERAGENT, $agent);
curl_setopt ($ack, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ack, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ack, CURLOPT_TIMEOUT, $timeout);
$syn = curl_exec($ack);
# $info = curl_getinfo($ack);
curl_close($ack);
# $info['http_code'];
return $syn;}
# example:
$wrapped = tor_wrapper("http://www.sillysite.com?page=1' OR 1=1");
echo $wrapped;?>
Windows Text Editors
Text editors. Everyone has their favourites. I have been using notepad++ for years now, and saw no reason to change. I used to use editpad pro, but it isn't free so i can't use it at work (it's regex support is excellent though). I have recently stumbled upon crimson editor, and am sad to say that it actually made me quite excited. It seems to have all the functionality of a basic IDE, certainly all I need for my basic hacking around with perl and php. It supports regex and has a cool built in calculator (type 8+4 and press ctrl+enter). It also has a built in file browser and project management pane, as well as being able to capture output from your scripts.
I think i am a convert
Batch renaming of files by extension (bash)
OK, lots of links on google, but none for doing what i want. I need to move some files like so '12%2012%20EE' >>> '12 12 EE' but i ended up ls > files.txt and editing a script in excel... Not very professoinal.
I subsequently found this:
# change .htm files to .htmlfor file in *.htm ; do mv $file `echo $file | sed 's/\(.*\.\)htm/\1html/'` ; done # change .html files to .htmfor file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1htm/'` ; done #change .html files to .shtmlfor file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1shtml/'` ; done #change .html files to phpfor file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1php/'` ; done
or:
for i in * ; domv \"$i\" \"$i.mp3\"done
But i'm still not happy












