2 \section{Exercise 2 - Task 1}
4 In order to use scapy we need to convert out pcap-ng dump to pcap.
6 $ editcap -F libpcap team15_ex21.pcapng team15_ex21.pcap
9 We are only interested in flows with more (or equal) than 400 packets, each exported as a separate pcap file.
12 $ ./somefilter.py | sh
16 \begin{redframe}\begin{scriptsize}\begin{verbatim}
19 from scapy.all import *
21 def somefilter(pcapfile):
23 for p in PcapReader(pcapfile):
28 if (src,dst) in flows:
33 for flow,cnt in flows.items():
35 print 'tshark -r '+pcapfile+' -w "flow_'+flow[0]+'_'+flow[1]+'.pcap" -F pcap ' \
36 + '\'ip.src == '+flow[0]+' and ip.dst == '+flow[1]+'\''
38 if __name__ == "__main__":
39 somefilter("team15_ex21.pcap")
40 \end{verbatim}\end{scriptsize}\end{redframe}
42 With Wireshark we poked around and exported the flows to csv to further investigate.
44 While poking around we came across an unexpected value of srcport.
46 $ ./srcfeat_power.py --input flow_114.176.157.191_221.72.61.209.csv --feature srcport
47 # 114.176.157.191,541,2,1.5469339647025981
49 There seemed to be 2 different srcports, occuring nearly equally often.
50 We looked into it with Rapidminer and found a suspiciously alternating srcport jumping between \emph{\textbf{5950}} and \emph{\textbf{5960}}.
52 \includegraphics[width=0.6\columnwidth,keepaspectratio]{content/e21_flow_114_176_157_191_221_72_61_209_srcport.png}
55 The message is \emph{\textbf{Data acquired. Key for message (len=42 \& pkts>200): nSa123 (Scott)}}
57 \begin{redframe}\begin{scriptsize}\begin{verbatim}
63 def somedecode(filename):
64 with open(filename, 'rb') as csvfile:
65 spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
69 for row in spamreader:
74 if row[2] == '114.176.157.191' and row[10] == '5950':
76 if row[2] == '114.176.157.191' and row[10] == '5960':
79 bits = bits[:-(len(bits)%8)]
80 print binascii.unhexlify('%x' % int(bits, 2))
82 if __name__ == "__main__":
83 somedecode("flow_114.176.157.191_221.72.61.209.csv")
84 \end{verbatim}\end{scriptsize}\end{redframe}
87 \section{Exercise 2 - Task 2}
90 Then we converted the file {\tt team15\_ex22.pcap} from the pcap-ng format to the pcap format to be able to use it with {\tt scapy}.
93 $ editcap -F libpcap team15_ex22.pcap ex22.pcap
96 Then we filtered out the large flows with more than 200 packets and a frame length of 42 as mentioned in the solution from task 1.
98 % TODO \begin{didntwork}
100 % {('53.151.211.106', '217.115.203.44'): (213, 0)}
103 ip.addr == 53.151.211.106 and ip.addr == 217.115.203.44 and eth.len == 42
108 save bytes (ipid) from stream to file
111 try decoding with password from previous task
112 openssl enc -d -rc4 -nosalt -k nSa123 -in stream\_encrypted -out stream\_decrypted
116 tried reversing the bytes (lower byte first, upper byte next)
120 trying to decode the second-largest flow:
121 ip.addr == 96.55.191.225 and ip.addr == 217.115.203.44 and eth.len == 42
124 % TODO \end{didntwork}
126 Finally we found out, that scapy removes the frame length when parsing packets with the {\tt PcapReader}.
128 This does not happen with the {\tt PcapRawReader}, so we rewrote the script a bit.
130 % TODO continue writing here
136 manually create csv files
138 for i in large\_flow\_*.csv ; do ./../../only\_decimal.sh \$i > \${i\%.csv}.dehexed.csv ; done
140 ./autocorrelate.sh | grep -v "All values are identical" | sort -k2
142 -> ./parse\_stream\_data.py
145 Agent South was captured! Aborting operation. (Agent Scott)