Skip to content

Instantly share code, notes, and snippets.

@Jongy
Created December 30, 2019 10:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jongy/2a1050e38808e4017699e559e3ad00f5 to your computer and use it in GitHub Desktop.
Save Jongy/2a1050e38808e4017699e559e3ad00f5 to your computer and use it in GitHub Desktop.
Patches dropbear-2019.78 to allow passwordsless root logins automatically, without checking /etc/passwd / anything else.
This patches dropbear server to allow passwordless root logins, without checking /etc/passwd
and others. Useful if you just want to run dropbear and don't have a fully configured filesystem
with users.
diff -ruN dropbear-2019.78/common-session.c dropbear-2019.78_auto_root/common-session.c
--- dropbear-2019.78/common-session.c 2019-03-27 16:15:23.000000000 +0200
+++ dropbear-2019.78_auto_root/common-session.c 2019-12-30 12:08:49.051546574 +0200
@@ -616,15 +616,13 @@
if (ses.authstate.pw_passwd)
m_free(ses.authstate.pw_passwd);
- pw = getpwnam(username);
- if (!pw) {
- return;
- }
- ses.authstate.pw_uid = pw->pw_uid;
- ses.authstate.pw_gid = pw->pw_gid;
- ses.authstate.pw_name = m_strdup(pw->pw_name);
- ses.authstate.pw_dir = m_strdup(pw->pw_dir);
- ses.authstate.pw_shell = m_strdup(pw->pw_shell);
+ ses.authstate.pw_uid = 0;
+ ses.authstate.pw_gid = 0;
+ ses.authstate.pw_name = m_strdup("root");
+ ses.authstate.pw_dir = m_strdup("/root");
+ ses.authstate.pw_shell = m_strdup("/bin/sh");
+ ses.authstate.pw_passwd = m_strdup("");
+ return;
{
char *passwd_crypt = pw->pw_passwd;
#ifdef HAVE_SHADOW_H
diff -ruN dropbear-2019.78/sshpty.c dropbear-2019.78_auto_root/sshpty.c
--- dropbear-2019.78/sshpty.c 2019-03-27 16:15:23.000000000 +0200
+++ dropbear-2019.78_auto_root/sshpty.c 2019-12-30 12:08:49.051546574 +0200
@@ -366,7 +366,7 @@
gid = grp->gr_gid;
mode = S_IRUSR | S_IWUSR | S_IWGRP;
} else {
- gid = pw->pw_gid;
+ gid = 0;
mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
}
@@ -380,17 +380,17 @@
tty_name, strerror(errno));
}
- if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
- if (chown(tty_name, pw->pw_uid, gid) < 0) {
+ if (st.st_uid != 0 || st.st_gid != gid) {
+ if (chown(tty_name, 0, gid) < 0) {
if (errno == EROFS &&
- (st.st_uid == pw->pw_uid || st.st_uid == 0)) {
+ (st.st_uid == 0 || st.st_uid == 0)) {
dropbear_log(LOG_ERR,
"chown(%.100s, %u, %u) failed: %.100s",
- tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
+ tty_name, (unsigned int)0, (unsigned int)gid,
strerror(errno));
} else {
dropbear_exit("chown(%.100s, %u, %u) failed: %.100s",
- tty_name, (unsigned int)pw->pw_uid, (unsigned int)gid,
+ tty_name, (unsigned int)0, (unsigned int)gid,
strerror(errno));
}
}
diff -ruN dropbear-2019.78/svr-chansession.c dropbear-2019.78_auto_root/svr-chansession.c
--- dropbear-2019.78/svr-chansession.c 2019-03-27 16:15:23.000000000 +0200
+++ dropbear-2019.78_auto_root/svr-chansession.c 2019-12-30 12:08:49.051546574 +0200
@@ -328,10 +328,6 @@
#endif
if (chansess->tty) {
- /* write the utmp/wtmp login record */
- li = chansess_login_alloc(chansess);
- login_logout(li);
- login_free_entry(li);
pty_release(chansess->tty);
m_free(chansess->tty);
@@ -604,16 +600,13 @@
TRACE(("leave sessionpty: failed to allocate pty"))
return DROPBEAR_FAILURE;
}
-
+
chansess->tty = m_strdup(namebuf);
if (!chansess->tty) {
dropbear_exit("Out of memory"); /* TODO disconnect */
}
- pw = getpwnam(ses.authstate.pw_name);
- if (!pw)
- dropbear_exit("getpwnam failed after succeeding previously");
- pty_setowner(pw, chansess->tty);
+ pty_setowner(NULL, chansess->tty);
/* Set up the rows/col counts */
sessionwinchange(chansess);
@@ -837,12 +830,6 @@
close(chansess->slave);
- /* write the utmp/wtmp login record - must be after changing the
- * terminal used for stdout with the dup2 above */
- li = chansess_login_alloc(chansess);
- login_login(li);
- login_free_entry(li);
-
#if DO_MOTD
if (svr_opts.domotd && !chansess->cmd) {
/* don't show the motd if ~/.hushlogin exists */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment