Skip to content

Instantly share code, notes, and snippets.

@tylrd
Last active June 22, 2018 03:33
Show Gist options
  • Save tylrd/5f0fbd0e0811aef29b2e8fc946108549 to your computer and use it in GitHub Desktop.
Save tylrd/5f0fbd0e0811aef29b2e8fc946108549 to your computer and use it in GitHub Desktop.
Useful Commands

Useful Misc Commands

Download and untar

$ curl -SL http://somewhere.com/path/to/something.tar.xz | tar xJv

View files in an archive

$ tar -tjvf something.tar.bz2 | less -eFMXR

Useful Commands for Networking

send 10 icmp requests to host

$ ping -c 10

View all interfaces

$ ifconfig -a

Active internet connections

# -t => --tcp
# -u => --udp
# -n => --numeric
# -a => --all
# -p => --program
# -l => --listening

$ netstat -tnap 
$ netstat -tunapl

view hops

$ traceroute domain

# double number of max hops
$ traceroute -m 60 domain 

Port scan for domain

$ nmap -A -T4 domain.com

Host scan on network

$ sudo nmap -sn x.x.x.x/x

Host & port scan on network w/ operating system

# TCP SYN scan
$ sudo nmap -sS -A x.x.x.x/x

View raw DNS queries

# -nnvv = don't resolve hosts or ports, verbose output
# -A = print out ascii tcp packets
$ tcpdump -nnvv -i any port 53

View raw TCP on port until x packets & write to file

$ tcpdump -nnvv -A -i any -c x -w output.pcap tcp port 80

Any packets arriving to port?

$ tcpdump -i any port xxxx

Which packets are coming to port from host

$ tcpdump port xxxx and host xxx

Packets by src/dest

$ tcpdump src xxx
$ tcpdump dest xxx

Packets by src going to dst port 3389

$ tcpdump -nnvvS src 10.5.2.3 and dst port 3389

show TLS certs for domain

$ openssl s_client -showcerts -connect domain.com:443

Get DNS info

$ dig www.google.com
$ dig @127.0.0.1 -p 8600 www.google.com 
$ dig @8.8.8.8 www.google.com SRV

Trace DNS requests

$ dig www.google.com +trace

Connect to remote port

$ nc localhost 2389

Send files with netcat

# send
$ cat happy.txt | ncat -v -l -p 5555

# receive
$ ncat xx.xx.xx.xx 5555 > happy_copy.txt

View routing table

$ route -n

Useful Commands on Start Up

Hostname & username

$ hostname
$ whoami

Display who is logged in and what they are doing

$ w

List all logged in/logged out users

$ last

Active processes

$ htop -d 10

Time since last reboot

$ uptime

# since when?
$ uptime -s 

Display file usage (human readable)

$ df -h

List of open sockets

$ netstat

System information

$ uname -a

Display amount of free memory (megabytes)

$ free -m

CPU info

$ cat /proc/cpuinfo

Memory info

$ cat /proc/meminfo

List mounted filesystems

$ mount
$ lsblk -a 

Virtual Memory stats

$ vmstat

Processor Stats

$ mpstat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment