Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Install-pfSenseBackup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ $LogsTaskName = "pfSense Logs - $Name"
$SshKeyFile = Join-Path $SecDir "$Name.ssh_ed25519"
$KnownHosts = Join-Path $SecDir "$Name.known_hosts"
$KeyLineFile = Join-Path $CfgDir "$Name-chave-ssh-pfsense.txt"
$ToolVersion = '2.1.1' # versao do pfSense-Backup
$ToolVersion = '2.1.2' # versao do pfSense-Backup
$SchemaVersion = 3 # versao do formato do config\<Nome>.json (1 = sem o campo; 3 = logs pelo SSH)
$DefaultLogSources = 'sistema,portal,openvpn,ipsec,dhcp,dns,gateways,firewall,pfblockerng,suricata,squid,squidguard,dhcp-concessoes'
$DefaultSshSources = 'sistema,autenticacao,portal,openvpn,ipsec,dhcp,dns,gateways,firewall,pfblockerng,suricata,squid,squidguard,dhcp-concessoes'
Expand Down
4 changes: 3 additions & 1 deletion Logs-pfSense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function New-ForcedCommand([string]$Root = '') {
# Script que o pfSense roda no lugar de QUALQUER comando enviado com a chave do
# servidor (command="..." no authorized_keys). Uma linha, sem aspas simples (vai
# dentro de sh -c '...' e o shell do usuario e o tcsh). $Root so existe para os testes.
# NUNCA usar o caractere de exclamacao: o sshd roda isto via "tcsh -c", e o tcsh faz
# expansao de historico com ele MESMO dentro de aspas simples ("0: Event not found.").
$files = @("$Root/var/log/system.log*", "$Root/var/log/auth.log*", "$Root/var/log/portalauth.log*",
"$Root/var/log/openvpn.log*", "$Root/var/log/ipsec.log*", "$Root/var/log/dhcpd.log*",
"$Root/var/log/resolver.log*", "$Root/var/log/gateways.log*", "$Root/var/log/filter.log*",
Expand All @@ -168,7 +170,7 @@ function New-ForcedCommand([string]$Root = '') {
'case "$1" in ' +
'list) [ $# -eq 1 ] || exit 2; for f in ' + $glob + '; do [ -f "$f" ] && [ -r "$f" ] && ok "$f" || continue; ' +
's=$(wc -c < "$f" | tr -d " "); case "$f" in *.bz2) h=-;; *) h=$(head -n 1 "$f" | cksum | cut -d " " -f 1);; esac; echo "$s $h $f"; done; exit 0;; ' +
'get) [ $# -eq 3 ] || exit 2; ok "$2" || exit 2; case "$3" in *[!0-9]*|"") exit 2;; esac; n=$(($3+1)); ' +
'get) [ $# -eq 3 ] || exit 2; ok "$2" || exit 2; [ -n "$3" ] && [ -z "$(printf %s "$3" | tr -d 0-9)" ] || exit 2; n=$(($3+1)); ' +
'case "$2" in *.bz2) bzcat -- "$2" | tail -c +$n;; *) tail -c +$n -- "$2";; esac; exit 0;; ' +
'sig) [ $# -eq 2 ] || exit 2; ok "$2" || exit 2; ' +
'case "$2" in *.bz2) bzcat -- "$2" | head -n 1;; *) head -n 1 -- "$2";; esac | cksum | cut -d " " -f 1; exit 0;; ' +
Expand Down
1 change: 1 addition & 0 deletions docs/atualizacao.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Rodar de novo um perfil **já atualizado** funciona como antes: o instalador mos
| 1 | (sem o campo) | Backup diário do `config.xml`, pinning, status para o Zabbix, cópia externa, criptografia |
| 2.0.0 | `2` | [Relatório de auditoria](auditoria.md), [coleta de logs](logs.md) (com a planilha de visitantes e o LightSquid) e atualização sem refazer o processo |
| 2.1.0 | `3` | Logs **pelo SSH com chave travada**: completos (inclusive firewall e autenticação), sem lacuna e quase sem peso no pfSense. Suricata por interface. Na atualização da 2.0, o instalador pergunta só o modo (SSH ou WebGUI) |
| 2.1.2 | `3` | Correções no Windows Server 2016 (PowerShell 5.1) e no pfSense (shell `tcsh`). Quem já instalou a 2.1.x: rodar o instalador de novo e **trocar a chave** no User Manager pela linha nova de `config\<Nome>-chave-ssh-pfsense.txt` |
4 changes: 3 additions & 1 deletion tests/Test-Logs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ function ArqSsh([string]$Cat) { $d = Get-Date; return (Join-Path $sw "logs-pfsen

Cenario 'a trava recusa tudo que nao for list/get/sig dos logs' {
$tentativas = @('id', 'list x', 'get /etc/passwd 0', 'get /var/log/../../../etc/passwd 0', 'get /var/log/system.log 0;id',
'get /var/log/system.log abc', 'sig /etc/passwd', 'get', 'get /var/log/nginx.log 0')
'get /var/log/system.log abc', 'get /var/log/system.log -n', 'get /var/log/system.log 1a', 'get /var/log/system.log 0x10',
'sig /etc/passwd', 'get', 'get /var/log/nginx.log 0')
foreach ($t in $tentativas) {
$r = Invoke-Ssh ($t -split ' ')
$out = Read-Text $r.Out
Expand Down Expand Up @@ -257,6 +258,7 @@ Cenario 'linha da chave para o pfSense: travas e aspas escapadas' {
if ($l -notmatch '^restrict,from="172\.16\.10\.7",command="/bin/sh -c ''.*''" ssh-ed25519 AAAAC3NzaTESTE pfSense-Backup$') { throw "formato: $l" }
$soltas = ([regex]::Matches(($l -replace '\\"', ''), '"')).Count
if ($soltas -ne 4) { throw "aspas sem escape dentro do command: $soltas (esperado 4: from e command)" }
if ((New-ForcedCommand).Contains([string][char]33)) { throw 'o comando forcado tem exclamacao: o tcsh do pfSense expande como historico e quebra tudo' }
"($($l.Length) caracteres)"
}

Expand Down
Loading