aboutsummaryrefslogtreecommitdiffstats
path: root/service
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2021-06-24 02:52:21 +0200
committerLouis Burda <quent.burda@gmail.com>2021-06-24 02:52:51 +0200
commita0bd3d833d916cadd23d17d0b3784e28c729967d (patch)
treedea52e19b1518f1489669c8a1e29d340ced61989 /service
parentaeb66a7b19008fabecbca23a1e21a9d6942ec28a (diff)
downloadenowars5-service-stldoctor-a0bd3d833d916cadd23d17d0b3784e28c729967d.tar.gz
enowars5-service-stldoctor-a0bd3d833d916cadd23d17d0b3784e28c729967d.zip
various fixes made while stress-testing exploit
Diffstat (limited to 'service')
-rwxr-xr-xservice/entrypoint.sh2
-rw-r--r--service/src/.gitignore2
-rw-r--r--service/src/main.c98
3 files changed, 59 insertions, 43 deletions
diff --git a/service/entrypoint.sh b/service/entrypoint.sh
index 4e6a8c4..94dbea1 100755
--- a/service/entrypoint.sh
+++ b/service/entrypoint.sh
@@ -5,7 +5,7 @@ chown -R service:service "$RESULTDIR"
while [ 1 ]; do
/cleaner.sh
- sleep 200
+ sleep 400
done &
CMD="socat -T180 -s TCP-LISTEN:9000,nodelay,reuseaddr,fork EXEC:/service/build/stldoctor,raw,pty,echo=0,stderr"
diff --git a/service/src/.gitignore b/service/src/.gitignore
new file mode 100644
index 0000000..140742a
--- /dev/null
+++ b/service/src/.gitignore
@@ -0,0 +1,2 @@
+build
+vgcore.*
diff --git a/service/src/main.c b/service/src/main.c
index d76ceb8..24279c5 100644
--- a/service/src/main.c
+++ b/service/src/main.c
@@ -92,6 +92,13 @@ fail:
return FAIL;
}
+int
+access_authorized(const char *file)
+{
+ return (loggedin && file[0] == '.' && file[1] != '.')
+ || (!loggedin && file[0] != '.');
+}
+
void
cat_cmd(const char *arg)
{
@@ -106,12 +113,10 @@ help_cmd(const char *arg)
{
int i;
- if (arg) {
- for (i = 0; i < ARRSIZE(commands); i++) {
- if (!strcmp(commands[i].name, arg)) {
- printf("%s\n", commands[i].desc);
- return;
- }
+ for (i = 0; arg && i < ARRSIZE(commands); i++) {
+ if (!strcmp(commands[i].name, arg)) {
+ printf("%s\n", commands[i].desc);
+ return;
}
}
@@ -124,6 +129,7 @@ help_cmd(const char *arg)
void
exit_cmd(const char *arg)
{
+ printf("bye!\n");
exit(0);
}
@@ -170,8 +176,9 @@ cleanup:
void
search_cmd(const char *arg)
{
- char *end, *scandir = NULL, *infopath = NULL, *modelpath = NULL;
- int i, which, dirstart, ishidden;
+ char *end, *scandir = NULL, *infopath = NULL,
+ *modelpath = NULL, **paths = NULL;
+ int i, which, dirstart, ishidden, pathc, pathcap = 100;
const char *hash, *name;
struct dirent *de;
DIR *d = NULL;
@@ -188,51 +195,49 @@ search_cmd(const char *arg)
hash = mhash(arg ? arg : ask("Model name: "), -1);
}
- if (!(d = opendir(resultdir))) return;
+ if (!(d = opendir(resultdir))) {
+ printf("Unable to access upload directory!\n");
+ return;
+ }
+ paths = checkp(malloc(pathcap * sizeof(char*)));
dirstart = telldir(d);
- for (i = 0; (de = readdir(d));) {
- name = de->d_name;
- if (loggedin && *name == '.' && !strpfcmp(hash, name + 1)
- || !loggedin && *name != '.' && !strpfcmp(hash, name)) {
- printf("%i : %s\n", i, de->d_name);
- i++;
+ for (pathc = 0; (de = readdir(d));) {
+ if (access_authorized(de->d_name)
+ && !strpfcmp(hash, de->d_name + loggedin)) {
+ printf("%i : %s\n", pathc, de->d_name);
+ paths[pathc++] = checkp(strdup(de->d_name));
+ if (pathc == pathcap) {
+ pathcap *= 2;
+ paths = checkp(realloc(paths, pathcap * sizeof(char*)));
+ }
}
}
+ closedir(d);
- if (i == 0) {
+ if (pathc == 0) {
printf("Sorry, couldnt find a matching scan result!\n");
goto cleanup;
- } else {
- which = strtoul(ask("Which of these results? "), &end, 10);
- if (which >= i || which < 0 || *end) {
- printf("Invalid index!\n");
- goto cleanup;
- }
- }
-
- seekdir(d, dirstart);
- for (i = 0; (de = readdir(d));) {
- name = de->d_name;
- if (loggedin && *name == '.' && !strpfcmp(hash, name + 1)
- || !loggedin && *name != '.' && !strpfcmp(hash, name)) {
- if (i == which) {
- scandir = aprintf("%s/%s", resultdir, de->d_name);
- break;
- }
- i++;
- }
}
- if (!scandir) {
- printf("Selected result spontaneously combusted!\n");
+ which = strtoul(ask("Which of these results? "), &end, 10);
+ if (which >= pathc || which < 0 || *end) {
+ printf("Invalid index!\n");
goto cleanup;
}
+ scandir = aprintf("%s/%s", resultdir, paths[which]);
+
infopath = aprintf("%s/%s", scandir, "info");
- if (!(f = fopen(infopath, "r"))) goto cleanup;
+ if (!(f = fopen(infopath, "r"))) {
+ printf("Selected result is missing!\n");
+ goto cleanup;
+ }
free_info(&cached);
- if (load_info(&cached, f) != OK) goto cleanup;
+ if (load_info(&cached, f) != OK) {
+ printf("Failed to parse info file!\n");
+ goto cleanup;
+ }
fclose(f);
f = NULL;
@@ -240,11 +245,17 @@ search_cmd(const char *arg)
if (strchr(ask("Download the model? "), 'y')) {
modelpath = aprintf("%s/%s", scandir, "model");
- if (!(f = fopen(modelpath, "r"))) goto cleanup;
+ if (!(f = fopen(modelpath, "r"))) {
+ printf("Failed to access file!\n");
+ goto cleanup;
+ }
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
- if (size > MAXFILESIZE) goto cleanup;
+ if (size > MAXFILESIZE) {
+ printf("File is too large to send!\n");
+ goto cleanup;
+ }
printf("Here you go.. (%liB)\n", size);
while ((i = getc(f)) != EOF)
putc(i, stdout);
@@ -254,10 +265,13 @@ search_cmd(const char *arg)
cleanup:
if (f) fclose(f);
- closedir(d);
+
free(scandir);
free(infopath);
free(modelpath);
+
+ for (i = 0; i < pathc; i++) free(paths[i]);
+ free(paths);
}
void