/
main.go
60 lines (46 loc) · 1.39 KB
/
main.go
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
package main
import (
"fmt"
"os"
"github.com/fsouza/go-dockerclient"
)
func main() {
args := os.Args[1:]
//endpoint := os.Getenv("DOCKER_HOST")
endpoint := "unix:///var/run/docker.sock"
//path := os.Getenv("DOCKER_CERT_PATH")
//ca := fmt.Sprintf("%s/ca.pem", path)
//cert := fmt.Sprintf("%s/cert.pem", path)
//key := fmt.Sprintf("%s/key.pem", path)
//client, _ := docker.NewTLSClient(endpoint, cert, key, ca)
client, _ := docker.NewClient(endpoint)
imgs, _ := client.ListImages(docker.ListImagesOptions{All: false})
for _, img := range imgs {
for i := range args {
config := &docker.Config{Image: img.ID, Entrypoint:[]string{"/bin/sh", "-c"}, Cmd: []string{"/script/shell.sh"}}
// Create the container from an id, specify the command, mount CVE volume
container, err := client.CreateContainer(docker.CreateContainerOptions{Config: config})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Get the working directory
pwd, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
binds := []string{pwd + "/cve/" + args[i] + "/:/script"}
hostConfig := &docker.HostConfig{Binds: binds}
err = client.StartContainer(container.ID, hostConfig)
code, err := client.WaitContainer(container.ID)
if code > 0 {
fmt.Println(args[i] + " in " + img.ID)
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
}