πŸ•΅οΈ
VeryLazyTech
πŸ“œ MediumπŸ›’ My ShopπŸ‘Ύ GithubπŸ“© Telegram πŸ“Ί YouTubeβœ– Twitter
  • πŸ•΅οΈWelcome!
    • VeryLazyTech
    • Support VeryLazyTech
      • πŸ‘Ύ GitHub
      • πŸ“œ Medium
      • β˜• My Shop
      • πŸ“Ί YouTube
      • βœ– Twitter
      • πŸ“© Telegram
  • πŸ›‘οΈ Vulnerabilities and Exploits
    • CVE - POC
      • Unauthenticated RCE Flaw in Rejetto HTTP File Server - CVE-2024-23692
      • POC - CVE-2024–4956 - Nexus Repository Manager 3 Unauthenticated Path Traversal
      • POC - CVE-2024-45241: Path Traversal in CentralSquare's CryWolf
      • Telerik Auth Bypass CVE-2024-4358
      • Check Point Security Gateways Information Disclosure - CVE-2024-24919
      • CVE-2024-23897 - Jenkins File Read Vulnerability
      • CVE-2024–10914- Command Injection Vulnerability in name parameter for D-Link NAS
      • POC - CVE-2024-21534 Jsonpath-plus vulnerable to Remote Code Execution (RCE)
      • CVE-2024-9935 - PDF Generator Addon for Elementor Page Builder <= 1.7.5 - Unauthenticated Arbitrary
      • CVE-2024-50623- Cleo Unrestricted file upload and download
      • POC - WordPress File Upload plugin, in the wfu_file_downloader.php file before version <= 4.24.11
      • POC - Remote and unauthenticated attacker can send crafted HTTP requests to RCE - cve-2025-3248
      • POC - CVE-2025-29306 FOXCMS /images/index.html Code Execution Vulnerability
  • πŸ•΅οΈβ€β™‚οΈDorks
    • GitHub Dorks
    • Google Dork Online Tool
  • πŸ“š Resources
    • Top Hacking Books for 2024: FREE and Paid
    • How to Study for OSCP with the PWK Book PDF
    • Top 20 phishing tools to use in 2024
    • Top 8 Bug Bounty Books for 2025: Must-Reads for Ethical Hackers
    • Top Hacking Tools and Skills You Need to Learn in 2025
    • Offensive Cloud
    • Penetration Testing & Hacking Tools List
    • Top Cybersecurity Books by Topic
  • πŸ•ΈοΈPentesting Web
    • Client Side Template Injection (CSTI)
    • Identify a Server’s Origin IP
    • 2FA/MFA/OTP Bypass
  • IDOR
  • Open Redirect
  • Subdomain Takeover
  • Penetration Testing WiFi Networks
  • Client-Side Path Traversal
  • Clickjacking
  • Command Injection
  • JWT Vulnerabilities
  • Bypass rating limit
  • CORS - Misconfigurations & Bypass
  • LDAP Injection
  • File upload vulnerabilities
  • Content Security Policy (CSP) bypass
  • 🐧Linux
    • Practical Linux Commands
    • Bypassing Bash Restrictions - Rbash
    • Privilege escalation - Linux
  • Linux Environment Variables
  • πŸͺŸWindows
    • Active Directory Methodology
  • 🌐Network Pentesting
    • FTP - Port 21
    • SSH- Port 22
    • Telnet - Port 23
    • SMTP/s - Port 25,465,587
    • WHOIS - Port 43
    • TACACS+ - Port 49
    • DNS - Port 53
    • TFTP/Bittorrent-tracker - Port 69/UDP
    • Finger - Port 79
    • Web - Port 80,443
    • Kerberos - Port 88
    • POP - Port 110/995
    • Portmapper - Port 111/TCP/UDP
    • Ident - Port 113
    • NTP - Port 123/UDP
    • MSRPC - Port 135, 539
    • NetBios - Port 137,138,139
    • SMB - Port 139 445
    • IMAP - Port 143, 993
    • SNMP - Ports 161, 162, 10161, and 10162/UDP
    • IRC - Ports 194,6667,6660-7000
    • Check Point Firewall - Port 264
    • LDAP - Ports 389, 636, 3268, 3269
    • IPsec/IKE VPN - Port 500/UDP
    • Modbus - Port 502
    • Rexec - Port 512
    • Rlogin - Port 513
    • Rsh - Port 514
    • Line Printer Daemon (LPD) - Port 515
    • Apple Filing Protocol (AFP) - PORT 548
    • RTSP - Port 554, 8554
    • IPMI - Port 623/UDP/TCP
    • Internet Printing Protocol (IPP) - Port 631
    • EPP - Port 700
    • Rsync - Port 873
    • Rusersd Service - Port 1026
    • Socks - Port 1080
    • Java RMI - RMI-IIOP - Port 1098/1099/1050
    • MSSQL (Microsoft SQL Server) - Port 1433
    • Oracle TNS Listener - Port 1521,1522-1529
  • PPTP - Port 1723
  • MQTT (Message Queuing Telemetry Transport) - Port 1883
  • Compaq HP Insight Manager - Port 2301, 2381
  • NFS Service - Port 2049
  • Docker - Port 2375,2376
  • Squid - Port 3128
  • iScsi - Port 3260
  • SAPRouter - Port 3299
  • 😎Post-exploitation
    • File Transfer Cheatsheet: Windows andΒ Linux
Powered by GitBook
On this page
  • Introduction to Linux Environment Variables
  • Types of Environment Variables in Linux
  • 1. System-Wide Environment Variables
  • 2. User-Specific Environment Variables
  • 3. Shell Variables
  • Commonly Used Linux Environment Variables
  • How to View Environment Variables in Linux
  • How to Set and Export Environment Variables in Linux
  • How to Unset Environment Variables
  • Working with Environment Variables in Scripts
  • Security Considerations for Environment Variables
  • Interesting variables for hacking

Was this helpful?

Linux Environment Variables

PreviousPrivilege escalation - LinuxNextActive Directory Methodology

Last updated 2 months ago

Was this helpful?

  • Become VeryLazyTech ! 🎁Comment

  • Follow us on:

    • βœ– Twitter .Comment

    • πŸ‘Ύ Github .Comment

    • πŸ“œ Medium .Comment

    • πŸ“Ί YouTube .Comment

    • πŸ“© Telegram .Comment

    • πŸ•΅οΈβ€β™‚οΈ My Site .Comment

    CommentComment

  • Visit our for e-books and courses. πŸ“šComment

  • Support us and . β˜•

Introduction to Linux Environment Variables

In a Linux operating system, environment variables are dynamic values that define the behavior of system processes and applications. These variables store configuration data, such as the system path, user preferences, and settings, making them essential for efficient system operations and automation.

Types of Environment Variables in Linux

1. System-Wide Environment Variables

These are available for all users and are set by the system administrator. They are defined in files such as:

  • /etc/environment

  • /etc/profile

  • /etc/bash.bashrc

2. User-Specific Environment Variables

These are defined per user and stored in:

  • ~/.bashrc

  • ~/.profile

  • ~/.bash_profile

3. Shell Variables

Shell variables exist only within the running shell session. They can be created and modified within the terminal.


Commonly Used Linux Environment Variables

  1. PATH The PATH variable defines directories where the system searches for executable files.

    echo $PATH
    export PATH=/usr/local/bin:$PATH
  2. HOME Represents the home directory of the current user.

    echo $HOME
  3. USER Stores the username of the logged-in user.

    echo $USER
  4. SHELL Specifies the default shell of the user.

    echo $SHELL
  5. EDITOR Defines the default text editor.

    export EDITOR=nano
  6. LANG Sets the system language.

    export LANG=en_US.UTF-8
  7. DISPLAY Specifies the display used by the X Window System.

    echo $DISPLAY
    export DISPLAY=:0.0
  8. HISTFILESIZE Sets the maximum number of lines contained in the history file.

    echo $HISTFILESIZE
    export HISTFILESIZE=5000
  9. HISTSIZE Defines the number of lines added to the history file per session.

    echo $HISTSIZE
    export HISTSIZE=1000
  10. HOSTNAME Stores the hostname of the computer.

    echo $HOSTNAME
  11. MAIL Specifies the location of the user’s mail spool.

    echo $MAIL
  12. MANPATH Defines the list of directories to search for manual pages.

    echo $MANPATH
    export MANPATH=/usr/local/share/man:$MANPATH
  13. OSTYPE Indicates the type of operating system.

    echo $OSTYPE
  14. PS1 Defines the default Bash prompt.

    echo $PS1
    export PS1="[\u@\h \W]\$ "
  15. PWD Stores the current working directory.

    echo $PWD
  16. TERM Specifies the current terminal type (e.g., xterm, linux).

    echo $TERM
    export TERM=xterm-256color
  17. TZ Sets the time zone.

    echo $TZ
    export TZ=America/New_York

How to View Environment Variables in Linux

1. Using the printenv Command

printenv
printenv PATH

2. Using the env Command

env

3. Using the set Command

set | less

How to Set and Export Environment Variables in Linux

1. Temporarily Setting an Environment Variable

export MY_VAR="Hello World"
echo $MY_VAR

This variable will be available only for the current session.

2. Permanently Setting an Environment Variable

To make a variable persistent, add it to ~/.bashrc or ~/.profile.

echo 'export MY_VAR="Hello World"' >> ~/.bashrc
source ~/.bashrc

How to Unset Environment Variables

To remove an environment variable:

unset MY_VAR
echo $MY_VAR  # No output

Working with Environment Variables in Scripts

Environment variables are often used in Bash scripting to automate tasks.

Example script:

#!/bin/bash
echo "The current user is: $USER"
echo "The home directory is: $HOME"

Save this as script.sh, then execute:

bash script.sh

Security Considerations for Environment Variables

  1. Avoid Storing Sensitive Data: Never store passwords in environment variables.

  2. Use readonly for Critical Variables:

    readonly SECURE_VAR="Sensitive Data"
  3. Restrict Access to Environment Files:

    chmod 600 ~/.bashrc

Interesting variables for hacking

HISTFILESIZE

Change the value of this variable to 0, so when you end your session the history file (~/.bash_history) will be deleted.

export HISTFILESIZE=0

HISTSIZE

Change the value of this variable to 0, so when you end your session any command will be added to the history file (~/.bash_history).

export HISTSIZE=0

http_proxy & https_proxy

The processes will use the proxy declared here to connect to internet through http or https.

export http_proxy="http://10.10.10.10:8080"
export https_proxy="http://10.10.10.10:8080"

SSL_CERT_FILE & SSL_CERT_DIR

The processes will trust the certificates indicated in these env variables.

export SSL_CERT_FILE=/path/to/ca-bundle.pem
export SSL_CERT_DIR=/path/to/ca-certificates

LD_PRELOAD Allows injecting shared libraries into running processes, often used for privilege escalation or bypassing security measures.

export LD_PRELOAD=/tmp/malicious.so

LD_LIBRARY_PATH Defines directories where the dynamic linker searches for shared libraries, which can be used for hijacking.

export LD_LIBRARY_PATH=/tmp/mylib:$LD_LIBRARY_PATH

PATH Manipulation Adding a malicious directory to PATH can be used for command hijacking.

export PATH=/tmp/malicious:$PATH

TMOUT Automatically logs out an idle user, useful for clearing sessions quickly.

export TMOUT=1

XDG_CONFIG_HOME Can be used to control where applications store configuration files, potentially allowing manipulation.

export XDG_CONFIG_HOME=/tmp/custom-config

IFS (Internal Field Separator) Modifying IFS can be used to change command parsing behavior in scripts.

export IFS=$'\n'

PS1 Manipulation Modify the prompt to hide the current user or create deception.

export PS1='[\u@\h \W]# '

HOME Change HOME to manipulate where programs store configurations or execute files.

export HOME=/tmp/fakehome

MAIL Modify the mail spool directory to read or redirect emails.

export MAIL=/tmp/mail

SUDO_ASKPASS Trick sudo into using a fake prompt to steal passwords.

export SUDO_ASKPASS=/tmp/fake-pass-prompt
sudo -A whoami

GDBINIT Define a malicious GDB startup file to execute arbitrary commands.

export GDBINIT=/tmp/malicious-gdbinit

Support VeryLazyTech πŸŽ‰
  • Follow us on:

Learn & practice

Become VeryLazyTech ! 🎁

βœ– Twitter .

πŸ‘Ύ Github .

πŸ“œ Medium .

πŸ“Ί YouTube .

πŸ“© Telegram .

πŸ•΅οΈβ€β™‚οΈ My Site .

Visit our for e-books and courses. πŸ“š

Support us and . β˜•

member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop
buy me a coffee
For the OSCP.
member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop
buy me a coffee
πŸ”₯ Best Seller πŸ”₯ - Essential Collection: 20+ Hacking and Pentesting E-Books BundleBuy Me a Coffee
Logo