Linux commands

apt

apt-get remove <package_name> --purge

OpenSSL

Will generate a password hash for the /etc/passwd file

openssl password123

ldd

Check for libraries associated with a binary

ldd /usr/bin/log-sweeper

Export variables

Check if your PATH variable is exported running export

export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/bin:/sbin:/binusr/local/sbin:/usr/local/bin:/usr/sbin:

Sudo as another user

sudo -u steven /usr/sbin/service ../../bin/bash

Unzip .tar.gz file

tar –xvzf documents.tar.gz

find

List all files from a directory

find smb-data-loot/ -type f 

List all files by its name

find / -name tomcat-users.xml 2</dev/null

mount

root@kali# mount -t cifs //10.10.10.134/Backups /mnt/mounted_share

curl

--header: to add an header to the request

-X: to specify the method

-u: authentication

--upload-file or -T: PUT method

--interface to specify an interface

To POST data

curl -X POST http://internal-01.bart.htb/simple_chat/register.php -d "uname=0xdf&passwd=password"

To PUT data

curl -u 'tomcat:$3cureP4s5w0rd123!' http://10.10.10.194:8080/manager/text/deploy?path=/shell.war --upload-file shell.war

Fetch google.com using wireless interface wlan0

curl --interface wlan0 google.com

grep

Print 5 lines before and 5 lines after the word password.

grep password -B5 -A5

Perform case insensitive search

grep -i password OR grep -i PASSWORD will give the same result

Perform search using regEx

grep -E "thm|tryhackme" log.txt

Useful to list all IP address having a specific port open from a masscan output.

# This create an alias for out command line. This permit select all IP address
alias grep-ip='grep -oE "\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b"'

# List all IP address having the port 445 open 
grep -iE 445/tcp masscan_all.txt | grep-ip | sort -u > <smb_hosts>.txt

pip3

To uninstall a package with pip3.

pip3 uninstall httpx

sed

Add a string after each line. Useful to add an "at [domain_name]" after each line of a file containing username for example.

sed -e 's/$/string after each line/' -i filename

Replace carriage return character with commas.

sed -z 's/\n/,/g' ip-scope.txt

To delete all lines in a file matching a specific pattern

sed '/pattern to match/d' ./infile

On each line, delete everything after a certain matching pattern.

#Delete everything that is after the commas by nothing. 

sed 's/\,.*//' linkedin_names.txt

Replace white space by a dot (.)

sed 's/\s\+/./g' linkedin_names.txt

Remove all empty lines from a file

sed '/^$/d' /tmp/data.txt

To transforme amandine.gagnon@example.com to gagnona@example.com

cat emails.txt| sed 's/([a-zA-Z])[a-zA-Z].([a-zA-Z])@(.*)/\2\1@\3/g' | tr '[:upper:]' '[:lower:]'

wget

To download a release from a GitHub repo.

wget https://github.com/projectdiscovery/dnsx/releases/download/v1.1.0/dnsx_1.1.0_linux_amd64.zip

rm

Remove a non-empty directory.

rm -r <DIR_NAME>

PATH environment

Check for PATH environment variable

echo $PATH

Add a directory to PATH environment variable

# Not permanent
  export PATH=$PATH:$GOPATH/bin
  
# Permanent
  export PATH=$PATH:$GOPATH/bin
  source ~./profile

Adding the binary to the /usr/local/bin directory

This will make the executable available from any location on our host. Example of moving the kerbrute binary into the bin folder.

sudo mv kerbrute_linux_amd64 /usr/local/bin/kerbrute

cat

Combine the content of two files.

cat emails-2.txt >> emails.txt

Combine the content of multiple files

cat file1.txt file2.txt file3.txt > file-end.txt

tr

Convert all the content of a file to lower case.

tr A-Z a-z < input_file.txt

Last updated