Skip to content

Commit 45da77d

Browse files
authored
Add files via upload
1 parent 2164beb commit 45da77d

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

bot_manual_tls.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'''
2+
PREDICTION : Compasses through bot activity files and manual activity files
3+
to get an idea about the differences in packet sizes between bot and manual activities
4+
CUSTOM INPUT : Enter the path to manual directory : *enter the location to the directory in your local machine*
5+
Enter the path to bot directory : *enter the location to the directory in your local machine*
6+
'''
7+
8+
import pyshark
9+
import asyncio
10+
import os
11+
12+
def main():
13+
#asking for input from the user
14+
15+
path1=input("Enter the path to manual directory : ")
16+
path2=input("Enter the path o bot directory : ")
17+
18+
#extracting all manual files from manual directory
19+
20+
l1=os.listdir(path1)
21+
22+
#initialize two sets to store the unique tls segment length
23+
24+
bot=set()
25+
manual=set()
26+
27+
#iterating over the manual file list
28+
29+
for i in l1:
30+
31+
f=open(path1+"/"+str(i),'r')
32+
cap=pyshark.FileCapture(f,only_summaries=False,display_filter='tls.record.content_type==23')
33+
34+
for pkt in cap:
35+
try:
36+
manual.add(pkt.tls.record_length)
37+
except:
38+
continue
39+
40+
f.close()
41+
42+
print("The unique tls segment lengths collected from all the manual capture files are as below \n")
43+
Manual=list(manual)
44+
print(Manual)
45+
print("\n")
46+
47+
#extracting all bot files from the bot directory
48+
49+
50+
l2=os.listdir(path2)
51+
#print(l2)
52+
53+
#iterating over the bot file list
54+
55+
for i in l2:
56+
57+
f=open(path2+"/"+str(i),'r')
58+
cap=pyshark.FileCapture(f,only_summaries=False,display_filter='tls.record.content_type==23')
59+
60+
for pkt in cap:
61+
try:
62+
bot.add(pkt.tls.record_length)
63+
except:
64+
continue
65+
f.close()
66+
67+
print("The unique tls segment lengths collected from all the bot capture files are as below \n")
68+
Bot=list(bot)
69+
print(Bot)
70+
print("\n")
71+
72+
#printing the similar segment lengths from both the directories
73+
print("The similar segment lengths from both types of capture files are as below \n")
74+
common=manual.intersection(bot)
75+
Common=list(common)
76+
print(Common)
77+
print("\n")
78+
79+
print("The unique manual tls segments are\n")
80+
manual_unique=manual-(manual.intersection(bot))
81+
print(list(manual_unique))
82+
print("\n")
83+
84+
print("The unique bot tls segments are\n")
85+
bot_unique=bot-(manual.intersection(bot))
86+
print(list(bot_unique))
87+
print("\n")
88+
89+
#storing the data in a file
90+
with open("bot_manual_data","w") as fhandle:
91+
fhandle.write("\n")
92+
for line in Manual:
93+
fhandle.write(line)
94+
fhandle.write(",")
95+
fhandle.write("\n")
96+
for line in Bot:
97+
fhandle.write(line)
98+
fhandle.write(",")
99+
fhandle.write("\n")
100+
for line in Common:
101+
fhandle.write(line)
102+
fhandle.write(",")
103+
fhandle.write("\n")
104+
105+
if __name__ == "__main__":
106+
#read()
107+
main()
108+
#dmain()
109+
110+

0 commit comments

Comments
 (0)