Operator On The Wire
Join
← Back to Knowledge Base
BLUE TEAM / THREAT HUNT / LINUX / NETWORK

Tunneling and Port Forwarding

This note documents detection patterns related to Linux Tunneling and Port Forwarding on Linux systems.


Direct Indicators

SourceGrep Pattern / ArtifactMeaningForensic ValueNotes
Shell historyssh -LLocal port forwardCriticalCommon attacker pivot method.
Shell historyssh -RRemote port forwardCriticalReverse pivot / callback tunnel.
Shell historyssh -DSOCKS proxy tunnelCriticalFlexible pivoting channel.
Shell historyProxyCommandSSH-based chained tunnelCriticalAdvanced pivot signal.
Shell historysocat TCP-LISTENCustom forward listenerCriticalStrong operator indicator.
Shell historysocat TCP:Direct relayCriticalManual tunnel construction.
Shell historync -lvpListener for forwardingHighSimple tunnel staging.
Shell historychiselDedicated tunneling utilityCriticalVery strong intrusion signal.
Shell historysshuttleTransparent tunnelCriticalAdvanced internal pivoting.
Shell historyiptables -t natTraffic redirectionCriticalPort redirection or covert relay.
ss -plantlistening unexpected local portActive tunnel endpointCriticalRuntime truth.
lsof -itunnel-owning processAttributionCriticalPID linkage.
auditdtunneling command executionProcess attributionCriticalBest attribution if enabled.
Network logslong-lived unusual SSH sessionTunnel persistenceCriticalStrong network clue.

Indirect Indicators

IndicatorWhat To Look ForForensic ValueNotes
Tunnel immediately after footholdPivot preparationCriticalCommon attacker progression.
SOCKS tunnel before internal reconInternal expansionCriticalStrong hostile chain.
Chisel in temp pathDedicated operator toolingCriticalVery strong signal.
SSH tunnel under service accountSuspicious contextCriticalOften exploitation shell.
Listener on high port unexpectedlyForward endpointCriticalRuntime clue.
Long-lived SSH with no shell activityTunnel likelyCriticalStrong operational clue.
Tunnel plus internal SSH movementActive pivotCriticalMulti-host compromise signal.
NAT redirection after root shellAdvanced pivotCriticalMature operator behavior.
Hidden binary owns listenerConcealed tunnelCriticalStrong malicious signal.
Tunnel plus cleanupMature intrusion disciplineHighOperator maturity clue.

Common Tools

ToolUsage
ssh -LLocal forward.
ssh -RReverse forward.
ssh -DSOCKS proxy.
socatFlexible TCP relay.
ncSimple listener/relay.
chiselDedicated HTTP tunnel.
sshuttleTransparent subnet tunnel.

Relevant Artifacts

ArtifactPath / CommandForensic ValueNotes
Shell history.bash_history, .zsh_historyCriticalTunnel command evidence.
Live socketsss -plant, netstat -plantCriticalActive endpoints.
Process attributionlsof -iCriticalPID linkage.
SSH config~/.ssh/configHighTunnel definitions.
Audit logs/var/log/audit/audit.logCriticalProcess attribution.
Firewall rulesiptables, nftablesCriticalRedirection clue.
Temp binaries/tmp, /var/tmp, /dev/shmHighchisel / helpers often staged here.

MITRE ATT&CK References

  • T1572 Protocol Tunneling
  • T1090 Proxy
  • T1021 Remote Services

Decision Tree

  1. Was tunneling command used?

    • Search shell history and audit logs.
  2. Which tunnel type?

    • Local, remote, SOCKS, relay.
  3. Is listener active?

    • Enumerate sockets and owners.
  4. Did tunnel enable movement?

    • Internal recon, SSH, file transfer.
  5. Is context suspicious?

    • Service account, temp tooling, hidden binary.
  6. Pivot

    • Port → remote endpoint.
    • Process → binary path.
    • Timeline → movement chain.
  7. Confirm tunneling abuse

    • Tunnel command + active socket + suspicious context = strong pivot finding.

Example Detection Templates

Grep

grep -R "ssh -L\|ssh -R\|ssh -D\|ProxyCommand\|socat TCP-LISTEN\|socat TCP:\|nc -lvp\|chisel\|sshuttle\|iptables -t nat" /home/*/.bash_history /root/.bash_history 2>/dev/null

Journalctl

journalctl | grep -E "ssh|socat|iptables"

File Inspection

ss -plant
lsof -i

Sigma

title: Linux Tunneling and Port Forwarding
id: linux-tunneling-port-forwarding
status: experimental
description: Detects suspicious tunneling and port forwarding activity on Linux
logsource:
  product: linux
detection:
  selection_keywords:
    message|contains:
      - 'ssh -L'
      - 'ssh -R'
      - 'ssh -D'
      - 'chisel'
      - 'socat'
  condition: selection_keywords
fields:
  - message
  - hostname
falsepositives:
  - Legitimate administration tunnels
level: high
tags:
  - attack.command_and_control
  - attack.t1572

Mitigation & Hardening

Control AreaMitigationEffectivenessNotes
SSH policyRestrict forwarding featuresCriticalRemoves common pivot path.
Egress filteringLimit arbitrary outbound tunnelsCriticalMajor reduction in tunnel success.
AuditdTrack tunneling commandsHighStrong attribution.
Socket monitoringAlert on unusual listenersHighRuntime visibility.
Temp monitoringDetect chisel / tunnel binariesHighStrong intrusion clue.

Fast Triage Checks

QuestionCommand / ArtifactWhy It Matters
Was forwarding used?grep historyImmediate pivot clue.
Is listener active?ss / lsofRuntime truth.
Which process owns tunnel?PID attributionCore linkage.
Did tunnel enable movement?correlate SSH/reconAttack progression.
Is tool hidden/temp?inspect binary pathStealth clue.

High Value Grep Strings

PatternWhy It Matters
ssh -LLocal forward.
ssh -RReverse forward.
ssh -DSOCKS tunnel.
socatManual relay.
chiselDedicated tunnel utility.
sshuttleTransparent subnet tunnel.
iptables -t natTraffic redirection.

Analyst Notes

ScenarioInterpretation
ssh -D then internal scansStrong pivot chain.
Chisel in temp pathVery strong operator evidence.
Hidden process listening high portConcealed tunnel likely.
Long SSH session no shell activityTunnel probable.
Tunnel plus SSH movementActive multi-host compromise.
NAT redirection after rootMature operator behavior.