T@b1e 0F C0ntent5
Unveiling Hidden Commands
Welcome to the third technical article, blue teamers! Today’s article isn’t about a well-known command, but rather a barely known one with significant impact on the offensive side. So, grab your bag of ships, sit down with your command line, and let’s begin detecting Windows secrets.
Delving into Lesser-Known Windows Secrets
Recently, I was investigating an incident, during the flow I created a table within the SIEM solution that displayed the attacker's_time
,ProcessCommandLine
,ParentProcessCommandLine
,message
, and more. I started analyzing the attacker's executed commands, which ranged from Active Directory enumerations to host enumerations and obfuscated PowerShell commands. However, one command that caught my attention was calledChcp
.
Have you ever heard of the chcp
command? I like to call it the "chips 'n' crisp"
(Bro is delusional), but its main name is the code page
. Now, let's dive into it. But first, let’s understand how the command line interprets the code we enter.
Command Line Demystified
When you write code in the command line, you're basically giving instructions to the computer's OS. The command line interpreter (CLI) processes these commands, into these sections.
- You type a command and press
Enter
. The CLI reads this input. - The CLI breaks down the command into parts, such as the
command name
and anyarguments
oroptions
. - The CLI recognizes
ls
as abuilt-in
command. It locates thels
executable and runs it. Thels
commandreads the current directory
andretrieves the list
of files and directories. - The result of the command is displayed on the console. This could be
text
, anerror
message, orsomething else
, depending on the command and its execution, for our example it will list all data inside the current directory.
$ ls
file1.txt file2.txt directory1 directory2
Decoding Console Code Pages: A Deep Dive into CHCP
The active console code page
is a crucial aspect of how text is displayed
and interpreted
in the Windows command prompt.
A code page
is essentially a set of character codes used to decode text
. The default code page is determined by the Windows Locale
, but you can change it using the CHCP
command, which stands for Change Code Page
.
Windows Locale refers to regional settings that define the user's language, date/time format, currency, and sorting preferences.
Why Does It Matter? Unveiling the Importance of Code Pages
- Character Display: The code page dictates
which characters are displayed
when you type in thecommand prompt
. This is especially important whendealing with characters outside
the standardASCII
range (0-127), likespecial symbols
orcharacters
fromnon-English
languages. - Session Specific:
Any changes made
to the code page usingCHCP
areonly
for the current session. If you open a new command prompt, it willuse the default code page
unless you change it again.
Real-World Applications: How to Use CHCP Effectively
- Simply type
CHCP
in the command prompt, and it will display thecurrent active code page
number. - To change the code page, use
CHCP
followed by the code page number, For example, to change to code page65001 (UTF-8)
, you would type: - This command
changes the code page
for the current session to65001
. - If you start
another command prompt
from within thecurrent one
, it willinherit
the new code page. For instance: - The new command prompt window will use the
code page 65001
set in the original session.
C:\> CHCP
Active code page: 437
C:\> CHCP 65001
C:\> CMD
Top Code Pages You Should Know
Code Page | Country/ Region/ Language |
437 | United States (default code page in the US) |
850 | Multilingual (Latin I) |
852 | Slavic (Latin II) |
65000 | UTF-7 |
65001 | UTF-8 |
Decoding Character Encoding Standards
ASCII
: American Standard Code for Information Interchange, a 7-bit
character encoding standard for text. Example: A
is represented by 65
.
UTF-8
: Universal Character Set Transformation Format, a variable-length encoding for Unicode that uses 1 to 4
bytes. Example: A
is represented by 65
, and 😊 (smiling face) by F0 9F 98 8A
.
- When we say
UTF-8
supports a range of up to4
bytes, it means a character can be represented using up to4 bytes
(or8 hexadecimal characters
, since each byte is2 hex
characters). - For instance, an emoji like 😊 is encoded in
UTF-8
using4
bytes, which in hexadecimal is represented as4
pairs of hex characters:F0 9F 98 8A
.
Code Page Clues: Unmasking Attackers Through the chcp
Command
An attacker exploits a Windows machine and executes the chcp
command to query the current code page.
For instance:
C:\> chcp
The system responds with:
C:\> Active code page: 437
Unveiling Locale Secrets
- Attackers identify system locale settings (e.g.,
language
,character encoding
). - Knowing the
code page
ensures their scripts or malware run without encoding errors.
Crafting Region-Specific Payloads
- A
non-English code page
(e.g., 850 for Western European languages) prompts attackers to use localized filenames, commands, or data formats.
Spotting Anomalies in Encoding Commands
- Security tools can flag unusual usage of
chcp
duringodd times
or by suspicious processes
. - Rare use by legitimate users makes it a potential red flag for malicious activity.
Turning Recon into a Defense Opportunity
Alerting
on such behavioroffers early insight
into possible reconnaissance attempts.- Defenders can
respond proactively
to mitigate further malicious actions.
IcedID
Detection through Code Page Change Monitoring
EDR agents detectedchcp.exe
being run bycmd.exe
with specificcommand-line arguments.
This activity can indicate malware, likeIcedID
, which uses this technique to determine thelocale
,language
, orcountry
of the compromised system. If malicious, this could lead tofurther system compromise
anddata exfiltration
Cracking the Code: MITRE ATT&CK
Resource Link: Command and Scripting Interpreter, Technique T1059 - Enterprise | MITRE ATT&CK®
KQL
Command-Line Sleuth: Detecting Suspicious CodePage
IcedID
Switches via CHCP
We are going to write a Kusto Query Language (KQL)
query to detect suspicious code page
switches in command line.
SecurityEvent
| where ProcessName endswith "chcp.com"
| where CommandLine has_any (" 936", " 1258")
| project TimeGenerated, Computer, ProcessName, CommandLine, ParentCommandLine
Closing Thoughts
I hope you found this article useful and enjoyed those chips and crisps! If you have any more questions or need further assistance, feel free to ask me on LinkedIn → www.linkedin.com
Written By: Sameer Fakhoury aka.semo