<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VirtualMinds &#187; Malware</title>
	<atom:link href="http://virtualminds.es/blog/index.php/category/malware/feed" rel="self" type="application/rss+xml" />
	<link>http://virtualminds.es/blog</link>
	<description>Think Virtually</description>
	<lastBuildDate>Mon, 07 Jun 2010 09:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using OSSEC &amp; SEC for Malware Detection</title>
		<link>http://virtualminds.es/blog/index.php/2010/03/using-ossec-sec-for-malware-detection.html</link>
		<comments>http://virtualminds.es/blog/index.php/2010/03/using-ossec-sec-for-malware-detection.html#comments</comments>
		<pubDate>Fri, 12 Mar 2010 18:07:25 +0000</pubDate>
		<dc:creator>Iñaki</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[OSSEC]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[virus]]></category>

		<guid isPermaLink="false">http://virtualminds.es/blog/?p=108</guid>
		<description><![CDATA[Hi all, this is my first english post so&#8230; excuse me I will try to show how we can use OSSEC and SEC for detect malware in our servers. We need a working installation of ossec (local or server mode), mhc, this small perl script and SEC. After installing (copy) mhc and the perl script [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all, this is my first english post so&#8230; excuse me <img src='http://virtualminds.es/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I will try to show how we can use OSSEC and SEC for detect malware in our servers.<br />
We need a working installation of <a href="http://www.ossec.net/main/downloads/">ossec</a> (local or server mode), <a href="http://code.google.com/p/virtualminds/downloads/list">mhc</a>, this <a href="http://www.virtualminds.es/uploads/scripts/sec-virustotal">small perl script</a> and <a href="http://simple-evcorr.sourceforge.net/">SEC</a>. After installing (copy) mhc and the perl script (do it in /usr/local/bin, for example), open a new file with your favorite text editor:</p>
<pre class="brush:plain">
#
# New syscheck event - Store agent name
#
type=Single
pattern= (\S+)->syscheck
ptype=regexp
desc=$0
action=create OSSEC_SYSCHECK; assign %agent $1

#
# Integrity checking - Store filename
#
type=Single
ptype=regexp
context=OSSEC_SYSCHECK
desc=$0
pattern=Integrity checksum changed for: '(\S+)'
action=assign %file $1;

#
# Integrity checking - New event for SingleWithScript (I can't use %vars with script directive)
#
type=Single
ptype=regexp
context=OSSEC_SYSCHECK
pattern=New md5sum is : '(\S+)'
desc=OSSEC: Filename: %file - md5sum: $1
action=event OSSEC: Filename: %file - md5sum: $1

#
# Integrity checking - Check againts Virustotal.com
#
type=SingleWithScript
desc=$0
ptype=regexp
context=OSSEC_SYSCHECK
pattern=^OSSEC: Filename: (\S+) - md5sum: (\S+)
script=/usr/local/bin/sec-virustotal $2 $1
action=none
action2=eval %a \
({	use Sys::Syslog; \
	openlog('sec-virustotal','','user'); \
	syslog('info', "%agent: File %file ($1) is tagged as VIRUS by virustotal.com"); \
	closelog; \
	1;  \
};); delete OSSEC_SYSCHECK
</pre>
<p>Save this file under /etc/sec directory (I used ossec.sec as filename). Then we must define a new ossec rule:</p>
<pre class="brush:plain">
<rule id="100002" level="12">
<program_name>sec-virustotal</program_name>
	<match>VIRUS</match>
	<description>Virus Found!!</description>
</rule>
</pre>
<p>Be sure to use an unused id for your new rule. You can add a group directive for correlating with another event if you want. Before start SEC, we can change sec-virustotal script to scan only those files with a desired extension:</p>
<pre class="brush:perl">
#!/usr/bin/perl

use strict;
my $virus_script = '/usr/local/bin/mhc';
my @extensions = qw/exe dll/; # Use * for all extensions
my $filename;
my $hash;
my $ext;
my @tmp;

if($#ARGV != 1) {
    print "usage: $0 md5hash filename\n";
    exit 100;
}

$filename = $ARGV[1];
$hash = $ARGV[0];
my @tmp=split(/\./,$filename);
$ext = lc($tmp[$#tmp]);

foreach (@extensions) {
    if($ext eq $_ || $_ eq '*') { # Extension found, scanning...
        my $res = qx/$virus_script --hash $hash --no-cache/;
        exit ($? >> 8);
    }
}
exit 0;
</pre>
<p>We can change @extensions variable to scan &#8216;.scr&#8217; files, for example. Now we have our new rule, restart ossec and launch SEC:</p>
<pre class="brush:plain">
 # /var/ossec/bin/ossec-control restart
 # /usr/bin/perl -w /usr/bin/sec -conf=/etc/sec/ossec.sec -quoting -input=/var/ossec/logs/alerts/alerts.log -detach
</pre>
<p>I leave to the reader the step of launching SEC at startup. But for Debian edit /etc/default/sec:</p>
<pre class="brush:plain">
#Defaults for sec
RUN_DAEMON="yes"
DAEMON_ARGS="-conf=/etc/sec/ossec.sec -input=/var/ossec/logs/alerts/alerts.log -pid=/var/run/sec.pid -detach -quoting"
</pre>
<p>I hope you find this useful. </p>
]]></content:encoded>
			<wfw:commentRss>http://virtualminds.es/blog/index.php/2010/03/using-ossec-sec-for-malware-detection.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Malware Hash Checker</title>
		<link>http://virtualminds.es/blog/index.php/2009/12/malware-hash-checker.html</link>
		<comments>http://virtualminds.es/blog/index.php/2009/12/malware-hash-checker.html#comments</comments>
		<pubDate>Mon, 07 Dec 2009 17:29:53 +0000</pubDate>
		<dc:creator>Iñaki</dc:creator>
				<category><![CDATA[Malware]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[virus malware mhc]]></category>

		<guid isPermaLink="false">http://virtualminds.es/blog/?p=97</guid>
		<description><![CDATA[Buenas a todos/as, he creado una versión del script que consulta virustotal.com desde la línea de comando, aunque lo he diseñado para que pueda ir integrando otros buscadores. De esta idea, nace Malware Hash Checker. Podéis descargarlo desde http://code.google.com/p/virtualminds/ Espero vuestros comentarios y sugerencias]]></description>
			<content:encoded><![CDATA[<p>Buenas a todos/as,</p>
<p>he creado una versión del script que consulta virustotal.com desde la línea de comando, aunque lo he diseñado para que pueda ir integrando otros buscadores. De esta idea, nace Malware Hash Checker. Podéis descargarlo desde <a href="http://code.google.com/p/virtualminds/">http://code.google.com/p/virtualminds/</a></p>
<p>Espero vuestros comentarios y sugerencias</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualminds.es/blog/index.php/2009/12/malware-hash-checker.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Packers y Yara</title>
		<link>http://virtualminds.es/blog/index.php/2009/01/packers-y-yara.html</link>
		<comments>http://virtualminds.es/blog/index.php/2009/01/packers-y-yara.html#comments</comments>
		<pubDate>Sat, 31 Jan 2009 22:59:17 +0000</pubDate>
		<dc:creator>Iñaki</dc:creator>
				<category><![CDATA[Malware]]></category>

		<guid isPermaLink="false">http://virtualminds.es/wordpress/?p=19</guid>
		<description><![CDATA[Desde hace poco, estoy metiéndome un poco en el mundo del reversing, malware,&#8230; Y buscando, encontré una herramienta muy curiosa. Yara. Esta herramienta busca patrones en ficheros. Por defecto, no hay ninguno, por lo que cada cual tendrá que hacerse los suyos. Ahora mismo lo estoy usando para descubrir binarios empaquetados y para ello, recurrí [...]]]></description>
			<content:encoded><![CDATA[<p>Desde hace poco, estoy metiéndome un poco en el mundo del reversing, malware,&#8230; Y buscando, encontré una herramienta muy curiosa. <a href="http://code.google.com/p/yara-project/"  title="http://code.google.com/p/yara-project/">Yara</a>. Esta herramienta busca patrones en ficheros. Por defecto, no hay ninguno, por lo que cada cual tendrá que hacerse los suyos. Ahora mismo lo estoy usando para descubrir binarios empaquetados y para ello, recurrí a la lista de patrones de PEiD, que es pública.</p>
<p>Pero antes había que pasarla al formato de reglas de yara. Total, que recurrí a un pequeño script que hice. Os lo cuelgo por si a alguien le fuera de utilidad:</p>
<p><a href="http://virtualminds.es/uploads/scripts/yararules.pl"  title="http://virtualminds.es/uploads/scripts/yararules.pl">http://virtualminds.es/uploads/scripts/yararules.pl</a></p>
<p>Y el fichero de reglas:</p>
<p><a href="http://virtualminds.es/uploads/scripts/packers.sig.gz"  title="http://virtualminds.es/uploads/scripts/packers.sig.gz">http://virtualminds.es/uploads/scripts/packers.sig.gz</a> -> Fichero de reglas</p>
<p><a href="http://virtualminds.es/uploads/scripts/rules.db.gz"  title="http://virtualminds.es/uploads/scripts/rules.db.gz">http://virtualminds.es/uploads/scripts/rules.db.gz</a> -> Correspondencia con los packers</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualminds.es/blog/index.php/2009/01/packers-y-yara.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consultar virustotal.com desde la lí­nea de comandos</title>
		<link>http://virtualminds.es/blog/index.php/2009/01/consultar-virustotal-com-desde-la-la%c2%adnea-de-comandos.html</link>
		<comments>http://virtualminds.es/blog/index.php/2009/01/consultar-virustotal-com-desde-la-la%c2%adnea-de-comandos.html#comments</comments>
		<pubDate>Tue, 20 Jan 2009 17:16:26 +0000</pubDate>
		<dc:creator>Iñaki</dc:creator>
				<category><![CDATA[Malware]]></category>

		<guid isPermaLink="false">http://virtualminds.es/wordpress/?p=17</guid>
		<description><![CDATA[Estoy haciendo unos scripts para mantener limpios (en la medida de lo posible) nuestros servidores windows. Buscando la mejor manera de hacerlo me dije&#8230; Y si en vez de instalar un antivirus, instalo 38. Alguien podría decir que es una locura a la par que un imposible. Pero llega Hispasec con su Virustotal.com y nos [...]]]></description>
			<content:encoded><![CDATA[<p>Estoy haciendo unos scripts para mantener limpios (en la medida de lo posible) nuestros servidores windows. Buscando la mejor manera de hacerlo me dije&#8230; Y si en vez de instalar un antivirus, instalo 38. Alguien podría decir que es una locura a la par que un imposible. Pero llega <a href="http://www.hispasec.com"  title="Hispasec">Hispasec</a> con su <a href="http://www.virustotal.com"  title="Virustotal.com">Virustotal.com</a> y nos pone de forma totálmente gratuita 38 antivirus.</p>
<p>Y aquí es donde nos aprovechamos un poco de ellos. Tengo que decir que antes de publicar el código, consulté con su soporte si había alguna limitación de uso. La única limitación es el número de consultas por ip así que si alguna vez no os funciona, ya sabéis por qué es <img src='http://virtualminds.es/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
<p>El código es bastante simple. Virustotal.com tiene una base de datos de hashes ya procesados y es posible consultar un determinado hash. El código no sube el fichero a virustotal, solo consulta esta base de datos por lo que os podéis encontrar que piezas de malware no son detectadas como tales:</p>
<pre class="brush:bash">
#!/usr/bin/perl

use strict;
use LWP;
use Digest::MD5;
use Getopt::Long;

my $md5 = Digest::MD5->new;
my $virhash;
my $file;
my $hash;

GetOptions  (	"file=s" => \$file,
				"hash=s" => \$hash
			);

if($file &#038;&#038; $hash) {
	usage();
	exit 100;
}

if(!$file &#038;&#038; !$hash) {
	usage();
	exit 100;
}

if(-f $file) {
	open FILE,$file;
	binmode(FILE);
	$virhash = $md5->addfile(*FILE)->hexdigest;
	print "[HASH] Using MD5 hash $virhash\n";
}
elsif ($hash) {
	$virhash = $hash;
	print "[HASH] Using hash $virhash\n";
}

my $ua = LWP::UserAgent->new;
push @{$ua->requests_redirectable }, 'POST';

my $resp = $ua->post('http://www.virustotal.com/vt/en/consultamd5',[ "hash" =>  $virhash , "x" => 138 , "y" => 24 ]);

if($resp->is_success) {
	my $data = $resp->content;

	$data =~ m,(
<div id="status_porcentaje".*</div>

),m;
	my $virdata = $1;
	$virdata =~ m,>(\d+)</span>/(\d+) ,;
	if($1 > 0) {
		print "Virus Found ($1/$2)\n";
		exit 1;
	} else {
		print "Virus Not Found\n";
		exit 0;
	}
} else {
	print $resp->status_line;
	exit 100;
}

sub usage () {
	print "$0 (--file fichero | --hash hash)\n";
}
</pre>
<p>Si puedo y me dejan, dentro de unos días publicaré el código algo más avanzado. Pero para los que tengan iniciativa, diré que Win32::Process::Info es un gran comienzo para sacar la lista de procesos y la ruta del ejecutable asociado.</p>
<p>Hasta pronto!</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualminds.es/blog/index.php/2009/01/consultar-virustotal-com-desde-la-la%c2%adnea-de-comandos.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
