1
0
mirror of https://github.com/moparisthebest/sslh synced 2024-11-30 21:12:15 -05:00

Merge pull request #51 from cernekee/adb

Add builtin handler for Android Debug Bridge (ADB) protocol
This commit is contained in:
yrutschle 2015-06-10 09:26:55 +02:00
commit 66f85dc608

18
probe.c
View File

@ -33,6 +33,7 @@ static int is_tinc_protocol(const char *p, int len, struct proto*);
static int is_xmpp_protocol(const char *p, int len, struct proto*); static int is_xmpp_protocol(const char *p, int len, struct proto*);
static int is_http_protocol(const char *p, int len, struct proto*); static int is_http_protocol(const char *p, int len, struct proto*);
static int is_tls_protocol(const char *p, int len, struct proto*); static int is_tls_protocol(const char *p, int len, struct proto*);
static int is_adb_protocol(const char *p, int len, struct proto*);
static int is_true(const char *p, int len, struct proto* proto) { return 1; } static int is_true(const char *p, int len, struct proto* proto) { return 1; }
/* Table of protocols that have a built-in probe /* Table of protocols that have a built-in probe
@ -46,6 +47,7 @@ static struct proto builtins[] = {
{ "http", NULL, NULL, is_http_protocol }, { "http", NULL, NULL, is_http_protocol },
{ "ssl", NULL, NULL, is_tls_protocol }, { "ssl", NULL, NULL, is_tls_protocol },
{ "tls", NULL, NULL, is_tls_protocol }, { "tls", NULL, NULL, is_tls_protocol },
{ "adb", NULL, NULL, is_adb_protocol },
{ "anyprot", NULL, NULL, is_true } { "anyprot", NULL, NULL, is_true }
}; };
@ -224,6 +226,22 @@ static int is_tls_protocol(const char *p, int len, struct proto *proto)
return p[0] == 0x16 && p[1] == 0x03 && ( p[2] >= 0 && p[2] <= 0x03); return p[0] == 0x16 && p[1] == 0x03 && ( p[2] >= 0 && p[2] <= 0x03);
} }
static int is_adb_protocol(const char *p, int len, struct proto *proto)
{
if (len < 30)
return PROBE_AGAIN;
/* The initial ADB host->device packet has a command type of CNXN, and a
* data payload starting with "host:". Note that current versions of the
* client hardcode "host::" (with empty serialno and banner fields) but
* other clients may populate those fields.
*
* We aren't checking amessage.data_length, under the assumption that
* a packet >= 30 bytes long will have "something" in the payload field.
*/
return !memcmp(&p[0], "CNXN", 4) && !memcmp(&p[24], "host:", 5);
}
static int regex_probe(const char *p, int len, struct proto *proto) static int regex_probe(const char *p, int len, struct proto *proto)
{ {
regex_t **probe = proto->data; regex_t **probe = proto->data;