<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wassim Dhif</title>
    <description>The latest articles on DEV Community by Wassim Dhif (@wdhif).</description>
    <link>https://dev.to/wdhif</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F236329%2F6ba6d55f-8efb-4762-992b-3f3511770dac.jpeg</url>
      <title>DEV Community: Wassim Dhif</title>
      <link>https://dev.to/wdhif</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wdhif"/>
    <language>en</language>
    <item>
      <title>A Docker Antivirus in Ruby</title>
      <dc:creator>Wassim Dhif</dc:creator>
      <pubDate>Mon, 09 Dec 2019 20:22:44 +0000</pubDate>
      <link>https://dev.to/wdhif/a-docker-antivirus-in-ruby-d4</link>
      <guid>https://dev.to/wdhif/a-docker-antivirus-in-ruby-d4</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://medium.com/@wdhif/a-docker-antivirus-in-ruby-a4cceb4528e0" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Last year, I've had the occasion to work on a project to build Docker images for developers. For security reasons, the developers were not allowed to push to a registry the Docker images they had built on their computer. Instead, they had to use a 'builder', in Ruby, that would take their Dockerfile and build the image for them, after running some tests of course.&lt;/p&gt;

&lt;p&gt;One of those test was an antivirus, the &lt;a href="https://github.com/wdhif/docker-antivirus" rel="noopener noreferrer"&gt;docker-antivirus&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/wdhif" rel="noopener noreferrer"&gt;
        wdhif
      &lt;/a&gt; / &lt;a href="https://github.com/wdhif/docker-antivirus" rel="noopener noreferrer"&gt;
        docker-antivirus
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Antivirus for Docker with ClamAV and Atomic
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  How to run an Antivirus on a Docker&amp;nbsp;image?
&lt;/h3&gt;

&lt;p&gt;The first thing was to choose an antivirus, the choice was pretty straight forward. It should be open-source, run on Linux, and be performant. The answer was ClamAV.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F500%2F0%2Anuijrp8xGa25YWLL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F500%2F0%2Anuijrp8xGa25YWLL.png" alt="ClamAV"&gt;&lt;/a&gt;&lt;br&gt;
ClamAV is an open-source antivirus that works on Linux with a public virus database with, as of 10 February 2017 contained over 5,760,000 virus signatures.&lt;/p&gt;



&lt;p&gt;The idea was to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Instantiate a Docker container with the image we want to test.&lt;/li&gt;
&lt;li&gt;Mount the container file system&lt;/li&gt;
&lt;li&gt;Run ClamAV on the mounted file system&lt;/li&gt;
&lt;li&gt;Print some result&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But we already got an issue here, &lt;strong&gt;it is not possible to mount the root of a container&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Atomic to the&amp;nbsp;rescue
&lt;/h3&gt;

&lt;p&gt;Atomic is a project by Red Hat to deploy and manage container-based infrastructures. One of the product of Project Atomic is the &lt;a href="https://github.com/projectatomic/atomic" rel="noopener noreferrer"&gt;Atomic Run Tool&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the command added by this tool is &lt;a href="https://github.com/projectatomic/atomic/blob/master/Atomic/mount.py" rel="noopener noreferrer"&gt;atomic mount&lt;/a&gt;, which allow us to mount a container root. Atomic mount uses &lt;a href="https://ostree.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;OSTree&lt;/a&gt;, a library allowing us to interact with hierarchical file systems.&lt;/p&gt;

&lt;p&gt;Using Atomic mount, we are able to mount the root of a container, and therefore this allow us to run ClamAV on it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Wrapping things&amp;nbsp;up
&lt;/h3&gt;

&lt;p&gt;By using both ClamAV and Atomic, I was able to create a little utility in Ruby to help me check viruses on a Docker image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2444%2F0%2A24jR-PvCoR_hn4NU.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2444%2F0%2A24jR-PvCoR_hn4NU.gif" alt="The docker-antivirus in&amp;nbsp;action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By running the docker-antivirus on the Busybox Docker image, we can confirm that this image is safe. We also have some informations about the scan itself. For example, how many files were scanned or how much time did it took. But we must also test the docker-antivirus on a malicious Docker image.&lt;/p&gt;
&lt;h3&gt;
  
  
  Testing our solution with the EICAR&amp;nbsp;test
&lt;/h3&gt;

&lt;p&gt;The EICAR test file is a simple characters chain created by the European Institute for Computer Antivirus Research (EICAR) to test without any risks antivirus solutions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple characters chain is designed to trigger any antivirus, although it is completely harmless. For testing purpose, I simply created a Docker image containing this file, the &lt;a href="https://github.com/wdhif/docker-eicar" rel="noopener noreferrer"&gt;docker-eicar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here, we can see the result of the docker-antivirus when analyzing the docker-eicar image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1262%2F1%2ALzA1i8eWKqkd4M5-geRNAA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F1262%2F1%2ALzA1i8eWKqkd4M5-geRNAA.png" alt="Running the docker-antivirus with the docker-eicar image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the docker-antivirus tells us that there is in fact something wrong with the docker-eicar image.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's next?
&lt;/h3&gt;

&lt;p&gt;I am planning on adding more information about the virus itself in case it's detected. I would also like to make the docker-antivirus more easy to use, maybe by embedding it inside a docker image, or maybe by using static builds.&lt;/p&gt;

&lt;p&gt;You can also participate yourself in the &lt;a href="https://github.com/wdhif/docker-antivirus" rel="noopener noreferrer"&gt;development of this project&lt;/a&gt;, contributions are more than welcome!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>antivirus</category>
      <category>clamav</category>
      <category>atomic</category>
    </item>
  </channel>
</rss>
