Ethical Hacking (1)
Ethical Hacking (1)
2.2 IP addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.8 Robtex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1
3.2 Packet switched networks – avoiding infinite loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.6 Layer 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2 Brute-forcing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2
Learning outcome
• have information on the legal aspects of performing ethical hacking and to judge what is within and outside
permitted activities
• be able to perform practical penetration testing using up-to-date tools and techniques
• be able to evaluate the security status of systems and suggest solutions for removing security vulnerabilities
• be able to use publicly available resources for verifying the status of vulnerabilities and for applying patches
8
1 Lecture 1: Basis of ethical hacking, general information gathering
Lecture Overview
• Checking the system from the attacker’s perspective can reveal serious security deficiencies
• The "attacker" thinks like a real hacker (but not totally) / understand the black hat hacker, mindset.
9
– Do we use the same methodology as the real hackers? – What makes hacking ethical?
– Do we have the same goals? – What is allowed and what is not?
– Do we have to hide ourselves when ethically hacking?
• The system security cannot be guaranteed without deep and regular penetration testing
– Can it be guaranteed with penetration testing? Unfortunately not always perfectly, the keyword is the
appropriate mitigation
• Because I can
• Money
• Revenge
• Annoyance
The goal of hacking Break the information security triple (confidentiality, integrity, availability)
• Modify data
10
1.1.4 Type of hackers
• Black hat hackers: with malicious intent • Grey hat hackers: usually white hat, but can be
black hat
• White hat hackers: perform penetration testing
to promote the security • Red hat hackers: Stopping black hat hackers by
attacking them
• Script kiddies: amateurs (usually young kids) us-
ing publicly available software tools to attack • Blue hat hackers: Hacking in order to take revenge
• Protest hackers (protest against something e.g. • Green hat hackers: beginners to hacking
anonymous)
How do I start? Which one of these will be used by the black hat and the white hat hackers?
• Try to sneak inside the building to have access to the internal network?
11
1.3 Main steps of hacking
• Information gathering
1. General information gathering: collecting collecting all available information from the target and systemize the
information
2. Technical information gathering: collecting network and system specific information like target ip ranges
3. Identifying available hosts in the target network (which computer can be attacked)
4. Identifying available services in the target network (which service can be attacked)
5. Manual mapping of the services (to check how it looks like, the impressions, system reactions, mitigations, etc.)
7. Manual verification of the findings (to check if the previous findings are real – true positive)
8. Exploitation
14. Removing the attacking files!!! (tools, data, script created temporarily during the pentest)
12
1.3.2 Type of ethical hacking projects
From the attacker’s location point of view: From the attacker’s access (right) point of view:
• Before getting contact with the target we need to prepare for the attack
• General information gathering covers all the efforts that is done for collecting all the information from the
target
• The collected information should be analyzed as well in order to filter the important information
• Sometimes it is not obvious which information will be useful later, all information should be systemized
• The result of the information gathering is a huge dataset with dedicated information (e.g. user lists, etc.)
– Cached data (data that are not online right now, but can be restored)
13
2 Lecture 2: Technical Information Gathering
Lecture Overview
• Domain registrants
• Ip range owner(s)
• Hosting companies
• Etc
A domain name is an identification string that defines a realm of administrative autonomy, authority or control
Domain names are formed by the rules and procedures of the Domain Name System (DNS). Any name registered in
Top level domain can be (com, net, info, edu, org and country code) Second and third level domains can be any
string. The full length of the domain cannot be longer than 255 characters.
14
• A hostname is a domain name that has at least one associated IP address
• Domains are registered by the domain registrators that are accredited by the Internet Corporation for Assigned
• each TLD is maintained and serviced technically by an administrative organization operating a registry
• All data has to be published and accessible with the whois protocol
• Name servers
Name servers are computers that provide subdomain in-
formation for the particular domain using the dns protocol
15
2.1.3 Domain name owner examples
• nrk.no
• dyreparken.no
• horsepro.n
• footish.se
• termesangiovanni.it
• timeanddate.com
2.2 IP addresses
• IP addresses are for the identification of computers during the communication (OSI 3rd layer, see later).
• In order to be easy to memorize it, 8bit (byte) blocks are used for ipv4 e.g. 129.240.171.52
• For ipv6 addresses are represented as eight groups of four hexadecimal digits
e.g. 2001:0db8:0000:0042:0000:8a2e:0370:7334
16
2.2.1 IP ranges - classful networking
In 1981 the classfull networking was created. It consisted of the A, B, and C class of network ranges. The idea
• What is the first and last address of the /23 network range that contains: 194.172.10.10?
• What is the first and last address of the /18 network range that contains: 164.44.20.52?
17
2.3 IP range owners
Who is the owner of the following ips and how big is the related network range?
• 5.44.65.150 • 198.62.101.225
• 195.88.55.16 • 194.61.183.124
• 188.44.50.103
In those cases the webpage cannot be attacked or separate permission is needed from the owner of the server computer
(Example: elektronikmesse.dk )
18
2.6 Finding network ranges
• Solution (demo)
– dn.no has the following second level domains: s1,s2,s3,s4, arkiv, multimedia, investor, hotell, idn, ww5,
sjakk, pad
– All the domains are associated with the same ip (87.238.54.132), except the pad.dn.no which is: 87.238.53.121,
19
2.7 Domain to ip options
2.8 Robtex
20
21
3 Lecture 3: Network reconnaissance, port scanning
Lecture Overview
22
3.2 Packet switched networks – avoiding infinite loops
No answer
• In case of icmp, we have no response from the host
that was addressed by the echo request
23
3.4 Internet Control Message Protocol (ICMP)
Since ICMP contains the ttl value, it is possible to guess the receiver host’s operating system by its ttl. Initial ttl
values:
Solaris: 255
Nmap is an universal port scanner. It is able to carry out ordinary and specific host and service discoveries. Nmap
has a scripting engine which makes it capable of carrying out complex scanning as well as vulnerability discovery,
24
The main parameter is the scanning type that can be set with the –s switch, e.g. -sP: ping scan
Example task: How many hosts are alive in our current local network range? E.g. nmap –sP 192.168.0.0/24
• Timing option (how many tries, how many parallel requests, max retries, scan delay, etc.)
• Scripts to run
25
3.6 Layer 4
Apart from sending short simple messages, bigger data blocks can be transmitted between the hosts. The data
• UDP : streaming the data (no guarantee that all data will arrive, but fast)
• TCP : the arrival of all data is guaranteed in the right order (trustworthy transmission, slower than UDP )
In addition, the data transmission is carried out using port numbers. One host can send and receive data in multiple
• UDP 53 DNS
• UDP 111 RPC (Remote Procedure Call)
• UDP 123 NTP (Network Time Protocol)
Remember that any service can be used in any port, these are only recommendations
26
3.6.5 TCP 3-way handshake
TCP handshake is the process when a connection is about to be established in a specific port.
In case of reverse scanning, Nmap looks for closed ports. The results of a reverse scan can be either open/filtered or
closed. It cannot be determined if a port is filtered or open. According to TCP if a port is closed the receiver sends
-sX Xmas scan (push, fin and rst flags are set)
With hping we can set any flag (more reverse scan options, see later)
27
3.8 Ack scan
• The stateful firewall can follow packet streams considering previous packets.
For a stateless firewall an ack package seems like the third step of the handshake. For the stateful firewall it is
If a TCP connection is established it will be logged by the firewalls – this is noisy (in a network with huge internet
Decoy scan uses the «needle in the haystack» theory: it sends out each request in multiple copies with different
source ip.
Questions: Can we modify our source ip in the packet? If so, why don’t we modify it all the time?
28
3.11 Hping2, hping3
• The table contains all the discovered hosts with all discovered services in separate rows
• Each service has a comment field if it was compromised during the pentest
• The client can evaluate each service if it should be closed or assign a responsible person for all operating services
Firewalk was a special internal network scanner in the beginning of the 2000s (cannot be used today). It was able to
exploit of a flow of the TCP implementation and scan the internal network with one hop behind a firewall (it used
Zmap is a superfast layer2 port scanner. It is able to map the whole ipv4 network range within 45 minutes for one
29
4 Lecture 4: Get in touch with services
Lecture Overview
• We mapped the target network and have an inventory (live hosts, responding services)
• What’s next?
– Find a vulnerability
30
4.1 How to start compromising a service?
An exploit (from the English verb to exploit, meaning "to use something to one’s own advantage") is a piece
of software, a chunk of data, or a sequence of commands that takes advantage of a bug or vulnerability to cause
unintended or unanticipated behavior to occur on computer software, hardware, or something electronic (usually
computerized). Such behavior frequently includes things like gaining control of a computer system, allowing privilege
31
4.4 Attacking ftp service
32
4.5 Attacking SMTP
DATA: Sent by a client to initiate the transfer of message content. Note there are no Subject, CC, BCC fields. All
these data are placed in the data section (these are not part of the smtp)
VRFY: Verifies that a mailbox is available for message delivery. If it’s allowed user enumeration is possible.
• If one of the client’s SMTP allows open-relay access then any email can be written unseeingly
33
How can the users make sure that an email arrived from the right person?
• There’s no 100
Asterisk, AFP, Cisco AAA, Cisco auth, Cisco enable, CVS, Firebird, FTP, HTTP-FORM-GET, HTTP-FORM-
HTTPS-GET, HTTPS-HEAD, HTTPS-POST, HTTPProxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MYSQL, NCP,
NNTP, Oracle Listener, Oracle SID, Oracle, PC-Anywhere, PCNFS, POP3, POSTGRES, RDP, Rexec, Rlogin,
Rsh, RTSP, SAP/R3, SIP, SMB, SMTP, SMTP Enum, SNMP v1+v2+v3, SOCKS5, SSH (v1 and v2), SSHKEY,
34
35