From a8e98c18392496fc86bcab2c13b4f713d5c88de3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 15 Dec 2017 23:48:20 +0100 Subject: [PATCH 1/4] stratum: ipset function to block botnets can be (manually) used, if needed, in client_authorize --- stratum/client.h | 1 + stratum/client_core.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/stratum/client.h b/stratum/client.h index 661c0cbc3..f2d150dc9 100644 --- a/stratum/client.h +++ b/stratum/client.h @@ -122,6 +122,7 @@ void get_random_key(char *key); void client_sort(); void client_block_ip(YAAMP_CLIENT *client, const char *reason); +void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name); bool client_reset_multialgo(YAAMP_CLIENT *client, bool first); bool client_initialize_multialgo(YAAMP_CLIENT *client); diff --git a/stratum/client_core.cpp b/stratum/client_core.cpp index 84521ae73..c7732a7cc 100644 --- a/stratum/client_core.cpp +++ b/stratum/client_core.cpp @@ -125,11 +125,17 @@ int client_ask(YAAMP_CLIENT *client, const char *method, const char *format, ... void client_block_ip(YAAMP_CLIENT *client, const char *reason) { char buffer[1024]; - sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port); int s = system(buffer); + stratumlog("%s: %s blocked (%s)\n", g_stratum_algo, client->sock->ip, reason); +} - stratumlog("%s %s blocked (%s)\n", client->sock->ip, client->username, reason); +void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name) +{ + char buffer[1024]; + sprintf(buffer, "ipset -q -A %s %s", ipset_name, client->sock->ip); + int s = system(buffer); + stratumlog("%s: %s blocked via ipset %s\n", g_stratum_algo, client->sock->ip, ipset_name); } bool client_reset_multialgo(YAAMP_CLIENT *client, bool first) From 35bfd756cc1608c9cb4d062db19c4fc5d7fe26f1 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 16 Dec 2017 12:24:49 +0100 Subject: [PATCH 2/4] New admin botnets view to list users with many ips fast, global view (all algos) to link/check wallets --- web/yaamp/core/functions/admin.php | 1 + web/yaamp/modules/site/SiteController.php | 9 ++ web/yaamp/modules/site/botnets.php | 108 ++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 web/yaamp/modules/site/botnets.php diff --git a/web/yaamp/core/functions/admin.php b/web/yaamp/core/functions/admin.php index 2ae8c05b6..baa65c511 100644 --- a/web/yaamp/core/functions/admin.php +++ b/web/yaamp/core/functions/admin.php @@ -6,6 +6,7 @@ function getAdminSideBarLinks() { $links = <<Exchanges  +Botnets  Users  Workers  Version  diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index 41d16d676..df0a71902 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -361,6 +361,15 @@ public function actionTriggerAdd() ///////////////////////////////////////////////// + public function actionBotnets() + { + if(!$this->admin) return; + + $this->render('botnets'); + } + + ///////////////////////////////////////////////// + public function actionIndex() { if(isset($_GET['address'])) diff --git a/web/yaamp/modules/site/botnets.php b/web/yaamp/modules/site/botnets.php new file mode 100644 index 000000000..b2c9c05c9 --- /dev/null +++ b/web/yaamp/modules/site/botnets.php @@ -0,0 +1,108 @@ +pageTitle = 'Botnets'; + +echo getAdminSideBarLinks().'

'; + +////////////////////////////////////////////////////////////////////////////////////// + +JavascriptFile("/yaamp/ui/js/jquery.metadata.js"); +JavascriptFile("/yaamp/ui/js/jquery.tablesorter.widgets.js"); + +echo << +.red { color: darkred; } +table.dataGrid { max-width: 99.5%; } +table.dataGrid a.red { color: darkred; } + +end; + +showTableSorter('maintable', "{ + tableClass: 'dataGrid', + textExtraction: { + 4: function(node, table, n) { return $(node).attr('data'); } + }, + widgets: ['zebra','Storage','saveSort'], + widgetOptions: { + saveSort: true + } +}"); + +echo << + + +Coin +Algo +Address +Time +PID +IPs +Workers +Version +Actions + + +end; + +$botnets = dbolist("SELECT userid, algo, pid, max(time) AS time, count(userid) AS workers, count(DISTINCT ip) AS ips, max(version) AS version ". + " FROM workers GROUP BY userid, algo, pid HAVING ips > 10 ORDER BY ips DESC" +); + +if(!empty($botnets)) +foreach($botnets as $botnet) +{ + if (!$botnet['userid']) continue; + + $user = getdbo('db_accounts', $botnet['userid']); + if (!$user) continue; + + $coin = getdbo('db_coins', $user->coinid); + if (!$coin) continue; + + $coinsym = $coin->symbol; + $coinimg = CHtml::image($coin->image, $coin->symbol, array('width'=>'16')); + $coinlink = CHtml::link($coin->name, '/site/coin?id='.$coin->id); + + $d = datetoa2($botnet['time']); + + echo ''; + + echo ''.$coinimg.''; + echo ''.$coinsym.''; + echo ''.$botnet['algo'].''; + echo ''.CHtml::link($user->username, '/?address='.$user->username).''; + echo ''.$d.''; + echo ''.$botnet['pid'].''; + echo ''.$botnet['ips'].''; + echo ''.$botnet['workers'].''; + echo ''.$botnet['version'].''; + + echo ''; + + if ($user->logtraffic) + echo 'unwatch '; + else + echo 'watch '; + + if ($user->is_locked) + echo 'unblock '; + else + echo 'block '; + + echo 'BAN'; + + echo ''; + + echo ''; +} + +echo ''; + +echo ''; +if(empty($botnets)) { + echo ''."No botnets detected".''; +} +echo ''; + +echo '
'; From ba7873e9f298192502f8d7eb2bd13eddfa22f7b5 Mon Sep 17 00:00:00 2001 From: AltMinerNet <31431085+AltMinerNet@users.noreply.github.com> Date: Sat, 16 Dec 2017 12:51:59 +0100 Subject: [PATCH 3/4] mining html fix (#195) coin reward html end tag correction. --- web/yaamp/modules/site/results/mining_results.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/modules/site/results/mining_results.php b/web/yaamp/modules/site/results/mining_results.php index ee3963570..9ea04e81f 100644 --- a/web/yaamp/modules/site/results/mining_results.php +++ b/web/yaamp/modules/site/results/mining_results.php @@ -154,7 +154,7 @@ function WriteBoxHeader($title) } else { echo "$name ($coin->algo)"; } - echo "$reward $coin->symbol_show"; + echo "$reward $coin->symbol_show"; $title = "POW $coin->difficulty"; if($coin->rpcencoding == 'POS') From 39d123a071038b7177e13485cb8923ec8ce8966f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 17 Dec 2017 07:25:25 +0100 Subject: [PATCH 4/4] stratum: reduce client algo & socket struct size to reduce a bit the memory usage... require a make clean! + prevent null/local ips from bans. --- stratum/client.cpp | 2 +- stratum/client.h | 4 ++-- stratum/client_core.cpp | 10 +++++++++- stratum/socket.cpp | 2 +- stratum/socket.h | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 4281737ee..223763cbc 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -442,7 +442,7 @@ bool client_auth_by_workers(YAAMP_CLIENT *client) // source = new YAAMP_SOURCE; // memset(source, 0, sizeof(YAAMP_SOURCE)); // -// strncpy(source->ip, client->sock->ip, 1024); +// strncpy(source->ip, client->sock->ip, 64); // source->speed = 1; // // g_list_source.AddTail(source); diff --git a/stratum/client.h b/stratum/client.h index f2d150dc9..c58260b04 100644 --- a/stratum/client.h +++ b/stratum/client.h @@ -5,12 +5,12 @@ // int count; // double speed; // -// char ip[1024]; +// char ip[64]; //}; struct YAAMP_ALGO { - char name[1024]; + char name[64]; YAAMP_HASH_FUNCTION hash_function; double diff_multiplier; diff --git a/stratum/client_core.cpp b/stratum/client_core.cpp index c7732a7cc..08f4098ea 100644 --- a/stratum/client_core.cpp +++ b/stratum/client_core.cpp @@ -126,6 +126,10 @@ void client_block_ip(YAAMP_CLIENT *client, const char *reason) { char buffer[1024]; sprintf(buffer, "iptables -A INPUT -s %s -p tcp --dport %d -j REJECT", client->sock->ip, g_tcp_port); + if(strcmp("0.0.0.0", client->sock->ip) == 0) return; + if(strstr(client->sock->ip, "192.168.")) return; + if(strstr(client->sock->ip, "127.0.0.")) return; + int s = system(buffer); stratumlog("%s: %s blocked (%s)\n", g_stratum_algo, client->sock->ip, reason); } @@ -134,8 +138,12 @@ void client_block_ipset(YAAMP_CLIENT *client, const char *ipset_name) { char buffer[1024]; sprintf(buffer, "ipset -q -A %s %s", ipset_name, client->sock->ip); + if(strcmp("0.0.0.0", client->sock->ip) == 0) return; + if(strstr(client->sock->ip, "192.168.")) return; + if(strstr(client->sock->ip, "127.0.0.")) return; + int s = system(buffer); - stratumlog("%s: %s blocked via ipset %s\n", g_stratum_algo, client->sock->ip, ipset_name); + stratumlog("%s: %s blocked via ipset %s %s\n", g_stratum_algo, client->sock->ip, ipset_name, client->username); } bool client_reset_multialgo(YAAMP_CLIENT *client, bool first) diff --git a/stratum/socket.cpp b/stratum/socket.cpp index 107b0ac08..b708f96ee 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -24,7 +24,7 @@ YAAMP_SOCKET *socket_initialize(int sock) memset(&name, 0, len); int res = getpeername(s->sock, (struct sockaddr *)&name, &len); - inet_ntop(AF_INET, &name.sin_addr, s->ip, 1024); + inet_ntop(AF_INET, &name.sin_addr, s->ip, 64); res = getsockname(s->sock, (struct sockaddr *)&name, &len); s->port = ntohs(name.sin_port); diff --git a/stratum/socket.h b/stratum/socket.h index 75a04219d..c169e3393 100644 --- a/stratum/socket.h +++ b/stratum/socket.h @@ -3,7 +3,7 @@ struct YAAMP_SOCKET { - char ip[1024]; + char ip[64]; int port; // pthread_mutex_t mutex;