- all process run in /proc
ls /proc
- We can see what command is used to run the process
cat /proc/<process_id>/cmdline
- process std std error log can be found in
cat /proc/<process_id>/fd/1
cat /proc/<process_id>/fd/2
ls /proc
cat /proc/<process_id>/cmdline
cat /proc/<process_id>/fd/1
cat /proc/<process_id>/fd/2
xargs pass the output(stdout) of first command to second command as argument.
ls | xargs rm -f
This will remove all file listed by ls command
-p flag. It’s like dry-run.[root@lp-k8control-1 xargs]# ls
test test2 test3
[root@lp-k8control-1 xargs]# ls | xargs -p rm -f
rm -f test test2 test3 ?...

flag -n1 = one at a time
[root@lp-k8control-1 xargs]# ls | xargs -p -n1 rm -f
rm -f test ?...
flag -I % = run multiple command
[root@lp-k8control-1 xargs]# ls | xargs -p -n1 -I % /bin/bash -c 'ls %; ll % '
/bin/bash -c ls test; ll test ?...y
test

Why?
– Run process in background
– Run database backup in background
Tmux:
#List
tmux ls
#Start session
tmux new -s mysession
#Reconnect
tmux a -t session_name
#Disconnect
ctrl + b + D
#Reconnect to 0 session
tmux a -t 0
More : https://tmuxcheatsheet.com
Screen :
#List
screen -ls
#Named session
screen -A -m -d -S session_name command
#Reconnect to named session
screen -r session_name
#Disconnect
CTRL + a + d
https://gist.github.com/jctosta/af918e1618682638aa82
Nohup:
Nohup command &
It’s create nohup.out file in same directory with all command logs
Jobs:
jobs
fg
bg
strings /lib64/libc.so.6 |grep GLIBC
strings /bin/ls
Usage: strings [option(s)] [file(s)]
Display printable strings in [file(s)] (stdin by default)
The options are:
-a - --all Scan the entire file, not just the data section [default]
-d --data Only scan the data sections in the file
-f --print-file-name Print the name of the file before each string
-n --bytes=[number] Locate & print any NUL-terminated sequence of at
-<number> least [number] characters (default 4).
-t --radix={o,d,x} Print the location of the string in base 8, 10 or 16
-w --include-all-whitespace Include all whitespace as valid string characters
-o An alias for --radix=o
-T --target=<BFDNAME> Specify the binary file format
-e --encoding={s,S,b,l,B,L} Select character size and endianness:
s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit
-s --output-separator=<string> String used to separate strings in output.
@<file> Read options from <file>
-h --help Display this information
-v -V --version Print the program's version number
strings: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex
dd bs=4M if=/home/input.iso of=/dev/sd[?] conv=fdatasync status=progress
[?] = Run lsblk and find your USB
1.Create file and add wifi name and creds (vi /etc/wpa_supplicant.conf)
network={
ssid="ssid_name"
psk="password"
}
2.Connect
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
sudo dhclient wlan0
More : https://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line
https://askubuntu.com/questions/294257/connect-to-wifi-network-through-ubuntu-terminal
WHY?
– Secure access
– Secure path
adduser kool -s /sbin/nologin
#edit /etc/ssh/sshd_config and ADD
Subsystem sftp internal-sftp
Match User kool
ChrootDirectory /opt/dir1/dir2
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
chown root:root -R /opt/dir1/dir2
chmod 755 -R /opt/dir1/dir2
chown kool:kool /opt/dir1/dir2/kool
chmod 700 /opt/dir1/dir2/kool
//Block port 8080
iptables -A INPUT -p tcp --dport 8080 -j DROP
//Allow port 8080
iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
//Delete rule from same command(-D)
iptables -D INPUT -p tcp --dport 8080 -j DROP
//Delete iptable rule for 8080 as per line number
iptables -L --line-numbers
iptables -D INPUT 1
//List rules
iptables -S
iptables -S TCP
iptables -L INPUT
iptables -L INPUT -v
#save
service iptables save
setuid permission:
When program is executed with setuid permission it will executed as owner of that program.
-rwsr-xr-x. 1 root root 27856 Aug 9 2019 /usr/bin/passwd
as passwd has setuid set that’s why normal user can reset their password
#exec will be as owner user
chmod u+s file_name
#exec will be as owner user
chmod 4750 file_name
setgid permission:
When program is executed with setgid permission it will executed as group owner of that program.
-r-xr-sr-x. 1 root tty 15344 Jun 10 2014 /usr/bin/wall
as wall has setgid enabled it has all the permission as group tty has.
chmod u+g file_name
chmod 2700 file_name
Sticky bit:
Owner of files and directory and root can only delete the file when sticky bit is set.
drwxrwxrwt. 16 root root 4096 Oct 10 10:10 tmp
all linux /tmp directory has sticky bit enabled.
chmod +t /tmp
NOTE: Capital S,T displayed when user does not have execute permission on that file
WHY?
– If telnet command is not present on system
– Easy to use
BASH:
ECHO:
#1
echo > /dev/tcp/192.168.0.183/22
#2
echo > /dev/tcp/192.168.0.183/22 && echo "open"
#3
echo > /dev/tcp/192.168.0.183/22 && echo "open" || echo "close"
#4
(echo > /dev/tcp/192.168.0.183/22) > /dev/null 2>&1 && echo "open" || echo "close"
CAT:
cat < /dev/tcp/192.168.0.183/22

CURL:
curl -v telnet://192.168.0.183:22
curl -v telnet://hackfi.initedit.com:80
