示例#1
0
func RunReplay(c *fuzzer.Connection, frames []string) {
	for _, frameJSON := range frames {
		frame := util.FromJSON([]byte(frameJSON))

		if c.Err != nil {
			fmt.Println("Connection Error", c.Err, "restarting connection")
			c = fuzzer.NewConnection(Target, c.IsTLS, c.IsPreface, c.IsSendSettings)
		}

		switch frame["FrameMethod"] {
		case "RawFrame":
			fmt.Println(frame)
			frameType := uint8(frame["FrameType"].(float64))
			flags := uint8(frame["Flags"].(float64))
			streamID := uint32(frame["StreamID"].(float64))
			payload := util.FromBase64(frame["Payload"].(string))
			c.WriteRawFrame(frameType, flags, streamID, payload)
			time.Sleep(time.Second * 1)
		}
	}
	fmt.Println("ALL DONE")
}
示例#2
0
func RunReplay(c *Connection, filename string) {

	file, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		frameJSON := scanner.Text()
		frame := util.FromJSON([]byte(frameJSON))

		if c.Err != nil {
			fmt.Println("Connection Error", c.Err, "restarting connection")
			c = NewConnection(c.Host, c.IsTLS, c.IsPreface, c.IsSendSettings)
		}

		switch frame["FrameMethod"] {

		case "RawFrame":
			frameType := uint8(frame["FrameType"].(float64))
			flags := uint8(frame["Flags"].(float64))
			streamID := uint32(frame["StreamID"].(float64))
			payload := util.FromBase64(frame["Payload"].(string))
			c.WriteRawFrame(frameType, flags, streamID, payload)
		case "Ping":
			pingData := frame["Data"].([]interface{})
			var pingDataArray [8]byte
			for i := 0; i < len(pingData); i++ {
				pingDataArray[i] = uint8(pingData[i].(float64))
			}
			c.SendPing(pingDataArray)
		case "SettingsFrame":
			arrSettings := frame["Settings"].([]interface{})
			settings := make([]http2.Setting, len(arrSettings))
			for i := 0; i < len(arrSettings); i++ {
				singleSettingsInterface := arrSettings[i].(map[string]interface{})
				http2Setting := http2.Setting{http2.SettingID(singleSettingsInterface["ID"].(float64)), uint32(singleSettingsInterface["Val"].(float64))}
				settings[i] = http2Setting
			}
			c.WriteSettingsFrame(settings)
		case "DataFrame":
			streamID := uint32(frame["StreamID"].(float64))
			endStream := bool(frame["EndStream"].(bool))
			data := util.FromBase64(frame["Data"].(string))
			c.WriteDataFrame(streamID, endStream, data)
		case "PushPromiseFrame":
			streamID := uint32(frame["StreamID"].(float64))
			promiseID := uint32(frame["PromiseID"].(float64))
			blockFragment := util.FromBase64(frame["BlockFragment"].(string))
			endHeaders := frame["EndHeaders"].(bool)
			padLength := uint8(frame["PadLength"].(float64))
			promise := http2.PushPromiseParam{streamID, promiseID, blockFragment, endHeaders, padLength}
			c.WritePushPromiseFrame(promise)
		case "HeadersFrame":
			headers := frame["Headers"].(map[string]interface{})
			headers_map := make(map[string]string)
			for key, value := range headers {
				switch value := value.(type) {
				case string:
					headers_map[key] = value
				}
			}
			c.cmdHeaders(headers_map)
		case "ContinuationFrame":
			streamID := uint32(frame["StreamID"].(float64))
			endStream := frame["EndStream"].(bool)
			data := util.FromBase64(frame["Data"].(string))
			c.WriteContinuationFrame(streamID, endStream, data)
		case "PriorityFrame":
			streamID := uint32(frame["StreamID"].(float64))
			streamDep := uint32(frame["StreamDep"].(float64))
			weight := uint8(frame["Weight"].(float64))
			exclusive := frame["Exclusive"].(bool)
			c.WritePriorityFrame(streamID, streamDep, weight, exclusive)
		case "ResetFrame":
			streamID := uint32(frame["StreamID"].(float64))
			errorCode := uint32(frame["ErrorCode"].(float64))
			c.WriteResetFrame(streamID, errorCode)
			c = NewConnection(c.Host, c.IsTLS, c.IsPreface, c.IsSendSettings)
		case "WindowUpdateFrame":
			streamID := uint32(frame["StreamID"].(float64))
			incr := uint32(frame["Incr"].(float64))
			c.WriteWindowUpdateFrame(streamID, incr)
		}
	}
	fmt.Println("ALL DONE")
}