Open Source Security Your Network More Secure With Open Source Tools
Open Source Security Your Network More Secure With Open Source Tools
Summary
Summary
Preface
Introduction
1 - Password Vault
1.2 Second Authenticator Factor
1.3 Resume
2 - Firewall
2.1 Firewall Builder
2.2 Blocking Countries
2.3 Resume
3 - HIDS
3.1 NTP
3.2 RSYSLOG
3.3 Rules Classification
3.4 Rules Group
3.5 Web Server Configuration
3.6 Resume
4 - Reverse Proxy
4.1 HARDENING
4.1.1 Automatic Security Upgrades
4.1.2 Blocking areas of your website
4.1.3 Forensic Software Installation
4.1.4 Unnecessary services and running on partitions
4.2 Resume
6 - SIEM
6.1 Resume
Final considerations
Appendix 1
Basic Operating System Linux
1 - Installing Debian
2 - Basic commands
Appendix 2
Basic Shell Script Language
Bibliography
Preface
Usually a preface is written by renowned and prestigious authors as a way of
endorsing a new writer who presents himself. I tell you, don't expect any of this from
me. I'm not even an author or a writer. I am just a person who has been working
directly with Diego for some years - as a coworker, now coordinating his work - who
knows how determined, pioneering, knowledgeable and passionate about
Information Security he is. So, believe me: if you work or think about going into this
area, don't miss this book!
This work also allows for reflection if, in fact, a safe environment is one that has a
high investment cost attached to it, by presenting free tools that, when well
configured and associated with some simple practices, ranging from changing
passwords to awareness of users, are examples of procedures with little or no
financial cost that have a great impact when it comes to Information Security.
All this knowledge and this learning curve are offered to you in this book, in a clear
and didactic language, so that you can optimize your time, in order to use it for new
discoveries and not to face issues that have already been overcome by someone
else. opportunity.
Want to know how to install and configure Open Source tools such as Linux
Operating System, password vault, second authentication factor, firewall, HIDS,
reverse proxy, WAF, SIEM, attack map, among others? Then browse this book and
find a chapter dedicated to each of the tools presented, with a tutorial that will guide
you through the entire process: download, installation and configuration. All this for
you to enjoy the tool in the best possible way and still optimize your time.
Computer, internet and book ready? So, get to work!
I have been working with Information Security since 2015. I started to get
interested in the subject when I was still an Officer of the Brazilian Air
Force. I remember that there was a defacement (attack that aims to
modify a web page, like graffiti) in one of the web systems of aeronautics
and this shocked me, as I believed the network was well protected. Only
later, working in the area, I realized that sometimes what happens is a
false sense of security, perhaps due to the huge expenses with the best
solutions for Firewall, WAF (Web Application Firewall), Antivirus, etc. I
realized that, even if you have resources for all these solutions, nothing
replaces the performance of a team making adjustments to these tools
and mainly investing in network visibility. Knowing what happens is
fundamental. I believe that one of the best resources in the security area
is Logs (system events). Knowing what is happening on your network,
where the attacks are coming from, what the targets are and what type
of exploitation is trying to be done in your environment makes all the
difference. A good IDS (Intrusion Detection System) is already capable
of revolutionizing security on your network.
- Sun Tzu
1 - Password Vault
I couldn't start with a tool other than the Password Vault, as there is still
little importance to password management. Information Security is in the
details. When it comes to Information Security, many think only of
complex, ingenious and expensive solutions. There is no shortage of
password leakage scandals even in large companies and the damage is
great, mainly because many people do not use the Second
Authentication Factor. The best password security is one that uses at
least two of the three authentication factors:
With these leaks, it is useless to have the best password in the world,
with many characters or of high complexity. Well, it is clear that this will
generate a HASH that is difficult to decipher by Rainbow Tables
(pre-calculated HASH tables), but when in doubt, and aiming at a better
security of your personal data, I strongly recommend that you use, if
possible in all your accounts on the internet, the Second Authentication
Factor.
The idea is that the network administrator, and his team, use a Vault
where the network passwords are managed and share it only with his
team. The Vault will assist in creating strong passwords and a host of
other password information. I recommend the tool KeePass
(https://keepass.info).
It is an Open Source tool, like all that I will show in this book, with
versions for various operating system platforms and very simple to use.
So let's test the tool. First download it from the Downloads menu on the
keepass website.
Here at MacPass, when clicking New Entry, I was asked if I would like to
create the password for accessing the Password Vault. As the image
below:
Image 1.5 - Password to access the Password Vault
You will see the fields for creating a password and creating a Password
File (KeyFile). Creating a password for the password vault leads us to a
problem: as we are creating a Password Vault to avoid sharing a
password that will end up on some post-it on the network administrator's
monitor. So I recommend using the Password File and making a control
through GitLab (software repository manager based on git). GitLab is
also Open Source and excellent for versioning software. It can be used
to manage changes to your Password Vault and your Firewall file, as we
will see in the next chapter. However, installing and using GitLab is
outside the scope of this book. The idea is quite simple: generate the
Password File and place it in the GitLab project together with the
Password Vault database, in such a way that only project members can
have access, both to the Password Vault bank and the Password File.
Why Debian? First of all, because Debian is, among all Linux other
distributions, one of the most faithful to the Open Source movement. In
addition, it is extremely stable, secure (as long as it stays up to date) and
easy to use. If you want to use another distribution, there will be no
problem.
Use your cell phone, with the second factor authentication application,
and enter the secret key or scan the QR Code.
When using the application, you will now have a token like the one in the
image above.
There will be five questions, the first, when answering y, made the QR
Code and emergency codes appear. The second question about
creating a hidden file in the home of the user who is installing google
authenticator. Type y, it is in this file that will be checked if the
the code that was entered is correct at the time of login via ssh. The third
wants to know if multiple users will be able to use the same token. Type
y, as the idea is that only team members share the token and access to
the Password Vault. The penultimate wants to know if there will be an
increase in the time window in case of time synchronization problems on
your server. For our book, where we have not yet configured an NTP
(Network Time Protocol) service, something we will see in the Hardening
chapter, type y. Finally, type y to block multiple login attempts.
Save and edit the file now /etc/ssh/sshd_config. For this book only, to
facilitate the process, enable ssh access with the root user:
PermitRootLogin yes. After, ChallengeResponseAuthentication yes.
Save the file and restart the ssh service: service ssh restart
Let's test, open a terminal and try SSH access with the root user on IP
192.168.15.7:
Image 1.15 - 2 authentication factors working
1.3 Resume
Now let's talk about edge security. Edge refers to data entering or
leaving your network. Also known as a network perimeter.
When you think about Firewall, at least in my head, the first thing that
comes up is Iptables. Iptables is a user interface tool that allows the
creation of rules from the Netfilter module, which provides the Linux
Operating System with the functions of Firewall, NAT and log. I do not
know how much knowledge you have in relation to Iptables, but I already
say that it is not trivial to use it without the use of tools such as Firewall
Builder, which we will talk about later.
Anyway, let's go to the basics of Iptables. Iptables sees only IP and Port,
not understanding layer 7 of the OSI model (Application). Nothing
prevents you from installing a Squid so that you have better visibility of
the layer, but the scope of the book is to set up an Iptables Firewall
through the Firewall Builder and still implement a basic Shell Script for
blocking Countries, something that can avoid a lot of pain Of Head.
Iptables works with tables: Filter, NAT and Mangle.
● In the Filter table are the rules for blocking or releasing network
packets, that is, it is the table that actually does the main functions
we want in the Firewall. It treats packets that are forwarded to the
Firewall as the final destination (INPUT chain), that are generated
in the Firewall and leave (OUTPUT chain) and those that are
forwarded and cross the Firewall (FORWARD chain).
● The NAT table has tasks such as changing the source (SNAT),
destination (DNAT) IP addresses, masking (MASQUERADE) and
redirecting packets (REDIRECT).
● Finally, the MANGLE table, which has special rules such as ToS
(IPv4 header service type).
To see the iptables rules in linux, just type, as root or using sudo, the
iptables -L command.
See that in the example above there are no rules in our Iptables Firewall.
Creating iptables rules by hand is not very productive and nothing trivial
even more when Firewall rules start to grow with the demands of the
network in the corporate environment, so let's learn how to use Firewall
Builder to create Firewall rules just by dragging objects.
2.1 Firewall Builder
I created the virtual machine that will be our Firewall, as shown in the
image below.
● Corporate (172.16.1.0/24)
● DMZ (192.168.1.0/24)
● Firewall IP on the wifi router's network via DHCP (192.168.15.30).
Probably yours will be different.
● Firewall GW (192.168.15.1). This is the IP of my Wi-Fi router.
At that moment we have to create our firewall object, clicking Create new
firewall.
Image 2.5 - Create FW
After creating the first interface, the others are created by pressing the
right mouse button on the FW object.
We will create the basic rules so that we can, for example, make a ssh in
the FW to manage it. Just press the or with the right mouse button in
the left corner of any FW rule and I nsert New Rule. We will use the
Firewall Builder facilities to create a rule that releases the SSH (Secure
Shell) service with any source (any) for FW. Just go to Find Object
and look for the service. You can search for the SSH name or port 22.
When you find it, just drag the object for the Service column of
the rule.
We already have the service, now the object that will occupy the
Destination column is missing, which in our example is FW. Just drag
the object or just the IP of the FW that we want to enable
SSH access, being a safer option, because if we drag the entire FW, we
will enable SSH on all of its interfaces. I will just drag the IP of the
interface I called ETH0, as it is the IP that is on the same network as my
wi-fi router and I will be able to administer my machine external to the
See that I put a comment on the rule, also a good practice. The rules
must be above the rule , because the FW reads the rules from
top to bottom. Let's try it out. For that, it is necessary to install these
Firewall Builder policies on the Debian machine that will be our FW. We
will do everything as root, but just to make things easier in the
virtualization environment for this book. In production it is recommended
to create a user with sudo powers in Debian and install the FW with it.
That said, click , to compile and check for errors, and then .
Image 2.14 - Expected build result
Only SSH is enabled, try other services like Telnet (port 23) or a PING.
They will be blocked by the FW in the last rule. To see the FW logs, do
the command: tailf /var/log/syslog
One of the tools that state-of-the-art Firewalls (e.g. Checkpoint and Palo
Alto) offer, with their so-called Next Generation Firewalls, is blocking of
countries, which is often very useful for the Network Administrator to
avoid having troubles. In order to implement this tool in our FW, we will
use the tool ipset, a text file with the IP of all countries
(https://pkgstore.datahub.io/core/geoip2-ipv4/geoip2-ipv4_csv/data/5ecd
20f7df0f626a2270b71d4c725630/geoip2-ipv4_csv.csv) and a shell
script.
The first step then is to install the ipset. For this, the command apt-get
update && apt-get install ipset. But first it is necessary to release our
FW to access the internet with apt-get. It's basically releasing http, https
and DNS for our FW.
Let's start by creating a table that will store the networks of the countries
we want. The command is as follows:
After creating the blacklist-net, I used the command ipset list to list the
created list. Of course it's still empty, so let's create Shell Script. Let's
create a file called bloqueio-pais.sh on /root.
If you want to release it, just run the script and put the letter l. Bearing in
mind that for the time being this is not enough to block the country, the
FW has yet to "tell" that it should consult the blacklist-net table for each
INPUT, OUTPUT and FORWARD. For this it is necessary to execute the
following commands:
See that the commands insert into iptables, at the top of the INPUT,
FORWARD and OUTPUT chains, so number 1, rules that compare the
IPs that travel with our blacklist, if there is a match, the ip will be blocked
(DROP ).
I put the commands in and listed to check if they were in the FW. Now
we are going to test on our client machine that was accessing the
internet normally. Let's see what happens with the blockade in Brazil.
See that the Brazilian website will not open, as it got caught in the
blockade of FW countries. We will release it and test again.
Image 2.41 - country release
For this chapter, we will install two new virtual machines, one that will be
our WEB server with OSSEC installed and another that will be our
Syslog. Syslog is a very important service on your network, as it
centralizes all the logs on your network in one place, facilitating the
administration and backup of these logs, if applicable.
Image 3.1 - VM
At this point, we already have four virtual machines (FW, Client, Syslog
and WebServer). The FW with three interfaces (192.168.15.30,
192.168.1.1 and 172.16.1.1), Client with an interface (172.16.1.10),
Syslog with an interface (192.168.1.10) and WebServer with an
interface (192.168.1.20). Remembering that the 172.16.1.0/24 network is
the corportiva and 192.168.1.0/24 is the DMZ.
In order for us to install the necessary packages on the two new virtual
machines, we will need to make the necessary releases on the FW.
FW releases were made with rule 1 and NAT. We will start with the
Syslog server. We will use the rsyslog package, which is a tool that
works well and is easy to configure. Usually it is already installed in
Debian, but if you need to install: apt-get update && apt-get install
rsyslog. It is not enough to have the logs if the date / time is incorrect,
then we will install the NTP (Network Time Protocol) package, which is a
protocol that synchronizes the clock so that it is always correct (apt-get
update && apt-get install ntp) .
In FW, ports 80, 443 and 53 were released, but not 123, which is the
NTP port, without it there will be no clock synchronization. Let's release
it.
3.2 RSYSLOG
Now that we've taken care of setting the date / time, let's configure the
rsyslog: nano /etc/rsyslog.conf. Uncomment the lines so that it looks
the same below:
After installing, we can already test if the service is working. Just put the
WebServer IP in the browser and, if everything is right, a standard
Apache page will appear. But first we need to release the http service
from the Corporate network to DMZ.
1. dpkg -i ossec-hids-server_3.3.0.6515stretch_amd64.deb.
2. apt-get install ossec-hids-server
3. apt --fix-broken install
4. apt-get install inotify-tools
<syslog_output>
<server>192.168.1.10</server>
</syslog_output>
Right after configuring the ossec.conf file, enable ossec to send alerts
via syslog and reset ossec-control, a few seconds later our syslog starts
receiving alerts, as shown above. Note that there are changes alerts in
the checksum of /etc/paswd, /etc/shadow, etc ... This happened because
there were actually changes in these files when installing ossec,
because it creates an ossec user in /etc/passwd and, for therefore, it
also modifies /etc/shadow and /etc/group. See that ossec keeps you
informed about everything that happens relevant on your server. Each
alert has a number, which in these cases was 7 (“Bad word” matching.
They include words like “bad”, “error”, etc. These events are most of the
time unclassified and may have some security relevance). The higher
the number, the more concerned you should be.
Rules are classified at multiple levels. From the lowest level (00) to the
maximum level 16. Some levels are not currently used. Other levels can
be added between or after them.
The rules will be read from the highest level to the lowest level.
● 01 - None -
● 08 - First time seen - Include events seen for the first time. First
time that an IDS event is triggered or the first time that a user has
logged in. If you have just used OSSEC HIDS, these messages
are likely to be frequent. After a while they should leave, it also
includes relevant security actions (like starting a sniffer or
something).
● invalid_login
● authentication_success
● authentication_failed
● connection_attempt
● attacks
● adduser
● sshd
● ids
● firewall
● squid
● apache
● syslog
Remember that we only configure ossec to send alerts via syslog and
nothing else. As we have a Web Server, we want to adapt ossec to
inform, for example, when someone creates a file with extension html,
php, sh, etc ... Because it could be an attack in progress.
This new configuration will alert changes in real time in the directories
listed above. Now add below those rules the ones that will monitor /var
/www/htm.
Save the changes and there is still one more step to make everything
work well. Ossec, even with the settings above, will still not send alerts,
as there is a rule (<rule id = "554" level = "0">), in / var / ossec / rules,
which is responsible for notifying new files, but it has level 0, and level 0
rules are not alerted. To resolve, we have to rewrite the rule in the
/var/ossec/rules/local_rules.xml file. Add to the end of the file:
<rule id="554" level="7" overwrite="yes">
<category>ossec</category>
<decoded_as>syscheck_new_entry</decoded_as>
<description>File added to the system.</description>
<group>syscheck,</group>
</rule>
With that done, let's restart ossec and create some "malicious" files and
modify the index.html to see what happens. Leave the syslog open and
with the command tailf /var/log/messages.
I edited the index.html file and added the word HACKED, then created
three "malicious" files in /var/www/html.
Image 3.26 - creating files in the html folder
To specify the types of files that ossec should check, just configure
ossec.conf as shown below:
<directories report_changes="yes" realtime="yes"
restrict=".php|.js|.py|.sh|.html"
check_all="yes">/var/www/html</directories>
Be careful with the spaces when copying the codes shown here, as
ossec may not work properly.
3.6 Resume
OSSEC is a HIDS that does its job well. The concepts exposed here
were a small sample of what ossec is capable of. I think I would give
another book if we were to go deeper into the tool. The idea is to show
the tool's potential and encourage them to research and deepen the
concepts to get the most out of it. We saw that ossec is like a "informer"
on your network, warning you of things that happen at the Operating
System level. We learned to receive alerts via syslog about changes and
file creations on our Web Server. We also learned the importance of
having an NTP service running, maintaining the correct times, after all,
without it, the logs would not make much sense to the Security Analyst.
We also learned to have a log server to centralize all the logs on the
network, making it easier to analyze what happens on your network.
4 - Reverse Proxy
Now we will create another virtual machine that will be in the DMZ and
will be our reverse Proxy. It will have the IP 192.168.1.30
.
Image 4.4 - Created virtual machines
● mod_poxy
● mod_proxy_http
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://192.168.1.20/
ProxyPassReverse / http://192.168.1.20/
</VirtualHost>
Then save the file and type: a2ensite webserver.conf. And finally:
systemctl reload apache2.
Image 4.12 - Access to the webserver /admin through the reverse proxy
There are many actions you can take to "harden" your server, here we
will focus on the actions below:
There are numerous other hardening activities that can be done, but I
believe that by doing the ones listed above, there will already be a huge
increase in security on your web server.
4.1.1 Automatic Security Upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
Image 4.15 - 20auto-upgrades
APT::Periodic::Verbose "2";
Ready! From now on your linux will be updated automatically and if you
installed and configured your OSSEC correctly, you will receive
notifications by email and/or syslog.
Another thing we can omit is the version of our Apache. I'm not a big fan
of security due to obscurity, which is precisely to hide information from
others, but if it is to hinder the possible attacker, why not ?!
<VirtualHost *:80>
<Directory /var/www/html/>
Options -Indexes -Includes
<LimitExcept HEAD>
Order deny,allow
allow from 172.16.1.0/24
deny from all
</LimitExcept>
</Directory>
<LocationMatch "^/admin">
Order deny,allow
allow from 172.16.1.0/24
deny from all
</LocationMatch>
</VirtualHost>
Now the Restricted Area (/admin) can only be accessed through the
corporate network (172.16.1.0/24). In addition, it is not possible to index
your site or include files. We also limited the HTTP protocol to use only
the HEAD method. A lot of people don't know that HTTP has several
methods and almost always you just need to enable the GET and POST
methods. It is a tremendous vulnerability to leave all methods open if
your website only needs, for example, GET to work. I've had problems
with some HTTP methods that were used for attacks, so now I only
release the methods that the site needs. Our webserver website is a
simple static website and the HEAD method is sufficient for browsing. To
quell curiosity about HTTP methods, the list taken from the site follows
https://developer.mozilla.org.
PUT: The PUT method replaces all current representations of the target
resource with the payload of the request.
ttp://192.168.1.20/aviso.html
ErrorDocument 403 h
When I talk about Forensics software I don't really mean exactly that,
because the topic of Forensics is something that would make an entire
book. The scope here, when using the term, actually refers to tools that
help to discover gaps in your server, such as rootkits and outdated
packages, as well as software that lets you know who is logged in, etc ...
In the absence of a better term, I am using Forensics.
Let's run each one to see how they work. Starting with: rkhunter
--check.
Really, to facilitate access to the virtual machines for the book, I left root
access for ssh, but it is not ideal and the tool warned about it. He also
warned about the ssh protocol and syslog. Anyway, it gives you a view
of what needs to be changed and you can adjust your server.
Image 4.30 - chkrootkit
The whowatch tool makes it possible to click on the user's name and
know which processes are running, among other information.
This topic closes the hardening section. Many of the software installed
above already helps to know about unnecessary services, but a great
tool is netstat. Always run netstat to see if strange services appear
running on your server. If you have a web server, then you are expected
to see web ports, such as 80 and 443.
Note that ports 80 (http) and 22 (ssh) are listening, but an unwanted port
25 (email) has appeared. For more details, like knowing which
application is using port 25, use netstat -putona.
Image 4.37 - netstat -putona
Now it appears that the software that is using port 25 is such an exim4.
Unfortunately this package comes with the standard Debian installation
and I always have to remove it. To list the packages installed on your
Debian, type dpkg -l. To filter the output and find the exim4 package
more easily, use grep. dpkg -l |grep exim4.
I created and ran harmless malware called malware.sh in /tmp. Now let's
run the command mount -o remount,rw,noexec /home /tmp.
See that even though I am root I can no longer run anything in /tmp and
/home.
Image 50 - Network with reverse proxy
4.2 Resume
In this chapter we saw the importance of the reverse proxy and learned
how to implement it. Then, we looked at the power to "harden" our
server and the security gains we achieved in doing so. Recalling that this
book is only providing an overview on the themes, so that there is still
much to be studied in all subjects. But by placing a reverse proxy on
your network and a hardening on your network templates, in order to
implement security already in the server design, your network will make
a big leap in security.
5 - Web Application Firewall
1. Install a new reverse proxy with Debian 8.11 (the latest version
before 9).
2. Install Apache and configure it as shown in the Reverse Proxy
chapter.
3. Install the new libapache2-mod-security2 library on the new
reverse proxy with Debian 8.11. (apt-get install
libapache2-mod-security2) .
4. Upgrade from Debian 8 to 9.
a. apt-get update && apt-get upgrade -y && apt-get
dist-upgrade
b. edit the /etc/apt/sources.list. Replace jessie with stretch
c. apt-get update && apt-get upgrade -y && apt-get
dist-upgrade
Following the steps above we will have our Debian 9, in the latest
version, with ModSecurity and Apache working perfectly.
mv /etc/modsecurity/modsecurity.conf-recommended modsecurity.conf
cd owasp-modsecurity-crs
mv crs-setup.conf.example /etc/modsecurity/crs-setup.conf
mv rules/ /etc/modsecurity/
Image 5.4 - owasp-modsecurity-crs
Added:
● Error and access log settings
● SecRuleEngine on, this enables ModSecurity
● SecRule ARGS, rewrites the log if it contains a certain string,
which in the example is "test"
Now let's edit a modsecurity file. Before you need to rename the file
below that is in /etc/modsecurity/rules:
mv RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example
RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
Now we are going to test a SQL Injection attack by inserting the string
index.php?postid=6641%22%20or%20(1,2)=(select*from(select%20
name_const(CHAR(111,108,111,108,111,115,104,101,114),1),name_c
onst(CHAR(111,108,111,108,111,115,104,101,114),1))a)%20--%20%2
2x%22=%22x on site 192.168.1.30 through the client's machine
(172.16.1.10), in what would be an internal attack. Leave the tailf
/var/log/apache2/webserver-error.log command from the reverse proxy.
Image 5.10 - SQL Injection
We go to two more tests via terminal with the curl command. Open a
terminal on your real machine and type the command: curl
http://192.168.15.30/index.html?testparam=test.
Finally, let's go to another attack, now one trying to bash via url, trying to
exploit a possible vulnerability: curl
http://192.168.15.30/index.html?exec=/bin/bash.
With the SIEM concept, the OSSIM concept emerged, which is nothing
more than the Open Source version of SIEM. And when it comes to
OSSIM, I think of AlienVault
(https://www.alienvault.com/products/ossim). Below are the security
features listed on the website:
● Asset discovery
● Vulnerability assessment
● Intruder detection
● Monitoring network behavior
● Correlation of SIEM events
Don't worry, all of the above settings can be done later. Figure 140
shows the host discovery feature, which is very useful for a complete
inventory of your network. 141 deals with HIDS, which we talked about in
chapter 3, and can also be configured in AlienVault. 142 is the syslog
configuration. 143 is a community, which I recommend that you join,
where you receive information in your AlienVault about new threats. See
that AlienVault, like a good SIEM, tries to centralize all its security
information in one place. This is to avoid having to look at countless
different tools.
Note that there are five large menus in the website header (Dashboards,
Analysis, Environment, Reports and Configuration). Let's go to the basic
characteristics of each one:
● Dashboards: here are the charts that are subdivided into five
specialties (Executive, Tickets, Security, Taxonomy and
Vulnerabilities).
When I first saw an attack map, with all that information in real time, I
found it very interesting. That cyber war going on, colored lines
representing the attacks like intercontinental missiles ... I was very
impressed. My goal, since I saw this technology, was to implement
something similar in my work network. So, I started to research Open
Source projects on the internet, of course, that I could incorporate into
the list of security tools that I had already implemented on the network. I
was pleasantly surprised to find an excellent project by Matthew Clark
May. He simply put together an attack map that, in addition to being
simple to implement on the network, was stable and, most importantly,
clearly presented the attacks that were taking place on the network. . As
soon as I downloaded it, I made some adjustments and sent an email to
Matthew, who really liked my improvements. From then on, I became
part of the project
(https://github.com/MatthewClarkMay/geoip-attack-map).
● Placing information on the Type of Attack, Exploit and IP; all at the
top of the map.
● Target information, the one at the bottom left of the map.
● Button to block the IP that is attacking and menu to check the
reputation of the IP. This was done by Prof. MSc. João Victor de
Araujo Oliveira (http://lattes.cnpq.br/6697354215628897).
● Animation that happens when pressing the Block IP button
● Improved IDS log management across the map, using fewer web
browser features.
Image 7.1 - Check Point cyber attack map
See that the map of Matthew's project does not leave much to be
desired compared to the maps shown by large companies. The fund,
which is a world map, is from a company called MapBox
(https://www.mapbox.com). Then you need to access the site and create
an account to access the map. The company makes the map available
for a limited number of accesses, but it is usually sufficient to use it for a
long time. Depending on the need, it may be more advantageous to
purchase a license. Then create an account and a token will be made
available, which we will use in the project's index.html settings.
The idea is to install the map on the syslog and access the attack map
through the external network, through a NAT on the FW. We will follow
the step by step of Matthew's project
(https://github.com/MatthewClarkMay/geoip-attack-map), but when
downloading the map, I will leave two options:
It just so happened that I made some changes and a while ago I stopped
uploading the modifications to the project. Actually the main changes I
already made available in the project, but if you want my version that is
all in Portuguese, the choice is yours.
First, we have to basically understand how the map works. It was written
in Python and has two systems, one for handling logs (DataServer) and
another for handling data structures and making information available on
the website, which is the AttackMapServer module. So there are two
systems: DataServer and
AttackMapServer. They are distinct, being processes that can be turned
on or off separately. The application server is Redis Server.
In addition, the project comes with a shell script that simulates the
operation of the map with fictitious attacks. We will use it to verify that
our map is working. The map works by reading a log file that must
receive the data from an IDS, which in a production network would be
our AlienVault. However, given the difficulties of running AlienVault in the
lab environment of this book, I will only explain a few ways to normalize
the AlienVault logs and make them available to the map.
cd geoip-attack-map_v4
redis-server
Image 7.6 - redis-server running
cd DataServer
python3 DataServer.py
cd ../AttackMapServer/
Now, edit the index.html. Put, as below, the NAT ip that we will use to
access the map: 192.168.15.30.
The token field must have what you obtained when registering with
MapBox. In addition to the dark background map, MapBox offers two
more interesting options: satellite and streets.
Enter the latitude and longitude of your location in the field below.
Image 7.12 - lat / long configuration
python3 AttackMapServer.py
● The map (background) does not appear. See if you have placed
your account token on the MapBox.
● Nothing appears in the browser. Make sure that the FW has the
release in the Policy and that there is NAT.
Let's test some features of the map. In the IP column, which is next to
the Target column, click on any IP and a menu will appear.
Image 7.18 - Map Menu
The IP block function is commented on in the code, but the idea is to ssh
the FW and using the ipset, which we saw in the FW chapter, to block it.
We already have our attack map working, but only with fictitious data. To
receive the data from an IDS, it takes a few steps to understand how the
attack map expects to receive the data. As it currently stands, the map
expects to receive in its log file (/var/log/suricata_geoip.log) six pieces of
information in the following sequence and without spaces:
● Source IP
● Destination IP
● Source port
● Destination port
● Attack type
● Exploit. Although it is called an exploit, it is actually a field that
details the attack more, it is not necessarily an exploit.
src_ip,dst_ip,src_port,dst_port,attack,exploit
7.2 Resume
The attack map is a tool that makes all the difference in the visibility of
your network. It is possible to take action as soon as an attack is seen in
progress. If not present, the other open source tools that we have
learned to use will contain the attacks. The map, despite having few
active users contributing to the project, is quite satisfactory for use in
production. Be one of the members and contribute to the project, which
in my view has excellent potential.
Final considerations
Throughout the book we learned about some Open Source tools that
can assist in the cyber defense of your network, but these tools do not
represent everything available. There are still excellent tools like ELK
(Elasticsearch, Logstash and Kibana),
https://www.elastic.co/pt/elk-stack, to store the logs for the entire
network and generate valuable information. There is also SELKS, a
solution from Stamus Networks,
https://www.stamus-networks.com/open-source/. It has excellent
potential as an IPS Suricata and the ELK battery, all together. There is
also the Pfsense Firewall, https://www.pfsense.org/download/, which in
addition to FW, also offers a huge amount of software that works in
conjunction with FW. Of course, there must still be many other excellent
Open Source solutions to be studied.
Facebook: https://www.facebook.com/LivroSegurancaOpenSource/
Instgram: https://www.instagram.com/segurancaopensource/
Blog: https://segurancaopensource.blogspot.com
Site: https://segurancaopensource.com
Linkedin: https://www.linkedin.com/in/diego-brum-lima-rocha-7ba78a22
Appendix 1
1 - Installing Debian
Image 5 - hostname
Image 6 - network domain
Image 9 - timezone
Image 10 - Always use LVM, so you can adjust the size of the hot partitions.
command description
file <foo> show the file type for the file "<foo>"
tar -cvf archive the contents of the "<bar> /" folder in
<foo>.tar the "<foo> .tar" file
<bar>/
tar -cvzf archive the contents of the folder "<bar> /" in
<foo>.tar.gz the compressed file "<foo> .tar.gz"
<bar>/
tar -cvjf archive the contents of the folder "<bar> /" in
<foo>.tar.bz2 the file "<foo> .tar.bz2"
<bar>/
tar -cvJf archive the contents of the folder "<bar> /" in
<foo>.tar.xz the file "<foo> .tar.xz"
<bar>/
zcat README.gz create the file "foo" with the unzipped content
> foo of "README.gz"
To execute: ./meuscript.sh
Image 2 - MyScript.sh output
I noticed that the echo command displays a string on the screen. The
exit command is to terminate the shell script. Implicitly, even if the exit is
not set, it will exist, but I like to put it together with parameter 0 to mean
that the program ended without errors. Inheritance when I programmed
in Java (System.exit (0)).
Image 4 - megasena.sh
In the Mega Sena project we use:
With the projects presented, you will be able to make good scripts. Good
luck!
Bibliography
https://e-tinet.com/linux/tabelas-do-iptables-firewall-linux/
https://wiki.sj.ifsc.edu.br/wiki/index.php/Tabelas_de_uso_do_IPTables
https://pt.wikibooks.org/wiki/Guia_do_Linux/Avançado/Firewall_iptable/A
_tabela_mangle
https://keepass.info/%0D/download.html
http://fwbuilder.sourceforge.net
https://www.debian.org
https://ossec-docs.readthedocs.io/en/latest/manual/output/syslog-output.
html
https://ossec-docs.readthedocs.io/en/latest/manual/rules-decoders/rule-l
evels.html
https://blog.wpscans.com/using-ossec-to-monitor-directory-and-file-chan
ges-in-wordpress/
https://www.digitalocean.com/community/tutorials/how-to-use-apache-as
-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04
https://pt.wikipedia.org/wiki/Hardening
https://www.tecmint.com/auto-install-security-updates-on-debian-and-ub
untu/
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
https://www.tecmint.com/hide-apache-web-server-version-information/
https://debian-handbook.info/browse/pt-BR/stable/sect.regular-upgrades.
html
http://rkhunter.sourceforge.net
http://www.chkrootkit.org
http://www.unhide-forensics.info/?Linux
https://packages.debian.org/sid/mtr-tiny
https://linux.die.net/man/1/whowatch
https://servidordebian.org/pt/wheezy/security/audit/debsecan
https://modsecurity.org/about.html
https://www.linode.com/docs/web-servers/apache-tips-and-tricks/configu
re-modsecurity-on-apache/
https://pt.wikipedia.org/wiki/Git
https://www.alienvault.com/products/ossim
https://pt.wikipedia.org/wiki/Gerenciamento_e_Correlação_de_Eventos_
de_Segurança
https://www.alienvault.com/products/ossim
https://networkhop.wordpress.com/2016/04/27/port-mirroring-with-iptable
s/
https://cybermap.kaspersky.com
https://github.com/MatthewClarkMay/geoip-attack-map
https://threatmap.checkpoint.com/ThreatPortal/livemap.html
http://www.norse-corp.com
https://www.mapbox.com
https://www.elastic.co/pt/elk-stack
https://www.stamus-networks.com/open-source/
https://www.debian.org/doc/manuals/debian-reference/ch01.pt.html#_mi
dnight_commander_mc
https://misc.flogisoft.com/bash/tip_colors_and_formatting