Building a Docker image to run Metabrik… from Metabrik

Today, we will show how we can use the system::docker Brik to build a Metabrik Docker image. Of course, you have to have installed Metabrik first, but it is as easy as following the online guide. Alternatively, you can use the publicly available Docker image, which is quite an inception concept.

Installing the Docker image from the hub

Installing Docker is also simple. Run the following command as a standard user:

wget -qO- | sh

Then, you may fetch the Metabrik Docker image and run it:

docker pull metabrik/metabrik
docker run -it metabrik/metabrik

And building your own image from your system

You may also start from a fresh Metabrik installation. If you want to customize your very own Docker image, you can download the Dockerfile from the trac server. Once you have it, put it in its own directory and start Metabrik.

$ mkdir ~/docker-metabrik
$ mv ~/Downloads/Dockerfile ~/docker-metabrik/

Once Metabrik is running, you have to use the system::docker Brik and change to the docker directory.

messiah:~> cd ~/docker-metabrik
messiah:~/docker-metabrik> use system::docker
[-] system::docker: brik_check_require_binaries: binary [wget] not found in PATH
[-] system::docker: brik_preinit: brik_checks failed
[-] core::context: call: use: unable to use Brik [system::docker]

But you got an error, cause some dependencies are not available yet. No worries, there is a dependencies handling feature in Metabrik for every Brik. Load the brik::tool Brik and install the system::docker one like:

messiah:~/docker-metabrik> use brik::tool 
[-] core::context: call: use: Brik [brik::tool] already used
messiah:~/docker-metabrik> run brik::tool install $USE
messiah:~/docker-metabrik> use system::docker
messiah:~/docker-metabrik> run system::docker install
[!] system::docker: brik_init: you have to execute install Command now
apparmor is enabled in the kernel, but apparmor_parser missing
+ sh -c sleep 3; apt-get update

Ready to build the Docker image

Everything is set-up, we can start building.

get system::docker
set system::docker username $username
set system::docker password $password
set system::docker email $email
run system::docker login

run system::docker get_image_id metabrik
run system::docker delete $RUN # Delete previous latest tag
run system::docker build metabrik .
run system::docker tag $RUN metabrik/metabrik:latest

run system::docker push metabrik/metabrik:latest

Automating it from a Metascript

If you have to repeat this task, you will of course want to write a script. And you can do it as a Metascript. Create a file called build-metabrik-docker-image.meta containing:

use system::file
use system::docker

my $email = 'EMAIL'
my $username = 'USERNAME'
my $password = 'PASSWORD'

set system::docker email $email
set system::docker username $username
set system::docker password $password
run system::docker login
if ($ERR) { exit 0; }

get core::global homedir
my $dir = $GET."/metabrik-docker/"
run system::file mkdir $dir
get core::global repository
my $file = $GET."/../Dockerfile"
run system::file copy $file $dir

run system::docker get_image_id metabrik
run system::docker delete $RUN # Delete previous latest tag
run system::docker build metabrik $dir
run system::docker tag metabrik metabrik/metabrik:latest

run system::docker push metabrik/metabrik:latest

exit 1

And run it:

metabrik --script metabrik-docker-image.meta


Metabrik has been demonstrated at YAPC::Europe 2016 in Cluj-Napoca, Romania

We are pleased to have demonstrated the power of Metabrik during the YAPC::Europe 2016 (we should now say The Perl Conference) at Cluj-Napoca in Romania.

Slides are available here:

You may also be interested in the demo that we’ve shown:

And the video starts at 1:18:00 and last for 30 minutes:

Using just a single Brik for a quick program

Today, we will show you how to use just a single Brik to build a standalone program without installing a multitude of packages or modules. To achieve that, we will use the brik::tool which is a helper to install dependencies, et use the classic lookup::iplocation Brik as the single Brik to use.

Note: you will need version 1.22 for this to work.

Install or update The Metabrik Platform

Installing should be as easy as running:

sudo cpan install Metabrik
sudo cpan install Metabrik::Repository

If that does not work for you, you can follow more complete installation instructions.

Then, you can update the platform at any time to latest repository version with this one-liner:

perl -MMetabrik::Core::Context -e 'Metabrik::Core::Context->new_brik_run("brik::tool", "update")'

You could put an alias in your shell to help doing so in the future:

alias update-metabrik="perl -MMetabrik::Core::Context -e 'Metabrik::Core::Context->new_brik_run(
\"brik::tool\", \"update\")'"

Installing a Brik dependencies

As a Brik may have some package(s) or module(s) dependencies, we’ve put some effort into simplifying their installation. There is a brik::tool install Command dedicated to that. It will even know when to use sudo for you. Use this one-liner to install dependencies for our example lookup::iplocation Brik:

perl -MMetabrik::Core::Context -e 'Metabrik::Core::Context->new_brik_run("brik::tool", "install", "lookup::iplocation")'

You could also have used The Metabrik Shell by launching

messiah:~> run brik::tool install lookup::iplocation

Creating a meta-tool

Now everything is in place, you need to know which Commands are available for the lookup::iplocation Brik. The easiest way is to use The Metabrik Shell help Command. And don’t forget to use <tab> keystroke to use completion at each step:

messiah:~> use lookup::iplocation
[*] core::shell: use: Brik [lookup::iplocation] success
messiah:~> help lookup::iplocation
[+] set lookup::iplocation datadir <datadir>
[+] run lookup::iplocation from_ip <ip_address>
[+] run lookup::iplocation from_ipv4 <ipv4_address>
[+] run lookup::iplocation from_ipv6 <ipv6_address>
[+] run lookup::iplocation organization_name <ip_address>
[+] run lookup::iplocation subnet4 <ipv4_address>
[+] run lookup::iplocation update

Two Commands are of interest here: update and from_ip. The first one let’s you get latest versions of the Maxmind IP geolocation database.

You now know what you want to do, let’s use another brik::tool Command to create a meta-tool skeleton:

perl -MMetabrik::Core::Context -e 'Metabrik::Core::Context->new_brik_run("brik::tool", "create_tool", "")'

Or from The Metabrik Shell by launching

messiah:~> run brik::tool create_tool

And you populate the generated content skeleton with required code to call update and from_ip Commands:

#!/usr/bin/env perl
# $Id$
use strict;
use warnings;

my $ip = shift or die("$0 ");

# Uncomment to use a custom repository
#use lib qw(/lib);

use Data::Dumper;
use Metabrik::Core::Context;
use Metabrik::Lookup::Iplocation;

my $con = Metabrik::Core::Context->new or die("core::context");

# Init other Briks here
my $li = Metabrik::Lookup::Iplocation->new_from_brik_init($con) or die("lookup::iplocation");
$li->update or die("update failed");

# Put Metatool code here
print Dumper($li->from_ip($ip))."\n";


And voilà. Test your program:

[+] mirror: file [/home/gomor/metabrik/lookup-iplocation/GeoIPv6.dat.gz] not modified since last check
[+] mirror: file [/home/gomor/metabrik/lookup-iplocation/GeoIP.dat.gz] not modified since last check
[+] mirror: file [/home/gomor/metabrik/lookup-iplocation/GeoIPCity.dat.gz] not modified since last check
[+] mirror: file [/home/gomor/metabrik/lookup-iplocation/GeoIPASNum.dat.gz] not modified since last check
$VAR1 = {
          'country_code3' => 'USA',
          'metro_code' => 506,
          'city' => 'Norwell',
          'dma_code' => 506,
          'country_code' => 'US',
          'postal_code' => '02061',
          'country_name' => 'United States',
          'continent_code' => 'NA',
          'region_name' => 'Massachusetts',
          'longitude' => '-70.8228',
          'region' => 'MA',
          'area_code' => 781,
          'latitude' => '42.1508'

Alternatively, for a so simple task, you could have used The Metabrik Shell:

messiah:~> use lookup::iplocation
[*] core::shell: use: Brik [lookup::iplocation] success
messiah:~> run lookup::iplocation update
messiah:~> run lookup::iplocation from_ip
  area_code      => 781,
  city           => "Norwell",
  continent_code => "NA",
  country_code   => "US",
  country_code3  => "USA",
  country_name   => "United States",
  dma_code       => 506,
  latitude       => 42.1508,
  longitude      => -70.8228,
  metro_code     => 506,
  postal_code    => "02061",
  region         => "MA",
  region_name    => "Massachusetts",


We have shown how to get up-to-date with The Metabrik Platform and how to develop a meta-tool. Helped with that, you can start to develop programs using the 200+ available Briks. For instance, try to add lookup::threatlist support to as an exercise.

Malware analysis with VM instrumentation, WMI, winexe, Volatility and Metabrik

In this article, we will show how to take advantage of Metabrik to automate some malware analysis tasks. The goal will be to execute a malware in a virtual machine (VM), just after you saved a snapshot of Windows operating system. In our example, this snapshot only includes running processes, but you will see you can do more than just that. Here, we introduce remote::wmi, remote::winexe and system::virtualbox Briks.

We will also introduce the forensic::volatility Brik which can help you perform dynamic malware analysis and extract IOCs, for instance.

Tip: you can use <tab> keystroke to complete Brik names and Commands while using The Metabrik Shell.

Setting up the environment

wmic and winexe are programs that have to be compiled by yourself. Fortunately, Metabrik makes this process as easy as running the install Command. Since wmic and winexe programs ship with the same software suite, you just have to run install Command for one of remote::wmi or remote::winexe Briks. We don’t run the install Command with system::virtualbox Brik, because we suppose you already have some VitualBox VMs installed.

use brik::tool
use remote::wmi
use remote::winexe
use forensic::volatility
help remote::wmi
help remote::winexe
help forensic::volatility
run brik::tool install_needed_packages remote::wmi
run brik::tool install_needed_packages remote::volatility


Your VM also has to be configured to allow WMI accesses for a given user, and have the WINEXESVC service started. Some help on how to do that can be found in remote::wmi and remote::winexe Briks source code.

Starting a VM and taking a snapshot

Our environment is up and running. Let’s start a VM and take a snapshot before we execute a malware within it remotely. For the purpose of this exercise, the malware will simply be calc.exe program.

use system::virtualbox
help system::virtualbox
run system::virtualbox list


Let’s start our Windows machine in headless mode: we don’t want to speak with this kind of GUI.

set system::virtualbox type headless
run system::virtualbox start 602782ec-40c0-42ba-ad63-4e56a8bd5657
run system::virtualbox snapshot_live 602782ec-40c0-42ba-ad63-4e56a8bd5657 "before calc.exe"



I know the IP address of the machine, but you could have found it by using ARP scanning on vboxnet0 interface thanks to the network::arp Brik.

my $win = ''
my $user = 'Administrator'
my $password = 'YOUR_SECRET'
set remote::wmi host $win
set remote::wmi user $user
set remote::wmi password $password
set remote::winexe host $win
set remote::winexe user $user
set remote::winexe password $password
run remote::wmi get_win32_process
for (@$RUN) {
print $_->{Name}."\n";

You should see no calc.exe right now.


Now, launch the calc.exe program and search in the process list if you can find it. Note that you will have to run Ctrl+C keystrokes because the program will block here. But calc.exe should still be running on the remote host.

run remote::winexe execute "cmd.exe /c calc.exe"
run remote::wmi get_win32_process
my @processes = map { $_->{Name} } @$RUN
my $found = grep { /calc.exe/ } @processes

In the below screenshot, you will see 2 as a result to the grep command. That’s because we ran two times the execute Command with calc.exe during our testing.


Now, we will restore the VM to its default state, when calc.exe “malware” was not yet run.

run system::virtualbox stop 602782ec-40c0-42ba-ad63-4e56a8bd5657
run system::virtualbox snapshot_restore 602782ec-40c0-42ba-ad63-4e56a8bd5657 "before calc.exe"
run system::virtualbox start 602782ec-40c0-42ba-ad63-4e56a8bd5657
run remote::wmi get_win32_process
my @processes = map { $_->{Name} } @$RUN
my $found = grep { /calc.exe/ } @processes

All clear. No more calc.exe process.

You spoke about Volatility?

Yes. And that’s where it starts to get interesting. You can do the same processes analysis with Volatility (and of course much more). To use Volatility, you need a dump of the system’s memory. To acquire this dump, it’s as simple as using the system::virtualbox dumpguestcore Command. Then, you have to extract the memory dump that is part of the generated core file. You will use the extract_memdump_from_dumpguestcore Command.

Then, you will be able to perform forensic stuff on this memory dump, for instance to search if calc.exe has been popped. If you go back to the original subject -malware analysis-, you will find the Volatility is the tool of choice to check what a malware you just run with remote::winexe Brik did to processes, network handles or registry. That’s a perfect combination of tools to extract IOCs from a malware.

run system::virtualbox dumpguestcore 602782ec-40c0-42ba-ad63-4e56a8bd5657 dump.core
run system::virtualbox extract_memdump_from_dumpguestcore dump.core dump.volatility


We have a dump usable by Volatility. Let’s dig into it with forensic::volatility Brik:

use forensic::volatility
set forensic::volatility input dump.volatility
run forensic::volatility imageinfo
set forensic::volatility profile $RUN->[0]
run forensic::volatility pslist



And voilà.

A feature of WINEXESVC: get a remote shell on Windows

One last screenshot in regards to remote::winexe Brik: how to get a Windows remote shell:

run remote::winexe execute cmd.exe



We have seen that we can easily perform malware analysis on a Windows machine by using a combination of Briks. By combining features of different tools (VirtualBox, winexe and Volatility) we can, for instance, analyse consequences of running a malware on a machine. Extracting IOCs from a malware is something useful if you want to find which machines were infected on your information systems from a particuliar sample. You could then use remote::wmi Brik to scan your network for these specific patterns.

Extracting IOCs is a huge topic in itself, and we just scratched the surface here by using a dynamic method associated with a “scapegoat” VM. Another way of extracting IOCs is to use static analysis, but that’s a complete different story.

We urge you to play with Volatility (and of course Metabrik), you will see how powerful it could be. Enjoy.

Solving a root-me forensic challenge with Metabrik and Scalpel

I recently discovered the wonderful world of forensic and challenges (read: today). So I decided to add some new Briks just to solve some of them. Let’s dig into the “Find the catroot-me challenge step-by-step. I will also show how I improved the Scalpel tool by wrapping it with other Briks.

Getting the files

Well, you have to register to to get access to challenge files. The one from this Metabrik Example is called “Find the cat“, or “Trouvez le chat” in French. Once downloaded and extracted, you got these files:

cd /home/gomor/hgwork/metabrik/challenges/trouvez-le-chat/
my $files = $RUN

First things to do is to check for MIME types of these files. You can also check for the MAGIC types:

use file::type
run file::type get_mime_type $files
run file::type get_magic_type $files


You have a txt file (you should read it for the story behind the cat theft) and a gzip file. Let’s uncompress this one:

use file::compress
run file::compress uncompress $files->[0]
my $file = $RUN
run file::type get_mime_type $file
run file::type get_magic_type $file


Wonderful. It appears to be some kind of filesystem. Let’s analyse that with Scalpel, a filesystem image forensic tool written in Python.

Introducing Scalpel

To use Scalpel, you usually have to create a scalpel.conf file containing metadata on how to extract (or carve) files. For instance, if you want to find and extract ZIP files, you search for the string PK\x03\x04 in a bytestream.

If you want to only check for some files (say odt files), you have to comment out all the lines from that conf file, except the one for odt documents. If you want to search for all file formats, you have to uncomment all the lines. That is the first thing I changed when writing the forensic::scalpel Brik: use a Command to help you generate the configuration file with only what you want to search for.

The other limitation of the tool is its inhability to identify extracted files using the libmagic (check for MIME types or MAGIC types). Thus, I added this feature within forensic::scalpel Brik to just do that: separate verified files from unverified ones.

So, let’s dig into this new Brik. It is made upon 4 existing Briks: shell::command, file::find, file::text and of course the file::type one. As you can see, new Briks can be written with already existing Briks.

We will use it to extract files from the challenge (remember, you have to find where is the cat). Because I already know the result (spoiler), I will only search for odt files from the filesystem image ch9:

use forensic::scalpel
run forensic::scalpel generate_conf "[ 'odt' ]"
run forensic::scalpel scan $file
my $verified = $RUN->{verified}

We just wanted to keep verified files. Yes, the ones that went through the file::type Brik and its MIME type identification. Read: the feature lacking from Scalpel.


We now have two odt files, let’s open them with LibreOffice (exercise for the reader).

my $files = join(' ', @$verified)
libreoffice $files

You have a picture of a cat, and a message saying: “Free Alsace, or we kill the cat“. We must locate those miscreants. This is a picture, is there some EXIF metadata? Use the image::exif Brik to discover. But first, we have to extract this picture. odt files are simple ZIP files, we use the file::compress Brik again:

run file::compress uncompress $verified->[0]
my $pic = './Pictures/1000000000000CC000000990038D2A62.jpg'
run file::type get_mime_type $pic

use image::exif
run image::exif get_metadata $pic


Lots of metadata. But more interestingly, you have the latitude and longitude of the camera which took the picture. Bingo. Sarge, we found the evil doers, let’s go catch them now. Over.


By using a few Briks, we have shown how to solve a simple challenge. As you can see, you can nearly automate it from the beginning to the end. Exercise yourself with Metabrik by downloading the docker image. Enjoy.

EDIT 2015/12/17: some Commands have moved from system::file to file::type, thus some Commands have been renamed in this post, but screen captures remain the same as before.

Is Telegram using encryption? How to discover it easily by yourself – Part 1

It is said that, by default, messages sent to a contact through Telegram -a messaging application for smartphones- are not encrypted. You have to enter a specific menu named “New Secret Chat” to enable end-to-end encryption. Let’s verify it is indeed the case by using some Briks.
Try by yourself using the Docker image:

docker pull metabrik/metabrik
docker run -it metabrik/metabrik

Let’s load some Briks for the work

We will need to perform a Man-in-The-Middle (MiTM) attack on our local network to allow interception of traffic from a smartphone to Telegram servers or remote peers. The network::arp Brik has such a function. We will also need to become a router, or the traffic will be lost: network::route comes to the rescue. Then we will have to analyse the traffic itself, we will use Briks network::read, network::stream and client::whois to locate Telegram IP addresses. We will also use lookup::oui to find a potential smartphone on the network.

use network::arp
use network::route
use network::read
use network::stream
use lookup::oui
use client::whois

Also, you have to execute an update Command on the lookup::oui Brik so it fetches the file from IEEE organization.

run lookup::oui update

Performing the MiTM attack

We will use ARP poisoning to perform a standard LAN MiTM attack. But we don’t want to poison everyone, we just want to listen to a smartphone traffic. We will use some ARP scanning technics to gather available neighbors, and we will perform a lookup on the MAC address to retrieve the vendor. This information will directly lead us to a smartphone.

run network::arp scan
my $scan = $RUN
my $mac = [ keys %{$RUN->{by_mac}} ]
run lookup::oui from_hex $mac->[0]
run lookup::oui from_hex $mac->[1]

Looks like we have found a Motorola smartphone. Perfect target for us. To gather its IP address, just issue a Command to ask data from a saved variable:

my $victim = $scan->{by_mac}{"5c:51:88:XX:XX:XX"}

Now, we want to intercept traffic between the victim and the Internet. Thus, we will attack the gateway. We have to find its IP address, configure our host as a network router, and we will be ready to perform the ARP poisoning:

my $victim = ""
run network::route default_ipv4_gateway
my $gateway = $RUN
run network::route enable_router_ipv4
run network::arp full_poison $victim $gateway



We have seen how to scan the local network in search for a specific device and how to launch a Man-in-The-Middle attack. This concludes the first part of this article. You may think it is a little bit short, but you will probably be eager to read the next part 🙂

Metabrik Core And Repository 1.10 Released

Following our lightning talk from 2015 conference, we are proud to release the version 1.10 of Metabrik Core and Repository. Update using Mercurial or follow the installation procedure.

You can find the few slides which were presented at the following link.

Lots of new awesome Briks

We added many Briks for this new release, here is the description for them:

  • api::bluecoat: play with Bluecoat REST API
  • api::splunk: play with the Splunk REST API
  • api::virustotal: play with Virustotal REST API
  • client::udp: a UDP socket client (UDP netcat)
  • client::ssl: check various stuff about a SSL/TLS connection
  • client::rest: the base REST client for use with Briks from API Category
  • client::rsync: a wrapper around rsync program
  • client::twitter: a Twitter client
  • database::mysql: interract with MySQL databases
  • file::dump: read and write dump files
  • file::hash: genrated various digests from files
  • file::ole: play with Microsoft files that embed OLE components
  • lookup::iplocation: geolocation for IP addresses
  • string::ascii: convert ASCII characters
  • string::csv: encode/decode CSV strings
  • string::hostname: parse a FQDN
  • string::regex: experiment with regexes
  • system::freebsd::pf: control Packet Filter
  • system::freebsd::jail: control jails

Just type help <Brik> to know more:

Meta:~> use string::regex 
[*] core::shell: use: Brik [string::regex] success
Meta:~> help string::regex 
[+] run string::regex encode <$regex|$regex_list>

Complete list of changes


1.10 Tue Oct 27 20:13:36 CET 2015
   - FEATURE: core::context: allows to pass complex structs arguments to run and set Commands
     Example: run network::arp scan $info->{subnet}
   - FEATURE: core::context: allows also to execute Perl code within an Argument of a
     run Command
     Example: run client::dns ptr_lookup "[ map { @$_ } values %$RUN ]"
   - FEATURE: core::shell: allows to complete aliases (can be disabled via
     aliases_completion Attribute
   - FEATURE: shell::command: use_sudo Attribute to launch sudo on executing external command
   - FEATURE: shell::command: file globbing enabled with capture Command
   - UPDATE: moved attributes_default() from brik_use_properties to brik_properties when
     there is no need to use $self. It allows instanciated Attributes inheritage to work.
   - UPDATE: shell::command: do not print STDERR when using capture Command when there is no
     STDERR string captured.
   - new: shell::command: execute Command to use capture_mode Attribute to launch either
     capture or system Command
   - bugfix: core::context: save_state to use Metabrik brik_attributes Command to correctly
     retrieve all Brik Attributes even those inherited
   - bugfix: core::shell: display error on chdir() failure
   - bugfix: core::shell: escapes " character when executing a multiline Perl/Metabrik Code
             my $test = 'root'
             for (0..1) {
                'run shell::command system "ls /$test"'
   - bugfix: Metabrik: error checking within new_from_brik_init Command
   - bugfix: Metabrik: logging correctly on class calls to _log_*()


- bugfixes and new Briks

   AFFECT: network::arp

   - network::arp scan Command now returns a hashref with results sorted
     with keys named by_mac, by_ipv4 and by_ipv6

   AFFECT: network::rsync

   - network::rsync renamed to client::rsync

   AFFECT: crypto::x509

   - Argument order changed for ca_sign_csr and cert_verify Commands

   AFFECT: file::csv

   - removed get_col_by_name and get_col_by_number obsolete Commands

IP location with Metabrik: different ways of doing it

We just released a new Brik: lookup::iplocation. Thanks to this Brik, you will be able to easily geo-locate any IP address. Well, it has to be in MaxMind’s database for that to work, of course. In this post, we propose to explore different ways of using a Metabrik Brik with this lookup::iplocation example.

Using The Metabrik Shell

Of course, the simplest way of doing is using The Metabrik Shell (which is just a simple Brik called core::shell). A screenshot is what best demonstrates the power of Metabrik.

The first call to ‘use lookup::location‘ fails because we currently lack one Perl module: Geo::IP. Metabrik tells you so and you can install it by using the perl::module Brik.

Then, you want to update the Geo::IP database. If you don’t, you will not have the required data to perform the lookup. You have to call ‘run lookup::location update‘.

Finally, you can geo-locate the IP address by calling ‘run lookup::location from_ip <IP>‘.


Using a Metabrik script

Before being able to execute Metabrik scripts (.meta files), you have to initiate the .metabrik_script_rc file. Just edit it using vi, for instance, and put in the lines below:

vi ~/.metabrik_script_rc
set core::shell echo 0
my $home = $ENV{HOME}
my $repository = "$HOME/metabrik/repository/lib"
push @INC, $repository
run core::context update_available

Now you are ready to write your very own Metabrik script. Create one using vi and put in this content:

vi iplocation-script.meta
use lookup::iplocation
if ($ERR) { exit }

run lookup::iplocation update
if ($ERR) { exit }

run lookup::iplocation from_ip
if ($ERR) { exit }

use Data::Dumper
print Dumper($RUN)

You can mix Metabrik Commands with Perl code. Wonderful, isn’t it? Ah, maybe you want to execute it:

metabrik --script iplocation-script.meta

The third way: use a Perl script

And finally, this is Perl. You can use a Brik as a plain Perl module if you want to. Try that:

use strict;
use warnings;

use Data::Dumper;
use Metabrik::Core::Context;
use Metabrik::Lookup::Iplocation;

my $context = Metabrik::Core::Context->new;
$context->brik_init or die("[FATAL] context init failed\n");

my $li = Metabrik::Lookup::Iplocation->new_from_brik_init($context)
   or exit(1);

   or exit(2);

my $info = $li->from_ip("")
   or exit(3);

print Dumper($info);


You see you can play with Metabrik in different ways. Even though Metabrik has been thought as a shell from the beginning, you are not bound to it in any way. And you, what is your favorite way of using Briks?

Metabrik Core And Repository 1.08 Released

A new version of Metabrik Core and Repository is available. Update using Mercurial or follow the installation procedure.



1.08 Thu Mar 19 06:48:34 CET 2015
 - FEATURE: core::shell: run executable commands found in PATH through system Command
 - UPDATE: shell::command: now use IPC::Run3 to capture shell commands output
 - update: shell::command: system Command now returns $? on success
 - update: Metabrik: display every missing items from brik_require_*_check() before erroring
 - update: new dependance on IPC::Run3

1.07 Sun Mar 8 17:52:37 CET 2015
 - bugfix: shell::history: correctly writes $* variables when calling history Commands
 - new: shell::rc: create an alias to make it easy to switch to root from Shell
 - new: brik::search and perl::module Briks integrated in main distribution
 - remove: no more metabrik-cpanm, enforce use of standard cpanm


- bugfixes and new Briks

 AFFECT: http::proxy, iana::countrycode, network::arpdiscover

 - http::proxy Brik renamed to proxy::http
 - iana::countrycode Brik renamed lookup::countrycode
 - network::arpdiscover removed: merged with network::arp

 AFFECT: client::www

 - post Command returns an HASHREF i/o of WWW::Mechanize object

 AFFECT: network::portscan

 - synscan Command renamed to tcp_syn


Exploiting ElasticSearch RCE For CVE-2015-1427

I told you so: it is a work for Metabrik. While the main target for Metabrik is not to write exploits (you have Metasploit for that), you can still write Briks within the Audit Category. Based on the exploit provided XiphosResearch, we wrote a Command to verify if an ElasticSearch target is vulnerable, and another Command to exploit the issue to execute commands on the target.

Loading the Brik

As always, if a Brik is not loaded yet, you have to do it. Then, the first thing to do is to ask for help, or how to use the Brik, which Attributes can be set and which Commands can be run.


Using a check or an exploit Command

To test a target, you can either use the check_cve_2015_1427_rce  Command or use the exploit_cve_2015_1427_rce Command with an innocuous command. We recommand to use the check one, which is actually made to be innocuous.

To use the check or exploit one, you just have to use the run Metabrik Command with the name of a Command, and add Arguments to it. Some Arguments can be set globally for the Brik: here you may use the set Metabrik Command to set uri Attribute.

Note: And don’t forget to use the <Tab> key to perform completion on every Command, and use the <Up> key to recall previous ones.



Our target is vulnerable. Too bad, but it is an exploit lab, it exists for that.

Exploiting the issue to execute commands

But well, if you are here, it is probably because you want to exploit a Remote Command Execution within ElasticSearch. With Metabrik, it is as easy as:


We even added some “post intrusion” work, like downloading a file.

A key feature of Metabrik

Yes, one of the key feature of Metabrik is to assemble Briks together to execute a complete scenario. We have shown how to use Briks, especially the one on exploiting a vulnerability within a product and, after this exploitation process, we have shown that we can use a special $RUN variable with another Brik.


  • run Command sets the global variable $RUN
  • set Command sets the global variable $SET
  • get Command sets the global variable $GET

Thanks to the $RUN variable, you can chain the use of Briks. In fact, Briks within Metabrik may also be written with other Briks. For instance, audit::elasticsearch Brik relies on:

Here, we have chained a few Briks, and one of them allowed to save a remote file to a local file (file::text). You have more global variables, but that’s enough for today. Follow us on twitter @Metabrik.