ArmyCyberInstitute / cmgr

CTF Challenge Manager
Apache License 2.0
17 stars 9 forks source link

test: fails with build artifacts #10

Closed royragsdale closed 4 years ago

royragsdale commented 4 years ago

When running cmgr test on a challenge with artifacts they fail to get written to disk prior to the solver image starting. When running with --no-solve the tar is properly written to disk.

relevant line:

cmgr: [ERROR:  failed to build solver image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=ecb-1%2Fsolver%3A3&ulimits=null": open /home/r/code/cmgr/4333f91abd45bb47dcac624a4cf08b3fe9c283267182287e80bab3c8e475378f.tar.gz: no such file or directory]

full log:

$ ./bin/cmgr test examples/ecb-1/
cmgr: [INFO:  challenge directory: /home/r/code/cmgr]
cmgr: [INFO:  artifacts directory: /home/r/code/cmgr]
cmgr: [INFO:  connected to docker (API v1.40)]
cmgr: [INFO:  searching /home/r/code/cmgr/examples/ecb-1 for challenges]
cmgr: [INFO:  found challenge ecb-1]
cmgr: [INFO:  searching /home/r/code/cmgr/examples/ecb-1 for challenges]
cmgr: [INFO:  found challenge ecb-1]
cmgr: [INFO:  searching /home/r/code/cmgr/examples/ecb-1 for challenges]
cmgr: [INFO:  found challenge ecb-1]
cmgr: [INFO:  created container 04d70c80cfeeeb1e068a586425caf9dd1554c56647816547810448eb6dea7aec]
cmgr: [INFO:  created new image: 9c518efd9686a13be76ddd9c7ddad578e1bbfb21cf778bd74c0f20e28d224c08]
cmgr: [ERROR:  failed to build solver image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=ecb-1%2Fsolver%3A3&ulimits=null": open /home/r/code/cmgr/4333f91abd45bb47dcac624a4cf08b3fe9c283267182287e80bab3c8e475378f.tar.gz: no such file or directory]
error (ecb-1): solver failed: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=ecb-1%2Fsolver%3A3&ulimits=null": open /home/r/code/cmgr/4333f91abd45bb47dcac624a4cf08b3fe9c283267182287e80bab3c8e475378f.tar.gz: no such file or directory
cmgr: [ERROR:  failed to remove image: Error response from daemon: conflict: unable to remove repository reference "ecb-1:f8a0ec358ae1b74474eb88020dacd3d7fbd8ba1aa13c5d10348ca72ecd658b52" (must force) - container d21c1daa9437 is using its referenced image 5d8b86ef20f7]
royragsdale commented 4 years ago

Turns out the tar is created but seemingly removed prior to when the solver can use it.

royragsdale commented 4 years ago

Seems that it is actually that the tar name is incorrect:

cmgr: [ERROR:  failed to build solver image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=cmgr%2Fexamples%2Fcustom-socat%2Fsolver%3A2&ulimits=null": open /home/r/code/cmgr/6fd0fa68915bdd38c63df70038c735ee360ccad95e022f1da4b79f0051c1c041.tar.gz: no such file or directory]
error (cmgr/examples/custom-socat): solver failed: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=cmgr%2Fexamples%2Fcustom-socat%2Fsolver%3A2&ulimits=null": open /home/r/code/cmgr/6fd0fa68915bdd38c63df70038c735ee360ccad95e022f1da4b79f0051c1c041.tar.gz: no such file or directory
cmgr: [DEBUG:  stopping instance 1]
cmgr: [DEBUG:  destroying build 2]
cmgr: [WARN:  Removing: 20e05690710b7a965eefa1d2cc53b060b9780031e1eebe578bd1ee474da62524.tar.gz]
docker.go:                      artifactsFileName := fmt.Sprintf("%s.tar.gz", image.DockerId)

v.s.

solver_framework.go:                    artifactsPath := filepath.Join(m.artifactsDir, fmt.Sprintf("%s.tar.gz", sumStr))
royragsdale commented 4 years ago
r@x: ~/code/cmgr $ ./bin/cmgr test examples/custom/
cmgr: [WARN:  extracting to: 20e05690710b7a965eefa1d2cc53b060b9780031e1eebe578bd1ee474da62524.tar.gz]
cmgr: [WARN:  artifacts: /home/r/code/cmgr/6fd0fa68915bdd38c63df70038c735ee360ccad95e022f1da4b79f0051c1c041.tar.gz]
cmgr: [ERROR:  failed to build solver image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=cmgr%2Fexamples%2Fcustom-socat%2Fsolver%3A1&ulimits=null": open /home/r/code/cmgr/6fd0fa68915bdd38c63df70038c735ee360ccad95e022f1da4b79f0051c1c041.tar.gz: no such file or directory]
error (cmgr/examples/custom-socat): solver failed: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.25/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=cmgr%2Fexamples%2Fcustom-socat%2Fsolver%3A1&ulimits=null": open /home/r/code/cmgr/6fd0fa68915bdd38c63df70038c735ee360ccad95e022f1da4b79f0051c1c041.tar.gz: no such file or directory
cmgr: [WARN:  Removing: 20e05690710b7a965eefa1d2cc53b060b9780031e1eebe578bd1ee474da62524.tar.gz]
royragsdale commented 4 years ago

yeah root cause ties back to changing the format of the seed:

cmgr/solver_framework.go
-                       sum := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%x", meta.Challenge, meta.Format, meta.Seed)))
+                       sum := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%d", meta.Challenge, meta.Format, meta.Seed)))

%x to %d

royragsdale commented 4 years ago

closing since was never an issue on master.

only an issue on #9. Since resolved.

As a meta point though, the construction of the hash/id/artifact path is scattered about a few places and might benefit from a helper function/struct method