Skip to content

Instantly share code, notes, and snippets.

@tsusanka
Created March 22, 2017 11:10
Show Gist options
  • Save tsusanka/8ce41c64f80836500410e490075b1df8 to your computer and use it in GitHub Desktop.
Save tsusanka/8ce41c64f80836500410e490075b1df8 to your computer and use it in GitHub Desktop.
package module
import (
"crypto/tls"
"encoding/hex"
"github.com/praetorian-inc/trudy/pipe"
"net"
)
//Data is a thin wrapper that provides metadata that may be useful when mangling bytes on the network.
type Data struct {
FromClient bool //FromClient is true is the data sent is coming from the client (the device you are proxying)
Bytes []byte //Bytes is a byte slice that contians the TCP data
TLSConfig *tls.Config //TLSConfig is a TLS server config that contains Trudy's TLS server certficiate.
ServerAddr net.Addr //ServerAddr is net.Addr of the server
ClientAddr net.Addr //ClientAddr is the net.Addr of the client (the device you are proxying)
}
var saved bool
var oldBytes []byte
//DoMangle will return true if Data needs to be sent to the Mangle function.
func (input Data) DoMangle() bool {
if input.ServerAddr.String() == "139.59.129.86:80" {
return true
}
return false
}
//Mangle can modify/replace the Bytes values within the Data struct. This can
//be empty if no programmatic mangling needs tos be done.
func (input *Data) Mangle() {
for i := range input.Bytes {
input.Bytes[i] = 0x00
}
}
//Drop will return true if the Data needs to be dropped before going through
//the pipe.
func (input Data) Drop() bool {
return false
}
//PrettyPrint returns the string representation of the data. This string will
//be the value that is logged to the console.
func (input Data) PrettyPrint() string {
return hex.Dump(input.Bytes)
}
//DoPrint will return true if the PrettyPrinted version of the Data struct
//needs to be logged to the console.
func (input Data) DoPrint() bool {
return true
}
//DoIntercept returns true if data should be sent to the Trudy interceptor.
func (input Data) DoIntercept() bool {
return false
}
//Deserialize should replace the Data struct's Bytes with a deserialized bytes.
//For example, unpacking a HTTP/2 frame would be deserialization.
func (input *Data) Deserialize() {
}
//Serialize should replace the Data struct's Bytes with the serialized form of
//the bytes. The serialized bytes will be sent over the wire.
func (input *Data) Serialize() {
}
//BeforeWriteToClient is a function that will be called before data is sent to
//a client.
func (input *Data) BeforeWriteToClient(p pipe.Pipe) {
}
//AfterWriteToClient is a function that will be called after data is sent to
//a client.
func (input *Data) AfterWriteToClient(p pipe.Pipe) {
}
//BeforeWriteToServer is a function that will be called before data is sent to
//a server.
func (input *Data) BeforeWriteToServer(p pipe.Pipe) {
}
//AfterWriteToServer is a function that will be called after data is sent to
//a server.
func (input *Data) AfterWriteToServer(p pipe.Pipe) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment