tddi41tddi41/lectures/tddi41-f2.pdf · 2017. 9. 6. · n users gain extra privileges by changing...

96
TDDI41 Agenda Frågor? Labbar Linux networking

Upload: others

Post on 21-Feb-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

TDDI41

• Agenda• Frågor?• Labbar• Linux networking

Page 2: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Labs

• UML• What is a UML machine

• COW• What is COW

• Network setup Lab1 and Projcte

Page 3: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Lab1

Page 4: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Lab 2:Project

Page 5: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Linux Process, Signals & Logging

Page 6: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

A Look at Linux: Processesn All execution takes place in processes

o Each process may consist of several threadso Every process has its own (protected) address spaceo Every process has an ID, a parent, and a controlling ttyo Processes have a state (running, stopped, suspended, etc)

n Processes can communicateo Signals are simple asynchronous messageso Processes can share memory areaso Processes can communicate using pipeso Processes can communicate using sockets

Page 7: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Example of processes% ps -H -eo s,pid,ppid,tty,user,cmdS PID PPID TT USER CMDS 1 0 ? root init [2]S 2188 1 ? snmp /usr/sbin/snmpd -Lsd -Lf /dev/null -u snmpS 2194 1 ? root /usr/sbin/sshdS 24294 2194 ? root sshd: davby [priv]S 24296 24294 ? davby sshd: davby@pts/0S 24297 24296 pts/0 davby -shR 24304 24297 pts/0 davby ps -H -eo s,pid,ppid,tty,user,cmdS 2206 1 ? uml-net /usr/bin/uml_switch -tap tap0 -unix S 2273 1 ? statd /sbin/rpc.statdS 2297 1 ? root sendmail: MTA: accepting connectionsS 2323 1 ? ntp /usr/sbin/ntpd -p /var/run/ntpd.pidS 2333 1 ? daemon /usr/sbin/atd

Process ID Controlling terminal

Parent process ID

EUIDCommand

Page 8: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Signalsn User point-of-view: suspend, resume, kill processes

n Send arbitrary signals using kill commandn If typing directly to process’s controlling tty

o C-c sends INTRo C-z sends TSTPo C-\ sends QUIT

% ps axu | grep ’[e]macs’Andla63 24613 0.6 0.2 9604 4596 pts/1 S+ 15:47 0:00 emacs -nw% kill –HUP 24613% ps axu | grep ’[e]macs’%

Page 9: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Privilege elevationn Users gain extra privileges by changing EUID or starting

processes with a different EUID than the current one

% ps -H -eo s,pid,ppid,tty,user,cmdS PID PPID TT USER CMDS 1 0 ? root init [2]S 2194 1 ? root /usr/sbin/sshdS 24294 2194 ? root sshd: davby [priv]S 24296 24294 ? davby sshd: davby@pts/0S 24297 24296 pts/0 davby -shR 24321 24297 pts/0 davby ps -H -eo s,pid,ppid,tty,user,cmdS 24312 2194 ? root sshd: davby [priv]S 24314 24312 ? davby sshd: davby@pts/1S 24315 24314 pts/1 davby -shS 24319 24315 pts/1 root passwd

sshd changed EUID from root to davby

passwd being run by davby with EUID root

Page 10: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

How does privilege elevation work?n Programs can change their own EUID/EGID

o The seteuid system call changes the EUIDo The setegid system call changes the EGIDo Very strict limitations on who can change to what

n Programs can have the setuid/setgid bits seto When setuid program started, process assumes file owner as

EUIDo When setgid program started, process assumes file group as

EGID

Page 11: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Example of setuid/setgid programs

% ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20 2006 crontab-rwsr-xr-x 1 root root 28480 Feb 27 08:53 passwd-rwsr-sr-x 1 root mail 72544 Apr 30 2006 procmail%

crontab is setgid news

passwd is setuid root

procmail is setuid root and setgid mail

Page 12: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

The shelln When a user logs in, the login program starts a shelln The shell accepts and interprets commands from the user

o Handles I/O redirection, environment variables, etc

n Two kinds of commands: built-in and externalo Built-in: affect the shell itself (e.g. cd) or are run often (e.g.

echo)o External: most everything elseo Also: programming structures (e.g. if-then-else)

n External commands are just files with the execute permission set that are in a directory listed in the PATH variable

Page 13: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

System startupn What happens when you start Linux

1. The computer firmware (BIOS) loads the boot loader2. The boot loader loads and executes the operating system3. The operating system runs the /sbin/init program4. The /sbin/init program does what /etc/inittab says to do

% cat /etc/inittabid:2:initdefault:si::sysinit:/etc/init.d/rcSl1:1:wait:/etc/init.d/rc 1l2:2:wait:/etc/init.d/rc 2l3:3:wait:/etc/init.d/rc 31:23:respawn:/sbin/getty 38400 tty12:23:respawn:/sbin/getty 38400 tty23:23:respawn:/sbin/getty 38400 tty3%

Set default run level to 2

To do (once) whenentering run level 2

To do wheninitializing system

To do when enteringrun level 2 or 3 (andwhen process terminatesit is restarted

Page 14: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Typical (sysvinit) system startupn /etc/init.d/rc script is run with run level as argument

o Runs scripts in /etc/rcN.d directoryo Scripts that start with K are run with argument stopo Scripts that start with S are run with argument start

n Note that /etc/rcS.d scripts are also run during boot

% ls /etc/rc2.dS10sysklogd S20cupsys S20snmpd S21eximS11klogd S20dbus S20ssh S23ntpS18portmap S20devtun-rights S20sysfsutils S89atdS19autofs S20dirmngr S20sysinfo S89cron%

Run with argument start to start ssh service

Page 15: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

System loggingn Linux (and unix) systems and software are often very chatty

o Detailed messages often show up in system and application logs

o By default, log files are stored in /var/log% ls -F /var/logaccount/ cfengine.log.0 fsck mail.log.0 quagga/acpid cfengine.log.1.gz kern.log mail.log.1.gz samba/acpid.1.gz daemon.log kern.log.0 mail.warn syslogapache/ daemon.log.0 kern.log.1.gz mail.warn.0 syslog.0apache2/ daemon.log.1.gz ksymoops/ mail.warn.1.gz syslog.1.gzaptitude debug lastlog messages user.logaptitude.1.gz debug.0 lpr.log messages.0 user.log.0auth.log debug.1.gz mail.err messages.1.gz user.log.1.gzauth.log.0 dmesg mail.err.0 mysql/ uucp.logauth.log.1.gz dpkg.log mail.err.1.gz nagios/ vtund/boot dpkg.log.1 mail.info nessus/ wtmpbtmp fai/ mail.info.0 news/ wtmp.1btmp.1 faillog mail.info.1.gz ntpstats/ wtmp.reportcfengine.log fontconfig.log mail.log pycentral.log%

Page 16: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

A Look at Linux: System loggingn Controlled by system logging service (syslogd)

o Configured in /etc/syslog.confo Controls what information goes whereo Controls what level of information is logged

% head -2 /var/log/syslog.confauth,authpriv.* /var/log/auth.log*.*;auth,authpriv.none -/var/log/syslog

Log everything except auth messages to /var/log/syslog

Page 17: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

System logging% /etc/init.d/bind9 reload% tail -12 /var/log/syslogAug 20 08:29:22 sysinst-gw postfix/cleanup[26219]: 3FE26748B9: message-id=<[email protected]>Aug 20 08:29:22 sysinst-gw postfix/bounce[26258]: F24931F4B7: sender non-delivery notification: 3FE26748B9Aug 20 08:29:22 sysinst-gw postfix/local[26259]: 3FE26748B9: to=<[email protected]>, relay=local, delay=0.16, delays=0.05/0.04/0/0.07, dsn=2.0.0, status=sent (delivered to mailbox)Aug 20 09:00:54 sysinst-gw named[7673]: loading configuration from '/etc/bind/named.conf'Aug 20 09:00:54 sysinst-gw named[7673]: zone 189.236.130.in-addr.arpa/IN: loaded serial 2007081500Aug 20 09:00:54 sysinst-gw named[7673]: zone 189.236.130.in-addr.arpa/IN: sending notifies (serial 2007081500)Aug 20 09:00:54 sysinst-gw named[7673]: zone sysinst.ida.liu.se/IN: loaded serial 2007081500Aug 20 09:00:54 sysinst-gw named[7673]: zone sysinst.ida.liu.se/IN: sending notifies (serial 2007081500)Aug 20 09:00:54 sysinst-gw named[7673]: client 130.236.177.25#34505: transfer of '189.236.130.in-addr.arpa/IN': AXFR-style IXFR startedAug 20 09:00:54 sysinst-gw named[7673]: client 130.236.177.25#34505: transfer of '189.236.130.in-addr.arpa/IN': AXFR-style IXFR ended

Page 18: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Linux Networking

Page 19: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Review: ProtocolsData link layern Shared physical medium

Network layern Hosts on different networks

Transport layern Between transport processes

Data link layer protocolsn Ethernet

Network layer protocolsn Internet Protocol (IP)

Transport layer protocolsn TCP/UDP

Page 20: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Data link layer: Ethernet

Page 21: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Ethernet addressingMAC addressn Address on LAN (48 bits)n Vendor ID (OUI)n Group/individual bitn Universal/local bit

Broadcastn Sent to ff:ff:ff:ff:ff:ff

Multicastn Sent to address with G set

MAC addressU G : : : : :

OUI

To send an Ethernet frame to a recipient one must know the recipient’s MAC address!

Page 22: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Ethernet in LinuxLogical interfacen Access with ifconfig/ipn Configure with ifconfig/ip

Hardware interfacen Access with ethtool/mii-diagn Configure with ethtool/mii-tool

% ip link show dev eth02: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:0f:20:6b:76:f3 brd ff:ff:ff:ff:ff:ff

% ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:0F:20:6B:76:F3

inet6 addr: fe80::20f:20ff:fe6b:76f3/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:183363968 errors:0 dropped:0 overruns:0 frame:0TX packets:139578378 errors:0 dropped:0 overruns:0 carrier:0RX bytes:2407195224 (2.2 GiB) TX bytes:3814089863 (3.5 GiB)

Page 23: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Ethernet in LinuxLogical interfacen Access with ifconfig/ipn Configure with ifconfig/ip

Hardware interfacen Access with ethtool/mii-diagn Configure with ethtool/mii-tool

% mii-diag eth0Basic registers of MII PHY #1: 1000 796d 0020 6162 05e1 cde1 000d 2001.The autonegotiated capability is 01e0.The autonegotiated media type is 100baseTx-FD.Basic mode control register 0x1000: Auto-negotiation enabled.You have link beat, and everything is working OK.Your link partner advertised cde1: Flow-control 100baseTx-FD 100baseTx 10baseT-FD 10baseT, w/ 802.3X flow control.

End of basic transceiver information.

% mii-tool eth0eth0: negotiated 100baseTx-FD flow-control, link ok

Page 24: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Network layer: IPv4

Page 25: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Internet Protocol FamilyIP is a family of protocolsn ICMP for control and error messagesn TCP for reliable data streamsn UDP for best-effort packet deliveryn GRE for tunneling other protocolsn ESP and AH for secure IP (IPSEC)n SAT-MON for monitoring SATNET

You can have your own! Talk to IANA.

Page 26: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IPv4 addressingIPv4 addressn Network address (N bits)n Host address (M bits)n N + M = 32 bits

CIDR notationn A.B.C.D/N

Broadcastn 255.255.255.255 (undirected)

Multicastn 224.0.0.0/4

Page 27: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

ICMPIP Control Messagesn Error messages – ”Can’t reach that address”n Control messages – ”Slow down, you’re sending too fast”n Test messages – ”Tell me if you get this message”n Autoconfiguration – ”Is there a router here?”

Some messages have sub-typesn Can’t reach destination because TTL was exceededn Can’t reach destination because the port does not existsn Can’t reach destination because the network is unreachable

Page 28: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IPv4 addressingn Addresses are divided into classes

o Class A has 8 bits network IDo Class B has 16 bits network IDo Class C has 24 bits network IDo Class D and E are special cases

n Subnetting divides large networks into several small onesn Supernetting is used to combine small networks into larger ones

Page 29: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IPv4 addressingn 32 bits divided into network ID and host IDn Netmask determines what is what

n Given address and netmask, compute:o Network ID netid = addr & netmasko Host ID host = addr & (~netmask)o Broadcast bcast = addr | (~netmask)o Address range netid to bcast

1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 0 1

130 236 189 17

130.236.189.17Address

~ 0 1

1 0

| 0 1

0 0 1

1 1 1

& 0 1

0 0 0

1 0 1

BitwiseOperators

Negate(Not)

Addition(Or)

Multiply(And)

Network ID: 130.236.189.16

Page 30: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Netmask

~ 0 1

1 0

| 0 1

0 0 1

1 1 1

& 0 1

0 0 0

1 0 1

BitwiseOperators

130.236.189.16/28 à 28 bit netmask

130.236.189.17/28 netmask

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0255 255 255 240

8 bits 8 bits 8 bits 4 bits

Page 31: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0

1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 0 0

130 236 189 16

1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 0 1AddressNetmask

Network

addr & mask

~ 0 1

1 0

| 0 1

0 0 1

1 1 1

& 0 1

0 0 0

1 0 1

BitwiseOperators

130.236.189.17/28 network

Page 32: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0

1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 1 1 1 1

130 236 189 16

1 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 0 1Address~Netmask

Broadcast

addr | (~mask)

~ 0 1

1 0

| 0 1

0 0 1

1 1 1

& 0 1

0 0 0

1 0 1

BitwiseOperators

130.236.189.17/28 broadcast

Page 33: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

130.236.189.17/28 summaryn CIDR block: 130.236.189.16/28n Network: 130.236.189.16n Lowest host: 130.236.189.17n Highest host: 130.236.189.30n Broadcast: 130.236.189.31

Page 34: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

10.0.0.0/29 summaryn CIDR block: 10.0.0.0/29n Network: ?n Broadcast: ?n Lowest host: ?n Highest host: ?

Network ID netid = addr & netmaskBroadcast bcast = addr | (~netmask)

Page 35: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

10.0.0.0/29 summaryn CIDR block: 10.0.0.0/29n Network: 10.0.0.0n Lowest host: 10.0.0.1n Highest host: 10.0.0.6n Broadcast: 10.0.0.7

Page 36: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

192.168.12.163/29 summaryn CIDR block: 192.168.12.160n Network: ?n Broadcast: ?n Lowest host: ?n Highest host: ?

Page 37: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

192.168.12.163/29 summaryn CIDR block: 192.168.12.160n Network: 192.168.12.160n Lowest host: 192.168.12.161n Highest host: 192.168.12.166n Broadcast: 192.168.12.167

Page 38: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IPv4 in Linuxn Addresses assigned to interfaces (e.g. eth0)n Each interface can have multiple addresses

n Configure with ifconfig or ip

% ifconfig br0br0 Link encap:Ethernet HWaddr 00:0F:20:6B:76:F3

inet addr:130.236.189.1 Bcast:130.236.189.63 Mask:255.255.255.192inet6 addr: fe80::20f:20ff:fe6b:76f3/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:183373446 errors:0 dropped:0 overruns:0 frame:0TX packets:139594398 errors:0 dropped:0 overruns:0 carrier:0RX bytes:3350149494 (3.1 GiB) TX bytes:2985901093 (2.7 GiB)

Page 39: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IPv4 in Linuxn Addresses assigned to interfaces (e.g. eth0)n Each interface can have multiple addresses

n Configure with ifconfig or ip

% ip addr show dev br07: br0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue

link/ether 00:0f:20:6b:76:f3 brd ff:ff:ff:ff:ff:ffinet 130.236.189.1/26 brd 130.236.189.63 scope global br0inet 10.17.1.1/24 scope global br0inet6 fe80::20f:20ff:fe6b:76f3/64 scope link

valid_lft forever preferred_lft forever

Page 40: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Delivery of IP over EthernetNetwork cards have MAC-addresses, not IP addressesn MAC addresses are not assigned systematically so can’t be used directlyn Translation from IP to MAC address needed

ARP – Address Resolution Protocoln ARP Request = What MAC address does this IP address correspond ton ARP Reply = This one

0:b0:d0:d1:7a:55 0:50:ba:7c:92:cc 0806 0001 0800 06 04 0002 0:50:ba:7c:92:cc 0:b0:d0:d1:7a:5562.20.4.211 62.20.4.212ff:ff:ff:ff:ff:ff 0:b0:d0:d1:7a:55 0806 0001 0800 0:b0:d0:d1:7a:55 0:0:0:0:0:062.20.4.212 62.20.4.21106 04 0001

Page 41: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

ARP Examples

06 04

0:b0:d0:d1:7a:55

0800

0:50:ba:7c:92:cc

0806 0001 0002 0:50:

:ba:7c:92:cc 62.20.4.211 0:b0:d0:d1:

62.20.4.212:7a:55:

ARP Request

62.20.4.211:0:0:

06 04

ff:ff:ff:ff:ff:ff

0800

0:b0:d0:d1:7a:55

0806 0001 0001 00:b0:

:d0:d1:7a:55 62.20.4.212 0:0:0:0:

62.20.4.211:0:0:

:d0:d1:7a:55 62.20.4.212 0:0:0:0:

06 0408000806 0001 0001 00:b0:

ff:ff:ff:ff:ff:ff 0:b0:d0:d1:7a:55

ARP Reply

Hardware type (2)Protocol (2)Hardware size (1)Protocol size (1)Opcode (2)

Sender MACSender protocol addressTarget MACTarget protocol address

tcpdump -ennqti eth0 \( arp or icmp \)tcpdump: listening on eth0 0:80:c8:f8:4a:51 ff:ff:ff:ff:ff:ff 42: arp who-has 192.168.99.254 tell 192.168.99.35 0:80:c8:f8:5c:73 0:80:c8:f8:4a:51 60: arp reply 192.168.99.254 is-at 0:80:c8:f8:5c:73

Page 42: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Sending an IP packet1. Destination in routing table?

§ YES: Continue§ NO: Signal no route to host

2. Is it directly connected?§ YES: Recipient = destination

address§ NO: Recipient = gateway address

3. ARP for recipient4. Got ARP reply?

§ YES: Send IP packet to Ethernet address in ARP reply

§ NO: Signal host unreachable

Page 43: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Linux routing tableWhere do we send a given packet?n To its final destination?n Somewhere else?n On which interface?

Determined by routing tablen Match destination against

prefixes in kernel routingtable

n Longest match winsn No match? No route to host!

Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface130.236.190.56 0.0.0.0 255.255.255.252 U 0 0 0 eth1130.236.189.128 130.236.189.38 255.255.255.248 UG 2 0 0 eth0130.236.189.0 0.0.0.0 255.255.255.192 U 0 0 0 eth010.17.219.0 10.17.1.219 255.255.255.0 UG 2 0 0 eth010.17.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth010.17.224.0 10.17.1.224 255.255.255.0 UG 2 0 0 eth00.0.0.0 130.236.190.57 0.0.0.0 UG 0 0 0 eth1

Page 44: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Labbarn Svart skärm på thinlinc-und

o Testa ~TDDI41/uml/start_lab1_ssh.sh n Scripting

o Skapa användare kommer förändras med tiden

n Redovisningo Lab 1-4 dema och skicka svar på frågor till

asso Projekt

n Skicka svar på frågor till assn Slutredovisa för mig när ni är klara (munta)

n Tidsram

Page 45: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Linux routingSources for routesn Connected interfacesn Static routesn Routing protocol (e.g. RIP)

Typically:n Connected interfacesn Static default route

Configure with route or ipn route –n or ip route listn route add or ip route addn route del or ip route del

Page 46: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Routing with RIPReviewn Distance-Vector protocoln Distributed Bellman-Ford

o Announce known prefixeswith a cost to reachdestination

o For each prefix use neighborwith lowest cost to destination

Routing vs. Forwardingn Routing: calculating pathsn Forwarding: sending packets

received on another interfacen Separate functions!

Practicalitiesn Announce which prefixes?n Accept which

announcements?n Run on which interfaces?n Which version to use?n Use of authentication?

n What to install in kernelrouting table (FIB)?

Page 47: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Routing with RIPWhat prefixes to announcen Redistribution of prefixesn Sources of prefixes

o Other RIP routerso Other routing protocolso Directly connected networkso Static routeso Kernel routing table

n Filter announcements?o distribute-list out

What announcements to acceptn What peers do we trust?n What routes do we expect?n Filter incoming prefixes

o distribute-list in

Page 48: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Routing with quaggaWhat it isn Open source portable routing

software suiten Supports RIP, OSPF, BGP…

Working with quaggan Command-line interface

similar to Cisco IOSn Access via telnet connection

ripd ospfd bgpd isisd

zebra

Kernel routing table(FIB)

Remote routers

Page 49: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Quagga (ripd) configuration exampleinterface br0ip rip send version 2ip rip receive version 2

router ripversion 2default-information originateredistribute connectedredistribute staticnetwork br0distribute-list prefix listen in br0distribute-list prefix announce out br0

ip prefix-list announce seq 5 permit 130.236.189.0/24 le 32ip prefix-list announce seq 10 permit 10.0.0.0/8ip prefix-list announce seq 25 permit 0.0.0.0/0ip prefix-list announce seq 30 deny any

ip prefix-list listen seq 5 permit 10.0.0.0/8 le 32ip prefix-list listen seq 25 permit 130.236.189.64/29ip prefix-list listen seq 30 permit 130.236.189.72/29[…]ip prefix-list listen seq 999 deny any

Page 50: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Transport layer: TCP/UDP

Page 51: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

TCP and UDP in LinuxReviewn Port conceptn Socket conceptn TCP state diagram

Toolsn Tuning parameters

o /proc/sys/net/…

n Examining sockets etco netstat

Page 52: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

TCP state diagram

timeout after 2 segment lifetime (2MSL)

CLOSED

LISTEN

SYNSENT

CLOSEWAIT

LASTACK

SYNRECVD

ESTAB-LISHED

CLOSINGFINWAIT1

FINWAIT2

TIMEWAIT

Passive open close

timeout/RST

Close/timeout/RST

SYN/SYN+ACK

FIN/ACK

Close/FIN

ACK/

Pass

ive

clos

eSimultaneous close

active close

Simultaneous open

FIN/ACK

FIN/ACK

ACK/

Clo

se/F

IN

ACK/

Page 53: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

% netstat -alp -A inetActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 *:login *:* LISTEN 22705/inetdtcp 0 0 *:7937 *:* LISTEN 15600/nsrexecdtcp 0 0 *:shell *:* LISTEN 22705/inetdtcp 0 0 *:7938 *:* LISTEN 15599/nsrexecdtcp 0 0 *:printer *:* LISTEN 27352/lpd Waitingtcp 0 0 *:sunrpc *:* LISTEN 24838/portmaptcp 0 0 *:www *:* LISTEN 27245/apachetcp 0 0 *:629 *:* LISTEN 25040/ypbindtcp 0 0 *:nessus *:* LISTEN 30517/nessusd: waittcp 0 0 localhost:953 *:* LISTEN 32675/namedtcp 0 0 *:smtp *:* LISTEN 28650/mastertcp 0 0 localhost:6010 *:* LISTEN 5891/83tcp 0 0 localhost:6011 *:* LISTEN 9720/138tcp 0 0 localhost:6012 *:* LISTEN 32607/202tcp 0 0 *:732 *:* LISTEN 26838/rpc.statdtcp 0 1 sysinst-gw.ida:webcache 222.90.98.244:1350 FIN_WAIT1 -tcp 0 1 sysinst-gw.ida:webcache h225n10c1o1049.br:13394 FIN_WAIT1 -tcp 0 0 sysinst-gw.ida.liu.:www obel19.ida.liu.se:62599 FIN_WAIT2 -udp 0 0 *:7938 *:* 15599/nsrexecdudp 0 0 *:902 *:* 25040/ypbindudp 0 0 *:route *:* 13790/ripdudp 0 0 *:726 *:* 26838/rpc.statdudp 0 0 *:729 *:* 26838/rpc.statdudp 0 0 *:sunrpc *:* 24838/portmapudp 0 0 *:626 *:* 25040/ypbindudp 0 0 10.17.1.1:ntp *:* 25800/ntpdudp 0 0 sysinst-gw.sysinst.:ntp *:* 25800/ntpdudp 0 0 sysinst-gw.ida.liu.:ntp *:* 25800/ntpdudp 0 0 localhost:ntp *:* 25800/ntpdudp 0 0 *:ntp *:* 25800/ntpd

Page 54: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

54

Network Address Translation (NAT)

Page 55: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

55

Private Networkn Private IP network is an IP network that is not directly connected to

the Internet

n IP addresses in a private network can be assigned arbitrarily. o Not registered and not guaranteed to be globally unique

n Generally, private networks use addresses from the following experimental address ranges (non-routable addresses): o 10.0.0.0 – 10.255.255.255o 172.16.0.0 – 172.31.255.255o 192.168.0.0 – 192.168.255.255

Page 56: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

56

Private Addresses

H1

R1

H2

10.0.1.3

10.0.1.1

10.0.1.2

H3

R2

H4

10.0.1.310.0.1.2

Private network 1

Internet

H5

10.0.1.1Private network 1

213.168.112.3

128.195.4.119 128.143.71.21

Page 57: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Network Address Translation (NAT)n RFC 1631

n A short term solution to the problem of the depletion of IP addresseso Long term solution is IP v6o CIDR (Classless InterDomain Routing ) is a possible short

term solutiono NAT is another

n NAT is a way to conserve IP addresseso Can be used to hide a number of hosts behind a single IP

addresso Uses private addresses:

n 10.0.0.0-10.255.255.255, n 172.16.0.0-172.32.255.255 or n 192.168.0.0-192.168.255.255

57

Page 58: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

58

Network Address Translation (NAT)n NAT is a router function where IP addresses (and possibly port

numbers) of IP datagrams are replaced at the boundary of a private network

n NAT is a method that enables hosts on private networks to communicate with hosts on the Internet

n NAT is run on routers that connect private networks to the public Internet, to replace the IP address-port pair of an IP packet with another IP address-port pair.

Page 59: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

59

Basic Operation of NAT

n NAT device has address translation tablen One to one address translation

Page 60: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

60

Pooling of IP Addressesn Scenario: Corporate network has many hosts but only a small

number of public IP addressesn NAT solution:

o Corporate network is managed with a private address spaceo NAT device, located at the boundary between the corporate network and

the public Internet, manages a pool of public IP addresses o When a host from the corporate network sends an IP datagram to a host

in the public Internet, the NAT device picks a public IP address from the address pool, and binds this address to the private address of the host

Page 61: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

61

Pooling of IP Addresses

H1

private address: 10.0.1.2public address:

H5

Privatenetwork

Internet

Source = 10.0.1.2Destination = 213.168.112.3

Source = 128.143.71.21Destination = 213.168.112.3

public address: 213.168.112.3NATdevice

PrivateAddress

PublicAddress

10.0.1.2

Pool of addresses: 128.143.71.0-128.143.71.30

Page 62: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

62

Supporting Migration between Network Service Providersn Scenario: In CIDR, the IP addresses in a corporate network are

obtained from the service provider. Changing the service provider requires changing all IP addresses in the network.

n NAT solution:o Assign private addresses to the hosts of the corporate networko NAT device has static address translation entries which bind the

private address of a host to the public address. o Migration to a new network service provider merely requires an

update of the NAT device. The migration is not noticeable to the hosts on the network.

Note:o The difference to the use of NAT with IP address pooling is that

the mapping of public and private IP addresses is static.

Page 63: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

63

Supporting Migration between network service Providers

Page 64: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

64

IP Masqueradingn Also called: Network address and port translation (NAPT), port

address translation (PAT).n Scenario: Single public IP address is mapped to multiple hosts in a

private network. n NAT solution:

o Assign private addresses to the hosts of the corporate networko NAT device modifies the port numbers for outgoing traffic

Page 65: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

65

IP Masquerading

Page 66: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

66

Load Balancing of Serversn Scenario: Balance the load on a set of identical servers, which are

accessible from a single IP address

n NAT solution:o Here, the servers are assigned private addresses o NAT device acts as a proxy for requests to the server from the public

networko The NAT device changes the destination IP address of arriving packets

to one of the private addresses for a servero A sensible strategy for balancing the load of the servers is to assign the

addresses of the servers in a round-robin fashion.

Page 67: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

67

Load Balancing of Servers

Page 68: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

68

Concerns about NATn Performance:

o Modifying the IP header by changing the IP address requires that NAT boxes recalculate the IP header checksum

o Modifying port number requires that NAT boxes recalculate TCP checksum

n Fragmentationo Care must be taken that a datagram that is fragmented before it reaches

the NAT device, is not assigned a different IP address or different port numbers for each of the fragments.

Page 69: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

69

Concerns about NAT

n End-to-end connectivity:o NAT destroys universal end-to-end reachability of hosts on the Internet.

o A host in the public Internet often cannot initiate communication to a hostin a private network.

o The problem is worse, when two hosts that are in a private network needto communicate with each other.

Page 70: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

70

Concerns about NAT

n IP address in application data:o Applications that carry IP addresses in the payload of the application

data generally do not work across a private-public network boundary.

o Some NAT devices inspect the payload of widely used application layerprotocols and, if an IP address is detected in the application-layerheader or the application payload, translate the address according to the

address translation table.

Page 71: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Brief Overview of FTPn RFC 959

n Uses two TCP Ports o One for controlo One for data transfers

n Command-response protocol

n Control port uses telnet protocol to negotiate sessiono US-ASCIIo <crlf> is end-of-line character

71

Page 72: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Active Mode FTPn Client connect from a random unprivileged port (n > 1023) to the servers

command port (21) and sends port command to tell server to connect to n+1then listens on the next higher unprivileged port (n+1) for server responses.The server connects from it’s data port (20) to the client data port (n+1).

ClientServer

20 21 1026 1027

1

2

3

4

72

Page 73: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Passive Mode FTPn Client opens two random unprivileged ports ( n > 1023 and n+1; for example

1026 and 1027) and connects the first port (n) to server command port 21 andissues a pasv command (server sends port to use for data); client connects toservers specified data port, server completes connection.

ClientServer

20 21 1026 1027

1

2

2024

3

4

73

Page 74: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

74

NAT and FTP

n Normal FTP operation

Page 75: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

75

NAT and FTP

n NAT device with FTP support

Page 76: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

76

NAT and FTP

n FTP in passive mode and NAT.

Page 77: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

NAT Supported Traffic TypesTraffic Types/Applications Supported Traffic Types/Applications not SupportedAny TCP/UDP Traffic that Does Not Carry Source and/or Destination IP Addresses in the Application Data Stream

IP Multicast

HTTP Routing Table UpdatesTFTP DNS Zone TransfersTelnet BOOTParchie Talk, Ntalkfinger H.323NTP VDOLiveNFS NetShowrlogin, rsh, rcp VXtreme

Although the Following Traffic Types Carry IP Addresses in the Application Data Stream, they

are Supported by Cisco IOS NAT:

SNMP

ICMPSMTPFTP (Including PORT and PASV Commands)NetBIOS over TCP/IPProgressive Networks?RealAudioWhite Pines CuSeeMe

Xing Technologies StreamWorksDNS "A" and "PTR" Queries

77

Page 78: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Firewall Programs

n Ipfwadm: Linux kernel 2.0.34

n Ipchains: Linux kernel 2.2.*

n Iptables : Linux kernel 2.4.*->

78

Page 79: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

InputChain Routing

Deny

LocalProcesses

ForwardChain

OutputChain

DenyDeny

Ipchains Packet Traversal

Page 80: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Iptables Packet Traversal

Page 81: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

81

Configuring NAT in Linuxn Linux uses the Netfilter/iptable package to add filtering rules to the

IP module

Page 82: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Iptables NAT Overview

n Source NATo The source address of the initial packet is modified.o Performed on the POSTROUTING Chain.o Includes MASQUERADE functionality.

n Destination NATo The destination address of the initial packet is modified.o Performed on the PREROUTING or OUTPUT chain.

82

Page 83: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

83

Configuring NAT with iptables

n First example:iptables –t nat –A POSTROUTING –s 10.0.1.2

–j SNAT --to-source 128.143.71.21n Pooling of IP addresses:

iptables –t nat –A POSTROUTING –s 10.0.1.0/24 –j SNAT --to-source 128.128.71.0–128.143.71.30

n ISP migration: iptables –t nat –R POSTROUTING –s 10.0.1.0/24

–j SNAT --to-source 128.195.4.0–128.195.4.254n IP masquerading:

iptables –t nat –A POSTROUTING –s 10.0.1.0/24 –o eth1 –j MASQUERADE

n Load balancing:iptables -t nat -A PREROUTING -i eth1 -j DNAT --to-destination 10.0.1.2-10.0.1.4

Page 84: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

NAT Summaryn NAT provides transparent and bi-directional connectivity between

networks having arbitrary addressing schemes

n NAT eliminates costs associated with host renumbering

n NAT conserves IP addresses

n NAT eases IP address management

n NAT enhances network privacy

84

Page 85: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

NAT Limitationsn Applications with IP-address content

o Need AGL (Application Level Gateway)

n Applications with inter-dependent control and and data sessions

85

Page 86: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Extra: Hacking through NATn Static Translation

o offers no protection of internal hostsn Internal Host Seduction

o internals go to the hackern e-mail attachments – Trojan Horse virus’n peer-to-peer connections n hacker run porn and gambling sites

o solution = application level proxiesn State Table Timeout Problem

o hacker could hijack a stale connection before it is timed outo very low probability but smart hacker could do it

n Source Routing through NATo if the hacker knows an internal address they can source route a

packet to that hostn solution is to not allow source routed packets through the firewall

Page 87: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Applications

Page 88: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

The Internet Super-Serverinetdn Manages network for other servicesn Other services started on demandn Configuration file: inetd.conf

# Internal servicesecho stream tcp nowait root internalecho dgram udp wait root internal

# Shell, login, exec and talk are BSD protocols.shell stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.rshdlogin stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.rlogind

# RPC based servicesrstatd/1-5 dgram rpc/udp wait nobody /usr/sbin/tcpd /usr/sbin/rpc.rstatdrusersd/2-3 dgram rpc/udp wait nobody /usr/sbin/tcpd /usr/sbin/rpc.rusersd

Page 89: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

TCP wrappersAccess control for TCP and UDP servicesn Configuration: /etc/hosts.allow, /etc/hosts.denyn Built-in support or through tcpd

ALL: UNKNOWN: DENYin.rshd: 130.236.189.1: ALLOWsshd: ALL: ALLOWstatd mountd nfsd @nfsclients: ALLOWALL: ALL: DENY

Page 90: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Remote access with sshSecure shelln Encrypted channeln Mutual authentication

Featuresn X11 forwardingn File transfer

… and lots more

Interactive shell: ssh remote_username@hostnameTo copy files from host: scp remote_username@hostname:path local_pathTo copy files to host: scp local_path remote_username@hostname:path

Page 91: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

X11 forwardingRun GUI programs on remote host with local display

Prerequisites:n X11 forwarding enabled on clientn X11 forwarding enabled on servern Server has xauth program installed

Necessary to run GUI programs (e.g. ethereal) on UMLs

Page 92: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Network troubleshooting

Page 93: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

IP connectivity problemn Is the destination interface configuration correct and interface enabled?

o Tools: ifconfig or ip on destinationo No: fix it and enable interface

n Is the source interface configuration correct and interface enabled?o Tools: ifconfig or ip on sourceo No: fix it and enable interface

n Is there a route from source to destination and from destination to source?o Tools: traceroute on source and destination and see where the problem startso No: troubleshoot routing (e.g. RIP failure)

n Do all gateways have forwarding enabled?o No: enable forwarding where it is disabled

Page 94: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Simple RIP failuresWhat interfaces to run on à We are not running on the right interfacesWhat version to use à We are using the wrong versionWhat authentication to use à We are using the wrong authentication

What prefixes to announce à We are not announcing the right prefixesn What is the source of the prefixes? Are we redistributing that source?n Do we have filters on outgoing announcements? Are they accurate?

What prefixes to accept à We are not accepting the correct prefixesn Do we have filters on incoming announcements? Are they accurate?n Do we install routes in the kernel as expected?

Page 95: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Troubleshooting toolstracerouten To trace path of packets

pingn To check connectivity

socatn To set up a simple servern To act as a client

wireshark/tcpdumpn Analyze network traffic

ip neigh/link/addr/routen To check configuration

netstatn Lots of host-related

information

Page 96: TDDI41TDDI41/lectures/TDDI41-F2.pdf · 2017. 9. 6. · n Users gain extra privileges by changing EUID or starting ... % ls -l passwd crontab mail-rwxr-sr-x 1 root news 26380 Dec 20

Next time: directory servicesDirectory servicesn Why directory servicesn What directory services are

Domain Name Systemn How it works in theoryn How it works in practicen How to set it up

Network Information Servicen How it works in theoryn How it works in practicen How to set it up

LDAPn Brief introduction