2018-10-06 19:25:03 +00:00
|
|
|
// Copyright 2018 Mikhail Klementev. All rights reserved.
|
2018-10-08 20:51:32 +00:00
|
|
|
// Use of this source code is governed by a AGPLv3 license
|
2018-10-06 19:25:03 +00:00
|
|
|
// (or later) that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2018-11-17 13:44:03 +00:00
|
|
|
"os/user"
|
2018-10-06 19:25:03 +00:00
|
|
|
|
2018-10-26 18:26:43 +00:00
|
|
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
2018-10-06 19:25:03 +00:00
|
|
|
)
|
|
|
|
|
2018-11-17 13:20:29 +00:00
|
|
|
func kernelListHandler(kcfg kernelConfig) (err error) {
|
|
|
|
for _, kernel := range kcfg.Kernels {
|
|
|
|
fmt.Println(kernel.DistroType, kernel.DistroRelease,
|
|
|
|
kernel.KernelRelease)
|
|
|
|
}
|
2018-10-26 18:26:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2018-10-27 08:14:10 +00:00
|
|
|
app := kingpin.New(
|
|
|
|
"out-of-tree",
|
|
|
|
"kernel {module, exploit} development tool",
|
|
|
|
)
|
|
|
|
|
|
|
|
app.Author("Mikhail Klementev <jollheef@riseup.net>")
|
|
|
|
app.Version("0.1.0")
|
|
|
|
|
|
|
|
pathFlag := app.Flag("path", "Path to work directory")
|
2018-10-27 07:48:06 +00:00
|
|
|
path := pathFlag.Default(".").ExistingDir()
|
|
|
|
|
2018-11-17 13:44:03 +00:00
|
|
|
usr, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defaultKcfgPath := usr.HomeDir + "/.out-of-tree/kernels.toml"
|
|
|
|
|
2018-11-17 13:17:28 +00:00
|
|
|
kcfgPathFlag := app.Flag("kernels", "Path to kernels config")
|
2018-11-17 13:44:03 +00:00
|
|
|
kcfgPathEnv := kcfgPathFlag.Envar("OUT_OF_TREE_KCFG")
|
|
|
|
kcfgPath := kcfgPathEnv.Default(defaultKcfgPath).ExistingFile()
|
2018-10-27 07:48:06 +00:00
|
|
|
|
2018-10-27 19:06:24 +00:00
|
|
|
qemuTimeoutFlag := app.Flag("qemu-timeout", "Timeout for qemu")
|
|
|
|
qemuTimeout := qemuTimeoutFlag.Default("1m").Duration()
|
|
|
|
|
|
|
|
dockerTimeoutFlag := app.Flag("docker-timeout", "Timeout for docker")
|
|
|
|
dockerTimeout := dockerTimeoutFlag.Default("1m").Duration()
|
|
|
|
|
2018-10-27 08:14:10 +00:00
|
|
|
pewCommand := app.Command("pew", "Build, run and test module/exploit")
|
2018-10-27 15:09:28 +00:00
|
|
|
pewKernelFlag := pewCommand.Flag("kernel", "Override kernel regex")
|
|
|
|
pewKernel := pewKernelFlag.String()
|
2018-10-26 18:26:43 +00:00
|
|
|
|
2018-10-27 15:33:54 +00:00
|
|
|
pewGuessFlag := pewCommand.Flag("guess", "Try all defined kernels")
|
|
|
|
pewGuess := pewGuessFlag.Bool()
|
|
|
|
|
2018-10-27 19:35:47 +00:00
|
|
|
pewBinaryFlag := pewCommand.Flag("binary", "Use binary, do not build")
|
|
|
|
pewBinary := pewBinaryFlag.String()
|
|
|
|
|
|
|
|
pewTestFlag := pewCommand.Flag("test", "Override path test")
|
|
|
|
pewTest := pewTestFlag.String()
|
|
|
|
|
2018-11-17 13:20:29 +00:00
|
|
|
kernelCommand := app.Command("kernel", "Manipulate kernels")
|
|
|
|
kernelListCommand := kernelCommand.Command("list", "List kernels")
|
|
|
|
|
2018-11-17 13:44:03 +00:00
|
|
|
kingpin.MustParse(app.Parse(os.Args[1:]))
|
|
|
|
|
2018-11-17 13:17:28 +00:00
|
|
|
kcfg, err := readKernelConfig(*kcfgPath)
|
|
|
|
if err != nil {
|
2018-11-17 13:28:56 +00:00
|
|
|
log.Fatalln(err)
|
2018-11-17 13:17:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 08:14:10 +00:00
|
|
|
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
|
|
|
case pewCommand.FullCommand():
|
2018-11-17 13:17:28 +00:00
|
|
|
err = pewHandler(kcfg, *path, *pewKernel, *pewBinary,
|
2018-10-27 19:35:47 +00:00
|
|
|
*pewTest, *pewGuess, *qemuTimeout, *dockerTimeout)
|
2018-11-17 13:20:29 +00:00
|
|
|
case kernelListCommand.FullCommand():
|
|
|
|
err = kernelListHandler(kcfg)
|
2018-10-26 18:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-17 13:28:56 +00:00
|
|
|
log.Fatalln(err)
|
2018-10-26 18:26:43 +00:00
|
|
|
}
|
2018-10-06 19:25:03 +00:00
|
|
|
}
|