How to use InitTarget method of linux Package

Best Syzkaller code snippet using linux.InitTarget

init.go

Source:init.go Github

copy

Full Screen

1// Copyright 2017 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package linux4import (5 "runtime"6 "github.com/google/syzkaller/prog"7 "github.com/google/syzkaller/sys/linux/gen"8 "github.com/google/syzkaller/sys/targets"9)10func init() {11 prog.RegisterTarget(gen.Target_amd64, initTarget)12 prog.RegisterTarget(gen.Target_386, initTarget)13 prog.RegisterTarget(gen.Target_arm64, initTarget)14 prog.RegisterTarget(gen.Target_arm, initTarget)15 prog.RegisterTarget(gen.Target_ppc64le, initTarget)16}17func initTarget(target *prog.Target) {18 arch := &arch{19 unix: targets.MakeUnixSanitizer(target),20 clockGettimeSyscall: target.SyscallMap["clock_gettime"],21 SYSLOG_ACTION_CONSOLE_OFF: target.ConstMap["SYSLOG_ACTION_CONSOLE_OFF"],22 SYSLOG_ACTION_CONSOLE_ON: target.ConstMap["SYSLOG_ACTION_CONSOLE_ON"],23 SYSLOG_ACTION_SIZE_UNREAD: target.ConstMap["SYSLOG_ACTION_SIZE_UNREAD"],24 FIFREEZE: target.ConstMap["FIFREEZE"],25 FITHAW: target.ConstMap["FITHAW"],26 PTRACE_TRACEME: target.ConstMap["PTRACE_TRACEME"],27 CLOCK_REALTIME: target.ConstMap["CLOCK_REALTIME"],28 ARCH_SET_FS: target.ConstMap["ARCH_SET_FS"],29 ARCH_SET_GS: target.ConstMap["ARCH_SET_GS"],30 AF_NFC: target.ConstMap["AF_NFC"],31 AF_LLC: target.ConstMap["AF_LLC"],32 AF_BLUETOOTH: target.ConstMap["AF_BLUETOOTH"],33 }34 target.MakeMmap = targets.MakePosixMmap(target)35 target.SanitizeCall = arch.sanitizeCall36 target.SpecialTypes = map[string]func(g *prog.Gen, typ prog.Type, old prog.Arg) (37 prog.Arg, []*prog.Call){38 "timespec": arch.generateTimespec,39 "timeval": arch.generateTimespec,40 "sockaddr_alg": arch.generateSockaddrAlg,41 "alg_name": arch.generateAlgName,42 "alg_aead_name": arch.generateAlgAeadName,43 "alg_hash_name": arch.generateAlgHashName,44 "alg_blkcipher_name": arch.generateAlgBlkcipherhName,45 "ipt_replace": arch.generateIptables,46 "ip6t_replace": arch.generateIptables,47 "arpt_replace": arch.generateArptables,48 "ebt_replace": arch.generateEbtables,49 }50 target.StringDictionary = stringDictionary51 if target.Arch == runtime.GOARCH {52 KCOV_INIT_TRACE = uintptr(target.ConstMap["KCOV_INIT_TRACE"])53 KCOV_ENABLE = uintptr(target.ConstMap["KCOV_ENABLE"])54 KCOV_DISABLE = uintptr(target.ConstMap["KCOV_DISABLE"])55 KCOV_TRACE_CMP = uintptr(target.ConstMap["KCOV_TRACE_CMP"])56 }57}58var (59 // This should not be here, but for now we expose this for syz-fuzzer.60 KCOV_INIT_TRACE uintptr61 KCOV_ENABLE uintptr62 KCOV_DISABLE uintptr63 KCOV_TRACE_CMP uintptr64 // TODO(dvyukov): get rid of this, this must be in descriptions.65 stringDictionary = []string{"user", "keyring", "trusted", "system", "security", "selinux",66 "posix_acl_access", "mime_type", "md5sum", "nodev", "self",67 "bdev", "proc", "cgroup", "cpuset",68 "lo", "eth0", "eth1", "em0", "em1", "wlan0", "wlan1", "ppp0", "ppp1",69 "vboxnet0", "vboxnet1", "vmnet0", "vmnet1", "GPL"}70)71type arch struct {72 unix *targets.UnixSanitizer73 clockGettimeSyscall *prog.Syscall74 SYSLOG_ACTION_CONSOLE_OFF uint6475 SYSLOG_ACTION_CONSOLE_ON uint6476 SYSLOG_ACTION_SIZE_UNREAD uint6477 FIFREEZE uint6478 FITHAW uint6479 PTRACE_TRACEME uint6480 CLOCK_REALTIME uint6481 ARCH_SET_FS uint6482 ARCH_SET_GS uint6483 AF_NFC uint6484 AF_LLC uint6485 AF_BLUETOOTH uint6486}87func (arch *arch) sanitizeCall(c *prog.Call) {88 arch.unix.SanitizeCall(c)89 switch c.Meta.CallName {90 case "syslog":91 cmd := c.Args[0].(*prog.ConstArg)92 cmd.Val = uint64(uint32(cmd.Val))93 // These disable console output, but we need it.94 if cmd.Val == arch.SYSLOG_ACTION_CONSOLE_OFF || cmd.Val == arch.SYSLOG_ACTION_CONSOLE_ON {95 cmd.Val = arch.SYSLOG_ACTION_SIZE_UNREAD96 }97 case "ioctl":98 cmd := c.Args[1].(*prog.ConstArg)99 // Freeze kills machine. Though, it is an interesting functions,100 // so we need to test it somehow.101 // TODO: not required if executor drops privileges.102 if uint64(uint32(cmd.Val)) == arch.FIFREEZE {103 cmd.Val = arch.FITHAW104 }105 case "ptrace":106 req := c.Args[0].(*prog.ConstArg)107 // PTRACE_TRACEME leads to unkillable processes, see:108 // https://groups.google.com/forum/#!topic/syzkaller/uGzwvhlCXAw109 if req.Val == arch.PTRACE_TRACEME {110 req.Val = ^uint64(0)111 }112 case "arch_prctl":113 // fs holds address of tls, if a program messes it at least signal114 // handling will break. This also allows a program to do writes115 // at arbitrary addresses, which usually leads to machine outbreak.116 cmd := c.Args[0].(*prog.ConstArg)117 if uint64(uint32(cmd.Val)) == arch.ARCH_SET_FS {118 cmd.Val = arch.ARCH_SET_GS119 }120 case "syz_init_net_socket":121 // Don't let it mess with arbitrary sockets in init namespace.122 family := c.Args[0].(*prog.ConstArg)123 switch uint64(uint32(family.Val)) {124 case arch.AF_NFC, arch.AF_LLC, arch.AF_BLUETOOTH:125 default:126 family.Val = ^uint64(0)127 }128 }129 switch c.Meta.Name {130 case "setsockopt$EBT_SO_SET_ENTRIES":131 arch.sanitizeEbtables(c)132 }133}134func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, old prog.Arg) (arg prog.Arg, calls []*prog.Call) {135 typ := typ0.(*prog.StructType)136 // We need to generate timespec/timeval that are either137 // (1) definitely in the past, or138 // (2) definitely in unreachable fututre, or139 // (3) few ms ahead of now.140 // Note: timespec/timeval can be absolute or relative to now.141 // Note: executor has blocking syscall timeout of 20ms,142 // so we generate both 10ms and 30ms.143 usec := typ.Name() == "timeval"144 switch {145 case g.NOutOf(1, 4):146 // Now for relative, past for absolute.147 arg = prog.MakeGroupArg(typ, []prog.Arg{148 prog.MakeResultArg(typ.Fields[0], nil, 0),149 prog.MakeResultArg(typ.Fields[1], nil, 0),150 })151 case g.NOutOf(1, 3):152 // Few ms ahead for relative, past for absolute153 nsec := uint64(10 * 1e6)154 if g.NOutOf(1, 2) {155 nsec = 30 * 1e6156 }157 if usec {158 nsec /= 1e3159 }160 arg = prog.MakeGroupArg(typ, []prog.Arg{161 prog.MakeResultArg(typ.Fields[0], nil, 0),162 prog.MakeResultArg(typ.Fields[1], nil, nsec),163 })164 case g.NOutOf(1, 2):165 // Unreachable fututre for both relative and absolute166 arg = prog.MakeGroupArg(typ, []prog.Arg{167 prog.MakeResultArg(typ.Fields[0], nil, 2e9),168 prog.MakeResultArg(typ.Fields[1], nil, 0),169 })170 default:171 // Few ms ahead for absolute.172 meta := arch.clockGettimeSyscall173 ptrArgType := meta.Args[1].(*prog.PtrType)174 argType := ptrArgType.Type.(*prog.StructType)175 tp := prog.MakeGroupArg(argType, []prog.Arg{176 prog.MakeResultArg(argType.Fields[0], nil, 0),177 prog.MakeResultArg(argType.Fields[1], nil, 0),178 })179 var tpaddr prog.Arg180 tpaddr, calls = g.Alloc(ptrArgType, tp)181 gettime := &prog.Call{182 Meta: meta,183 Args: []prog.Arg{184 prog.MakeConstArg(meta.Args[0], arch.CLOCK_REALTIME),185 tpaddr,186 },187 Ret: prog.MakeReturnArg(meta.Ret),188 }189 calls = append(calls, gettime)190 sec := prog.MakeResultArg(typ.Fields[0], tp.Inner[0].(*prog.ResultArg), 0)191 nsec := prog.MakeResultArg(typ.Fields[1], tp.Inner[1].(*prog.ResultArg), 0)192 msec := uint64(10)193 if g.NOutOf(1, 2) {194 msec = 30195 }196 if usec {197 nsec.OpDiv = 1e3198 nsec.OpAdd = msec * 1e3199 } else {200 nsec.OpAdd = msec * 1e6201 }202 arg = prog.MakeGroupArg(typ, []prog.Arg{sec, nsec})203 }204 return205}...

Full Screen

Full Screen

InitTarget

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l.InitTarget()4 fmt.Println(l.Target)5}6import (7type Linux struct {8}9func (l *Linux) InitTarget() {10 fmt.Println("Enter target")11 fmt.Scanln(&l.Target)12}13import (14func TestInitTarget(t *testing.T) {15 l.InitTarget()16 if l.Target == "" {17 t.Error("InitTarget() failed")18 }19}

Full Screen

Full Screen

InitTarget

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 target := golssh.InitTarget(golenv.Vars("USER"), golenv.Vars("HOST"))4 fmt.Println(target)5 fmt.Println(target.User, target.Host, target.Port, target.Password, target.PrivateKey)6}7import (8func main() {9 target := golssh.InitTarget(golenv.Vars("USER"), golenv.Vars("HOST"), golenv.Vars("PORT"))10 fmt.Println(target)11 fmt.Println(target.User, target.Host, target.Port, target.Password, target.PrivateKey)12}13import (14func main() {15 target := golssh.InitTarget(golenv.Vars("USER"), golenv.Vars("HOST"), golenv.Vars("PORT"), golenv.Vars("PASSWORD"))16 fmt.Println(target)17 fmt.Println(target.User, target.Host, target.Port, target.Password, target.PrivateKey)18}19import (20func main() {21 target := golssh.InitTarget(golenv.Vars("USER"), golenv.Vars("HOST"), golenv.Vars("PORT"), golenv.Vars("PASSWORD"), golenv.Vars("PRIVATEKEY"))22 fmt.Println(target)23 fmt.Println(target.User, target.Host, target.Port, target.Password, target.PrivateKey)24}25import (

Full Screen

Full Screen

InitTarget

Using AI Code Generation

copy

Full Screen

1import (2func main() {3bus := gobus.NewBus()4linux := linux.NewLinux(bus)5linux.InitTarget()6}7import (8func main() {9bus := gobus.NewBus()10linux := linux.NewLinux(bus)11linux.InitTarget()12}13import (14func main() {15bus := gobus.NewBus()16linux := linux.NewLinux(bus)17linux.InitTarget()18}19import (20func main() {21bus := gobus.NewBus()22linux := linux.NewLinux(bus)23linux.InitTarget()24}25import (26func main() {27bus := gobus.NewBus()28linux := linux.NewLinux(bus)29linux.InitTarget()30}31import (32func main() {33bus := gobus.NewBus()34linux := linux.NewLinux(bus)35linux.InitTarget()36}37import (38func main() {39bus := gobus.NewBus()40linux := linux.NewLinux(bus)41linux.InitTarget()42}43import (44func main() {45bus := gobus.NewBus()

Full Screen

Full Screen

InitTarget

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj.InitTarget("test")4 fmt.Println(obj.Target)5}6import (7func main() {8 obj.InitTarget("test")9 fmt.Println(obj.Target)10}11import (12func main() {13 obj.InitTarget("test")14 fmt.Println(obj.Target)15}16import (17func main() {18 obj.InitTarget("test")19 fmt.Println(obj.Target)20}21import (22func main() {23 obj.InitTarget("test")24 fmt.Println(obj.Target)25}26import (27func main() {28 obj.InitTarget("test")29 fmt.Println(obj.Target)30}31import (32func main() {33 obj.InitTarget("test")34 fmt.Println(obj.Target)35}36import (

Full Screen

Full Screen

InitTarget

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l.InitTarget("Ubuntu")4 fmt.Println(l.name)5}6import (7func main() {8 l.InstallPackage("Ubuntu", "vim")9}10import (11func main() {12 l.RemovePackage("Ubuntu", "vim")13}14import (15func main() {16 l.UpdatePackage("Ubuntu", "vim")17}18import (19func main() {20 l.ListPackage("Ubuntu")21}22import (23func main() {24 l.SearchPackage("Ubuntu", "vim")25}26import (27func main() {28 w.InstallPackage("Windows", "vim")29}30import (31func main() {32 w.RemovePackage("Windows", "vim")33}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful