Refactor
This commit is contained in:
parent
b654fb29b9
commit
73b39b5c0d
@ -32,7 +32,9 @@ func (km KernelMask) DockerName() string {
|
|||||||
type ArtifactType int
|
type ArtifactType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// KernelModule is any kind of kernel module
|
||||||
KernelModule ArtifactType = iota
|
KernelModule ArtifactType = iota
|
||||||
|
// KernelExploit is the privelege escalation exploit
|
||||||
KernelExploit
|
KernelExploit
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,11 +113,15 @@ func (ka Artifact) Supported(ki KernelInfo) (supported bool, err error) {
|
|||||||
type DistroType int
|
type DistroType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Ubuntu https://ubuntu.com/
|
||||||
Ubuntu DistroType = iota
|
Ubuntu DistroType = iota
|
||||||
|
// CentOS https://www.centos.org/
|
||||||
CentOS
|
CentOS
|
||||||
|
// Debian https://www.debian.org/
|
||||||
Debian
|
Debian
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DistroTypeStrings is the string version of enum DistroType
|
||||||
var DistroTypeStrings = [...]string{"Ubuntu", "CentOS", "Debian"}
|
var DistroTypeStrings = [...]string{"Ubuntu", "CentOS", "Debian"}
|
||||||
|
|
||||||
// NewDistroType is create new Distro object
|
// NewDistroType is create new Distro object
|
||||||
@ -160,12 +166,14 @@ func (dt DistroType) MarshalTOML() (data []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByRootFS is sorting by .RootFS lexicographically
|
||||||
type ByRootFS []KernelInfo
|
type ByRootFS []KernelInfo
|
||||||
|
|
||||||
func (a ByRootFS) Len() int { return len(a) }
|
func (a ByRootFS) Len() int { return len(a) }
|
||||||
func (a ByRootFS) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByRootFS) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByRootFS) Less(i, j int) bool { return a[i].RootFS < a[j].RootFS }
|
func (a ByRootFS) Less(i, j int) bool { return a[i].RootFS < a[j].RootFS }
|
||||||
|
|
||||||
|
// KernelInfo defines kernels.toml entries
|
||||||
type KernelInfo struct {
|
type KernelInfo struct {
|
||||||
DistroType DistroType
|
DistroType DistroType
|
||||||
DistroRelease string // 18.04/7.4.1708/9.1
|
DistroRelease string // 18.04/7.4.1708/9.1
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
"code.dumpstack.io/tools/out-of-tree/config"
|
"code.dumpstack.io/tools/out-of-tree/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const KERNELS_ALL int64 = math.MaxInt64
|
const kernelsAll int64 = math.MaxInt64
|
||||||
|
|
||||||
func kernelListHandler(kcfg config.KernelConfig) (err error) {
|
func kernelListHandler(kcfg config.KernelConfig) (err error) {
|
||||||
if len(kcfg.Kernels) == 0 {
|
if len(kcfg.Kernels) == 0 {
|
||||||
@ -496,7 +496,7 @@ func generateKernels(km config.KernelMask, max int64) (err error) {
|
|||||||
|
|
||||||
err = dockerImageAppend(km, pkg)
|
err = dockerImageAppend(km, pkg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
max -= 1
|
max--
|
||||||
} else {
|
} else {
|
||||||
log.Println("dockerImageAppend", err)
|
log.Println("dockerImageAppend", err)
|
||||||
}
|
}
|
||||||
@ -590,7 +590,7 @@ func kernelGenallHandler(distro, version string, host bool) (err error) {
|
|||||||
DistroRelease: version,
|
DistroRelease: version,
|
||||||
ReleaseMask: ".*",
|
ReleaseMask: ".*",
|
||||||
}
|
}
|
||||||
err = generateKernels(km, KERNELS_ALL)
|
err = generateKernels(km, kernelsAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -118,7 +118,7 @@ func main() {
|
|||||||
pewCommand := app.Command("pew", "Build, run and test module/exploit")
|
pewCommand := app.Command("pew", "Build, run and test module/exploit")
|
||||||
|
|
||||||
pewMax := pewCommand.Flag("max", "Test no more than X kernels").
|
pewMax := pewCommand.Flag("max", "Test no more than X kernels").
|
||||||
PlaceHolder("X").Default(fmt.Sprint(KERNELS_ALL)).Int64()
|
PlaceHolder("X").Default(fmt.Sprint(kernelsAll)).Int64()
|
||||||
|
|
||||||
pewRuns := pewCommand.Flag("runs", "Runs per each kernel").
|
pewRuns := pewCommand.Flag("runs", "Runs per each kernel").
|
||||||
Default("1").Int64()
|
Default("1").Int64()
|
||||||
@ -153,7 +153,7 @@ func main() {
|
|||||||
"Download random kernels from set defined by regex in "+
|
"Download random kernels from set defined by regex in "+
|
||||||
"release_mask, but no more than X for each of "+
|
"release_mask, but no more than X for each of "+
|
||||||
"release_mask").PlaceHolder("X").Default(
|
"release_mask").PlaceHolder("X").Default(
|
||||||
fmt.Sprint(KERNELS_ALL)).Int64()
|
fmt.Sprint(kernelsAll)).Int64()
|
||||||
kernelDockerRegenCommand := kernelCommand.Command("docker-regen",
|
kernelDockerRegenCommand := kernelCommand.Command("docker-regen",
|
||||||
"Regenerate kernels config from out_of_tree_* docker images")
|
"Regenerate kernels config from out_of_tree_* docker images")
|
||||||
kernelGenallCommand := kernelCommand.Command("genall",
|
kernelGenallCommand := kernelCommand.Command("genall",
|
||||||
|
2
pew.go
2
pew.go
@ -392,7 +392,7 @@ func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath,
|
|||||||
|
|
||||||
if supported {
|
if supported {
|
||||||
found = true
|
found = true
|
||||||
max -= 1
|
max--
|
||||||
for i := int64(0); i < runs; i++ {
|
for i := int64(0); i < runs; i++ {
|
||||||
swg.Add()
|
swg.Add()
|
||||||
go whatever(&swg, ka, kernel, binaryPath,
|
go whatever(&swg, ka, kernel, binaryPath,
|
||||||
|
Loading…
Reference in New Issue
Block a user