-
Notifications
You must be signed in to change notification settings - Fork 160
/
CTPlugin.py
77 lines (61 loc) · 2.31 KB
/
CTPlugin.py
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
#
# CapTipper is a malicious HTTP traffic explorer tool
# By Omri Herscovici <omriher AT gmail.com>
# http://omriher.com
# @omriher
#
#
# This file is part of CapTipper, and part of the Whatype library
# Whatype is an independent file type identification python library
# https://github.com/omriher/whatype
#
# CapTipper is a free software under the GPLv3 License
#
from collections import namedtuple
import inspect
import imp
import os
import glob
import CTCore
class ConsolePlugin(object):
description = ""
author = ""
def __init__(self):
self.conversations = CTCore.conversations
self.objects = CTCore.objects
self.hosts = CTCore.hosts
def run(self):
raise NotImplementedError
def get_name_by_id(self,id):
name = CTCore.get_name(id)
return name
def get_body_by_id(self,id):
response, size = CTCore.get_response_and_size(id, "all")
return response
def get_plaintext_body_by_id(self,id):
if id < len(self.conversations) and self.conversations[id].magic_ext == "GZ":
data, name = CTCore.ungzip(id)
else:
data = self.get_body_by_id(id)
return data
def is_valid_id(self,id):
if int(id) >= len(self.objects) or int(id) < 0:
return False
return True
def init_plugins():
p_files = glob.glob(CTCore.plugins_folder + "*.py")
for p in p_files:
p_full = os.path.join(os.path.dirname(os.path.realpath(__file__)),p)
(path, name) = os.path.split(p_full)
(name, ext) = os.path.splitext(name)
(p_file, filename, data) = imp.find_module(name, [path])
mod = imp.load_module(name, p_file, filename, data)
for name, value in inspect.getmembers(mod):
if inspect.isclass(value):
if issubclass(value, ConsolePlugin) and value is not ConsolePlugin:
p_num = len(CTCore.plugins)
CTCore.plugins.append(namedtuple('Plugin', ['id', 'name','module', 'description']))
CTCore.plugins[p_num].id = p_num
CTCore.plugins[p_num].name = name
CTCore.plugins[p_num].module = value
CTCore.plugins[p_num].description = value.description