Ejemplo n.º 1
0
// TestDump executes all of the tests described by dumpTests.
func TestDump(t *testing.T) {
	// Setup tests.
	addIntDumpTests()
	addUintDumpTests()
	addBoolDumpTests()
	addFloatDumpTests()
	addComplexDumpTests()
	addArrayDumpTests()
	addSliceDumpTests()
	addStringDumpTests()
	addInterfaceDumpTests()
	addMapDumpTests()
	addStructDumpTests()
	addUintptrDumpTests()
	addUnsafePointerDumpTests()
	addChanDumpTests()
	addFuncDumpTests()
	addCircularDumpTests()
	addPanicDumpTests()
	addErrorDumpTests()
	addCgoDumpTests()

	t.Logf("Running %d tests", len(dumpTests))
	for i, test := range dumpTests {
		buf := new(bytes.Buffer)
		spew.Fdump(buf, test.in)
		s := buf.String()
		if testFailed(s, test.wants) {
			t.Errorf("Dump #%d\n got: %s %s", i, s, stringizeWants(test.wants))
			continue
		}
	}
}
Ejemplo n.º 2
0
func heartbleedCheck(conn *tls.Conn, buf *bytes.Buffer, vuln chan bool) func([]byte) {
	return func(data []byte) {
		spew.Fdump(buf, data)
		if bytes.Index(data, padding) == -1 {
			vuln <- false
		} else {
			vuln <- true
		}
	}
}
Ejemplo n.º 3
0
func (d *dumper) work() {
	for {
		msg := <-d.msgchan
		file, err := os.OpenFile(
			d.filename,
			os.O_APPEND|os.O_CREATE|os.O_RDWR,
			0666,
		)
		if err != nil {
			panic(err)
		}
		spew.Fdump(file, msg)
		file.Close()
	}
}
Ejemplo n.º 4
0
// dumpDaemon appends the daemon datastructures into file in dir and returns full path
// to that file.
func (d *Daemon) dumpDaemon(dir string) (string, error) {
	// Ensure we recover from a panic as we are doing this without any locking
	defer func() {
		recover()
	}()

	path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
	f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump")
	}
	defer f.Close()
	spew.Fdump(f, d) // Does not return an error
	f.Sync()
	return path, nil
}
Ejemplo n.º 5
0
// dumpDaemon appends the daemon datastructures into file in dir and returns full path
// to that file.
func (d *Daemon) dumpDaemon(dir string) (string, error) {
	// Ensure we recover from a panic as we are doing this without any locking
	defer func() {
		recover()
	}()

	path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
	f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump")
	}
	defer f.Close()

	dump := struct {
		containers      interface{}
		names           interface{}
		links           interface{}
		execs           interface{}
		volumes         interface{}
		images          interface{}
		layers          interface{}
		imageReferences interface{}
		downloads       interface{}
		uploads         interface{}
		registry        interface{}
		plugins         interface{}
	}{
		containers:      d.containers,
		execs:           d.execCommands,
		volumes:         d.volumes,
		images:          d.imageStore,
		layers:          d.layerStore,
		imageReferences: d.referenceStore,
		downloads:       d.downloadManager,
		uploads:         d.uploadManager,
		registry:        d.RegistryService,
		plugins:         d.PluginStore,
		names:           d.nameIndex,
		links:           d.linkIndex,
	}

	spew.Fdump(f, dump) // Does not return an error
	f.Sync()
	return path, nil
}
Ejemplo n.º 6
0
func (dg *DebugGraph) DebugNode(v interface{}) {
	if dg == nil {
		return
	}
	dg.Lock()
	defer dg.Unlock()

	// record the ordinal value for each node
	ord := dg.ord
	dg.ord++

	name := graphDotNodeName("root", v)

	var node *dot.Node
	// TODO: recursive
	for _, sg := range dg.Dot.Subgraphs {
		node, _ = sg.GetNode(name)
		if node != nil {
			break
		}
	}

	// record as much of the node data structure as we can
	spew.Fdump(&dg.buf, v)

	// for now, record the order of visits in the node label
	if node != nil {
		node.Attrs["label"] = fmt.Sprintf("%s %d", node.Attrs["label"], ord)
	}

	// if the node provides debug output, insert it into the graph, and log it
	if nd, ok := v.(GraphNodeDebugger); ok {
		out := nd.NodeDebug()
		if node != nil {
			node.Attrs["comment"] = out
			dg.buf.WriteString(fmt.Sprintf("NodeDebug (%s):'%s'\n", name, out))
		}
	}
}
Ejemplo n.º 7
0
// Dump displays the passed parameters with newlines and additional debug information such as complete types and all pointer addresses used to indirect to the final value.
// Delegates to spew.Fdump, see http://godoc.org/github.com/davecgh/go-spew/spew#Dump
func (w *Watchpoint) Dump(a ...interface{}) *Watchpoint {
	writer := new(bytes.Buffer)
	spew.Fdump(writer, a...)
	return w.printcontent(strings.TrimRight(string(writer.Bytes()), "\n"))
}
func dump(infos ...interface{}) {
	spew.Fdump(os.Stderr, infos)
}
Ejemplo n.º 9
0
func Heartbleed(tgt *Target, payload []byte, skipVerify bool) (out []byte, err error) {
	host := tgt.HostIp

	if strings.Index(host, ":") == -1 {
		host = host + ":443"
	}
	net_conn, err := net.DialTimeout("tcp", host, 3*time.Second)
	if err != nil {
		return
	}
	net_conn.SetDeadline(time.Now().Add(9 * time.Second))

	if tgt.Service != "https" {
		err = DoStartTLS(net_conn, tgt.Service)
		if err != nil {
			return
		}
	}

	hname := strings.Split(host, ":")
	conn := tls.Client(net_conn, &tls.Config{InsecureSkipVerify: skipVerify, ServerName: hname[0]})
	err = conn.Handshake()
	if err != nil {
		return
	}

	var vuln = make(chan bool, 1)
	buf := new(bytes.Buffer)
	err = conn.SendHeartbeat([]byte(buildEvilMessage(payload, host)), func(data []byte) {
		spew.Fdump(buf, data)
		if bytes.Index(data, padding) == -1 {
			vuln <- false
		} else {
			if strings.Index(string(data), host) == -1 {
				err = errors.New("Please try again")
				vuln <- false
			} else {
				vuln <- true
			}
		}
	})
	if err != nil {
		return
	}

	go func() {
		// Needed to process the incoming heartbeat
		conn.Read(nil)
		// spew.Dump(read_err)
	}()

	go func() {
		time.Sleep(3 * time.Second)
		_, err = conn.Write([]byte("quit\n"))
		conn.Read(nil) // TODO: here we should probably check that it succeeds
		vuln <- false
	}()

	select {
	case status := <-vuln:
		conn.Close()
		if status {
			out = buf.Bytes()
			return out, nil // VULNERABLE
		} else if err != nil {
			return
		} else {
			err = Safe
			return
		}
	case <-time.After(6 * time.Second):
		err = Timeout
		conn.Close()
		return
	}

}