Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jeanqasaur on github.
  • I am jeanqasaur (https://keybase.io/jeanqasaur) on keybase.
  • I have a public key whose fingerprint is FDD9 E9A0 695F CAA4 3F78 C99B 80ED 8A7A 6F7B 2CC2

To claim this, I am signing this object:

@jeanqasaur
jeanqasaur / harclient_sample.py
Created April 14, 2021 18:20
Code sample for Akita Flask blog post: HarClient class definition
class HarClient(FlaskClient):
def __init__(self, *args
, har_file_path=f'akita_trace_{time.time()}.har'
, **kwargs):
self.har_writer = HarWriter(har_file_path, 'w')
self.url_prefix = ""
super().__init__(*args, **kwargs)
@jeanqasaur
jeanqasaur / harclient_open.py
Created April 14, 2021 18:24
Code sample for Akita Flask blog post: HarClient class definition
def open(self, *args, **kwargs):
start = datetime.now(timezone.utc)
resp: Response = super().open(*args, **kwargs)
self.har_writer.write_entry(
self._create_har_entry(start, args, kwargs, resp))
return resp
@jeanqasaur
jeanqasaur / newTCPStream.go
Last active May 4, 2021 04:37
Function for creating new tcpStream struct
func newTCPStream(clock clockWrapper, netFlow gopacket.Flow,
outChan chan<- akinet.ParsedNetworkTraffic,
fs akinet.TCPParserFactorySelector) *tcpStream {
return &tcpStream{
clock: clock,
bidiID: akinet.TCPBidiID(uuid.New()),
netFlow: netFlow,
factorySelector: fs,
outChan: outChan,
}
@jeanqasaur
jeanqasaur / sampleStreamFactory.go
Created April 26, 2021 23:48
How we implement the StreamFactory interface at Akita
func (fact *tcpStreamFactory) New(netFlow, tcpFlow gopacket.Flow, _ *layers.TCP, _ reassembly.AssemblerContext) reassembly.Stream {
return newTCPStream(fact.clock, netFlow, fact.outChan, fact.fs)
}
@jeanqasaur
jeanqasaur / example_tcpdump.sh
Created April 27, 2021 00:16
Example use of tcpdump
tcpdump -i lo -w lo.pcap
@jeanqasaur
jeanqasaur / pcap_example.go
Last active May 4, 2021 04:41
Example use of pcap filters
package main
import (
"github.com/google/gopacket"
_ "github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
)
const (
@jeanqasaur
jeanqasaur / stream_example.go
Last active April 27, 2021 04:39
Example implementation of the Stream interface for packet processing
// tcpStream represents a pair of uni-directional tcpFlows. It
// implements reassembly.Stream interface to receive reassembled
// packets for BOTH flows, which it then directs to the correct
// tcpFlow.
type tcpStream struct {
clock clockWrapper // constant
bidiID akinet.TCPBidiID // constant
// Network layer flow.
netFlow gopacket.Flow
@jeanqasaur
jeanqasaur / parsing_example.go
Last active May 4, 2021 04:42
Example of using StreamFactory, StreamPool, and Assembler for TCP packet parsing
func (p *NetworkTrafficParser) ParseFromInterface(
interfaceName, bpfFilter string, signalClose <-chan struct{},
fs ...akinet.TCPParserFactory)
(<-chan akinet.ParsedNetworkTraffic, error) {
// Read in packets, pass to assembler
packets, err := p.pcap.capturePackets(signalClose,
interfaceName,
bpfFilter)
if err != nil {
return nil, errors.Wrapf(