%{{{ introduction
\section{Introduction}

The internet has become an irreplaceable part of our day to day lives.
We are always connected via numerous \enquote{smart} and \ac{iot} devices.
We use the internet to communicate, shop, handle financial transactions and much more.
Many personal and professional workflows are so dependent on the internet, that they won't work when being offline.

%{{{ motivation
\subsection{Motivation}

The number of connected \ac{iot} devices is around 10 billion in 2021 and estimated to be constantly growing over the next years up to 25 billion in 2030~\cite{statista_iot_2020}.
Many of these devices run on outdated software, don't receive any updates and don't follow general security best practices.
While in 2016 only 77\% of German households had a broadband connection with a bandwidth of 50 Mbit/s or more, in 2020 it were already 95\% with more than 50 Mbit/s and 59\% with at least 1000 Mbit/s~\cite{statista_broadband_2021}.
This makes them an attractive target for botmasters since they are easy to infect, always online, behind internet connections that are getting faster and faster, and due to their nature as small devices, often without any direct user interaction, an infection can go unnoticed for a long time.
In recent years, \ac{iot} botnets have been responsible for some of the biggest \ac{ddos} attacks ever recorded, creating up to 1 Tbit/s of traffic~\cite{ars_ddos_2016}.


% TODO: what is a bot? Infected systems. Malware. DGA, beispiele, tree vs graph

A botnet describes a network of connected computers with some way to control the infected systems.
In classic botnets, there are one or more central coordinating hosts called \ac{c2} servers.
These \ac{c2} servers could use anything from \ac{irc} over \ac{http} to Twitter as communication channel with the infected systems.
The infected systems can be abused for a number of things, \eg{} \ac{ddos} attacks, stealing data from victims, as proxies to hide the attackers identity, send spam emails\dots{}

Analyzing and shutting down a centralized botnet is comparatively easily since every bot knows the IP address, domain name, Twitter handle or \ac{irc} channel the \ac{c2} servers are using.

A targeted operation with help from law enforcement, hosting providers, domain registrars and platform providers could shut down or take over the operation by changing how requests are rooted or simply shutting down the controlling servers/accounts.

% TODO: better image for p2p, really needed?
%{{{ fig:c2vsp2p
\begin{figure}[h]
\centering
\begin{subfigure}[b]{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{c2.pdf}
  \caption{Topology of a \ac{c2} controlled botnet}\label{fig:c2}
\end{subfigure}%
\begin{subfigure}[b]{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{p2p.pdf}
  \caption{Topology of a \ac{p2p} botnet}\label{fig:p2p}
\end{subfigure}%
\caption{Communication paths in different types of botnets}\label{fig:c2vsp2p}
\end{figure}
%}}}fig:c2vsp2p

% TODO: too informal?
A number of botnet operations were shut down like this and as the defenders upped their game, so did attackers --- the idea of \ac{p2p} botnets came up.
The idea is to build a decentralized network without single points of failure where the \ac{c2} servers are as shown in \autoref{fig:p2p}.
In a \ac{p2p} botnet, each node in the network knows a number of it's neighbours and connects to those, each of these neighbours has a list of neighbours on his own, and so on.

This lack of a \ac{spof} makes \ac{p2p} botnets more resilient to take-down attempts since the communication is not stopped and botmasters can easily rejoin the network and send commands.

Formally, a \ac{p2p} botnet can be modeled as a digraph

\begin{align*}
G &= (V, E)
\end{align*}

With the set of vertices \(V\) describing the bots in the network and the set of edges \(E\) describing the \enquote{is neighbour of} relationships between bots.
For a vertex \(v \in V\), the in and out degree \(\deg^{+}\) and \(\deg^{-}\) describe how many bots know \(v\) or are known by \(v\) respectively.

\begin{align*}
  \deg^{+}(v) &= \abs{\{ u \in V \mid (u, v) \in E \}} \\
  \deg^{-}(v) &= \abs{\{ u \in V \mid (v, u) \in E \}}
\end{align*}

For a vertex \(v \in V\), the in degree \(\deg^{+}(v) = \abs{\{ u \in V \mid (u, v) \in E \}}\) and out degree \(\deg^{-}(v) = \abs{\{ u \in V \mid (v, u) \in E \}}\) describe how many bots know \(v\) and how many nodes \(v\) knows respectively.

% TODO: source for constantly growing, position in text
% TODO: take-down? take down?
The damage produced by botnets has been constantly growing and there are many researchers and law enforcement agencies trying to shut down these operations.
The monetary value of these botnets directly correlates with the amount of effort, botmasters are willing to put into implementing defense mechanisms against take-down attempts.
Some of these countermeasures include deterrence, which limits the amount of allowed bots per IP address or subnet to 1; blacklisting, where known crawlers and sensors are blocked from communicating with other bots in the network (mostly IP based); disinformation, when fake bots are placed in the neighbourhood lists, which invalidates the data collected by crawlers; and active retaliation like \ac{ddos} attacks against sensors or crawlers~\cite{andriesse_reliable_2015}.


%}}} motivation


%{{{ detection techniques
\subsection{Detection Techniques for \Acs*{p2p} Botnets}

There are two distinct methods to map and get an overview of the network topology of a \ac{p2p} botnet:

%{{{ passive detection
\subsubsection{Passive Detection}

For passive detection, traffic flows are analyzed in large amounts of collected network traffic (\eg{} from \acp{isp}).
This has some advantages in that it is not possible for botmasters to detect or prevent data collection of that kind but it is not trivial to distinguish valid \ac{p2p} application traffic (\eg{} BitTorrent, Skype, cryptocurrencies, \ldots) from \ac{p2p} bots.
\citeauthor{zhang_building_2014} propose a system of statistical analysis to solve some of these problems in~\cite{zhang_building_2014}.
Also getting access to the required datasets might not be possible for everyone.

% TODO: no context
\begin{itemize}

  % TODO: BotGrep (in zhang_building_2014)
  \item Large scale network analysis (hard to differentiate from legitimate \ac{p2p} traffic (\eg{} BitTorrent), hard to get data, knowledge of some known bots required)~\cite{zhang_building_2014}

  % TODO: BotMiner (in zhang_building_2014)
  \item Heuristics: Same traffic patterns, same malicious behaviour

\end{itemize}

%}}} passive detection

%{{{ active detection
\subsubsection{Active Detection}

In this case, a subset of the botnet protocol are reimplemented to place pseudo-bots or sensors in the network, which will only communicate with other nodes but won't accept or execute commands to perform malicious actions.
The difference in behaviour from the reference implementation and conspicuous graph properties (\eg{} high \(\deg^{+}\) vs.\ low \(\deg^{-}\)) of these sensors allows botmasters to detect and block the sensor nodes.

There are three subtypes auf active detection:

\begin{enumerate}

  \item Crawlers: recursively ask known bots for their neighbourhood lists

  \item Sensors: implement a subset of the botnet protocol and become part of the network without performing malicious actions

  \item Hybrid of crawlers and sensors

\end{enumerate}

%}}} active detection

%}}} detection techniques

%{{{ detection criteria
\subsection{Detection Criteria}

\begin{itemize}

  \item \ac{p2p} online time vs host online time

  \item neighbourhood lists

  \item no/few \ac{dns} lookups; instead direct lookups from routing tables

\end{itemize}
%}}} detection criteria

%}}} introduction


%{{{ methodology
\section{Methodology}

The implementation of the concepts of this work will be done as part of \ac{bms}\footnotemark, a monitoring platform for \ac{p2p} botnets described by \citeauthor{bock_poster_2019} in~\cite{bock_poster_2019}.
\footnotetext{\url{https://github.com/Telecooperation/BMS}}
\Ac{bms} uses a hybrid active approach of crawlers and sensors (reimplementations of the \ac{p2p} protocol of a botnet, that won't perform malicious actions) to collect live data from active botnets.

% TODO: reference for page rank
In an earlier project, I implemented different node ranking algorithms (among others \enquote{PageRank}~\cite{page_pagerank_1998}) to detect sensors and crawlers in a botnet, as described in \citetitle{karuppayah_sensorbuster_2017}.
Both ranking algorithms use the \(\deg^+\) and \(\deg^-\) to weight the nodes.
Another way to enumerate candidates for sensors in a \ac{p2p} botnet is to find \acp{wcc} in the graph.
Sensors will have few to none outgoing edges, since they don't participate actively in the botnet.

The goal of this work is to complicate detection mechanisms like this for botmasters, by centralizing the coordination of the system's crawlers and sensors, thereby reducing the node's rank for specific graph metrics.
The changes should allow the current sensors to use the new abstraction with as few changes as possible to the existing code.

The final result should be as general as possible and not depend on any botnet's specific behaviour but it assumes, that every \ac{p2p} botnet has some kind of \enquote{getNeighbourList} method in the protocol, that allows other peers to request a list of active nodes to connect to.

In the current implementation, each sensor will itself visit and monitor each new node it finds.
The idea for this work is to report newfound nodes back to the \ac{bms} backend first, where the graph of the known network is created and a sensor is selected, so that the specific ranking algorithm doesn't calculate to a suspiciously high or low value.
That sensor will be responsible to monitor the new node.

If it is not possible, to select a specific sensor so that the monitoring activity stays inconspicuous, the coordinator can do a complete shuffle of all nodes between the sensors to restore the wanted graph properties or warn if more sensors are required to stay undetected.

The improved sensor system should allow new sensors to register themselves and their capabilities (\eg{} bandwidth, geolocation, ), so the amount of work can be scaled accordingly between hosts.
Further work might even consider autoscaling the monitoring activity using some kind of cloudcomputing provider.

To validate the result, the old sensor implementation will be compared to the new system using different graph metrics.

% TODO: maybe?
If time allows, \ac{bsf}\footnotemark{} will be used to simulate a botnet place sensors in the simulated network and measure the improvement achieved by the coordinated monitoring effort.
\footnotetext{\url{https://github.com/tklab-tud/BSF}}

% TODO: which botnet?
As a proof of concept, the coordinated monitoring approach will be implemented and deployed in the (Sality, Mirai, ...)? botnet.

%}}} methodology

%{{{ primitives
\subsection{Protocol Primitives}

The coordination protocol must allow the following operations:

% TODO: Testnet + testnet crawler erweitern um mit complete knowledge zu verifizieren

%{{{ sensor to backend
\subsubsection{Sensor to Backend}

\begin{itemize}

    % TODO: bestehende session Mechanik verwenden/erweitern
  \item \mintinline{go}{registerSensor(capabilities)}: Register new sensor with capabilities (which botnet, available bandwidth, \ldots). This is called periodically and used to determine which crawler is still active, when splitting the workload.

    % TODO: failedTries im backend statt eigenem nachrichtentyp: remove?
  \item \mintinline{go}{unreachable(targets)}:

  \item \mintinline{go}{requestTasks() []PeerTask}: Receive a batch of crawl tasks from the coordinator. The tasks consist of the target peer, if the crawler should start or stop the operation, when it should start and stop monitoring and the frequency.

\end{itemize}

\begin{minted}{go}
type Peer struct {
  BotID string
  IP    string
  Port  uint16
}
type PeerTask struct {
  Peer         Peer
  StartAt      *Time
  StopAt       *Time
  Frequency    uint
  StopCrawling bool
}
\end{minted}


%}}} sensor to backend

%{{{ backend to sensor
% TODO: remove?
\subsubsection{Backend to Sensor}

\begin{itemize}


  % \item \mintinline{go}{stopCrawling(targets)}: Stop crawling a batch of nodes

\end{itemize}

%}}} backend to sensor

%}}} primitives

%}}} methodology

%{{{ strategies
\section{Coordination Strategies}

%{{{ frequency reduction
\subsection{Reduction of Request Frequency}

The GameOver Zeus botnet deployed a blacklisting mechanism, where crawlers are blocked based in their request frequency~\cite{andriesse_goz_2013}.
In a single crawler approach, the crawler frequency has to be limited to prevent being hitting the request limit.
Using collaborative crawlers, an arbitrarily fast frequency can be achieved without being blacklisted.
With \(L \in \mathbb{N}\) being the frequency limit at which a crawler will be blacklisted, \(F \in \mathbb{N}\) being the crawl frequency that should be achieved.
The amount of crawlers \(C\) required to achieve the frequency \(F\) without being blacklisted and the offset \(O\) between crawlers are defined as

\begin{align*}
  C &= \left\lceil \frac{F}{L} \right\rceil \\
  O &= \frac{1 \si{\request}}{F}
\end{align*}

Taking advantage of the \mintinline{go}{StartAt} field from the \mintinline{go}{PeerTask} returned by the \mintinline{go}{requestTasks} primitive above, the crawlers can be scheduled offset by \(O\) at a frequency \(L\) to ensure, the overall requests to each peer are evenly distributed over time.

Given a limit \(L = 5 \si{\request\per 100\second}\), crawling a botnet at \(F = 20 \si{\request\per 100\second}\) requires \(C = \left\lceil \frac{20\si{\request\per 100\second}}{5\si{\request\per 100\second}} \right\rceil = 4\) crawlers.
Those crawlers must be scheduled \(O = \frac{1\si{\request}}{20\si{\request\per 100\second}} = 5 \si{\second}\) apart at a frequency of \(L\) for an even request distribution.


%{{{ fig:crawler_timeline
\begin{figure}[h]
\centering
\begin{chronology}[10]{0}{100}{0.9\textwidth}
  \event{0}{\(C_0\)}
  \event{20}{\(C_0\)}
  \event{40}{\(C_0\)}
  \event{60}{\(C_0\)}
  \event{80}{\(C_0\)}
  \event{100}{\(C_0\)}

  \event{5}{\(C_1\)}
  \event{25}{\(C_1\)}
  \event{45}{\(C_1\)}
  \event{65}{\(C_1\)}
  \event{85}{\(C_1\)}

  \event{10}{\(C_2\)}
  \event{30}{\(C_2\)}
  \event{50}{\(C_2\)}
  \event{70}{\(C_2\)}
  \event{90}{\(C_2\)}

  \event{15}{\(C_3\)}
  \event{35}{\(C_3\)}
  \event{55}{\(C_3\)}
  \event{75}{\(C_3\)}
  \event{95}{\(C_3\)}
\end{chronology}
\caption{Timeline of crawler events as seen from a peer}\label{fig:crawler_timeline}
\end{figure}
%}}} fig:crawler_timeline

As can be seen in~\autoref{fig:crawler_timeline}, each crawler \(C_0\) to \(C_3\) performs only 5 \si{\request\per 100\second} while overall achieving \(20 \si{\request\per 100\second}\).

Vice versa given an amount of crawlers \(C\) and a request limit \(L\), the effective frequency \(F\) can be maximized to \(F = C \times L\) without hitting the limit \(L\) and being blocked.

Using the example from above with \(L = 5 \si{\request\per 100\second}\) but now only two crawlers \(C = 2\), it is still possible to achieve an effective frequency of \(F = 2 \times 5 \si{\request\per 100\second} = 10 \si{\request\per 100\second}\) and \(O = \frac{1 \si{\request}}{10 \si{\request\per 100\second}} = 10 \si{s}\):

%TODO: name
%{{{ fig:crawler_timeline
\begin{figure}[h]
\centering
\begin{chronology}[10]{0}{100}{0.9\textwidth}
  \event{0}{\(C_0\)}
  \event{20}{\(C_0\)}
  \event{40}{\(C_0\)}
  \event{60}{\(C_0\)}
  \event{80}{\(C_0\)}
  \event{100}{\(C_0\)}

  \event{10}{\(C_1\)}
  \event{30}{\(C_1\)}
  \event{50}{\(C_1\)}
  \event{70}{\(C_1\)}
  \event{90}{\(C_1\)}

\end{chronology}
% \caption{Timeline of crawler events as seen from a peer}\label{fig:crawler_timeline}
\end{figure}
%}}} fig:crawler_timeline

While the effective frequency of the whole system is halved compared to~\autoref{fig:crawler_timeline}, it is still possible to double the frequency over the limit.

%}}} frequency reduction

%{{{ against graph metrics
% TODO: sinnvoll?
\subsection{Working Against Suspicious Graph Metrics}

\citetitle*{karuppayah_sensorbuster_2017} describes different graph metrics to find sensors in \ac{p2p} botnets.
One of those, \enquote{SensorBuster} uses \acp{wcc} since crawlers don't have any edges back to the main network in the graph.
It would be possible to implement the crawlers so they return other crawlers in their peer list responses but this would still produce a disconnected component and as long as this component is smaller than the main network, it is still easily detectable since there is no path from the crawler component back to the main network.

% TODO: caption, label
\begin{figure}[h]
\centering
\begin{subfigure}[b]{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{sensorbuster1.pdf}
  \caption{\acp{wcc} for independent crawlers}\label{fig:sensorbuster1}
\end{subfigure}%
\begin{subfigure}[b]{.5\textwidth}
  \centering
  \includegraphics[width=1\linewidth]{sensorbuster2.pdf}
  \caption{\acp{wcc} for collaborated crawlers}\label{fig:sensorbuster2}
\end{subfigure}%
\caption{Differences in graph metrics}\label{fig:sensorbuster}
\end{figure}

% TODO: pagerank, sensorrank calculations
\begin{figure}
  \centering
\begin{tabular}{|l|l|l|l|l|}
  \hline
  Node & \(\deg_a^{+}\) & \(\deg_a^{-}\) & \(\deg_b^+\) & \(\deg_b^-\) \\
  \hline\hline
  n0 & 0 & 4 & 0 & 4 \\
  n1 & 1 & 3 & 1 & 3 \\
  n2 & 2 & 2 & 2 & 2 \\
  c0 & 3 & 0 & 5 & 2 \\
  c1 & 1 & 0 & 3 & 2 \\
  c2 & 2 & 0 & 4 & 2 \\
  \hline
\end{tabular}
\end{figure}

%}}} against graph metrics

%}}} strategies

% vim: set filetype=tex ts=2 sw=2 tw=0 et foldmethod=marker spell :
