Example #1
0
func main() {
	c := cmd.NewUsercornRawCmd()
	c.NoArgs = true

	var shellcode []byte
	oldMake := c.MakeUsercorn
	c.MakeUsercorn = func(exe string) (models.Usercorn, error) {
		var err error
		shellcode, err = hex.DecodeString(exe)
		if err != nil {
			return nil, err
		}
		return oldMake(exe)
	}
	c.RunUsercorn = func(args, env []string) error {
		u := c.Usercorn
		mem, err := u.Mmap(u.Entry(), uint64(len(shellcode)))
		if err != nil {
			return err
		}
		mem.Desc = "shellcode"
		if err := u.MemWrite(mem.Addr, shellcode); err != nil {
			return err
		}
		u.SetEntry(mem.Addr)
		u.SetExit(mem.Addr + uint64(len(shellcode)))
		return u.Run(args, env)
	}
	c.Run(os.Args, os.Environ())
}
Example #2
0
func main() {
	c := cmd.NewUsercornRawCmd()
	c.NoExe = true
	c.NoArgs = true

	c.RunUsercorn = func(args, env []string) error {
		u := c.Usercorn
		mem, err := u.Mmap(u.Entry(), 0x10000)
		if err != nil {
			return err
		}
		mem.Desc = "repl"

		status := models.StatusDiff{U: u}
		fmt.Printf("%s", status.Changes(false).String("", c.Config.Color))
		addr := mem.Addr
		end := addr
		input := bufio.NewScanner(os.Stdin)
		for {
			fmt.Printf("%s", status.Changes(true).String("", c.Config.Color))
			fmt.Printf("0x%x: ", addr)
			if !input.Scan() {
				break
			}
			text := input.Text()
			if len(text) > 0 && text[0] == '.' {
				if handleCmd(c, text) {
					continue
				}
			}
			sc, err := u.Assemble(text, addr)
			if err != nil {
				fmt.Printf("asm err: %s\n", err)
				continue
			}
			if err := u.MemWrite(addr, sc); err != nil {
				fmt.Printf("write err: %s\n", err)
				continue
			}
			end = addr + uint64(len(sc))
			u.SetEntry(addr)
			u.SetExit(end)
			if err := u.Run(os.Args, os.Environ()); err != nil {
				fmt.Printf("exec err: %s\n", err)
			}
			addr = end
		}
		fmt.Printf("\n%s", status.Changes(false).String("", c.Config.Color))
		return nil
	}
	c.Run(os.Args, os.Environ())
}