Commit 6ae58221 authored by Jaromil's avatar Jaromil

documentation and build fixes for stable release

parent c02c53ba
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
......@@ -2,49 +2,41 @@ CC?=gcc
LDD?=ld
DESTDIR?=
PREFIX?=/usr/local
VERSION=0.2
VERSION=1.0
USER=root
GROUP=root
CFLAGS?=-Os -O2
all: shared
shared: CFLAGS+=-fPIC -fPIE -Wall
shared: LDFLAGS=-fPIC -fPIE -pie -lcrypto
shared: config.h sup.o sha256.o
${CC} ${LDFLAGS} sup.o sha256.o -o sup
musl: musl=/usr/local/musl
musl: CC=/usr/local/musl/bin/musl-gcc
musl: CC=${musl}/bin/musl-gcc
musl: CFLAGS+=-I${musl}/include
musl: LDFLAGS+=-static ${musl}/lib/libc.a
musl: config.h sup.o sha256.o
${CC} ${LDFLAGS} sup.o sha256.o -o sup
shared: CFLAGS+=-fPIC -fPIE -Wall
shared: LDFLAGS=-fPIC -fPIE -pie -lcrypto
shared: config.h sup
static: CFLAGS+=-DSTATIC=1
static: LDFLAGS=libressl/crypto/libcrypto.a -static-libgcc
static: config.h sup
test: CC=colorgcc
test: CFLAGS+=--std=gnu99
test: LDFLAGS=-lcrypto -lm
test: test.o sha256.o
test: config.h test.o sha256.o
${CC} ${LDFLAGS} test.o sha256.o -o test
all: shared
debug: CFLAGS+=-ggdb
debug: sup.o
${CC} ${LDFLAGS} sup.o sha256.o -o sup
config.h:
cp config.def.h config.h
sup.o: config.h sup.c
${CC} ${CFLAGS} -c sup.c -DVERSION=${VERSION}
sup: sup.o
${CC} ${LDFLAGS} sup.o -o sup
debug: CFLAGS+=-ggdb
debug: sup.o
${CC} ${LDFLAGS} sup.o -o sup
.c.o:
$(CC) $(CFLAGS) -c $< -o $@ -DVERSION=${VERSION}
clean:
rm -f *.o sup test
......
# sup
## a "small is beautiful" tool for UNIX privilege escalation
sup is a very small and secure C application. it is designed to run as root (with suid bit on) to facilitate the privilege escalation of users to execute certain programs as superuser.
all settings in sup are hard-coded at compile time. sup is very portable and self-contained, designed for production use as a static binary. sup is a sort of hard-coded sudo: it is an ideal companion for artisans building small containers and embedded systems.
the latest version of sup can be found on https://git.devuan.org/jaromil/sup and on its mirrors at dyne.org and github.com.
## why are you whispering?
as you may have realised already, sup is so minimal that all its documentation is written lowercase. it was originally written in 2009 by pancake of nopcode.org and maintained until 2011 as part of the suckless tools. in 2016 sup is being adopted by jaromil of dyne.org, extending its features to support static build with [http://www.musl-libc.org/](musl-libc) and hardcoded sha256 hashing of binary files.
## configure
sup's configuration resides in config.h and should be set before
building. here below an intuitive example
```c
#define USER 1000
#define GROUP -1
#define SETUID 0
#define SETGID 0
#define CHROOT ""
#define CHRDIR ""
#define HASH 1
#define ENFORCE 1
static struct rule_t rules[] = {
// allow user to run these programs when found in path location
{ USER, GROUP, "whoami", "/usr/bin/whoami", "" },
{ USER, GROUP, "ifconfig", "/sbin/ifconfig", "" },
{ USER, GROUP, "ls", "/bin/ls", "" },
{ USER, GROUP, "wifi", "/root/wifi.sh", "" },
// allow to run id when found in PATH with matching hash
{ USER, GROUP, "id", "*", "db533b77fc9e262209a46e0f.." },
// allow to run any program found in PATH
{ USER, GROUP, "*", "*"},
{ 0 }, // end of configuration
};
```
Fields are organized as following:
| UID | GUID | binary name | binary path | hash (optional) |
- `UID` is the numeric id which must own the binary for authorized execution
- `GID` is the numeric group id which must own the binary for authorized execution (can be -1 for none)
- `hash` can be computed before build using sha256sum (GNU coreutils)
using `sup -l` the configuration can be displayed at runtime.
## build
sup requires a C compiler and the GNU make tool to be built.
a simple `make` command will build a sup binary good enough for
evaluation purposes, with dynamic links to the libm and libc libraries
installed system-wide.
for production use sup should be built as a static binary: this is
easily done by first installing musl-libc in its default location and
then using the `make musl` command.
## technical details
sup consists of 3 files: sup.c is the main source and config.h is the
configuration, hardcoded at compile time. sha256.c is optional and
provides the hashing functionality if the define HASH is set.
sup is written in ANSI C with POSIX1.b compliancy for GNU/Linux and
BSD systems. it uses `setuid/gid` for privilege escalation and
`execv()` to launch processes as superuser.
## licensing
sup is copyleft software licensed as GNU Lesser Public License
(LGPLv3). when compiled with hashing capability, its license turns
into GNU GPLv2 because of the sha256 component.
```
sup is copyleft (c) 2009-2011 by pancake of nopcode.org
(c) 2016 by jaromil of dyne.org
the FIPS-180-2 sha-256 implementation optionally included in sup is
copyleft (c) 2001-2003 by Christophe Devine
```
* Enforce with checksums (sha1?)
// sup configuration file
#define HASH 1
#define ENFORCE 1
#ifndef FLAGSONLY
#define USER 1000
#define GROUP -1
......@@ -7,9 +15,6 @@
#define CHROOT ""
#define CHRDIR ""
#define ENFORCE 1
static struct rule_t rules[] = {
// allow user to run these programs when found in path location
{ USER, GROUP, "whoami", "/usr/bin/whoami", "" },
......@@ -22,3 +27,5 @@ static struct rule_t rules[] = {
/* { USER, GROUP, "*", "*"}, // allow to run any program found in PATH */
{ 0 },
};
#endif
......@@ -18,6 +18,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define FLAGSONLY 1
#include "config.h"
// this is not compiled in if HASH is not set
// meaning the license above doesn't applies.
#ifdef HASH
#include <string.h>
#include "sha256.h"
......@@ -260,6 +266,8 @@ void sha256_finish( sha256_context *ctx, uint8 digest[32] )
PUT_UINT32( ctx->state[7], digest, 28 );
}
#endif
#ifdef TEST
#include <stdlib.h>
......
.TH SUP 1 sup\-VERSION
.TH SUP 1 sup\-1.0
.SH NAME
sup - scale user priviledges
sup - a "small is beautiful" tool for UNIX privilege escalation
.SH SYNOPSIS
.B sup
.RB [ \-hlv ]
.SH DESCRIPTION
sup is a minimal priviledge scalation utility that allow normal
users to run other programs as different user and group.
sup is a very small and secure C application. it is designed to run as root (with suid bit on) to facilitate the privilege escalation of users to execute certain programs as superuser.
.P
The configuration is done in config.h at compile time.
all settings in sup are hard-coded at compile time. sup is very portable and self-contained, designed for production use as a static binary. sup is a sort of hard-coded sudo: it is an ideal companion for artisans building small containers and embedded systems.
.SH OPTIONS
.TP
.B \-h
print help message
.TP
.B \-l
list command whitelist
list configuration
.TP
.B \-v
prints version information
print version information
.SH AUTHOR
pancake <nopcode.org>
sup is copyleft software licensed as GNU Lesser Public License
(LGPLv3). when compiled with the HASH flag on its license turns
into GNU GPLv2 because of the sha256 component.
.P
sup is copyleft (c) 2009-2011 by pancake of nopcode.org
.BR
(c) 2016 by jaromil of dyne.org
.P
the FIPS-180-2 sha-256 implementation optionally included in sup is
copyleft (c) 2001-2003 by Christophe Devine
/* sup 0.3
/* sup 1.0
*
* (c) 2016 Dyne.org Foundation, Amsterdam
*
......@@ -7,22 +7,21 @@
* 2016 Denis Roio <jaromil@dyne.org> (current maintainer)
*
* This source code is free software; you can redistribute it and/or
* modify it under the terms of the GNU Public License as published
* by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* Please refer to the GNU Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer
* to the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Public License along with
* this source code; if not, write to:
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this source code; if not, write to: Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
......@@ -30,9 +29,10 @@
#include <stdlib.h>
#include <sys/stat.h>
#ifndef STATIC
#include <sys/types.h>
#include <pwd.h>
#endif
struct rule_t {
int uid;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment