Skip to content

Commit

Permalink
Add disable socks proxy protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Oct 18, 2023
1 parent e96cd97 commit bcd4478
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 44 additions & 1 deletion proxy/include/proxy/proxy_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ namespace proxy {
// http doc 目录, 用于伪装成web站点.
std::string doc_directory_;

// 禁用未加密 http 服务.
// 禁用 http 服务.
bool disable_http_{ false };

// 禁用 socks proxy 服务.
bool disable_socks_{ false };
};

// proxy server 虚基类, 任何 proxy server 的实现, 必须基于这个基类.
Expand Down Expand Up @@ -333,6 +336,14 @@ namespace proxy {

if (socks_version == SOCKS_VERSION_5)
{
if (m_option.disable_socks_)
{
LOG_DBG << "socks protocol"
", connection id: " << m_connection_id
<< ", Forbidden";
co_return;
}

LOG_DBG << "connection id: " << m_connection_id
<< ", socks version: " << socks_version;

Expand All @@ -341,6 +352,14 @@ namespace proxy {
}
if (socks_version == SOCKS_VERSION_4)
{
if (m_option.disable_socks_)
{
LOG_DBG << "socks protocol"
", connection id: " << m_connection_id
<< ", Forbidden";
co_return;
}

LOG_DBG << "connection id: " << m_connection_id
<< ", socks version: " << socks_version;

Expand All @@ -349,6 +368,14 @@ namespace proxy {
}
if (socks_version == 'G')
{
if (m_option.disable_http_)
{
LOG_DBG << "http protocol"
", connection id: " << m_connection_id
<< ", Forbidden";
co_return;
}

auto ret = co_await http_proxy_get();
if (!ret)
{
Expand All @@ -361,6 +388,14 @@ namespace proxy {
}
else if (socks_version == 'C')
{
if (m_option.disable_http_)
{
LOG_DBG << "http protocol"
", connection id: " << m_connection_id
<< ", Forbidden";
co_return;
}

auto ret = co_await http_proxy_connect();
if (!ret)
{
Expand Down Expand Up @@ -2911,6 +2946,14 @@ Content-Length: 0
// plain socks4/5 protocol.
if (detect[0] == 0x05 || detect[0] == 0x04)
{
if (m_option.disable_socks_)
{
LOG_DBG << "socks protocol"
", connection id: " << connection_id
<< ", Forbidden";
continue;
}

LOG_DBG << "socks protocol:"
" connection id: " << connection_id;

Expand Down
4 changes: 4 additions & 0 deletions server/proxy_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ std::string socks_listen;
std::string doc_directory;
std::string log_directory;
bool disable_http = false;
bool disable_socks = false;
bool disable_logs;
bool reuse_port = false;

Expand Down Expand Up @@ -184,6 +185,8 @@ start_proxy_server(net::io_context& ioc, server_ptr& server)
opt.ssl_sni_ = ssl_sni;

opt.disable_http_ = disable_http;
opt.disable_socks_ = disable_socks;

opt.reuse_port_ = reuse_port;

opt.doc_directory_ = doc_directory;
Expand Down Expand Up @@ -332,6 +335,7 @@ int main(int argc, char** argv)
("logs_path", po::value<std::string>(&log_directory)->value_name(""), "Logs dirctory.")
("disable_logs", po::value<bool>(&disable_logs)->value_name(""), "Disable logs.")
("disable_http", po::value<bool>(&disable_http)->value_name("")->default_value(false), "Disable http protocol.")
("disable_socks", po::value<bool>(&disable_socks)->value_name("")->default_value(false), "Disable socks proxy protocol.")
;

// 解析命令行.
Expand Down

0 comments on commit bcd4478

Please sign in to comment.