-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add root/admin user warning #693
Open
NoahvdAa
wants to merge
4
commits into
PaperMC:master
Choose a base branch
from
NoahvdAa:feature/root-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
BungeeCord-Patches/0062-Add-root-admin-user-detection.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
From 763d9ab434a3fcf6dcf0ebd2218e55cbb22333e2 Mon Sep 17 00:00:00 2001 | ||
From: Noah van der Aa <[email protected]> | ||
Date: Thu, 30 Sep 2021 16:59:18 +0200 | ||
Subject: [PATCH] Add root/admin user detection | ||
|
||
This patch detects whether or not the server is currently executing as a privileged user and spits out a warning. | ||
The warning serves as a sort-of PSA for newer server admins who don't understand the risks of running as root. | ||
We've seen plenty of bad/malicious plugins hit markets, and there's been a few close-calls with exploits in the past. | ||
Hopefully this helps mitigate some potential damage to servers, even if it is just a warning. | ||
|
||
Co-authored-by: egg82 <[email protected]> | ||
|
||
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/utils/ServerEnvironment.java b/api/src/main/java/io/github/waterfallmc/waterfall/utils/ServerEnvironment.java | ||
new file mode 100644 | ||
index 00000000..1ec9fe05 | ||
--- /dev/null | ||
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/utils/ServerEnvironment.java | ||
@@ -0,0 +1,34 @@ | ||
+package io.github.waterfallmc.waterfall.utils; | ||
+ | ||
+import java.io.BufferedReader; | ||
+import java.io.IOException; | ||
+import java.io.InputStreamReader; | ||
+ | ||
+public class ServerEnvironment { | ||
+ private static final boolean RUNNING_AS_ROOT_OR_ADMIN; | ||
+ | ||
+ static { | ||
+ boolean isWindows = System.getProperty("os.name").startsWith("Windows"); | ||
+ boolean isAdmin = false; | ||
+ String[] command = isWindows ? new String[]{"reg", "query", "reg query \"HKU\\S-1-5-19\"" } : new String[]{"id", "-u" }; | ||
+ | ||
+ try { | ||
+ Process process = new ProcessBuilder(command).start(); | ||
+ process.waitFor(); | ||
+ if (isWindows) { | ||
+ isAdmin = process.exitValue() == 0; | ||
+ } else { | ||
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
+ String uid = reader.readLine(); | ||
+ isAdmin = uid.equals("0"); | ||
+ } | ||
+ } catch (InterruptedException | IOException ignored) { | ||
+ } | ||
+ | ||
+ RUNNING_AS_ROOT_OR_ADMIN = isAdmin; | ||
+ } | ||
+ | ||
+ public static boolean userIsRootOrAdmin() { | ||
+ return RUNNING_AS_ROOT_OR_ADMIN; | ||
+ } | ||
+} | ||
\ No newline at end of file | ||
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java | ||
index 07d74c67..d66c5a6c 100644 | ||
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java | ||
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java | ||
@@ -287,6 +287,16 @@ public class BungeeCord extends ProxyServer | ||
|
||
isRunning = true; | ||
|
||
+ // Waterfall start - detect running as root | ||
+ if ( io.github.waterfallmc.waterfall.utils.ServerEnvironment.userIsRootOrAdmin() ) { | ||
+ getLogger().warning("****************************"); | ||
+ getLogger().warning("YOU ARE RUNNING THIS SERVER AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED."); | ||
+ getLogger().warning("YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS."); | ||
+ getLogger().warning("FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/"); | ||
+ getLogger().warning("****************************"); | ||
+ } | ||
+ // Waterfall end | ||
+ | ||
pluginManager.enablePlugins(); | ||
|
||
if ( config.getThrottle() > 0 ) | ||
-- | ||
2.33.0 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs 😢
Does this implement the fixed check from the new PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java 8 (or at least in Waterfall's setup) doesn't seem to like the NTSystem/UnixSystem classes, so I used the "running a command" method from the start, so this isn't affected by the OpenJDK bug.