Skip to content

Commit 5cf1fb9

Browse files
committed
HG: Deleted create-profile. Merged with malboxes.py now. Added reg and dir commands.
1 parent 4b13c95 commit 5cf1fb9

File tree

2 files changed

+111
-147
lines changed

2 files changed

+111
-147
lines changed

create-profile

Lines changed: 0 additions & 140 deletions
This file was deleted.

malboxes.py

Lines changed: 111 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,70 @@
2727
import sys
2828

2929
from jinja2 import Environment, FileSystemLoader
30-
from sh import packer_io
30+
# from sh import packer_io
3131

3232
CONFIG_CACHE = 'config_cache/'
3333

3434

3535
def initialize():
3636
parser = argparse.ArgumentParser(description=
37-
"Vagrant box builder and config generator for malware analysis")
37+
"Vagrant box builder and config generator for malware analysis.")
3838
subparsers = parser.add_subparsers()
3939

4040
# list command
4141
parser_list = subparsers.add_parser('list', help=
42-
"Lists available profiles")
42+
"Lists available profiles.")
4343
parser_list.set_defaults(func=list_profiles)
4444

4545
# build command
4646
parser_build = subparsers.add_parser('build',
47-
help="Builds a Vagrant box based on a given profile")
47+
help="Builds a Vagrant box based on a given profile.")
4848
parser_build.add_argument('profile', help='Name of the profile to build. '
4949
'Use list command to view available profiles.')
5050
parser_build.set_defaults(func=build)
5151

5252
# spin command
5353
parser_spin = subparsers.add_parser('spin', help=
54-
"Creates a Vagrantfile for your profile / Vagrant box")
54+
"Creates a Vagrantfile for your profile / Vagrant box.")
5555
parser_spin.add_argument('profile', help='Name of the profile to spin.')
5656
parser_spin.add_argument('name', help='Name of the target VM. '
57-
'Must be unique on your system. Ex: Cryptolocker_XYZ')
57+
'Must be unique on your system. Ex: Cryptolocker_XYZ.')
5858
parser_spin.set_defaults(func=spin)
5959

60+
# reg command
61+
parser_reg = subparsers.add_parser('reg', help=
62+
"Modifies a registry key.")
63+
parser_reg.add_argument('profile', help=
64+
'Name of the profile to add the regkey modification.')
65+
parser_reg.add_argument('modtype', help=
66+
'The modification type (add, delete or modify).')
67+
parser_reg.add_argument('key', help=
68+
'Location of the key to modify.')
69+
parser_reg.add_argument('name', help=
70+
'Name of the key.')
71+
parser_reg.add_argument('value', help=
72+
'Value of the key.')
73+
parser_reg.add_argument('valuetype', help=
74+
'Type of the value of the key: '
75+
'DWORD for integer, String for string')
76+
parser_reg.set_defaults(func=reg)
77+
78+
# dir command
79+
parser_dir = subparsers.add_parser('dir', help=
80+
'Modifies a directory')
81+
parser_dir.add_argument('profile', help=
82+
'Name of the profile to apply modifications.')
83+
parser_dir.add_argument('modtype', help=
84+
'Modification type (delete or add).')
85+
parser_dir.add_argument('dirpath', help=
86+
'Path of the directory to modify.')
87+
parser_dir.set_defaults(func=directory)
88+
89+
# wallpaper command
90+
91+
# parser_wallpaper = subparsers.add_parser('wallpaper', help=
92+
# '')
93+
6094
# no command
6195
parser.set_defaults(func=default)
6296

@@ -68,7 +102,7 @@ def prepare_autounattend(config):
68102
"""
69103
Prepares an Autounattend.xml file according to configuration and writes it
70104
into a temporary location where packer later expects it.
71-
105+
72106
Uses jinja2 template syntax to generate the resulting XML file.
73107
"""
74108
# os type is extracted from profile json
@@ -226,6 +260,76 @@ def spin(parser, args):
226260
"and issue a `vagrant up` to get started with your VM.")
227261

228262

263+
def reg(parser, args):
264+
"""
265+
Adds a registry key modification to a profile with PowerShell commands.
266+
"""
267+
if args.modtype == "add":
268+
command = "New-ItemProperty"
269+
line = "{0} -Path {1} -Name {2} -Value {3} -PropertyType {4}\r\n".format(
270+
command, args.key, args.name, args.value, args.valuetype)
271+
print("Adding: " + line)
272+
elif args.modtype == "modify":
273+
command = "Set-ItemProperty"
274+
line = "{0} -Path {1} -Name {2} -Value {3}\r\n".format(
275+
command, args.key, args.name, args.value)
276+
print("Adding: " + line)
277+
elif args.modtype == "delete":
278+
command = "Remove-ItemProperty"
279+
line = "{0} -Path {1} -Name {2}\r\n".format(
280+
command, args.key, args.name)
281+
print("Adding: " + line)
282+
else:
283+
print("Registry modification type invalid.")
284+
print("Valid ones are: add, delete and modify.")
285+
286+
filename = "scripts/windows/{}.ps1".format(args.profile)
287+
f = open(filename, "a")
288+
f.write(line)
289+
f.close()
290+
291+
""" Add the script to the profile."""
292+
config = load_config(args.profile)
293+
provisioners_list = config["provisioners"][0]["scripts"]
294+
""" If the script is not already in the profile."""
295+
if filename not in provisioners_list:
296+
provisioners_list.append(fiString)
297+
f = open("profiles/{}.json".format(args.profile), "w")
298+
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
299+
f.close()
300+
301+
302+
def directory(parser, args):
303+
""" Adds the directory manipulation commands to the profile."""
304+
if args.modtype == "add":
305+
command = "New-Item"
306+
line = "{0} -Path {1} -Type directory\r\n".format(command, args.dirpath)
307+
print("Adding: " + line)
308+
elif args.modtype == "delete":
309+
command = "Remove-Item"
310+
line = "{0} -Path {1}\r\n".format(
311+
command, args.dirpath)
312+
print("Adding: " + line)
313+
else:
314+
print("Directory modification type invalid.")
315+
print("Valid ones are: add, delete.")
316+
317+
filename = "scripts/windows/{}.ps1".format(args.profile)
318+
f = open(filename, "a")
319+
f.write(line)
320+
f.close()
321+
322+
""" Add the script to the profile."""
323+
config = load_config(args.profile)
324+
provisioners_list = config["provisioners"][0]["scripts"]
325+
""" If the script is not already in the profile."""
326+
if filename not in provisioners_list:
327+
provisioners_list.append(filename)
328+
f = open("profiles/{}.json".format(args.profile), "w")
329+
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
330+
f.close()
331+
332+
229333
if __name__ == "__main__":
230334
try:
231335
parser, args = initialize()

0 commit comments

Comments
 (0)