Ejemplo n.º 1
0
func (m *HttpTampererSymptom) MuckRequest(ctx *muxy.Context) {

	// Body
	if m.Request.Body != "" {
		newreq, err := http.NewRequest(ctx.Request.Method, ctx.Request.URL.String(), bytes.NewBuffer([]byte(m.Request.Body)))
		if err != nil {
			log.Error(err.Error())
		}
		*ctx.Request = *newreq
		log.Debug("Spoofing HTTP Request Body with %s", log.Colorize(log.BLUE, m.Request.Body))
	}

	// Set Cookies
	for _, c := range m.Request.Cookies {
		c.Expires = stringToDate(c.RawExpires)
		log.Debug("Spoofing Request Cookie %s => %s", log.Colorize(log.LIGHTMAGENTA, c.Name), c.String())
		ctx.Request.Header.Add("Cookie", c.String())
	}

	// Set Headers
	for k, v := range m.Request.Headers {
		key := strings.ToTitle(strings.Replace(k, "_", "-", -1))
		log.Debug("Spoofing Request Header %s => %s", log.Colorize(log.LIGHTMAGENTA, key), v)
		ctx.Request.Header.Set(key, v)
	}

	// This Writes all headers, setting status code - so call this last
	if m.Request.Method != "" {
		ctx.Request.Method = m.Request.Method
	}
}
Ejemplo n.º 2
0
func (l *LoggerMiddleware) HandleEvent(e muxy.ProxyEvent, ctx *muxy.Context) {
	switch e {
	case muxy.EVENT_PRE_DISPATCH:
		if ctx.Request == nil {
			if len(ctx.Bytes) > 0 {
				log.Info("Handle TCP event " + log.Colorize(log.GREY, "PRE_DISPATCH") + fmt.Sprintf(" Received %d%s", len(ctx.Bytes), " bytes"))
				data := fmt.Sprintf(l.format, ctx.Bytes)
				log.Debug("Handle TCP event " + log.Colorize(log.GREY, "PRE_DISPATCH") + " Received request: " + bytesTab + log.Colorize(log.BLUE, data))
			}
		} else {
			log.Info("Handle HTTP event " + log.Colorize(log.GREY, "PRE_DISPATCH") + " Proxying request " +
				log.Colorize(log.LIGHTMAGENTA, ctx.Request.Method) +
				log.Colorize(log.BLUE, " \""+ctx.Request.URL.String()+"\""))
		}
	case muxy.EVENT_POST_DISPATCH:
		if ctx.Request == nil {
			if len(ctx.Bytes) > 0 {
				log.Info("Handle TCP event " + log.Colorize(log.GREY, "POST_DISPATCH") + fmt.Sprintf(" Sent %d%s", len(ctx.Bytes), " bytes"))
				data := fmt.Sprintf(l.format, ctx.Bytes)
				log.Debug("Handle TCP event " + log.Colorize(log.GREY, "POST_DISPATCH") + " Sent response: " + bytesTab + log.Colorize(log.BLUE, data))
			}
		} else {
			log.Info("Handle HTTP event " + log.Colorize(log.GREY, "POST_DISPATCH") + " Returning " +
				log.Colorize(log.GREY, fmt.Sprintf("%s", ctx.Response.Status)))
		}
	}
}
Ejemplo n.º 3
0
func (s *ShittyNetworkSymptom) Teardown() {
	log.Debug("Tearing down ShittyNetworkSymptom")
	s.config.Stop = true
	supressOutput(func() {
		throttler.Run(&s.config)
	})
}
Ejemplo n.º 4
0
func (m *HttpTampererSymptom) MuckResponse(ctx *muxy.Context) {

	// Body
	if m.Response.Body != "" {
		var cl io.ReadCloser
		cl = &responseBody{body: []byte(m.Response.Body)}
		r := &http.Response{
			Request:          ctx.Request,
			Header:           ctx.Response.Header,
			Close:            ctx.Response.Close,
			ContentLength:    ctx.Response.ContentLength,
			Trailer:          ctx.Response.Trailer,
			TLS:              ctx.Response.TLS,
			TransferEncoding: ctx.Response.TransferEncoding,
			Status:           ctx.Response.Status,
			StatusCode:       ctx.Response.StatusCode,
			Proto:            ctx.Response.Proto,
			ProtoMajor:       ctx.Response.ProtoMajor,
			ProtoMinor:       ctx.Response.ProtoMinor,
			Body:             cl,
		}
		log.Debug("Injecting HTTP Response Body with %s", log.Colorize(log.BLUE, m.Response.Body))
		*ctx.Response = *r
	}

	// Set Cookies
	for _, c := range m.Response.Cookies {
		c.Expires = stringToDate(c.RawExpires)
		log.Debug("Spoofing Response Cookie %s => %s", log.Colorize(log.LIGHTMAGENTA, c.Name), c.String())
		ctx.Response.Header.Add("Set-Cookie", c.String())
	}

	// Set Headers
	for k, v := range m.Response.Headers {
		key := strings.ToTitle(strings.Replace(k, "_", "-", -1))
		log.Debug("Spoofing Response Header %s => %s", log.Colorize(log.LIGHTMAGENTA, key), v)
		ctx.Response.Header.Add(key, v)
	}

	// This Writes all headers, setting status code - so call this last
	if m.Response.Status != 0 {
		ctx.Response.StatusCode = m.Response.Status
		ctx.Response.Status = http.StatusText(m.Response.Status)
	}
}
Ejemplo n.º 5
0
func (m *HttpTampererSymptom) HandleEvent(e muxy.ProxyEvent, ctx *muxy.Context) {
	switch e {
	case muxy.EVENT_POST_DISPATCH:
		log.Debug("Spoofing status code, responding with %s", log.Colorize(log.YELLOW, fmt.Sprintf("%d %s", m.Status, http.StatusText(m.Status))))

		// Body
		if m.Body != "" {
			var cl io.ReadCloser
			cl = &responseBody{body: []byte(m.Body)}
			r := &http.Response{
				Request:          ctx.Request,
				Header:           ctx.Response.Header,
				Close:            ctx.Response.Close,
				ContentLength:    ctx.Response.ContentLength,
				Trailer:          ctx.Response.Trailer,
				TLS:              ctx.Response.TLS,
				TransferEncoding: ctx.Response.TransferEncoding,
				Status:           ctx.Response.Status,
				StatusCode:       ctx.Response.StatusCode,
				Proto:            ctx.Response.Proto,
				ProtoMajor:       ctx.Response.ProtoMajor,
				ProtoMinor:       ctx.Response.ProtoMinor,
				Body:             cl,
			}
			log.Debug("Injecting HTTP Response Body with %s", log.Colorize(log.BLUE, m.Body))
			*ctx.Response = *r
		}

		// Set Headers
		for k, v := range m.Headers {
			key := strings.ToTitle(strings.Replace(k, "_", "-", -1))
			log.Debug("Spoofing Header %s => %s", log.Colorize(log.LIGHTMAGENTA, key), v)
			ctx.Response.Header.Add(key, v)
			ctx.ResponseWriter.Header().Add(key, v)
		}

		// This Writes all headers, setting status code - so call this last
		ctx.Response.StatusCode = m.Status
		ctx.Response.Status = http.StatusText(m.Status)
		ctx.ResponseWriter.WriteHeader(m.Status)
	}
}
Ejemplo n.º 6
0
func (h *HttpDelaySymptom) Muck(ctx *muxy.Context) {
	delay := time.Duration(h.Delay) * time.Second
	log.Debug("HTTP Delay Muck(), delaying for %v seconds\n", delay.Seconds())

	for {
		select {
		case <-time.After(delay):
			return
		}
	}
}
Ejemplo n.º 7
0
func (s *ShittyNetworkSymptom) Setup() {
	log.Debug("Setting up ShittyNetworkSymptom: Enabling firewall")

	s.config = throttler.Config{
		Device:           s.Device,
		Latency:          s.Latency,
		TargetBandwidth:  s.TargetBandwidth,
		DefaultBandwidth: s.DefaultBandwidth,
		PacketLoss:       s.PacketLoss,
		TargetIps:        s.TargetIps,
		TargetIps6:       s.TargetIps6,
		TargetPorts:      s.TargetPorts,
		TargetProtos:     s.TargetProtos,
		DryRun:           false,
	}

	supressOutput(func() {
		throttler.Run(&s.config)
	})

}
Ejemplo n.º 8
0
func (s *ShittyNetworkSymptom) Setup() {
	log.Debug("Setting up ShittyNetworkSymptom: Enabling firewall")

	ports := ParsePorts(strings.Join(s.TargetPorts, ","))
	targetIPv4, targetIPv6 := parseAddrs(strings.Join(append(s.TargetIps, s.TargetIps6...), ","))

	s.config = throttler.Config{
		Device:           s.Device,
		Latency:          s.Latency,
		TargetBandwidth:  s.TargetBandwidth,
		DefaultBandwidth: s.DefaultBandwidth,
		PacketLoss:       s.PacketLoss,
		TargetIps:        targetIPv4,
		TargetIps6:       targetIPv6,
		TargetPorts:      ports,
		TargetProtos:     s.TargetProtos,
		DryRun:           false,
	}

	supressOutput(func() {
		throttler.Run(&s.config)
	})

}
Ejemplo n.º 9
0
func (s *ShittyNetworkSymptom) Muck(ctx *muxy.Context) {
	log.Debug("ShittyNetworkSymptom Mucking...")
}
Ejemplo n.º 10
0
func (m HttpDelaySymptom) Teardown() {
	log.Debug("HTTP Delay Teardown()")
}
Ejemplo n.º 11
0
func (m HttpDelaySymptom) Setup() {
	log.Debug("HTTP Delay Setup()")
}
Ejemplo n.º 12
0
func (m HttpTampererSymptom) Teardown() {
	log.Debug("HTTP Error Teardown()")
}
Ejemplo n.º 13
0
func (m HttpTampererSymptom) Setup() {
	log.Debug("HTTP Error Setup()")
}