Virus & Malware Scanning Object Storage in OCI
Posted: Thursday, Jul 14
Virus & Malware Scanning Object Storage in OCI cover

i 3 Table of Contents

Virus & Malware Scanning Object Storage in OCI
From KBI

If youโ€™re like me, then working in IT means you also assume Tech Support duties for friends, family, and those distant relatives that only seem to call when theyโ€™ve got a problem.

I just clicked on this link, and my computer is doing something weird. I think my PC has a virus, what do I do?

When itโ€™s just a single computer, the answer is simple, contain and validate the rouge software is removed, install an AV solution, change their passwords, enable MFA, and provide some education on what to look out for next time.

But now imagine youโ€™re an organisation building a new application, or are moving applications to the cloud. Are you simply performing a lift-and-shift or are you planning to make use of cloud native services? Where are you going to store your data, specifically user uploaded files? Object Storage was built specifically to solve the challenges of how to store unstructured data in the cloud.

However, there is a catch. If you were previously storing files on a server file system, then itโ€™s likely you were also running an anti-virus / anti-malware solution to identify malicious files. With Object Storage the underlying file system is transparent, so you canโ€™t install AV, yet many compliance requirements still state โ€œUploaded files must be scanned for viruses and malwareโ€.

The Shared Responsibility Model

Iโ€™ve heard many times that โ€œWeโ€™re in the cloud, so my provider takes care of that right? Unfortunately not. Cloud Providers are responsible only for the security of their platform, you are responsible for what you put in the cloud. If youโ€™re not familiar with the concept, take a look at: https://www.oracle.com/a/ocom/docs/cloud/shared-responsibility-model-wp.pdf

Iโ€™m using Object Storage and need to scan for malware, what are my options?

  • DIY, and build scanning integration capabilities into each application.
  • Use a 3rd Party Cloud Security Posture Management tool that has AV / Malware scanning capabilities.
  • Or donโ€™t use Object Storage, store files on a file system where an AV / Malware solution is installed. Unless you have a specific requirement to interact with the underlying file system I wouldnโ€™t recommend this for a range of reasons, but it is still an option.

Each of these options has its merits. In any case they require time, and some may end up costing more than any benefits you might realise. Saying that, Iโ€™ve also seen first hand what happens in the absence of any anti-malware controls, and object storage buckets being full with malware.

It isnโ€™t all doom and gloom however! If youโ€™re using Oracle Cloud Infrastructure Iโ€™m going to show you how you can easily achieve the requirement of checking uploaded files using OCI native services and the https://virustotal.com/ API.

Itโ€™s important to mention that Iโ€™m using a community API key from https://virustotal.com/ for demo purposes only. And you could easily adapt this approach to use any AV / Malware scanning solution that has an API.

AV / Malware Scanning Considerations

Before I jump into showing you how to configure this in your own OCI Tenancy, there are some things that must be considered first. These considerations would also apply if you were wanting to DIY a solution, or use a Cloud Security Posture Management Tool.

  • Data Sovereignty. Do you need to keep data within a specific set of geographic regions? Your chosen cloud anti-malware solution may not store data in your geographic area, or they may replicate your data across the globe.
  • Local Laws & Regulations. What data resides in your files? You may not want files containing PII leaving your environment, or accessible by 3rd Parties.
  • 3rd Party Risks. If you are using a cloud based anti-malware solution, youโ€™ll want to ensure they have adequate controls to protect the privacy of your data.
  • AV / Malware Licensing & Infrastructure. Do you want to purchase, install and manage the solution, integrations, and support the underlying infrastructure?
  • In-band vs Out-of-band scanning. If users can upload files, specifically large files, the time required to scan may have a negative impact on user experience if they have to wait. Similarly if you scan post upload youโ€™ll need to consider how to handle broken file links when a file is quarantined.
  • Adequate Coverage. Files can get into object storage many different ways including web forms, APIโ€™s, FTP, WEBDAV etc. Whatever solution you choose needs to ensure all files are scanned.
  • Performance & Scalability. Youโ€™ll need to plan how to handle large files, and potentially large numbers of files. If youโ€™re doing in-band scanning, then there is the possibility of users experiencing a Denial of Service if you donโ€™t have adequate capacity.
  • Fail open vs closed. In the case thereโ€™s scan failure, or the scanning service is unavailable, do you want to reject the file, or let it through?
  • Operating Model. If youโ€™re doing out-of-band scanning, how will you support reviewing and responding to files identified as malicious.

Checking for Malware in Oracle Cloud Infrastructure

 

OCI AV / Malware Solution Architecture

The image above illustrates the architecture of my proposed solution. It comprises of:

  • A Compartment, Virtual Cloud Network, Public Subnet, and Internet Gateway. This will likely already exist in your own environment.
  • A custom Ruby OCI Function called scan-upload.
  • One or more buckets where files are uploaded, in my diagram these are called bucket-1 and bucket-2.
  • An Event rule, that triggers the scan-upload function when an object is uploaded to a Bucket.
  • An external API provider returning metadata for known malicious MD5 file hashes. For this demo Iโ€™ve chosen Virus Total.
  • A quarantine Bucket where files that meet the quarantine criteria are moved.
  • A Custom Log called scan-results where JSON file scan results are stored.
  • A Service Connector that pushes logs from the scan-results Custom Log to Object Storage.
  • An Object Collection Rule, Custom Parser and Dashboard in Logging Analytics to view file upload activity and files flagged as malicious.

The benefits of this approach are:

  • The Event Rule will fire for every object uploaded regardless of which Bucket. You can exclude certain Buckets by specifying then in the Function configuration.
  • You can deploy this in more regions, ensuring data sovereignty.
  • Only the fileโ€™s MD5 Hash is send to the 3rd party, removing PII and 3rd party risks.
  • The function makes an outbound HTTPS call only, no inbound rules are required.
  • Scanning is performed out-of-band / post upload, meaning weโ€™re not impacting the user experience.
  • Itโ€™s fast, as weโ€™re only checking the MD5 hash.
  • Itโ€™s scalable as OCI functions scale automatically.
  • You can easily extend the existing Function logic to handle your specific rejection workflows e.g. Updating a file link in your database.
  • You can view real-time insights in Logging Analytics.

For this demo Iโ€™ve limited the scope to a specific compartment and region, however you could easily expand this approach to multiple regions and compartments.

Setup & Configuration

Before we begin, youโ€™ll need a Compartment, Virtual Cloud Network, Public Subnet, and Internet Gateway. If required you can create the networking components via the VCN Wizard.

Youโ€™ll also need to install Docker, and the Fn Project. On OSX installing the Fn Project is easy with Homebrew:

$ brew install fn

To push the function to the OCI container repository youโ€™ll also need an Auth Token which can be generated in OCI Identity by selecting your user, and clicking โ€œAuth Tokensโ€.

Download the function source code from Github https://github.com/scotti-fletcher/oci-av-function. As always I recommend inspecting any source code that you download from the Internet for security issues.

Now weโ€™ll create a Functions application. An application is just a logical grouping of functions, and in this demo we only have one application called โ€œred-thunder-demoโ€ and one function called โ€œscan-uploadโ€.

After creating the application, follow the โ€œGetting Startedโ€ instructions for โ€œLocal setupโ€. The instructions displayed will be unique for your OCI environment, however Iโ€™ll explain the steps as not all are required for this demo.

In terminal, cd into the scan-upload directory containing the function files:

scott@scott-mac ~ % cd ~/Desktop/oci-av-function-main/scan-upload 
scott@scott-mac scan-upload % ls
Gemfile		func.rb		func.yaml

Create a context for this compartment and select it for use. As my compartment is called โ€œred-thunder-demoโ€ you see it in the next statement.

$ fn create context red-thunder-demo --provider oracle
$ fn use context red-thunder-demo

Update the context with the compartment OCID where you created the application and the Oracle Functions API URL.

$ fn update context oracle.compartment-id [your compartment ocid]
$ fn update context api-url https://functions.ap-sydney-1.oraclecloud.com

Create a repository where your function container image will be stored.

$ fn update context registry syd.ocir.io/[your namespace]/red-thunder-demo

Log into the OCI container registry.

$ docker login -u '[your namespace]/oracleidentitycloudservice/scott.fletcher@oracle.com' syd.ocir.io

You should see a โ€œLogin Successfulโ€ message. You can now build and deploy your application. The first time you do this it might take a few minutes:

scott@scott-mac scan-upload % fn deploy --app red-thunder-demo
Deploying scan-upload to app: red-thunder-demo
Bumped to version 1.0.1
Using Container engine docker
Building image syd.ocir.io/abcd/red-thunder-demo/scan-upload:1.0.1 ...................................................
Parts:  [syd.ocir.io abcd red-thunder-demo scan-upload:1.0.1]
Using Container engine docker to push
Pushing syd.ocir.io/abcd/red-thunder-demo/scan-upload:1.0.1 to docker registry...The push refers to repository [syd.ocir.io/abcd/red-thunder-demo/scan-upload]
cd394e6f57be: Pushed 
71adf80122ed: Pushed 
dcec050cc620: Pushed 
3668420c8d32: Mounted from abcd/test-av-setup/scan-upload 
5e4a9dac9f74: Mounted from abcd/test-av-setup/scan-upload 
dedbd9e80d19: Mounted from abcd/test-av-setup/scan-upload 
7c1c8ad8e410: Mounted from abcd/test-av-setup/scan-upload 
1.0.1: digest: sha256:769bbe97af259c710033b59e494c9765413a11e7cb5eab19fade525e293c82ee size: 1783
Updating function scan-upload using image syd.ocir.io/abcd/red-thunder-demo/scan-upload:1.0.1...
Successfully created function: scan-upload with syd.ocir.io/abcd/red-thunder-demo/scan-upload:1.0.1

Once created, you should be able to see the function in the OCI console under applications and also in the Container Registry.

Now we need to create a Log Group to hold our Function specific logs and scan results. Create a log group, Iโ€™ve named mine โ€œav-function-log-groupโ€:

In logs, click โ€œCreate custom logโ€ and call it โ€œscan-resultsโ€.

When prompted select โ€œAdd configuration laterโ€ and click create. You should see the log โ€œscan-resultsโ€ in the โ€œav-function-log-groupโ€:

Click the โ€œscan-resultsโ€ log, and note down the OCID as weโ€™ll need this later.

Now we need to create the following Buckets:

When creating the buckets, Iโ€™m using the default options however you need to ensure the โ€œEmit Object Eventsโ€ checkbox is selected on bucket-1 and bucket-2. If you have other buckets that you wish to scan youโ€™ll need to update them too. By clicking โ€œEmit Object Eventsโ€ when an object is uploaded the Events Service rule will trigger our function.
Note: We donโ€™t โ€œEmit Object Eventsโ€ for our quarantine bucket, otherwise the function will run twice for the same file.

Next we need to create an Event Service rule that triggers our function:

Now we need to create a Service-Connector to push the scan-results logs into a bucket so they can be collected and ingested by Logging Analytics:

Note you will need to โ€œCreate default policyโ€ as prompted. When you click create this will also enable the โ€œEmit Object Eventsโ€ on the scan-results bucket as itโ€™s required for the Service Connector to run.

Now weโ€™ll go back to our Function, and update the required configuration items. Configuration items are just environment variables that are made accessible to the function:

You can configure the following items:

  • VT_API_KEY: This is your Virus Total API Key.
  • QUARANTINE_BUCKET_NAME: This is the name of the bucket where you want quarantined files to be moved. In this demo we created a bucket called โ€œquarantineโ€ for this purpose.
  • EXCLUDE_BUCKETS: If you have any buckets that you donโ€™t want scanned you can add them here as a comma separated list (with no spaces). Because we donโ€™t want our logs in the scan-results bucket scanned (as thereโ€™s no point) Iโ€™ve added it here.
  • QUARANTINE_THRESHOLD: Virus Total uses a number of different scan engines to provide great coverage. My value of 1 means if 1% of the scan engines report the file as malicious, then I want the function to move the file to the quarantine bucket. I suggest a low value here.
  • DELETE_THRESHOLD: My value of 50 means if 50% of the scan engines report the file as malicious, then I want the function to delete the file. Depending on your specific use case you might want to increase or decrease this value.
  • OCI_LOG_OCID: This is the OCID of the scan-results custom log you created earlier.
  • QUARANTINE_BUCKET_REGION: This is the region where the bucket called โ€œquarantineโ€ is located. Iโ€™ve entered ap-sydney-1 as this is where I created the bucket.
  • ON_ERROR: As I mentioned earlier, you need to consider what to do if thereโ€™s a scan error, network connectivity failure, or API failure (like exceeding your Virus Total API limits). Depending on your use case you might want to delete the object, quarantine the object, or fail open. You can choose to enter โ€œQUARANTINEโ€, โ€œDELETEโ€, or remove this configuration item altogether and fail open if an error occurs.

Functions also emit logs, and itโ€™s useful to see them for debugging purposes. To enable these logs, click โ€œEnable Logโ€:

Before we test our function, we need to create a Dynamic Group, and Policies to allow our function to operate in our environment. Depending on your use-case and where your object storage buckets are, you may need to adjust the policies. My examples below are scoped to the โ€œred-thunder-demoโ€ compartment.

Create a Dynamic Group that defines the Function and compartment:

Create a new policy, with the following policy statements. If youโ€™ve chosen different Dynamic Group and Compartment names, you will need to update the policy statements accordingly:

  • โ€œallow dynamic-group red-thunder-demo-scan-upload-dynamic-group to manage objects in compartment red-thunder-demoโ€. This allows the function defined by the Dynamic Group to manage Objects.
  • โ€œallow dynamic-group red-thunder-demo-scan-upload-dynamic-group to use log-content in compartment red-thunder-demoโ€. This allows the function to write to the custom log that we created to hold our scan results.The last two statements:
  • โ€œallow service faas to {KEY_READ} in compartment red-thunder-demo where request.operation=โ€™GetKeyVersion’โ€
  • allow service faas to {KEY_VERIFY} in compartment red-thunder-demo where request.operation=โ€™Verifyโ€™allow the functions service to read the key used to encrypt and decrypt the files stored in Object Storage.

You should now have two policies in your compartment:

At this point the function should be installed and configured correctly. Before we continue I feel itโ€™s important to mention that handling malware does come with risks and you should take appropriate steps to protect yourself and your organisation from inadvertently executing malware. If youโ€™re not familiar with safe handling practises, consult someone who is, and Iโ€™d also recommend using a sandbox environment for the next parts of this demo.

Iโ€™ve uploaded two ZIP files containing malware. I chose ZIP files specifically so the files contained are not immediately executable. I also know these files are flagged by Virus Total. Iโ€™ve uploaded them to bucket-1 and bucket-2. Once uploaded looking at the function invocation logs I can see the function has run. One object is quarantined because the confidence level is 5%, and the other is deleted outright because the confidence is 80%, which is above my configured value of 50:

At this point, weโ€™ve confirmed the scan-upload function works as expected. Great! However looking at these logs isnโ€™t very exciting so Iโ€™m going to show you how you can visualise these results with Logging Analytics.

If youโ€™ve been following this guide then you might have noticed weโ€™ve already set ourselves up to collect and ingest logs into Logging Analytics. We did this by creating a scan-results bucket and a Service Connector. If youโ€™ve uploaded some malware, after about 10 minutes you should see some logs in the scan-results bucket:

In Logging Analytics create a Log Group to hold our scan-results logs. Iโ€™ve called mine โ€œmalware-scan-resultsโ€:

Download the Logging Analytics Log Source & Parser configuration if you havenโ€™t retrieved it from GitHub https://github.com/scotti-fletcher/oci-av-function/blob/main/malware-log-source.zip

Click โ€œImport Configuration Contentโ€, select the ZIP file and click Import:

Now we need to create an Object Collection Rule that enables collection of the logs from our scan-results bucket and loads them into our malware-scan-results Log Group.

$ oci log-analytics  object-collection-rule create --name malware-collection-rule --compartment-id [Your Compartment OCID] --os-namespace [Your Object Storage Namespace]  --os-bucket-name scan-results --log-group-id [The OCID of the malware-scan-results Log Group] --log-source-name malware-log-source --namespace-name [Your Object Storage Namespace] --collection-type HISTORIC_LIVE --poll-since BEGINNING

The CLI should return a JSON response, indicating your rule creation succeeded. You should also be able to see another Event Rule created:

Download the Logging Analytics Dashboard if you havenโ€™t already from GitHub https://github.com/scotti-fletcher/oci-av-function/blob/main/malware-dashboard.json . Youโ€™ll need to find and replace all values of โ€œENTER_COMPARTMENT_IDโ€ with the OCID of the compartment where you want to create the dashboard.

Using the CLI run the following command. Youโ€™ll also need to update the URL to the endpoint for the region where you want the Dashboard to be created:

$ oci raw-request --target-uri https://managementdashboard.ap-sydney-1.oci.oraclecloud.com/20200901/managementDashboards/actions/importDashboard --http-method POST --request-body file://malware-dashboard.json

You should then be able to view your dashboard. If you donโ€™t see any data, make sure your scan-results bucket has logs in it, and you have selected the correct compartment from the drop down list:

The Dashboard Iโ€™ve created shows some useful information, such as the volume of files scanned, the scan results, the actions taken, the threat names, in which buckets your malware is located, and information about the files flagged as malicious.

Some Final Thoughts

Malware is one of those things we wish didnโ€™t exist, however hopefully Iโ€™ve shown you how you can tackle the problem and perform a basic check of a fileโ€™s MD5 hash using OCI services.

From here, you could easily extend the Functionโ€™s logic to upload the files themselves to Virus Total, or submit them to your own anti-malware solution. You could also invoke other functions to drive your own custom workflows.

Happy Malware Scanning!

The Production Team
The KBI Production Team is a staff of specialist technology professionals with a detailed understanding across much of cybersecurity and emerging technology. With many decades of collective industry experience, as well as expertise in marketing & communications, we bring news and analysis of the cybersecurity industry.
Share This