1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 __author__ = "Michael Cohen <scudette@gmail.com>"
23
24
25
26 import logging
27 import pdb
28 import sys
29
30 import rekall
31 from rekall import args
32 from rekall import config
33 from rekall import constants
34 from rekall import plugin
35 from rekall import session
36 from rekall import quotas
37
38 from pkg_resources import iter_entry_points
39 for entry_point in iter_entry_points(group='rekall.plugins', name=None):
40 entry_point.load()
41
42
43 from rekall import plugins
44
45
46 config.DeclareOption(
47 "--version", default=False, type="Boolean",
48 help="Prints the Rekall version and exits.")
49
50
51 -class Run(plugin.PrivilegedMixIn, plugin.Command):
52 """A plugin which runs its argument (using eval).
53
54 Note: This plugin is only defined and available when using the main entry
55 point. It is not available when Rekall is used as a library since it allows
56 arbitrary code execution.
57 """
58
59 name = "run"
60
61 @classmethod
62 - def args(cls, parser):
69
70 - def __init__(self, script, run=None, **kwargs):
76
77
78 -def main(argv=None):
79
80 user_session = session.InteractiveSession()
81 user_session.session_list.append(user_session)
82
83
84 user_session.privileged = True
85
86 def global_arg_cb(global_flags, _):
87 if global_flags.version:
88 print "This is Rekall Version %s (%s)" % (
89 constants.VERSION, constants.CODENAME)
90
91 print rekall.get_versions()
92 sys.exit(0)
93
94 plugin_cls, flags = args.parse_args(
95 argv=argv, global_arg_cb=global_arg_cb,
96 user_session=user_session)
97
98
99 user_session = quotas.wrap_session(user_session)
100 try:
101
102 user_session.RunPlugin(plugin_cls, **config.RemoveGlobalOptions(flags))
103 except Exception as e:
104 logging.fatal("%s. Try --debug for more information." % e)
105 if getattr(flags, "debug", None):
106 pdb.post_mortem(sys.exc_info()[2])
107 raise
108 finally:
109 user_session.Flush()
110
111 if __name__ == '__main__':
112 main()
113