-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdocker_remnux.py
More file actions
86 lines (70 loc) · 2.44 KB
/
Copy pathdocker_remnux.py
File metadata and controls
86 lines (70 loc) · 2.44 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
#!/usr/bin/python
# To run this script, install and start Docker first. You also need to
# get the Docker images you want to run. You can do this with a command
# like "docker pull remnux/pescanner"
import docker
import ConfigParser
import time
from os import path
import docker.tls as tls
# Location of config file
cfgfile = "remnux.conf"
# File to be analyzed
malware_file = "1d53a61b4ec187230f23fd66076ff605"
# Docker tool to use
docker_tool = "pescanner"
# Read in parameters from the config file
config = ConfigParser.ConfigParser()
config.read(cfgfile)
container_name = config.get(docker_tool, "container_name")
local_working_dir = config.get(docker_tool, "local_working_dir")
docker_bind_dir = config.get(docker_tool, "docker_bind_dir")
command_line_exe = config.get(docker_tool, "command_line_exe")
options = config.get(docker_tool, "options")
mode = config.get(docker_tool, "mode")
# Docker or docker-machine
docker_exec = config.get("docker", "docker_exec")
# The command to run -- add options later?
command2run = command_line_exe + " " + malware_file
c = docker.Client()
# Make a connection to docker
if (docker_exec.lower() == 'docker'):
c = docker.Client(base_url='unix://var/run/docker.sock')
# Make a connection to docker-machine
if (docker_exec.lower() == 'docker-machine'):
ip_address = config.get("docker", "ip_address")
port = config.get("docker", "port")
address_str = 'https://' + ip_address + ':' + port
certs = config.get("docker", "cert_path")
tls_config = tls.TLSConfig(
client_cert=(path.join(certs, 'cert.pem'), path.join(certs,'key.pem')),
ca_cert=path.join(certs, 'ca.pem'),
verify=True,
assert_hostname=False
)
c = docker.Client(base_url=address_str, tls=tls_config)
# Grab the image
c.images(container_name)
# Create a container based on parameters
cntnr = c.create_container(
container_name, command2run, volumes=[docker_bind_dir],
host_config=c.create_host_config(binds={
local_working_dir: {
'bind': docker_bind_dir,
'mode': mode,
}
})
)
# Start the container
c.start(cntnr)
# Wait for container to finish executing before accessing logs
containers = c.containers()
# For now, just see if there are any containers executing
num_containers = len(containers)
while (num_containers > 0):
time.sleep(1)
containers = c.containers()
num_containers = len(containers)
# Access output logs
output = c.logs(cntnr)
print(output)