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

libbpf-tools: Add sslsniff #4706

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

libbpf-tools: Add sslsniff #4706

wants to merge 4 commits into from

Conversation

yunwei37
Copy link
Contributor

@yunwei37 yunwei37 commented Aug 15, 2023

Description:

This PR aims to transition the sslsniff tool from the tools directory to the libbpf-tools collection.

Reference:

Testing:

Setup:

  1. In one terminal, initiate sslsniff by running:
sudo ./sslsniff
  1. In a separate terminal, execute:
$ curl https://example.com
<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    .... { rest of curl data }
<body>
<div>
    .... { rest of curl data }
</div>
</body>
</html>

Output:

Upon running the curl command, sslsniff is expected to display the following output:

READ/RECV    0.132786160        curl             47458   1256  
----- DATA -----
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        
    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>    
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>

----- END DATA -----

Note: The displayed HTML content might vary based on the fetched page from example.com.

Test for latency and handshake

$ sudo ./sslsniff -l --handshake
OpenSSL path: /lib/x86_64-linux-gnu/libssl.so.3
GnuTLS path: /lib/x86_64-linux-gnu/libgnutls.so.30
NSS path: /lib/x86_64-linux-gnu/libnspr4.so
FUNC         TIME(s)            COMM             PID     LEN     LAT(ms)
HANDSHAKE    0.000000000        curl             6460    1      1.384  WRITE/SEND   0.000115400        curl             6460    24     0.014 

Test for hexdump

$ sudo ./sslsniff --hexdump
WRITE/SEND   0.000000000        curl             16104   24    
----- DATA -----
505249202a20485454502f322e300d0a
0d0a534d0d0a0d0a
----- END DATA -----

WRITE/SEND   0.000079802        curl             16104   27    
----- DATA -----
00001204000000000000030000006400
0402000000000200000000
----- END DATA -----

Further Work:

While the basic tests validate the primary functionality, comprehensive testing is needed to ensure compatibility and stability across various environments and use-cases.

  • pass CI
  • test for more libraries and arguments
  • test with asan
  • Improve code quality

Copy link
Collaborator

@chenhengqi chenhengqi left a comment

Choose a reason for hiding this comment

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

Besides the inline comments, please:

  • Follow kernel coding style
  • Squash 4 commits into one

return true;
}

SEC("uprobe/do_handshake")
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is another uprobe/do_handshake section below, this one looks incorrect.

{},
};

static bool verbose = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make verbose a member of struct env ?

})

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a compat layer in compat.bpf.h which abstracts this percpu array out, see mountsnoop for example.

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.

2 participants