mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-02 09:07:56 +00:00
Add Protocol
struct and make it effect the UI
This commit is contained in:
parent
c668680f54
commit
ccb924f507
@ -140,9 +140,9 @@ func loadExtensions() {
|
|||||||
extension.Dissector = dissector
|
extension.Dissector = dissector
|
||||||
log.Printf("Extension Properties: %+v\n", extension)
|
log.Printf("Extension Properties: %+v\n", extension)
|
||||||
extensions[i] = extension
|
extensions[i] = extension
|
||||||
extensionsMap[extension.Name] = extension
|
extensionsMap[extension.Protocol.Name] = extension
|
||||||
allOutboundPorts = mergeUnique(allOutboundPorts, extension.OutboundPorts)
|
allOutboundPorts = mergeUnique(allOutboundPorts, extension.Protocol.OutboundPorts)
|
||||||
allInboundPorts = mergeUnique(allInboundPorts, extension.InboundPorts)
|
allInboundPorts = mergeUnique(allInboundPorts, extension.Protocol.InboundPorts)
|
||||||
}
|
}
|
||||||
log.Printf("allOutboundPorts: %v\n", allOutboundPorts)
|
log.Printf("allOutboundPorts: %v\n", allOutboundPorts)
|
||||||
log.Printf("allInboundPorts: %v\n", allInboundPorts)
|
log.Printf("allInboundPorts: %v\n", allInboundPorts)
|
||||||
|
@ -111,7 +111,7 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension
|
|||||||
|
|
||||||
for item := range outputItems {
|
for item := range outputItems {
|
||||||
fmt.Printf("item: %+v\n", item)
|
fmt.Printf("item: %+v\n", item)
|
||||||
extension := extensionsMap[item.Protocol]
|
extension := extensionsMap[item.Protocol.Name]
|
||||||
fmt.Printf("extension: %+v\n", extension)
|
fmt.Printf("extension: %+v\n", extension)
|
||||||
// var req *http.Request
|
// var req *http.Request
|
||||||
// marshedReq, _ := json.Marshal(item.Data.Request.Orig)
|
// marshedReq, _ := json.Marshal(item.Data.Request.Orig)
|
||||||
|
@ -7,13 +7,23 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Protocol struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
LongName string `json:"long_name"`
|
||||||
|
Abbreviation string `json:"abbreviation"`
|
||||||
|
BackgroundColor string `json:"background_color"`
|
||||||
|
ForegroundColor string `json:"foreground_color"`
|
||||||
|
FontSize int8 `json:"font_size"`
|
||||||
|
ReferenceLink string `json:"reference_link"`
|
||||||
|
OutboundPorts []string `json:"outbound_ports"`
|
||||||
|
InboundPorts []string `json:"inbound_ports"`
|
||||||
|
}
|
||||||
|
|
||||||
type Extension struct {
|
type Extension struct {
|
||||||
Name string
|
Protocol Protocol
|
||||||
Path string
|
Path string
|
||||||
Plug *plugin.Plugin
|
Plug *plugin.Plugin
|
||||||
InboundPorts []string
|
Dissector Dissector
|
||||||
OutboundPorts []string
|
|
||||||
Dissector Dissector
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionInfo struct {
|
type ConnectionInfo struct {
|
||||||
@ -44,7 +54,7 @@ type RequestResponsePair struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OutputChannelItem struct {
|
type OutputChannelItem struct {
|
||||||
Protocol string
|
Protocol Protocol
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
ConnectionInfo *ConnectionInfo
|
ConnectionInfo *ConnectionInfo
|
||||||
Pair *RequestResponsePair
|
Pair *RequestResponsePair
|
||||||
@ -95,6 +105,7 @@ type MizuEntry struct {
|
|||||||
|
|
||||||
type BaseEntryDetails struct {
|
type BaseEntryDetails struct {
|
||||||
Id string `json:"id,omitempty"`
|
Id string `json:"id,omitempty"`
|
||||||
|
Protocol Protocol `json:"protocol,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
Url string `json:"url,omitempty"`
|
||||||
RequestSenderIp string `json:"requestSenderIp,omitempty"`
|
RequestSenderIp string `json:"requestSenderIp,omitempty"`
|
||||||
Service string `json:"service,omitempty"`
|
Service string `json:"service,omitempty"`
|
||||||
|
@ -7,20 +7,30 @@ import (
|
|||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var protocol api.Protocol = api.Protocol{
|
||||||
|
Name: "amqp",
|
||||||
|
LongName: "Advanced Message Queuing Protocol",
|
||||||
|
Abbreviation: "AMQP",
|
||||||
|
BackgroundColor: "#ff6600",
|
||||||
|
ForegroundColor: "#ffffff",
|
||||||
|
FontSize: 10,
|
||||||
|
ReferenceLink: "https://www.rabbitmq.com/amqp-0-9-1-reference.html",
|
||||||
|
OutboundPorts: []string{"5671", "5672"},
|
||||||
|
InboundPorts: []string{},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("Initializing AMQP extension.")
|
log.Println("Initializing AMQP extension...")
|
||||||
}
|
}
|
||||||
|
|
||||||
type dissecting string
|
type dissecting string
|
||||||
|
|
||||||
func (d dissecting) Register(extension *api.Extension) {
|
func (d dissecting) Register(extension *api.Extension) {
|
||||||
extension.Name = "amqp"
|
extension.Protocol = protocol
|
||||||
extension.OutboundPorts = []string{"5671", "5672"}
|
|
||||||
extension.InboundPorts = []string{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Ping() {
|
func (d dissecting) Ping() {
|
||||||
log.Printf("pong AMQP\n")
|
log.Printf("pong %s\n", protocol.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
||||||
|
@ -4,13 +4,14 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/romana/rlog"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/romana/rlog"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ func handleHTTP2Stream(grpcAssembler *GrpcAssembler, tcpID *api.TcpID, emitter a
|
|||||||
}
|
}
|
||||||
|
|
||||||
if item != nil {
|
if item != nil {
|
||||||
|
item.Protocol = http2Protocol
|
||||||
emitter.Emit(item)
|
emitter.Emit(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,30 @@ import (
|
|||||||
var requestCounter uint
|
var requestCounter uint
|
||||||
var responseCounter uint
|
var responseCounter uint
|
||||||
|
|
||||||
|
var protocol api.Protocol = api.Protocol{
|
||||||
|
Name: "http",
|
||||||
|
LongName: "Hypertext Transfer Protocol -- HTTP/1.0",
|
||||||
|
Abbreviation: "HTTP",
|
||||||
|
BackgroundColor: "#205cf5",
|
||||||
|
ForegroundColor: "#ffffff",
|
||||||
|
FontSize: 10,
|
||||||
|
ReferenceLink: "https://www.ietf.org/rfc/rfc1945.txt",
|
||||||
|
OutboundPorts: []string{"80", "8080", "443"},
|
||||||
|
InboundPorts: []string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
var http2Protocol api.Protocol = api.Protocol{
|
||||||
|
Name: "http",
|
||||||
|
LongName: "Hypertext Transfer Protocol Version 2 (HTTP/2)",
|
||||||
|
Abbreviation: "HTTP/2",
|
||||||
|
BackgroundColor: "#244c5a",
|
||||||
|
ForegroundColor: "#ffffff",
|
||||||
|
FontSize: 10,
|
||||||
|
ReferenceLink: "https://datatracker.ietf.org/doc/html/rfc7540",
|
||||||
|
OutboundPorts: []string{"80", "8080", "443"},
|
||||||
|
InboundPorts: []string{},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("Initializing HTTP extension.")
|
log.Println("Initializing HTTP extension.")
|
||||||
requestCounter = 0
|
requestCounter = 0
|
||||||
@ -23,16 +47,12 @@ func init() {
|
|||||||
|
|
||||||
type dissecting string
|
type dissecting string
|
||||||
|
|
||||||
const ExtensionName = "http"
|
|
||||||
|
|
||||||
func (d dissecting) Register(extension *api.Extension) {
|
func (d dissecting) Register(extension *api.Extension) {
|
||||||
extension.Name = ExtensionName
|
extension.Protocol = protocol
|
||||||
extension.OutboundPorts = []string{"80", "8080", "443"}
|
|
||||||
extension.InboundPorts = []string{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Ping() {
|
func (d dissecting) Ping() {
|
||||||
log.Printf("pong HTTP\n")
|
log.Printf("pong %s\n", protocol.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
||||||
@ -114,6 +134,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
|||||||
func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails {
|
func (d dissecting) Summarize(entry *api.MizuEntry) *api.BaseEntryDetails {
|
||||||
return &api.BaseEntryDetails{
|
return &api.BaseEntryDetails{
|
||||||
Id: entry.EntryId,
|
Id: entry.EntryId,
|
||||||
|
Protocol: protocol,
|
||||||
Url: entry.Url,
|
Url: entry.Url,
|
||||||
RequestSenderIp: entry.RequestSenderIp,
|
RequestSenderIp: entry.RequestSenderIp,
|
||||||
Service: entry.Service,
|
Service: entry.Service,
|
||||||
|
@ -86,7 +86,7 @@ func (matcher *requestResponseMatcher) registerResponse(ident string, response *
|
|||||||
|
|
||||||
func (matcher *requestResponseMatcher) preparePair(requestHTTPMessage *api.GenericMessage, responseHTTPMessage *api.GenericMessage) *api.OutputChannelItem {
|
func (matcher *requestResponseMatcher) preparePair(requestHTTPMessage *api.GenericMessage, responseHTTPMessage *api.GenericMessage) *api.OutputChannelItem {
|
||||||
return &api.OutputChannelItem{
|
return &api.OutputChannelItem{
|
||||||
Protocol: ExtensionName,
|
Protocol: protocol,
|
||||||
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
|
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
|
||||||
ConnectionInfo: nil,
|
ConnectionInfo: nil,
|
||||||
Pair: &api.RequestResponsePair{
|
Pair: &api.RequestResponsePair{
|
||||||
|
@ -7,20 +7,30 @@ import (
|
|||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var protocol api.Protocol = api.Protocol{
|
||||||
|
Name: "kafka",
|
||||||
|
LongName: "Apache Kafka Protocol",
|
||||||
|
Abbreviation: "KAFKA",
|
||||||
|
BackgroundColor: "#000000",
|
||||||
|
ForegroundColor: "#ffffff",
|
||||||
|
FontSize: 10,
|
||||||
|
ReferenceLink: "https://kafka.apache.org/protocol",
|
||||||
|
OutboundPorts: []string{"9092"},
|
||||||
|
InboundPorts: []string{},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("Initializing Kafka extension.")
|
log.Println("Initializing Kafka extension...")
|
||||||
}
|
}
|
||||||
|
|
||||||
type dissecting string
|
type dissecting string
|
||||||
|
|
||||||
func (d dissecting) Register(extension *api.Extension) {
|
func (d dissecting) Register(extension *api.Extension) {
|
||||||
extension.Name = "kafka"
|
extension.Protocol = protocol
|
||||||
extension.OutboundPorts = []string{"9092"}
|
|
||||||
extension.InboundPorts = []string{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Ping() {
|
func (d dissecting) Ping() {
|
||||||
log.Printf("pong Kafka\n")
|
log.Printf("pong %s\n", protocol.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, emitter api.Emitter) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from './style/HarEntry.module.sass';
|
import styles from './style/HarEntry.module.sass';
|
||||||
import StatusCode, {getClassification, StatusCodeClassification} from "./StatusCode";
|
import StatusCode, {getClassification, StatusCodeClassification} from "./StatusCode";
|
||||||
|
import Protocol, {ProtocolInterface} from "./Protocol"
|
||||||
import {EndpointPath} from "./EndpointPath";
|
import {EndpointPath} from "./EndpointPath";
|
||||||
import ingoingIconSuccess from "./assets/ingoing-traffic-success.svg"
|
import ingoingIconSuccess from "./assets/ingoing-traffic-success.svg"
|
||||||
import ingoingIconFailure from "./assets/ingoing-traffic-failure.svg"
|
import ingoingIconFailure from "./assets/ingoing-traffic-failure.svg"
|
||||||
@ -10,6 +11,7 @@ import outgoingIconFailure from "./assets/outgoing-traffic-failure.svg"
|
|||||||
import outgoingIconNeutral from "./assets/outgoing-traffic-neutral.svg"
|
import outgoingIconNeutral from "./assets/outgoing-traffic-neutral.svg"
|
||||||
|
|
||||||
interface HAREntry {
|
interface HAREntry {
|
||||||
|
protocol: ProtocolInterface,
|
||||||
method?: string,
|
method?: string,
|
||||||
path: string,
|
path: string,
|
||||||
service: string,
|
service: string,
|
||||||
@ -64,7 +66,14 @@ export const HarEntry: React.FC<HAREntryProps> = ({entry, setFocusedEntryId, isS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <>
|
return <>
|
||||||
<div id={entry.id} className={`${styles.row} ${isSelected ? styles.rowSelected : backgroundColor}`} onClick={() => setFocusedEntryId(entry.id)}>
|
<div
|
||||||
|
id={entry.id}
|
||||||
|
className={`${styles.row}
|
||||||
|
${isSelected ? styles.rowSelected : backgroundColor}`}
|
||||||
|
onClick={() => setFocusedEntryId(entry.id)}
|
||||||
|
style={{border: isSelected ? `1px ${entry.protocol.background_color} solid` : "1px transparent solid"}}
|
||||||
|
>
|
||||||
|
<Protocol protocol={entry.protocol}/>
|
||||||
{entry.statusCode && <div>
|
{entry.statusCode && <div>
|
||||||
<StatusCode statusCode={entry.statusCode}/>
|
<StatusCode statusCode={entry.statusCode}/>
|
||||||
</div>}
|
</div>}
|
||||||
|
37
ui/src/components/Protocol.tsx
Normal file
37
ui/src/components/Protocol.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import React from "react";
|
||||||
|
import internal from "stream";
|
||||||
|
import styles from './style/Protocol.module.sass';
|
||||||
|
|
||||||
|
export interface ProtocolInterface {
|
||||||
|
name: string,
|
||||||
|
long_name: string,
|
||||||
|
abbreviation: string,
|
||||||
|
background_color: string,
|
||||||
|
foreground_color: string,
|
||||||
|
font_size: number,
|
||||||
|
reference_link: string,
|
||||||
|
outbound_ports: string[],
|
||||||
|
inbound_ports: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProtocolProps {
|
||||||
|
protocol: ProtocolInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
const Protocol: React.FC<ProtocolProps> = ({protocol}) => {
|
||||||
|
return <a target="_blank" rel="noopener noreferrer" href={protocol.reference_link}>
|
||||||
|
<span
|
||||||
|
className={`${styles.base}`}
|
||||||
|
style={{
|
||||||
|
backgroundColor: protocol.background_color,
|
||||||
|
color: protocol.foreground_color,
|
||||||
|
fontSize: protocol.font_size,
|
||||||
|
}}
|
||||||
|
title={protocol.long_name}
|
||||||
|
>
|
||||||
|
{protocol.abbreviation}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Protocol;
|
@ -19,17 +19,17 @@
|
|||||||
|
|
||||||
.rowSelected
|
.rowSelected
|
||||||
border: 1px $blue-color solid
|
border: 1px $blue-color solid
|
||||||
border-left: 5px $blue-color solid
|
// border-left: 5px $blue-color solid
|
||||||
margin-left: 10px
|
margin-left: 10px
|
||||||
margin-right: 3px
|
margin-right: 3px
|
||||||
|
|
||||||
.ruleSuccessRow
|
.ruleSuccessRow
|
||||||
border: 1px $success-color solid
|
border: 1px $success-color solid
|
||||||
border-left: 5px $success-color solid
|
// border-left: 5px $success-color solid
|
||||||
|
|
||||||
.ruleFailureRow
|
.ruleFailureRow
|
||||||
border: 1px $failure-color solid
|
border: 1px $failure-color solid
|
||||||
border-left: 5px $failure-color solid
|
// border-left: 5px $failure-color solid
|
||||||
|
|
||||||
.service
|
.service
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
|
20
ui/src/components/style/Protocol.module.sass
Normal file
20
ui/src/components/style/Protocol.module.sass
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
@import 'variables.module'
|
||||||
|
|
||||||
|
.base
|
||||||
|
// border-radius: 4px
|
||||||
|
border-radius: 4px 0 0 4px
|
||||||
|
width: 22px
|
||||||
|
height: 48px
|
||||||
|
font-size: 10px
|
||||||
|
display: inline-block
|
||||||
|
text-align: center
|
||||||
|
line-height: 22px
|
||||||
|
font-weight: 600
|
||||||
|
writing-mode: vertical-lr;
|
||||||
|
// transform: rotate(-180deg);
|
||||||
|
text-orientation: upright;
|
||||||
|
// letter-spacing: 2px;
|
||||||
|
background-color: #000
|
||||||
|
color: #fff
|
||||||
|
margin-left: -8px;
|
||||||
|
margin-bottom: -4px;
|
@ -9,6 +9,7 @@
|
|||||||
text-align: center
|
text-align: center
|
||||||
line-height: 22px
|
line-height: 22px
|
||||||
font-weight: 600
|
font-weight: 600
|
||||||
|
margin-left: 8px
|
||||||
|
|
||||||
.neutral
|
.neutral
|
||||||
background: gray
|
background: gray
|
||||||
@ -20,4 +21,4 @@
|
|||||||
|
|
||||||
.failure
|
.failure
|
||||||
background: $failure-color
|
background: $failure-color
|
||||||
color: white
|
color: white
|
||||||
|
Loading…
Reference in New Issue
Block a user