Understanding Network Hacks: Attack and Defense with Python 3 2nd Edition Bastian Ballmann instant download
Understanding Network Hacks: Attack and Defense with Python 3 2nd Edition Bastian Ballmann instant download
https://textbookfull.com/product/understanding-network-hacks-
attack-and-defense-with-python-3-2nd-edition-bastian-ballmann/
https://textbookfull.com/product/advanced-asp-net-
core-3-security-understanding-hacks-attacks-and-vulnerabilities-
to-secure-your-website-1st-edition-scott-norberg/
https://textbookfull.com/product/cybersecurity-attack-and-
defense-strategies-infrastructure-security-with-red-team-ens-
blue-team-taxtics-1st-edition-yuri-diogenes/
https://textbookfull.com/product/cybersecurity-attack-and-
defense-strategies-infrastructure-security-with-red-team-ens-
blue-team-taxtics-1st-edition-yuri-diogenes-2/
https://textbookfull.com/product/python-2-and-3-compatibility-
with-six-and-python-future-libraries-nanjekye/
https://textbookfull.com/product/network-defense-and-
countermeasures-principles-and-practices-3rd-edition-chuck-
easttom/
https://textbookfull.com/product/applied-network-security-proven-
tactics-to-detect-and-defend-against-all-kinds-of-network-
attack-1st-edition-arthur-salmon/
https://textbookfull.com/product/python-network-programming-
cookbook-kathiravelu/
https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-2nd-edition-irv-
kalb/
Bastian Ballmann
Understanding
Network Hacks
Attack and Defense with Python 3
2nd Edition
Understanding Network Hacks
Bastian Ballmann
Understanding Network
Hacks
Attack and Defense with Python 3
2nd Edition
Bastian Ballmann
Uster, Switzerland
Doesn’t this book explain how to break into a computer system? Isn’t that illegal and a
bad thing at all?
I would like to answer both questions with no (at least the second one). Knowledge is
never illegal nor something bad, but the things you do with it.
You as an admin, programmer, IT manager or just an interested reader cannot protect
yourself if you don’t know the techniques of the attackers. You cannot test the effective-
ness of your firewalls and intrusion detection systems or other security related software if
you are not able to see your IT infrastructure through the eyes of an attacker. You cannot
weigh up the danger to costs of possible security solutions if you don’t know the risks
of a successful attack. Therefore it is necessary to understand how attacks on computer
networks really work.
The book presents a selection of possible attacks with short source code samples to
demonstrate how easy and effectively and maybe undetected a network can be infiltrated.
This way you can not only learn the real techniques, but present them to your manager
or employer and help them in the decision if it would make sense to care a little bit more
about IT security. At the end of the book you should be able to not only understand how
attacks on computer networks really work, but also to modify the examples to your own
environment and your own needs.
Sure, the book also tells those bad guys how to crack the net and write their own
tools, but IT security is a sword with two sharp blades. Both sides feed themselves off
the same pot of knowledge and it is an continuous battle, which the protecting side can
never dream of winning if it censors itself or criminalizes their knowledge!
vii
Introduction
ix
x Introduction
At the end of each chapter you will find a selection of tools also written in Python that
attack the described protocol in a more detailed way.
Thanks to the basic knowledge learned in the chapter it shouldn’t be too hard to read
and understand the source code of the tools.
1 Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 The Right Operating System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 The Right Python Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Python Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Pip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 Virtualenv. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Network 4 Newbies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1 Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Topologies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 ISO/OSI Layer Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Ethernet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 VLAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6 ARP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.7 IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.8 ICMP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.9 TCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.10 UDP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.11 An Example Network. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.12 Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.13 Gateway. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.14 Router. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.15 Bridge. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.16 Proxies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.17 Virtual Private Networks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.18 Firewalls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.19 Man-in-the-middle-Attacks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
xi
xii Contents
3 Python Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1 Every Start is Simple. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2 The Python Philosophy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4 Data Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.5 Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.6 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7 Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.8 Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.9 Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.10 Sockets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4 Layer 2 attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1 Required modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2 ARP-Cache-Poisoning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.3 ARP-Watcher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.4 MAC-Flooder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.5 VLAN hopping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.6 Let’s play switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.7 ARP spoofing over VLAN hopping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.8 DTP abusing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.9 Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.9.1 NetCommander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.9.2 Hacker’s Hideaway ARP Attack Tool . . . . . . . . . . . . . . . . . . . . 46
4.9.3 Loki . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5 TCP / IP Tricks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.1 Required Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.2 A Simple Sniffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.3 Reading and Writing PCAP Dump Files. . . . . . . . . . . . . . . . . . . . . . . . . 49
5.4 Password Sniffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.5 Sniffer Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.6 IP-Spoofing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.7 SYN-Flooder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.8 Port-scanning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.9 Port-scan Detection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.10 ICMP-Redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.11 RST Daemon. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.12 Automatic Hijack Daemon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.13 Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.13.1 Scapy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Contents xiii
6 WHOIS DNS?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.1 Protocol Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2 Required Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.3 Questions About Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.4 WHOIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.5 DNS Dictionary Mapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.6 Reverse DNS Scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.7 DNS-Spoofing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.8 Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.8.1 Chaosmap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7 HTTP Hacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.1 Protocol Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.2 Web Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.3 Required Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.4 HTTP Header Dumper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.5 Referer Spoofing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
7.6 The Manipulation of Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.7 HTTP-Auth Sniffing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.8 Webserver Scanning. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.9 SQL Injection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.10 Command Injection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.11 Cross-Site-Scripting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.12 HTTPS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.13 SSL / TLS Sniffing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.14 Drive-by-Download. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
7.15 Proxy Scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.16 Proxy Port Scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.17 Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.17.1 SSL Strip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.17.2 Cookie Monster. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
7.17.3 Sqlmap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
7.17.4 W3AF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
8 Wifi Fun. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
8.1 Protocol Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
8.2 Required Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.3 Wifi Scanner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.4 Wifi Sniffer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
8.5 Probe-Request Sniffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
8.6 Hidden SSID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
8.7 MAC-Address-Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
8.8 WEP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
xiv Contents
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Installation
1
Abstract
This chapter explains on which operating system the sources can be executed, which
Python version you will need and how to install additional Python modules. Last but
not least, we will discuss some possible solutions for setting up a complete development
environment. If you are already familiar with the Python programming language you can
skip this introductory chapter without missing anything.
Yes, I know the title of this section can lead to flame wars. It should just illustrate on which
operating systems the source codes of this book are run. The author is using a GNU/Linux
systems with kernel version 5.x for development, but most of the sources, except the chapter
about Bluetooth, should also runable on BSD or Mac OS X systems. If you succeed in
running the source code on other systems the author would be happy if you could drop him
a tiny email. Of course all other comments or criticisms are also welcome.
All source code examples are written in Python 3 and have been tested with Python 3.7.
To check which version of Python is installed on your system, execute the following
command
python3 --version
Python 3.7.4
© The Author(s), under exclusive license to Springer-Verlag GmbH, DE, part of Springer 1
Nature 2021
B. Ballmann, Understanding Network Hacks,
https://doi.org/10.1007/978-3-662-62157-8_1
2 1 Installation
Python modules can be found in the Python packet index pypi.python.org. New modules
can be installed by one of the following three possibilities:
1.5 Pip 3
1 Download the source archive, unpack it and execute the magic line
2 Use easy_install
easy_install <modulname>
3 Get your feet wet with pip. Maybe you have to install a package like python-pip
before you can use it.
You should use pip, because it also supports deinstallation and upgrading of one or all
modules. You could also export a list of installed modules and its version, reinstall them on
another system, you can search for modules and more.
Alternatively you can tell pip to install the modules in a directory of your homedir by
adding the parameter –user.
Which Python modules are needed for which tools and source code snippets will be
described at the beginning of the chapter or in the description of the snippet, if the module
is only used for that code. This way, you will only install modules that you really want to
use.
1.5 Pip
To uninstall a module just use the option uninstall. A listing of all installed modules
and their versions can be achieved with the parameter freeze and later on used to reinstall
them.
Which modules are outdated reveas the command pip list –outdated. A single
module can be upgraded by executing pip3 install –upgrade <modulname>.
4 1 Installation
1.6 Virtualenv
If you like you could install all Python modules needed for this book in a subfolder (a so
called virtualenv) so that they wont conflict with the modules installed in your operating
system. As an example we will create a virtualenv called python-network-hacks,
install the module scapy into it and exit from the virtual environment.
Make sure that the prompt is the default prompt again after deactivating.
Network 4 Newbies
2
Abstract
Computer networks are the veins of the information age, protocols the language of the
net. This chapter describes the basics of networking starting with hardware going over
to topology and the functionality of the most common protocols of an Ethernet/IP/TCP
network up to Man-in-the-middle attacks. For all who want to rebuild or refresh their
knowledge of networking.
2.1 Components
To be able to build a computer network of course you need some hardware. Depending on
the kind of net you’ll need cables, modems, old school acoustic in banana boxes, antennas
or satellite receivers beside computers and network cards as well as router (Sect. 2.14),
gateways (Sect. 2.13), firewalls (Sect. 2.18), bridges (Sect. 2.15), hubs and switches.
A hub is just a simple box you plug network cables in and it will copy all signals to all
connected ports. This property will probably lead to an explosion of network traffic. That’s
a reason why hubs are rarely used these days. Instead most of the time you will see switches
building the heart of the network. The difference between a hub and a switch is a switch
remembers the MAC address of the network card connected to the port and sends traffic
only to the port it’s destinated to. MAC addresses will be explained in more detail in Sect.
2.4.
© The Author(s), under exclusive license to Springer-Verlag GmbH, DE, part of Springer 5
Nature 2021
B. Ballmann, Understanding Network Hacks,
https://doi.org/10.1007/978-3-662-62157-8_2
6 2 Network 4 Newbies
2.2 Topologies
You can cable and construct computer networks in different ways. Nowadays the most com-
mon variant is the so called star network (see Fig. 2.1), where all computer are connected
to a central device. The disadvantage is that this device is a single point of failure and the
whole network will break down if it gets lost. This disadvantage can be circumstanced by
using redundant (multiple) devices.
Another possibility is to connect all computers in one long row one after the other, the so
called bus network (see Fig. 2.2). The disadvantage of this topology is that each computer
must have two network cards and depending on the destination the traffic gets routed through
all computers of the net. If one of them fails or has too high a load the connections behind
that host are lost.
The author has seen only a few bus networks this decade and all consisted of two com-
puters directly connected to guarantee time critical or traffic intensive services like database
replication, clustering of application servers or synchronization of backup servers. In all
cases the reason for a bus network was to lower the load of the star network.
As last variant the ring network (Fig. 2.3) should be mentioned, which as the name
implies connects all computers in a circle. The ring network has the same disadvantages as
a bus network except that the network will only fail partly if a computer gets lost as long as
the net can route the traffic the other way round. The author has not seen a productive ring
network, but some wise guys whisper that it it the topology of backbones used by ISPs and
large companies.
Additionally one often reads about LAN (Local Area Network), WAN (Wide Area Net-
work) and sometimes even about MAN (Middle Area Network). A LAN is a local network
that’s most of the time limited to a building, floor or room.
In modern networks most computers are connected on a LAN over one or more switches.
Multiple LANs connected over a router or VPN (see Sect. 2.17) are called MAN. If the
network spreads over multiple countries or even the whole world like the internet than it is
defined as a WAN.
According to the pure doctrine the ISO/OSI layer model, technically separates a computer
network into seven layers (see Fig. 2.4).
Each layer has a clearly defined task and each packet passes them one after another in
the operating systems kernel up to the layer it’s operating on (Table 2.1).
8 2 Network 4 Newbies
2.4 Ethernet
Have you ever bought a “normal” network cable or card in a shop? Than the chance is nearly
100% that you own ethernet hardware, because Ethernet is with huge margin the most used
network technology today. You will see network components with different speed limits like
1, 10, 100 MBit or gigabit and an ethernet can be constructed with different cable types like
coaxial (old school), twisted pair (common) or glass fiber (for data hungry guys).
2.4 Ethernet 9
Twisted pair cables can be divided into to the variations STP (Single Twisted Pair) and
UTP (Unshielded Twisted Pair) as well as patch- and crossover cables.
The difference between STP and UTP cables is that the fibers of the UTP cables are
unshielded and therefore they have a lower quality compared to STP cables. Nowadays new
cables in a shop should all be STP.
Patch and cross cables can be separated from each other by looking at the plugs of the
cable. If the colors of the fibers are in the same order than its a patch otherwise a cross cable.
A cross cable is used to directly connect two computers, a patch cable is used to connect
a computer to a hub or switch. Modern network cards can automatically cross the fibers so
cross cables are a dying race.
Every network card in an Ethernet network has a MAC address that’s worldwide unique
and are used to address devices on the net. The MAC address consists of six two digit
hexadecimal numbers, which are separated by colons (e.g. aa:bb:cc:11:22:33).
Its a common misbelief that a computer in a local TCP/IP network is reached over its IP
address; in reality the MAC address is used for this purpose. Another common misunder-
standing is that the MAC address cannot be spoofed. The operating system is responsible
to write the MAC into the Ethernet header and systems like GNU/Linux or *BSD have
possibilities in their base system to change the MAC with one command.
Beside the source destination MAC address an Ethernet header (see Fig. 2.5) consists of
a type field and a checksum. The type field defines the protocol that follows Ethernet e.g.
0x0800 for IP or 0x0806 for ARP.
Last but not least the term CSMA/CD should be explained. CSMA/CD stands for Carrier
Sense Multiple Access/Collision Detect and describes how a computer sends data over an
Ethernet. First of all it listens on the wire if someone is currently sending something. If
that’s the case it just waits a couple of random seconds and tries again. If the channel is
free it sends the data over the network. Should two stations be transmitting data at the same
data a collusion will result, therefore every sending station must listen afterwards to detect
a collusion, than randomly wait some seconds and retransmit the data.
2.5 VLAN
A VLAN (Virtual Local Area Network) separates several networks on a logical base. Only
devices on the same VLAN can see each other. VLANs where invented to define a networks
structure independently from its physical hardware, to prioritize connections and to minimize
broadcast traffic. They were not developed with security in mind, but its a common myth
that VLANs can add to your security. Don’t rely on this myth, because several ways exist
to circumvent the separation of a VLAN (see Sect. 4.5).
Switches implement VLANs in two different ways: through tagging of packets using a
IEEE 802.1q Header (see Fig. 2.6), that’s inserted after the Ethernet header or simply defined
by port. 802.1q is a newer variant, which allows the creation of a VLAN spread over several
switches.
2.6 ARP
ARP (Address Resolution Protocol) translates between layer 2 (Ethernet) and 3 (IP). It is
used to resolve MAC addresses to IP addresses. The other way round is done by RARP
(Reverse Address Resolution Protocol). The structure of an ARP headers can be seen in
Fig. 2.7.
The destination host (192.168.2.3) now shrieks up and screams “Hey that’s me!” by
sending his MAC address to the requesting host (192.168.2.13).
2.7 IP
IP like Ethernet is a connection-less protocol, that means it doesn’t know a relation between
packets. It is used to define the source and destination host on layer 3, to find the (quickest)
path between two communications partners by routing packets (see Sect. 2.14) and to handle
errors with ICMP (Sect. 2.8). An example error is the famous host not reachable packet.
Beside that it handles fragmentation by cutting packets bigger than the MTU (Max Trans-
mission Unit) into smaller ones. Last but not least does it implement a timeout mechanism
thanks to the header TTL (Time-to-live) and such avoids endless network loops. Every host
called hop a packet passes subtracts the TTL by one and if it reaches 0 it should be thrown
away and the source host gets a error via ICMP.
Today there are two variants of IP IPv4 and IPv6. Both protocols differ widely and not
only in size of IP addresses. IPv6 can be extended through so called optional headers and
IPv6 alone can fill a whole book. This book only covers IPv4.
11000000.10101000.00000001.00000010
11111111.11111111.11111111.00000000
Now one combines both addresses using a binary AND-operation that means every posi-
tion, where both number are 1, stays 1, otherwise it is replaced with a 0. At the end you have
the number of figure (Fig. 2.9).
11000000.1010100.00000001.00000000
so called CIDR block. If the complete last byte is accessible for hosts the net is classified as
a class c, two byte make a class b, and three a class a otherwise the net is called a subnet.
Our example host computes the same AND-operation for the destination to obtain its net-
start-address. If they differ the destination is in another network and the packet is send to the
default gateway, otherwise the net is looked up in the routing table (see Sect. 2.14) and the
packet is sent over the specified device or to the next router depending on its configuration.
2.8 ICMP
ICMP (Internet Control Message Protocol) is used by IP for error handling. Therefore it
sets a type and a code field in its header to define the error. The header looks like in Fig.
2.10.
Most readers know the protocol for the famous ICMP echo-request packet sent
by the program ping, that hopes to receive an echo-response to test if a computer is
reachable and measures the network latency. Other ICMP messages include redirect-host
for telling a host that there is a better router to reach his destination. Table 2.2 lists all type
and code combinations.
2.9 TCP
TCP (Transmission Control Protocol) provides session management. A new TCP session is
initialized by the famous Three-Way-Handshake (see Fig. 2.13). TCP numbers all packets to
ensure that they are processed in the same order they were transmitted by the source system.
The destination host sends an acknowledgment to let the source know that the packet was
received correctly after checking a checksum otherwise the source retransmits the packet.
Last but not, least TCP addresses programs on a host by the use of ports. The port of the
sending instance is called source port the receiving destination port. Commonly used
application protocols like HTTP, FTP, IRC etc. have default port under 1024 e.g. a HTTP
server normally listens on port 80.
A typical TCP looks like Fig. 2.11.
Beside ports one also needs to know about TCP flags (see Table 2.3), sequence- and
acknowledgment-number and windowsize. Flags are used for session management to create
or destroy a connection and to bid the destination to handle a packet with a higher priority.
The Sequence-Number is used to sort the received packets into the same order as they
were send by the origin and to detect lost packets. Each packet gets an individual number
that is incremented by one for every transmitted byte.
The Acknowledgment-Number as the name suggests acknowledges the counterpart
that a packet with a certain sequence number has been received correctly. Therefore it uses
the sequence number and adds one. The Acknowledgment-number contains the next
expected Sequence-Number.
The window size defines the size of the operating systems cache of received, but not yet
processed packets. A window size of zero indicates the sending station is under pressure
and asks to be friendly and to slow down or even stop sending more packets until a bigger
window size is received.
16 2 Network 4 Newbies
Beside that the window size defines the receive window. A host accepts all packets
lower than Acknowledgment-Number + Windowsize (Fig. 2.12).
The establishment of a TCP connection is divided into three actions the Three-Way-
Handshake (see Fig. 2.13): First of all the initiating computer sends a packet with the
SYN-Flag set and to stay by our example an Initial-Sequence-Number of 1000. The Initial-
Sequence-Number must be as random as possible to avoid Blind-IP-Spoofing attacks, where
the attacker guesses a sequence number without being able to read the network traffic.
The destination host responds with a packet where the SYN- and ACK-Flag are set. As
Initial-Sequence-Number it chooses 5000 and the Acknowledgment-Number contains the
Sequence-Number of the source host incremented by one (1001).
Last but not least the source host sends a final packet with set ACK- (but not SYN) flag
set and uses the acknowledgment number of the SYN/ACK packet as sequence number as
well as the sequence number of the previous packet plus one as acknowledgment number.
This completes the Three-Way-Handshake. From now on both parties send packets with the
ACK flag set.send ACK packets.
If a packets hits a closed port the destination must send a RST-Packet to be conform
to RFC793. This signals the source host that the request was invalid. Lot of firewalls (see
WIFE. [To MASTER STIG as she leaves the room by the door at the
right] Pray for us!
MONS and ANDERS withdraw to the left corner of the room and sit
down there. Master Stig shows plainly that he is much alarmed.
OLAVUS. Is it the quartz or the pyrites that make the worst smoke?
ANDERS. Why do you ask?
OLAVUS. That's a poor answer!
MONS. May I ask you in return whether King Christian still is free?
OLAVUS. [Looking hard at him] Do you put your trust in the enemy?
[Pause] What kind of a man is Nils of Söderby?
MONS. His friends think him better and his enemies worse than
anybody else.
OLAVUS. What kind of a bell in the Siljan valley was that you spoke
of?
MONS. It's the largest one in all Dalecarlia.
OLAVUS. Have you many bells of that kind?
ANDERS. Of the kind that calls the people to arms we have still a lot.
MONS and ANDERS move from one chair to another and give
other evidence of agitation.
ANDERS. [Beyond himself] In the name of Christ, will this never come
to an end?
OLAVUS. [Rising] Yes, this is the end!
OLAVUS. Look!
MONS and ANDERS. Another blood-bath!
MONS. Without trial or hearing!
OLAVUS. The trial took place two years age, and sentence was
passed. But the King put mercy above justice and let the traitors
remain at large to see whether their repentance was seriously
meant. When he learned that they remained incorrigible and went
on with their rebellious talk as before, he decided to execute the
sentences. That's how the matter looks when presented truthfully.
MONS. And yet there was a lot of talk about everything being
forgiven and forgotten....
OLAVUS. So it was, provided the same offence was not repeated. But
it was repeated, and what might have been forgotten was again
remembered. All that is clear as logic. [To HERMAN ISRAEL] These two
trustworthy men.... [To MONS and ANDERS] You are trustworthy, are
you not?
MONS and ANDERS. Hope so!
OLAVUS. Answer yes or no! Are you trustworthy?
MONS and ANDERS. Yes!
OLAVUS. [To ISRAEL] In the presence of you as my witness, syndic,
these two trustworthy men have given a true report of conditions in
Dalecarlia. They have unanimously assured us that the mines are
being worked profitably; that agriculture and cattle-breeding prosper
no less than the mining; that famines occur but rarely, and that,
during the last one, our gracious King distributed grain in quantities
not insufficient, which went to those that really were in need. These
trustworthy and upright miners have also confirmed the following
facts: that bells to summon the congregations still remain in all the
churches; that no bad priests are spreading devices of men, and that
nothing is preached here but the pure word of God. You have
likewise heard them say, syndic, that the province of Dalecarlia can
raise from sixteen to eighteen thousand men capable of bearing
arms—the figures vary as their courage falls or rises. Being in charge
of the current debt, and for that reason entitled to know the actual
status of the country, you have now heard the people declare with
their own lips, that all the Dalecarlian grievances are unwarranted,
and that those who have spread reports to the contrary are traitors
and liars.
MONS. Veto!
ANDERS. I deny it!
OLAVUS. If you deny your own words, then you are liars twice over!
MONS. He is drawing the noose tighter! Better keep silent!
ANDERS. No, I most speak. [To OLAVUS] I want to know what our fate
is to be.
OLAVUS. So you shall. Your fate is in your own hands. You are invited
to Stockholm and given full safe-conduct. You can travel freely by
yourselves. This is granted you as old friends of the King, to whom
he acknowledges a great debt of gratitude.
MONS. More guile!
OLAVUS.No guile at all. Here is the King's safe-conduct, signed by his
own hand.
ANDERS. We know all about his safe-conducts!
MONS. [To ANDERS] We must consent and submit in order to gain
time! [To OLAVUS] Will you let us go into the next room and talk the
matter over?
OLAVUS. You can now go wherever you want—except to the King.
MONS. [As he opens the door] We'll bring you an answer shortly.
OLAVUS. As you please, and when you please.
MONS and ANDERS show how deeply the news hits them; neither
one has a word to say.
ACT II
FIRST SCENE
ERIC.Oh, let them hear. Marcus and I are old friends, and we met at
the Blue Dove last night.
JACOB. Ugh! Why do you visit a vulgar place like that, Prince?
ERIC.Where can I go? I have no one to talk with at home; and it
seems to me, for that matter, that people are equally good or bad
everywhere—although I prefer what is generally called bad company.
—Do you know John Andersson?
JACOB. [Embarrassed] I have never heard his name even. Who is he?
ERIC.A man from Småland who is full of sensible ideas.—Do you still
need to have your forehead bandaged?
JACOB.Do you think I wear the bandage as an ornament, or as a
souvenir of the city mob?
ERIC.You should not bear a grudge against the good folk because
some scamp has misbehaved himself.
JACOB.I don't, my friend, and I know perfectly well what a stranger
must expect in a hostile country. If you come to Luebeck, you will
see how they stone Swedes.
ERIC. You talk just like Jorghen Persson. Do you know him?
JACOB. I don't.
ERIC. He looks at everything in the same way as you do.
JACOB. How do you mean?
ERIC. He thinks every one is right, and that whatever happens is
juste. There is something sensible and enlightened in his view of life.
That's why my father hates him....
JACOB.Don't talk badly of your father. It sounds dreadful—if you will
pardon me!
ERIC.But if he acts badly, why shouldn't I say so? And I hate him, for
that matter!
JACOB.Don't say that—don't! The greatness of your royal father is so
boundless that you can't grasp it.
ERIC. It only looks that way—I know! Last night he came up to me
and put his arm around my shoulders—for the first time in my life—
and I, who have been living in the belief that I barely came up to his
hip, found to my surprise that I am as tall as he. But as soon as I
looked at him from a distance again, he grew taller and turned into a
giant.
JACOB. That's what he is. And he resembles one of Buonarotti's
prophets—Isaiah, I think. And, verily, the Lord on high is with him.
ERIC. Do you really believe in God?
JACOB. Are you not ashamed of yourself?
ERIC. Well, what are you to believe in times like these, when kings
and priests persecute the faithful and profane everything that used
to be held sacred. And yet they call themselves "defenders of the
faith."
JACOB. Can't we talk of something else? Please, let us!
ERIC. That's what the King always says when I go after him, and for
that reason I hate him still more—as he hates me! Do you know that
it was your father who brought my mother to him from Lauenburg?
[2]
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com