Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accented Character Encoding Problems When Using Chameleon with PowerShell #8

Open
RobertoMarcelino opened this issue Jan 21, 2025 · 1 comment

Comments

@RobertoMarcelino
Copy link

RobertoMarcelino commented Jan 21, 2025

Hi, I have this function to enable rules in the firewall.

function Set-FirewallRules {
	chcp 1252 | Out-Null
	# Enable all firewall profiles
	Set-NetFirewallProfile -All -Enabled True
	
	# Specific rules to enable (using DisplayName)
	$rulesToEnable = @(
		'Compartilhamento de Arquivo e Impressora (SMB-Entrada)',
		'Coordenador de Transações Distribuídas (RPC)',
		'Coordenador de Transações Distribuídas (RPC-EPMAP)',
		'Coordenador de transações distribuídas (TCP-Entrada)',
		'Gerenciamento Remoto de Tarefas Agendadas (RPC)',
		'Gerenciamento Remoto de Tarefas Agendadas (RPC-EPMAP)',
		'Gerenciamento de Volumes Remoto - Carregador de Serviço de Disco Virtual (RPC)',
		'Gerenciamento de Volumes Remoto (RPC-EPMAP)',
		'Gerenciamento de Volumes Remoto - Serviço de Disco Virtual (RPC)',
		'Gerenciamento Remoto (RPC) do Windows Defender Firewall',
		'Gerenciamento Remoto de Serviços (NP-Entrada)',
		'Gerenciamento Remoto de Serviços (RPC)',
		'Gerenciamento Remoto de Serviços (RPC-EPMAP)',
		'Gerenciamento Remoto do Log de Eventos (NP-Entrada)',
		'Gerenciamento Remoto do Log de Eventos (RPC)',
		'Gerenciamento Remoto do Log de Eventos (RPC-EPMAP)',
		'Gerenciamento Remoto do Windows Defender Firewall (RPC-EPMAP)',
		'Instrumentação de Gerenciamento do Windows (ASync-In)',
		'Instrumentação de Gerenciamento do Windows (DCOM-In)',
		'Instrumentação de Gerenciamento do Windows (WMI-In)',
		'Logs e Alertas de Desempenho (DCOM-Entrada)',
		'Logs e Alertas de Desempenho (TCP-Entrada)'
	)
	
	# Enable specific rules
	$rulesToEnable | ForEach-Object {
		$rule = Get-NetFirewallRule -DisplayName $_ -ErrorAction SilentlyContinue
		if ($rule) {
			if ($rule.Enabled -ne 'True') {
				Set-NetFirewallRule -DisplayName $_ -Enabled True -Profile Domain
				Write-Host "Rule enabled: $_"
			} else {
				Write-Host "Rule already enabled: $_"
			}
		} else {
			Write-Warning "Rule not found: $_"
		}
	}
}

The rules are written in Brazilian Portuguese (PT-BR) and contain accented characters. When the function is run directly in PowerShell, it works correctly and the rules are enabled without any problems. However, when using Chameleon (with the command python .\chameleon --base64 -t r file.ps -o file1.ps1), the rules stop working because the accented characters are not interpreted correctly at the PowerShell prompt, resulting in distortions in the text.

Rule already enabled: Compartilhamento de Arquivo e Impressora (SMB-Entrada)
AVISO: Rule not found: Coordenador de Transações Distribuídas (RPC)
AVISO: Rule not found: Coordenador de Transações Distribuídas (RPC-EPMAP)
AVISO: Rule not found: Coordenador de transações distribuídas (TCP-Entrada)
Rule already enabled: Gerenciamento Remoto de Tarefas Agendadas (RPC)
Rule already enabled: Gerenciamento Remoto de Tarefas Agendadas (RPC-EPMAP)
AVISO: Rule not found: Gerenciamento de Volumes Remoto - Carregador de Serviço de Disco Virtual (RPC)

@RobertoMarcelino
Copy link
Author

RobertoMarcelino commented Jan 22, 2025

Resolved!

I changed the function:

function Set-FirewallRules {
    # Enable all firewall profiles
    Set-NetFirewallProfile -All -Enabled True
    
    # Rule patterns to enable (using wildcards)
    $rulePatterns = @(
        'Compartilhamento de Arquivo e Impressora (SMB-Entrada)',
        'Coordenador de Transa* (RPC)',
        'Coordenador de Transa* (RPC-EPMAP)',
        'Coordenador de transa* (TCP-Entrada)',
        'Gerenciamento Remoto de Tarefas Agendadas (RPC)',
        'Gerenciamento Remoto de Tarefas Agendadas (RPC-EPMAP)',
        'Gerenciamento de Volumes Remoto - Carregador de Servi* de Disco Virtual (RPC)',
        'Gerenciamento de Volumes Remoto (RPC-EPMAP)',
        'Gerenciamento de Volumes Remoto - Servi* de Disco Virtual (RPC)',
        'Gerenciamento Remoto (RPC) do Windows Defender Firewall',
        'Gerenciamento Remoto de Servi* (NP-Entrada)',
        'Gerenciamento Remoto de Servi* (RPC)',
        'Gerenciamento Remoto de Servi* (RPC-EPMAP)',
        'Gerenciamento Remoto do Log de Eventos (NP-Entrada)',
        'Gerenciamento Remoto do Log de Eventos (RPC)',
        'Gerenciamento Remoto do Log de Eventos (RPC-EPMAP)',
        'Gerenciamento Remoto do Windows Defender Firewall (RPC-EPMAP)',
        'Instrumenta* de Gerenciamento do Windows (ASync-In)',
        'Instrumenta* de Gerenciamento do Windows (DCOM-In)',
        'Instrumenta* de Gerenciamento do Windows (WMI-In)',
        'Logs e Alertas de Desempenho (DCOM-Entrada)',
        'Logs e Alertas de Desempenho (TCP-Entrada)'
    )
    
    # Enable rules that match the patterns
    foreach ($pattern in $rulePatterns) {
        # Convert pattern to use PowerShell wildcard
        $wildcardPattern = $pattern.Replace('*', '*')
        
        # Find all rules that match the pattern
        $matchingRules = Get-NetFirewallRule -DisplayName $wildcardPattern -ErrorAction SilentlyContinue
        
        if ($matchingRules) {
            foreach ($rule in $matchingRules) {
                if ($rule.Enabled -ne 'True') {
                    Set-NetFirewallRule -DisplayName $rule.DisplayName -Enabled True -Profile Domain
                    Write-Host "Rule enabled: $($rule.DisplayName)"
                } else {
                    Write-Host "Rule already enabled: $($rule.DisplayName)"
                }
            }
        } else {
            Write-Warning "No rules found for pattern: $pattern"
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant