Skip to content

Commit

Permalink
Much accurate sudokill ssh login detect
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Dec 26, 2023
1 parent d56afe3 commit ac9f6d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domcloud-bridge",
"version": "0.34.3",
"version": "0.35.0",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
19 changes: 11 additions & 8 deletions sudokill.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const opts = cli.parse({
ignore: ['i', 'Ignore user list', 'string', ''],
});

const output = exec('ps -eo user:20,pid,etimes,command --forest --no-headers', {
const psOutput = exec('ps -eo user:20,pid,etimes,command --forest --no-headers', {
silent: true,
fatal: true,
}).stdout.trim().split('\n');

const whoOutput = exec('who', {
silent: true,
fatal: true,
}).stdout.trim().split('\n');
Expand All @@ -26,24 +31,22 @@ ignoreUsers.root = true;

// process and filter output
const splitTest = /^([\w.-]+\+?) +(\d+) +(\d+) (.+)$/;
const lists = output
const lists = psOutput
.map(x => splitTest.exec(x))
.filter(x => x !== null && !ignoreUsers[x[1]]).map(match => ({
raw: match[0],
user: match[1],
pid: match[2],
etimes: match[3],
etimes: parseInt(match[3]),
command: match[4],
}));

for (const item of lists) {
if (item.command === ' \\_ (sd-pam)') {
ignoreUsers[item.user] = true;
}
for (const item of whoOutput) {
ignoreUsers[item.match(/^[\w.-]+/)[0]] = true;
}

// scan for any processes not in ssh sessions or longer than 3 hours
let candidates = lists.filter(x => parseInt(x.etimes) > 10800 || (x.command[0] != ' ' && !ignoreUsers[x.user]));
let candidates = lists.filter(x => x.etimes > 10800 || (x.command[0] != ' ' && !ignoreUsers[x.user] && x.etimes > 60));

if (opts.test) {
console.log(candidates.map(x => x.raw).join('\n'));
Expand Down

0 comments on commit ac9f6d4

Please sign in to comment.