Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
c5ad8909
Commit
c5ad8909
authored
10 years ago
by
rl1987
Committed by
Nick Mathewson
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Respond with 'Command not supported' SOCKS5 reply message upon reception of unsupported request.
parent
e170205c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changes/bug12971
+5
-0
5 additions, 0 deletions
changes/bug12971
src/or/buffers.c
+20
-0
20 additions, 0 deletions
src/or/buffers.c
src/test/test_socks.c
+14
-4
14 additions, 4 deletions
src/test/test_socks.c
with
39 additions
and
4 deletions
changes/bug12971
0 → 100644
+
5
−
0
View file @
c5ad8909
o Bugfixes:
- Handle unsupported SOCKS5 requests properly by responding with
'Command not supported' reply message before closing a TCP connection
to the user. Fixes bug 12971.
This diff is collapsed.
Click to expand it.
src/or/buffers.c
+
20
−
0
View file @
c5ad8909
...
...
@@ -55,6 +55,9 @@
* forever.
*/
static
void
send_socks5_error
(
socks_request_t
*
req
,
socks5_reply_status_t
reason
);
static
int
parse_socks
(
const
char
*
data
,
size_t
datalen
,
socks_request_t
*
req
,
int
log_sockstype
,
int
safe_socks
,
ssize_t
*
drain_out
,
size_t
*
want_length_out
);
...
...
@@ -1831,6 +1834,21 @@ fetch_ext_or_command_from_evbuffer(struct evbuffer *buf, ext_or_cmd_t **out)
}
#endif
/** Create a SOCKS5 reply message with <b>reason</b> in its REP field and
* have Tor send it as error response to <b>req</b>.
*/
static
void
send_socks5_error
(
socks_request_t
*
req
,
socks5_reply_status_t
reason
)
{
req
->
replylen
=
10
;
memset
(
req
->
reply
,
0
,
10
);
req
->
reply
[
0
]
=
0x05
;
// VER field.
req
->
reply
[
1
]
=
reason
;
// REP field.
req
->
reply
[
3
]
=
0x01
;
// ATYP field.
}
/** Implementation helper to implement fetch_from_*_socks. Instead of looking
* at a buffer's contents, we look at the <b>datalen</b> bytes of data in
* <b>data</b>. Instead of removing data from the buffer, we set
...
...
@@ -1966,6 +1984,8 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
req
->
command
!=
SOCKS_COMMAND_RESOLVE
&&
req
->
command
!=
SOCKS_COMMAND_RESOLVE_PTR
)
{
/* not a connect or resolve or a resolve_ptr? we don't support it. */
send_socks5_error
(
req
,
SOCKS5_COMMAND_NOT_SUPPORTED
);
log_warn
(
LD_APP
,
"socks5: command %d not recognized. Rejecting."
,
req
->
command
);
return
-
1
;
...
...
This diff is collapsed.
Click to expand it.
src/test/test_socks.c
+
14
−
4
View file @
c5ad8909
...
...
@@ -143,23 +143,33 @@ test_socks_5_unsupported_commands(void *ptr)
ADD_DATA
(
buf
,
"
\x05\x02\x00\x01\x02\x02\x02\x01\x01\x01
"
);
tt_int_op
(
fetch_from_buf_socks
(
buf
,
socks
,
get_options
()
->
TestSocks
,
get_options
()
->
SafeSocks
),
==
,
-
1
);
/* XXX: shouldn't tor reply 'command not supported' [07]? */
tt_int_op
(
5
,
==
,
socks
->
socks_version
);
tt_int_op
(
10
,
==
,
socks
->
replylen
);
tt_int_op
(
5
,
==
,
socks
->
reply
[
0
]);
tt_int_op
(
SOCKS5_COMMAND_NOT_SUPPORTED
,
==
,
socks
->
reply
[
1
]);
tt_int_op
(
1
,
==
,
socks
->
reply
[
3
]);
buf_clear
(
buf
);
socks_request_clear
(
socks
);
/* SOCKS 5 Send unsupported UDP_ASSOCIATE [03] command */
ADD_DATA
(
buf
,
"
\x05\x0
3
\x00\x01
\x02
"
);
ADD_DATA
(
buf
,
"
\x05\x0
2
\x00\x01
"
);
tt_int_op
(
fetch_from_buf_socks
(
buf
,
socks
,
get_options
()
->
TestSocks
,
get_options
()
->
SafeSocks
),
==
,
0
);
tt_int_op
(
5
,
==
,
socks
->
socks_version
);
tt_int_op
(
2
,
==
,
socks
->
replylen
);
tt_int_op
(
5
,
==
,
socks
->
reply
[
0
]);
tt_int_op
(
2
,
==
,
socks
->
reply
[
1
]);
tt_int_op
(
0
,
==
,
socks
->
reply
[
1
]);
ADD_DATA
(
buf
,
"
\x05\x03\x00\x01\x02\x02\x02\x01\x01\x01
"
);
tt_int_op
(
fetch_from_buf_socks
(
buf
,
socks
,
get_options
()
->
TestSocks
,
get_options
()
->
SafeSocks
),
==
,
-
1
);
/* XXX: shouldn't tor reply 'command not supported' [07]? */
tt_int_op
(
5
,
==
,
socks
->
socks_version
);
tt_int_op
(
10
,
==
,
socks
->
replylen
);
tt_int_op
(
5
,
==
,
socks
->
reply
[
0
]);
tt_int_op
(
SOCKS5_COMMAND_NOT_SUPPORTED
,
==
,
socks
->
reply
[
1
]);
tt_int_op
(
1
,
==
,
socks
->
reply
[
3
]);
done:
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment