Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example DNS parser #163

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Example DNS parser #163

wants to merge 2 commits into from

Conversation

glaslos
Copy link
Member

@glaslos glaslos commented Jun 1, 2024

No description provided.

Comment on lines +32 to +34
- match: udp dst port 53
type: conn_handler
target: dns
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule to handle all UDP traffic on port 53 with the new DNS handler

Comment on lines +177 to +185
con, err := net.DialUDP("udp", dstAddr, srcAddr)
if err != nil {
g.Logger.Error("failed to dial UDP connection", producer.ErrAttr(err))
return
}
defer con.Close()
_, err = con.Write(response)
if err != nil {
g.Logger.Error("failed to send UDP response", producer.ErrAttr(err))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to create a new outgoing connection. If we send through the UDP listener, we will have the wrong source port.

@@ -15,13 +15,16 @@ import (

type TCPHandlerFunc func(ctx context.Context, conn net.Conn, md connection.Metadata) error

type UDPHandlerFunc func(ctx context.Context, srcAddr, dstAddr *net.UDPAddr, data []byte, md connection.Metadata) error
type UDPHandlerFunc func(ctx context.Context, srcAddr, dstAddr *net.UDPAddr, data []byte, md connection.Metadata) ([]byte, error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UDP handlers now return a byte slice as response to the client.

last int64
}

var throttle = map[string]throttleState{}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to become a UDP amplification service.

Name: name,
Type: q.Type,
Class: q.Class,
TTL: 453,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make this not fingerprintable


switch q.Type {
case dnsmessage.TypeA:
answer.Body = &dnsmessage.AResource{A: [4]byte{127, 0, 0, 1}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually do a DNS lookup instead of localhost? If we resolve anything, it's a dead giveaway.

return nil, fmt.Errorf("failed to pack DNS response: %w", err)
}

if err := h.ProduceUDP("dns", srcAddr, dstAddr, md, data[:len(data)%1024], nil); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to also report the structured message instead of just the raw payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant