-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Readd root/admin user detection #6593
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
597a378
Readd root/admin user detection
NoahvdAa f601aa1
Use original test for Windows, use UID for unix and add co-author
NoahvdAa 574c6f4
Move logging and remove unnecessary reader
NoahvdAa f3c1c7d
try with resources
NoahvdAa eeae49e
Use Windows security identifiers + reduce size of Unix check
NoahvdAa 49e124d
Remove extra newline at the bottom of the message
NoahvdAa f039623
Change wording
NoahvdAa eeb9df1
Address comments
NoahvdAa c7e0bb7
Link to Maddy's article
NoahvdAa 65ed556
Use warning log level
NoahvdAa 8f9d43f
Rebase patches
me4502 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
This file contains hidden or 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,79 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: egg82 <[email protected]> | ||
| Date: Sat, 11 Sep 2021 22:55:14 +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. | ||
|
|
||
| diff --git a/src/main/java/io/papermc/paper/util/ServerEnvironment.java b/src/main/java/io/papermc/paper/util/ServerEnvironment.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..0f41ea267c2cde6dc897e2c6e1615e1bb42d3a60 | ||
| --- /dev/null | ||
| +++ b/src/main/java/io/papermc/paper/util/ServerEnvironment.java | ||
| @@ -0,0 +1,41 @@ | ||
| +package io.papermc.paper.util; | ||
| + | ||
| +import org.apache.commons.lang.SystemUtils; | ||
| + | ||
| +import java.io.File; | ||
| +import java.io.IOException; | ||
| + | ||
| +public class ServerEnvironment { | ||
| + private static final boolean runningAsRootOrAdmin; | ||
NoahvdAa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + | ||
| + static { | ||
| + if (SystemUtils.IS_OS_WINDOWS) { | ||
| + String programFiles = System.getenv("ProgramFiles"); | ||
| + if (programFiles == null) { | ||
| + programFiles = "C:\\Program Files"; | ||
| + } | ||
| + File programFile = new File(programFiles); | ||
| + boolean canWrite = programFile.canWrite(); | ||
| + | ||
| + if (canWrite) { | ||
| + // Make sure that the path can actually be written to. | ||
| + try { | ||
| + File test = File.createTempFile(".paperwritecheck", null, programFile); | ||
| + if (!test.delete()) { | ||
| + test.deleteOnExit(); | ||
| + } | ||
| + } catch (IOException exception) { | ||
| + canWrite = false; | ||
| + } | ||
| + } | ||
| + | ||
| + runningAsRootOrAdmin = canWrite; | ||
| + } else { | ||
| + runningAsRootOrAdmin = System.getProperty("user.name", "").equals("root"); | ||
| + } | ||
| + } | ||
| + | ||
| + public static boolean userIsRootOrAdmin() { | ||
| + return runningAsRootOrAdmin; | ||
| + } | ||
| +} | ||
| diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java | ||
| index 22e9dd17f62103c5061435099ce96a3d70d54808..0c7247a3703f26ae3389daaa95ffbb30275c0125 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/Main.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/Main.java | ||
| @@ -261,6 +261,17 @@ public class Main { | ||
| System.setProperty(TerminalConsoleAppender.JLINE_OVERRIDE_PROPERTY, "false"); // Paper | ||
| } | ||
|
|
||
| + // Paper start - detect running as root | ||
| + if (io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) { | ||
NoahvdAa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + System.err.println("****************************"); | ||
| + System.err.println("YOU ARE RUNNING AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED."); | ||
| + System.err.println("YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS."); | ||
| + System.err.println("MALWARE, BAD PLUGINS, AND ATTACKERS WILL HAVE COMPLETE ACCESS AND CONTROL OF YOUR MACHINE."); | ||
| + System.err.println("****************************"); | ||
| + System.err.println(); | ||
| + } | ||
| + // Paper end | ||
| + | ||
| if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) { | ||
| Date buildDate = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(Main.class.getPackage().getImplementationVendor()); // Paper | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.