The Hive
GitHubLinkedInEmail
  • šŸ Home
  • 🌐RECON
    • šŸ“”Passive (OSINT)
      • ā©Metadata
      • ā©Social Platforms
        • Email
        • Tumbler
        • Redit
        • Github
        • Tinder
        • TikTok
        • Snapchat
        • Instagram
        • Facebook
        • Twitter
        • Google
        • LinkedIn
    • šŸ“”Active
      • ā©Host Discovery / Network Mapping
      • ā©nmap cheat sheet
      • ā©masscan cheat sheet
    • šŸ“”Web Recon
      • ā©Web Server Discovery
      • ā©Hidden Hosts
      • ā©Directories & Subdomains
      • ā©SSL Certs
      • ā©CMS
      • ā©WAF Detection
    • šŸ“”Firewall Evasion
  • šŸ“—Web Attacks
    • 🟢Server Side
      • 🟩Authentication Mechanisms
      • 🟩Access Control (Authorization)
      • 🟩Directory Traversal
      • 🟩OS Command Injection
      • 🟩Server-Side Request Forgery (SSRF)
      • 🟩XML External Entity (XXE) Injection
      • 🟩File Upload
      • šŸ”§SQL Injection
      • 🟩Information Disclosure
      • 🟩Business Logic
    • 🟢Client Side
      • 🟩Cross-site request forgery (CSRF)
      • šŸ”§Cross-site scripting (XSS)
  • šŸ“’Network attacks
    • 🟔Network Services
      • 🟨Brute Force
      • 🟨DNS
      • 🟨IPv6
      • 🟨FTP
      • 🟨SSH
      • 🟨SMB
      • 🟨SNMP
      • 🟨SMTP
      • 🟨POP3
      • 🟨IMAP
      • 🟨MSSQL
      • 🟨MySQL
      • 🟨MSRPC / RPCbind
      • 🟨LDAP
      • 🟨NTP
      • 🟨NFS
      • 🟨Telnet
      • 🟨WebDAV
      • 🟨RDP
      • 🟨RSIP
      • 🟨Rlogin
      • 🟨VPNs
      • 🟨Echo
      • šŸ”§RTP
      • šŸ”§VOIP
        • SIP
    • 🟔Network Devices
      • 🟨IPv6 Attacks
        • Neighbor Impersonation
        • Router Advertisement Flooding
      • 🟨Switch Attacks
        • Cisco Exploitation
        • STP Spoofing
        • VLAN Hopping
        • MAC Flood
      • 🟨Router Attacks
        • Router Exploitation
        • HSRP Hijacking
        • šŸ”§RIP Spoofing
        • šŸ”§OSPF Attacks
        • šŸ”§VRRP MitM
      • 🟨NAC Bypass
        • Captive Portal
        • 802.1X / EAP Bypass
      • 🟨Printer Exploitation
    • 🟔MITM & Poisoning
      • 🟨Bettercap
      • 🟨HTTPS Downgrade / HSTS Bypass
      • 🟨Session Hijackings
      • 🟨Malicious Update
      • 🟨RDP Downgrade
      • 🟨DNS Spoofing
      • 🟨NTP Spoofing
      • 🟨ARP Spoofing
      • 🟨DHCP Poisoning
      • 🟨DHCPv6 Spoofing
      • 🟨SSDP Spoofing
      • 🟨WSUS Spoofing
      • 🟨ADIDNS Poisoning
      • 🟨WPAD Abuse
    • 🟔Wireless Attacks
      • 🟨Protocol Concepts
      • 🟨Basics
      • 🟨Attacks
    • 🟔Sniffing
      • 🟨Wireshark
      • 🟨tcpdump
    • 🟔Denial of Service
  • šŸ“•Red Team
    • šŸ”“Windows
      • ā­•Security Concepts
        • Windows Security Components
        • Active Directory Components
        • Kerberos
        • Loggon Sessions and Access Tokens
        • Permissions and Access Control
        • Windows Registry
        • Object Management
      • ā­•Physical Attack
      • ā­•Enumeration
      • ā­•Privilege Escalation
        • DLL Hijacking
          • Phantom DLL Hijacking / Replacement
          • Search Order Hijacking ( Preloading )
          • DLL Side-Loading
        • Service Misconfigurations
          • Weak Registry Permissions
          • Insecure Service Executables
          • Insecure Permission
          • Unquoted Service Path
        • Creating a New Service (admin to system)
        • Registry
          • AlwaysInstallElevated
          • AutoRuns
        • Scheduled Tasks
        • Mass Roll-outs
        • Startup Apps
        • Installed Applications
        • Loopback Services
        • Insecure GUI APPs
        • Potatos
        • Printspoofer / SEImpersonate
        • PSEXEC (admin to system)
      • ā­•Credential Dumping
      • ā­•Persistence
        • Invisible Account Forger
        • Add User
        • Scheduled Tasks
        • Run Registry Keys
        • Logon Scripts
        • Screensavers Hijack
        • Powershell Profiles & Modules
        • Service Creation/Modification
        • Shortcut Modification
        • Startup Folder
        • RDP backdoors
        • COM Hijacking
    • šŸ”“Active Directory
      • ā­•Domain Enumeration
      • ā­•Tools & Frameworks
        • Evil-WinRM
        • CME cheat sheet
        • SharpSploit
        • impacket cheat sheet
        • DeathStar
      • ā­•Exploitation
        • LLMNR Poisoning
        • SMB/NTLM Relay
        • DNS Takeover + LDAP Relay
        • Cracking Hashes
        • Password spraying
        • ADCS + PetitPotam NTLM Relay
        • EternalBlue
        • ZeroLogon
        • MS Exchange ProxyShell
        • MS Exchange ProxyLogon
        • Java JBOSS
      • ā­•Privilege Escalation
        • Token Impersonation
        • DNS Admins
        • AD CS Abuse
        • ACL Abuse
          • GenericAll
          • Write Property
          • Self-membership
          • ForceChangePassword
          • Managed Security Groups
          • Exchange Windows Permissions
        • Group Policy Objects (GPOs)
        • Custom SSPs
        • PrintNightmare
      • ā­•Lateral Movement
        • RDP Password Decryption
        • RDP Session Hijacking
        • headless RDP with SharpRDP
        • Domain Shares
        • SCF File Attacks
        • Pass the Hash / Password
        • Overpass the Hash / Pass the Key
        • Pass The Ticket
        • Kerberosting / AS-REP Rosting
        • Kerberos Delegation
      • ā­•Credential Dumping
        • CredSSP / TSPKG
        • Wdigest Clear Text
        • DPAPI secrets
        • SAM & Registry
        • NTDS.dit & vshadow
        • comsvcs.dll
        • Meterpreter
        • Procdump & LSASS
        • AD User Comments
        • SYSVOL & Group Policy Preferences
        • LAPS Passwords
        • GSMA Passwords
        • HiveNightmare
        • Mimikatz Cheat sheet
        • Other Tools / Techniques
      • ā­•Persistence
        • Certificates
        • DCSync
        • DCShadow
        • Silver Ticket
        • Golden Ticket
        • Skeleton Key
        • WMI
        • PowerShell Remoting
        • Remote Registry
        • Rights Abuse
        • AdminSDHolder
        • DSRM
        • Kerberos Checksum Validation ( MS14-068 )
    • šŸ”“Linux
      • ā­•Physical Attacks
      • ā­•Enumeration
      • ā­•Privilege Escalation
        • SUID / SGID abuse
        • /etc/shadow & /etc/passwd
        • cron/crontab abuse
        • Sudo Abuse
        • Capabilities Abuse
        • Environment Variables
          • LD_LIBRARY_PATH
          • LD_PRELOAD
        • Shared Object Injection
        • NFS
        • man CE Pager Argument
        • MySQL UDF
        • UDEVD
        • STDIN/STDOUT
        • Unix Socket Exploitation
        • Dirty Pipe
        • Docker
          • SUID Docker
      • ā­•Lateral Movement
        • Infecting Running Processes
        • VIM Config File Keylogger
        • SSH Hijacking
        • Samba Secrets to Domain Admin
        • Hiding Processes
        • Simple User-mode Rootkits
        • Vino VNC Server
      • ā­•Credential Dumping
        • Swap Dump
        • mimipinguin
        • unshadow
        • 3snake
      • ā­•Persistence
        • Startup User File Backdoor
        • PHP Backdoor
        • Apache mod_rootme
        • Startup Service Backdoor
        • xdg Backdoor
        • rootbash SUID
        • apt Backdoor
        • Driver Backdoor
        • Core Pattern
        • dash Backdoor
        • Creating an SUID Binary
        • Systemd netcat bind shell
        • Xinetd UDP portnock
        • openSSL reverse shell
        • motd Backdoor
        • Auth Log Backdoor
        • RSYSLOG Backdoor
        • sshd Backdoor
        • VIM Config Backdoor
        • .bashrc Backdoor
        • Adding a Root user
        • Crontab Reverse Shell
        • SSH persistence password-less
      • ā­•Covering Tracks
    • šŸ”“Command & Control (C2)
      • ā­•Cobalt Strike
      • ā­•Metasploit
      • ā­•Empire & Starkiller
      • ā­•Covenant
    • šŸ”“Shells and Payloads
      • ā­•Shell Escape / Interactive Shell
      • ā­•LOL Binaries
      • ā­•msfvenom
      • ā­•SharpShooter & Ivy
      • ā­•Other Payloads
    • šŸ”“Payload Delivery
      • ā­•Powershell Reflective DLL Load
      • ā­•HTML Smuggling
      • ā­•Office Macros
      • ā­•DDE Auto - Word/Excel
      • ā­•.SLK Excel
      • ā­•XLM Macro 4.0
      • ā­•LNK
      • ā­•embedded OLE + LNK objects
      • ā­•JScript
      • ā­•HTA
      • ā­•VBS
      • ā­•VBA
      • ā­•RTF
      • ā­•REG
      • ā­•MSI / MSIEXEC
      • ā­•IQY
      • ā­•CHM / HHC
      • ā­•SCR
    • šŸ”“Pivoting
      • ā­•SSH Forwarding
      • ā­•Socat Stealth Port Forward
      • ā­•Socat Reverse Shell Relay
      • ā­•HTTP Tunneling
      • ā­•ICMP Tunneling
      • ā­•DNS Tunneling
      • ā­•Metasploit Pivoting
      • ā­•Cobalt Strike Pivoteing
      • ā­•VPN Tunneling
      • ā­•Other Tools
    • šŸ”“Exfiltration / File Transfer
      • ā­•Encode / Decode Files
      • ā­•TCP / UDP
      • ā­•DNS
      • ā­•SSH
      • ā­•ICMP
      • ā­•SMB
      • ā­•FTP
      • ā­•HTTP
      • ā­•Other Methods
    • šŸ”“Password Attacks
      • ā­•Online Attacks
      • ā­•Offline Attack
      • ā­•Word List
      • ā­•Cheat Sheet
    • šŸ”“Defense Evasion
      • ā­•Basic Tricks
      • šŸ”§Powershell Tricks
      • ā­•Disabling Defenses
      • ā­•UAC Bypass
      • ā­•Process Migration
      • ā­•Dechaining Macros
      • ā­•VBA Sandbox Evasion
      • ā­•AMSI Bypass
      • ā­•SRP & AppLocker Bypass
      • ā­•GPO Bypass
  • šŸ“˜Blue Team
    • šŸ”µThreat Modeling / Hunting / Intelligence
    • šŸ”µLinux Hardening
      • šŸ”¹OS Security
        • Update Strategy
        • Service Management
        • Physical Security
        • Grub Hardening
        • Kernel Parameters
        • Process Isolation
      • šŸ”¹Accounts & Passwords
        • Users & Groups
        • Password Security & Sudoers
      • šŸ”¹Access Control & Ownership
      • šŸ”¹File System Security
      • šŸ”¹Integrity Check
      • šŸ”¹Sandboxing
      • šŸ”¹Network
      • šŸ”¹iptables
        • Rule Sets
      • šŸ”¹Service Hardening
        • BIND9
        • vsftpd
        • Nginx
        • Apache
        • SSH
      • šŸ”¹System Audit
      • šŸ”¹Logging
        • auditd
      • šŸ”¹Encryption
    • šŸ”µSecurity Architecture
      • šŸ”¹Layered Security
  • 🟪Purple Teaming
    • 🟣Adversary Emulation
  • 🟧programming
    • 🟠C Programming
      • šŸ”øBasic Structure
      • šŸ”øGCC Compiler
      • šŸ”øPreprocessors
      • šŸ”øData Types
      • šŸ”øType Qualifiers
      • šŸ”øPointers
      • šŸ”øDynamic Memory Allocation
      • šŸ”øLoops
      • šŸ”øConditional Statements
      • šŸ”øFunctions
      • šŸ”øInput / Output
      • šŸ”øMacros
      • šŸ”øFiles
      • šŸ”øStrings Manipulation
      • šŸ”øBit Manipulation
      • šŸ”øData Structures
        • Arrays
        • Structures
        • Unions
      • šŸ”øAbstract Data Types
        • Stack
        • Queue
        • Linked List
          • Singly Linked List
          • Doubly Linked List
      • šŸ”øLibraries & Linking
      • šŸ”øError Recovery
    • šŸ”§Assembly ( NASM )
      • Intel IA-32 Environment
      • Basic Structure
      • Variables and Data Types
      • Most-used Instructions
      • input / output
  • 🟫Miscellaneous
    • 🟤GNU Screen / tmux
    • 🟤SSH Tricks
    • 🟤Cats
      • netcat
      • ncat
      • pwncat
      • socat
      • šŸ”§powercat
    • 🟤Curl
    • 🟤Cross-compiling Binaries
Powered by GitBook
On this page
  • Normal User
  • Sudoer User
  1. Red Team
  2. Linux
  3. Persistence

VIM Config Backdoor

Normal User

Obviously this will work only if the user runs the vim editor.

The VIM editor is a widely used command line text editor on Linux and it (or its predecessor vi ) is installed on nearly all Unix and Linux systems by default. It is well known for its extensive functionality and, as a result, presents us with an opportunity for exploitation

On many Linux systems, user-specific VIM configuration settings are located in a user’s home directory in the .vimrc file. This file takes VIM-specific scripting commands and configures the VIM environment when a user starts the application.

These commands can also be run from within the editor by typing a colon (:) character followed by the desired command. For example, if we want to print a message to the user, we can use the following command in the .vimrc file or within the editor

:echo "this is a test"

Putting our commands directly into the user’s .vimrc file isn’t particularly stealthy, as a user modifying their own settings may accidentally discover the changes we’ve made. There is, however, another option.

We can ā€œsourceā€ a shell script using the bash source command. This loads a specified shell script and runs it for us during the normal configuration process.

We can also ā€œimportā€ other VIM configuration files into the user’s current config with the :source command. Note that the source call for loading a VIM configuration file is prepended with a colon and not an exclamation point, which is used for shell commands.

As a more stealthy approach, we can leverage the VIM plugin directory. As long as the files have a .vim extension, all VIM config files located in the user’s ~/.vim/plugin directory will be loaded when VIM is run.

We can modify the user’s .vimrc file in their home directory (or create one if they don’t have it) and add the following line.

!source ~/.vimrunscript

This will load and run a shell script called .vimrunscript from the user’s home directory. In a real- world scenario, it might be useful to pick a file path outside the user’s home directory but for simplicity, we’ll keep it here.

Next, we can create the shell script file at /home/w4lk3r/.vimrunscript with the following contents.

#!/bin/bash
echo "hacked" > /tmp/hacksrcout.txt

The script echoes the word ā€œhackedā€ to a file called /tmp/hacksrcout.txt

if we try to run VIM now, we get an obvious debug output message explaining that we’re sourcing a configuration file.

vi /tmp/test.txt
:!source /home/offsec/.vimrunscript

This is obviously undesirable as it would tip off the user. Luckily, VIM has a built-in command for this, the :silent command.

This command mutes any debug output which would normally be sent to the user when running VIM. We’ll change our line in the user’s .vimrc file to the following.

:silent !source ~/.vimrunscript

Sudoer User

In most cases, users with sudo rights are required to enter their password when performing activities with elevated permissions via the sudo command. We can’t perform activities as root via sudo because we don’t know the user’s password. We can weaponize this VIM vector to gain root privileges if the user runs VIM as root or uses the visudo command

VIM handles its configuration files differently for a user in a sudo context depending on the distribution of Linux. In some systems such as Ubuntu and Red Hat, VIM will use the current user’s .vimrc configuration file even in a sudo context. In other distributions, such as Debian, in a sudo context, VIM will use the root user’s VIM configuration

if the user runs VIM via sudo, our script being sourced will also run as root. Because of this, we will achieve root access without any extra effort. On a Debian or similar system that does not persist the user’s shell environment information when moving to a sudo context, we can add an alias to the user’s .bashrc file.

alias sudo="sudo -E"

An alias is just a shortcut to substitute a different command when a specific command is entered on the command line. The alias above replaces a standard sudo call with one that will force sudo to persist the user’s VIM settings. The shell script being loaded will then also run as root. We will need to source our .bashrc file from the command line if we want the alias changes to go into effect right away.

source ~/.bashrc
Previoussshd BackdoorNext.bashrc Backdoor

Last updated 2 years ago

šŸ“•
šŸ”“
ā­•