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
|
# File 'lib/pwn/plugins/detonate.rb', line 12
public_class_method def self.detonate(opts = {})
path = (opts[:path] || opts[:sample]).to_s
raise 'ERROR: path is required' if path.empty?
raise "ERROR: sample not found: #{path}" unless File.file?(path)
timeout = (opts[:timeout] || 30).to_i
net = (opts[:network] || :none).to_s
return { error: 'isolation preconditions unmet', hint: 'install podman (rootless); never falling back to host', path: path } unless PWN::Plugins::PreflightChecker.bin?(name: 'podman')
home = Dir.home
Dir.mktmpdir('pwn-detonate') do |tmp|
FileUtils.cp(path, File.join(tmp, File.basename(path)))
cmd = [
'podman', 'run', '--rm', '--network', 'none',
'--timeout', timeout.to_s, '-v', "#{tmp}:/sample:ro", 'alpine:latest',
'sh', '-c', 'touch /tmp/ioc; echo attempted_write_home=$HOME'
]
stdout, stderr, status = Open3.capture3(*cmd)
iocs = {
stdout: stdout,
stderr: stderr,
exit: status.exitstatus,
home_untouched: File.directory?(home),
attempted_home_write: stdout.include?('attempted_write_home')
}
{ iocs: iocs, network: net, timeout: timeout, isolated: true }
end
end
|