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