Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

HTTP Host and TLS SNI fragmentation/stuttering/fuzzing test #1522

Closed
wants to merge 8 commits into from

Conversation

joelanders
Copy link
Contributor

@joelanders joelanders commented Dec 18, 2017

Link to spec PR

l@nl2 ~/code/measurement-kit [sni_stutter] $ ./measurement_kit -n dpi_fragment -u wikipedia.org                                                                                                            
Contacting bouncer: https://bouncer.ooni.io
Using discovered collector: https://c.collector.ooni.io:443
Your public IP address: 185.52.0.143
Your country: NL
Your ISP identifier: AS198203
5%: geoip lookup
10%: open report
starting dpi_fragment
resolved wikipedia.org to 91.198.174.192, now doing 4 http(s) requests...
fragmented https response length: 1174
unfragmented https response length: 1174
fragmented http response length: 500
unfragmented http response length: 500
95%: ending the test
Overall data usage (bytes): 1286 down - 413 up
100%: test complete

So instead of trying to hook things at the libevent level, which even Simone says is Hard To Do (:)), I'm doing a good ol' blocking socket(); connect(); select(); read(); write(); loop in my own thread. I'm telling OpenSSL to talk to some buffers instead of the socket directly, and I'm taking care of read/writing them to the socket (with the sleep() trick around the plaintext hostname).

auto aread = std::make_shared<std::string>();
auto awrite = std::make_shared<std::string>();

SSL_CTX* ctx = SSL_CTX_new(SSLv23_method()); //XXX don't ignore errors
Copy link
Member

Choose a reason for hiding this comment

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

SSLv23_method() cannot fail, IIRC. It should return a pointer to a statically allocated struct.

return *aread; //XXX probably raise exception
}

if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

If think you can ask OpenSSL to connect on your behalf


void dpi_fragment(Settings options, Callback<SharedPtr<report::Entry>> callback,
SharedPtr<Reactor> reactor, SharedPtr<Logger> logger) {
reactor->call_in_thread(logger, [=]() {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to do [callback = std::move(callback)]. This is C++14 and should guarantee that the thread uniquely owns the callback. I remember not doing that was leading to weird behavior sometimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

logger->info("unfragmented https response length: %d", unfragmented_https.length());
logger->info("fragmented http response length: %d", fragmented_http.length());
logger->info("unfragmented http response length: %d", unfragmented_http.length());
callback(entry);
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to do

reactor->call_soon([entry = std::move(entry), callback = std::move(callback)]() {
    callback(entry);
});

so that the callback is called from the I/O thread loop, which is what usually happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

int main(std::list<Callback<BaseTest &>> &initializers, int argc, char **argv) {
mk::nettests::DpiFragmentTest test;
int ch;
while ((ch = getopt(argc, argv, "B:f:")) != -1) {
Copy link
Member

Choose a reason for hiding this comment

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

You should clean the options string here

@joelanders
Copy link
Contributor Author

l@nl2 ~/code/measurement-kit [sni_stutter] $ ./measurement_kit -n dpi_fragment -u wikipedia.org                                                                                                            
Contacting bouncer: https://bouncer.ooni.io
Using discovered collector: https://c.collector.ooni.io:443
Your public IP address: 185.52.0.143
Your country: NL
Your ISP identifier: AS198203
5%: geoip lookup
10%: open report
starting dpi_fragment
resolved wikipedia.org to 91.198.174.192, now doing 4 http(s) requests...
fragmented https response length: 1174
unfragmented https response length: 1174
fragmented http response length: 500
unfragmented http response length: 500
95%: ending the test
Overall data usage (bytes): 1286 down - 413 up
100%: test complete

@joelanders joelanders changed the title [WIP] HTTP Host and TLS SNI fragmentation/stuttering/fuzzing test HTTP Host and TLS SNI fragmentation/stuttering/fuzzing test Feb 8, 2018
@bassosimone
Copy link
Member

Closing as stated in ooni/spec#103 (comment).

@bassosimone bassosimone deleted the sni_stutter branch August 28, 2019 10:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants