% LVA-Feedback: mehr Freitext, weniger REP$x.$y !!! Diese Stuktur ist wirr und z.b. Failed attempts stehen an 3 unterschiedlichen stellen, obwohl sie doch alle irgendwie zusammenhängen -.-

\section{Exercise 1 - Task 1}
\subsection{Rep:1.a}
\fbox{\parbox{\textwidth}{
What is the IP address of the suspicious notebook?
}}

The IP address of the suspicious notebook (our own IP address) is \emph{\textbf{192.168.67.37}}.


\subsection{Rep:1.b}
\fbox{\parbox{\textwidth}{
What is the IP address of the machine presumably leaking information?
}}

The remote IP address is \emph{\textbf{192.168.67.83}}.


\subsection{Rep:1.c}
\fbox{\parbox{\textwidth}{
Give a detailed (but brief) explanation of these steps you carried out to filter irrelevant data (either Wireshark or Rapidminer).\\
Do also specify the keyworks and operators required.
}}

The necessary wireshark filter expression is \emph{\textbf{ip.addr == 192.168.67.83}}.


\subsection{Rep:1.d}
\fbox{\parbox{\textwidth}{
Which features are not viable to mask a covert channel and could be removed from the analysis?\\
List the rejected features and provide short but meaningful reasons for rejection.
}}

\begin{itemize}
	\item \emph{\textbf{No.}} is just the packet number in the pcap file.
	\item \emph{\textbf{Source IP}} fixed value: \emph{\textbf{192.168.67.83}}
	\item \emph{\textbf{Destination IP}} fixed value: \emph{\textbf{192.168.67.37}}
	\item \emph{\textbf{Protocol}} fixed value: \emph{\textbf{UDP}}
	\item \emph{\textbf{Length}} fixed value: \emph{\textbf{82}}
	\item \emph{\textbf{TTL}} fixed value: \emph{\textbf{64}}
	\item \emph{\textbf{Dest port}} fixed value: \emph{\textbf{118}}
	\item \emph{\textbf{Flags}} fixed value: \emph{\textbf{n/a}}
	\item \emph{\textbf{Frag offset}} fixed value: \emph{\textbf{0}}
\end{itemize}

Features containing fixed values have been rejected as one obviously cannot hide more than one bit of information in them.


\subsection{Rep:1.e}
\fbox{\parbox{\textwidth}{
From the remaining features, which ones are not viable to mask a covert channel and could be removed from the analysis?\\
List the newly rejected features and provide short but meaningful reasons for rejection.
}}

We see that the source port changes only between transmissions. The transmission contains only one flow.\\
Therefore we can assume that the \emph{\textbf{source port}} can be ignored.\\

The next step was to apply the following filter in wireshark: \emph{\textbf{ip.addr == 192.168.67.83 and udp.srcport == 52899}}, export the result to a new pcap file and reload in wireshark (to reset the packet numbers) and export the pcap to csv.


\subsection{Rep:1.f}
\fbox{\parbox{\textwidth}{
Do you think that you have found the covert channel?\\
Give a detailed description of where the covert channel is occurring (feature value:covert symbol relationship) and provide a capture of the plot where the abnormal behaviour of the suspicious feature is isolated and clearly visible.
}}

At first we wrote a decoder that made a diff between the current and the last csv line looking at \emph{\textbf{IP.ID}}.\\
Combined with the hint 8 bit ASCII we tried to extract full. The results did not made any sense.\\

After analysis with rapidminer we found that the timing diffrences were obviously not randomly distributed.\\
\includegraphics[width=0.8\columnwidth]{content/e11_timing.pdf}

So the hacky solution was to multiply the time-diff by 10 and cast the result to int. This resulted in a nice one bit/packet list which we quickly converted to 8 bit ascii.


\subsection{Rep:1.g}
\fbox{\parbox{\textwidth}{
Write in the report the formula of the deployed filter and the steps carried out to prepare the required file.
}}
\emph{\textbf{Dest port == 118}} and later \emph{\textbf{ip.addr == 192.168.67.83 and udp.srcport == 52899}}.


\subsection{Rep:1.h}
\fbox{\parbox{\textwidth}{
Write in the report the decoded message. Explain clearly how you carried out the decoding task (step by step in a numbered list).
}}

The message was \emph{\textbf{Starting transmission from Ministry of Cyber {\ucr}ffairs. (Agent Scott)Star{\ucr}i{\ucr}}}\\
By applying a corrective timing diffrence of 0.05 we can fully decode the message: \emph{\textbf{Starting transmission from Ministry of Cyber affairs. (Agent Scott)Startin}}\\

Final py-code
\begin{scriptsize}\begin{verbatim}
#!/usr/bin/env python                                                                                                                                            
                                                                                                                                                                
import csv                                                                                                                                                       
import binascii                                                                                                                                                  
                                                                                                                                                                 
def somedecode(filename):                                                                                                                                        
  with open(filename, 'rb') as csvfile:                                                                                                                          
    spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')                                                                                               
    header = last = None                                                                                                                                         
    ln = 0                                                                                                                                                       
    v = ""                                                                                                                                                       
                                                                                                                                                                 
    for row in spamreader:                                                                                                                                       
      if header is None:                                                                                                                                         
        header = row                                                                                                                                             
        continue                                                                                                                                                 
      if last is None:                                                                                                                                           
        last = row                                                                                                                                               
        continue                                                                                                                                                 
                                                                                                                                                                 
      va = str(int((float(row[1])-float(last[1])-0.05)*10))                                                                                                      
      if va not in ["0","1"]:                                                                                                                                    
        va = "1"                                                                                                                                                 
                                                                                                                                                                 
      v = v+va                                                                                                                                                   
      ln += 1                                                                                                                                                    
      if ln == 8:                                                                                                                                                
        print binascii.unhexlify('%x' % int(v, 2)),                                                                                                                      
        v = ""                                                                                                                                                   
        ln = 0                                                                                                                                                   
      last = row                                                                                                                                                 
                                                                                                                                                                 
if __name__ == "__main__":                                                                                                                                       
    somedecode("filtered.dehexed.csv")                                                                                                                           
\end{verbatim}\end{scriptsize}


\subsection{Rep:1.i}
\fbox{\parbox{\textwidth}{
Report briefly any additional comment or observation related to the exercise solving to be considered during the review of your exercise.
}}

We had our wireshark misconfigured and were looking into the DSCP field for quite some time, before we realising that it was actually IP.ID.


\section{Exercise 1 - Task 2}
\subsection{Rep:1.j}
\fbox{\parbox{\textwidth}{
Give a detailed (but brief) explanation of the steps you carried out to filter irrelevant data (either Wireshark or Rapidminer). Do also specify the keywords and operators required.
}}

Captured. Our new IP is \emph{\textbf{192.168.67.26}}.\\

Selected local network packets: \emph{\textbf{ip.src == 192.168.67.0/24 and ip.dst == 192.168.67.0/24}} and saved as separate pcap file and also exported the packets to csv.\\

In Rapidminer we analyzed the csv and removed our gateway (.1) and self (.26) as sources.\\

% TODO image:stream\_localnet.pdf

We get 4 network flows: The first from .83 to 80/udp, then from .82 to 443/udp, then .81 to 465/tcp, then .84 to 464/udp.\\

% TODO image:stream\_localnet\_ports.pdf

Filters for one complete transmission:
\emph{\textbf{udp.port == 58493 or udp.port == 45875 or tcp.port == 40875 or udp.port == 36842}}

% TODO: failed attempt

%%%%%%%%%%%%%%%%%%%%%
% WTF ?! % WTF ?! % WTF ?! % WTF ?! % WTF ?! 
% WTF ?! % WTF ?! % WTF ?! % WTF ?! % WTF ?! 
% WTF ?! % WTF ?! % WTF ?! % WTF ?! % WTF ?! 
% WTF ?! % WTF ?! % WTF ?! % WTF ?! % WTF ?! 
% WTF ?! % WTF ?! % WTF ?! % WTF ?! % WTF ?! 
%%%%%%%%%%%%%%%%%%%%%

%filtered away nfs and ssh
%!(tcp.port == 666 || tcp.port == 2049)
%asdf.{pcap,csv}

%look at it via rapidminer
%image:stream2.pdf

%((ip.addr eq 192.168.67.81 or ip.addr eq 192.168.67.82 or ip.addr eq 192.168.67.83) and ip.addr eq 192.168.67.37)
%better.{pcap,csv}

%look at it again via rapidminer
%image:stream\_better.pdf

%dest ports are always first 80/udp, then 443/udp, then 465/tcp

%filtered for one complete transaction
%tcp.port == 56533 or udp.port == 50293 or udp.port == 56040
%cool.{pcap,csv}

%look at it again via rapidminer
%image:stream\_cool.pdf

%%%%%%%%%%%%%%%%%%%%%%%


\subsection{Rep:1.k}
\fbox{\parbox{\textwidth}{
Which features are not viable to mask a covert channel and could be removed from the analysis? List the
rejected features and provide short but meaningful reasons for rejection.
}}

\begin{itemize}
	\item \emph{\textbf{No.}} (it is generated while monitoring and is strictly monotonically increasing by 1 with each packet)
	\item \emph{\textbf{Time}} (packets arrive with almost equal delays)
	\item \emph{\textbf{TTL}} (fixed value: \emph{\textbf{64}})
	\item \emph{\textbf{Frag offset}} (fixed value: \emph{\textbf{0}})
\end{itemize}

We can also ignore \emph{\textbf{IP.Flags}} as they meet our expected distribution:
\begin{itemize}
	\item 0x0002: SYN (1x)
	\item 0x0012: SYN,ACK (1x)
	\item 0x0010: ACK (602x)
	\item 0x0018: ACK,PSH (600x)
	\item 0x0011: ACK,FIN (2x)
\end{itemize}


\subsection{Rep:1.l}
\fbox{\parbox{\textwidth}{
From the remaining features, which ones are not viable to mask a covert channel and could be removed
from the analysis? List the newly rejected features and provide short but meaningful reasons for rejection.
}}


% TODO continue writing here.

not a high variance detected:
\begin{itemize}
\item UDP Stream from 192.168.67.83:56040 to 192.168.67.37:80 %TODO fix
\item UDP Stream from 192.168.67.82:50293 to 192.168.67.37:443 %TODO fix
\item TCP Traffic between 192.168.67.81:56533 to 192.168.67.37:465 %TODO fix
\item UDP Stream from 192.168.67.84:36842 to 192.168.67.26:464
\end{itemize}

Length also does not vary very much:
\begin{itemize}
\item Length 60 for Source Port 56040/udp
\item Length 60 for Source Port 52093/udp
\item Length 70 for ACK,PSH (600x), 74 for SYN (1x), 66 for ACK (1x) and 66 for FIN (1x) for Source Port 56533/tcp
\item Length 66 for ACK, 74 for SYN,ACK for Source Port 465/tcp
\item %TODO fix for sport 464
\end{itemize}

% TODO: failed attempt
%-> map in rapidminer ipid vs dscp
%-> every dscp has two ipid's? (ipid1 xor ipid2) or (ipid1 - ipid2) -> char


\subsection{Rep:1.m}
\fbox{\parbox{\textwidth}{
What is the IP address of the machine presumably leaking information?
}}

Unknown, because we do have two shorter transmissions before a longer transmission from different source ips

% TODO: failed attempt 1 - nicht alles
Later the IP address turned out to be 192.168.67.84.


\subsection{Rep:1.n}
\fbox{\parbox{\textwidth}{
Do you think that you have found the covert channel?\\
Give a detailed description of where the covert channel is occurring (feature value:covert symbol relationship) and provide a capture of the plot where the abnormal behaviour of the suspicious feature is isolated and clearly visible.
}}

Not yet. We do not know if the three transmissions are connected to each other.

% TODO: failed attempt 2 - dumm rum gesucht
Most likely it is in the DSCP field of the third transmission. (This also has responses from the local system)

Turned out that the 6 bits from the DSCP field in the 4. transmission just needed to be concatenated and then split into 8 bit chunks again.


\subsection{Rep:1.o}
\fbox{\parbox{\textwidth}{
Write in the report the decoded message. Explain clearly how you carried out the decoding task (step by step in a numbered list).
}}

\emph{\textbf{Agent South already successfully infiltrated The minister's office. In the next step, we try to acquire data from the Ministry of Cyber Affair's office network. Stay tuned, I will keep you updated on the progress. (This message was sent by agent Scott)Agent South already successfully infiltrated The minister's office. In the next step, we try to acquire data from the Ministry of Cyber Affair's office network. Stay tuned, I will keep you updated on t}}\\

code\\
\begin{verbatim}
#!/usr/bin/python                                                                                                                                                   
                                                                                                                                                                    
from pprint import pprint                                                                                                                                           
                                                                                                                                                                    
fullstr = ""                                                                                                                                                        
                                                                                                                                                                    
with open('stream_data.txt', 'r') as infile:                                                                                                                        
    for line in infile:                                                                                                                                             
        if len(line) > 0:                                                                                                                                           
            i = int(line)                                                                                                                                           
            bin = "{0:06b}".format(i)                                                                                                                               
            fullstr += bin                                                                                                                                          
                                                                                                                                                                    
bytelist = [ fullstr[i:i+8] for i in range(0, len(fullstr), 8) ]                                                                                                    
                                                                                                                                                                    
solution = ""                                                                                                                                                       
                                                                                                                                                                    
for bchar in bytelist:                                                                                                                                              
    solution += chr(int(bchar, 2))                                                                                                                                  
                                                                                                                                                                    
print ("%s" % solution)                                                                                                                                             
print ("len: %d" % len(solution))                                                                                                                                   
\end{verbatim}


\subsection{Rep:1.p}
\fbox{\parbox{\textwidth}{
Report briefly any additional comment or observation related to the exercise solving to be considered during the review of your exercise.
}}


% TODO: failed attempt 3 - config fail


