Skip to content
Permalink
Browse files
Merge pull request #1 from aa9863/BuildTest
Build test
  • Loading branch information
aa9863 committed Jan 23, 2023
2 parents f169bed + c54dafd commit ca3e7782e40ae626bf218533a688d1f001af067d
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 41 deletions.
@@ -0,0 +1,3 @@
FROM debian:stable

RUN apt update && apt install -y gcc gcc-multilib
@@ -0,0 +1,28 @@
FROM 6048_builder as ServerBuilder

ADD ./server.c /opt/server.c

WORKDIR /opt
RUN gcc /opt/server.c -o /opt/server


FROM debian:stable

#Get SSH
#Install SSH Server
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
openssh-server libc6-i386

#Configure SSH (Cant run as Daemon if this doenst exit)
RUN mkdir /var/run/sshd

ADD ./runscript.sh /tmp/runscript.sh

# --- System Configuration --------
#Add a User
RUN useradd -ms /bin/bash cueh && echo cueh:cueh | chpasswd

COPY --from=ServerBuilder /opt/server /opt/server

CMD ["/usr/sbin/sshd", "-D"]
@@ -0,0 +1,15 @@
#!/bin/bash

# turn on bash's job control
set -m



echo "Starting SSH"
/usr/sbin/sshd -D &

echo "Running server with $1"
/opt/server $1

wait -n
exit $?
@@ -0,0 +1,72 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>

//https://stackoverflow.com/questions/5194666/disable-randomization-of-memory-addresses/30385370#30385370
#include <sys/personality.h>
#include <signal.h>

int processConnection(int fd, int argc, char* argv[]) {
close(0);
close(1);
close(2);
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);

if(getenv("RUN_ALSR")) {
printf("Running with ALSR turned off\n");
fflush(stdout);
int out = personality(ADDR_NO_RANDOMIZE);
printf("Result %d\n", out);
fflush(stdout);
}

execvp(argv[1], &argv[1]);
}

int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Please provide the application to run on connection");
exit(-1);
}

struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(1337);
address.sin_addr.s_addr = INADDR_ANY;

int sock = socket(AF_INET, SOCK_STREAM, 0);
int status = bind(sock, (struct sockaddr *) &address, sizeof(address));

if (status == -1) {
printf("Failed to bind socket, error is: %s\n", strerror(errno));
exit(-2);
}

listen(sock, 0);


printf("Server started, listening on 0.0.0.0:1337, connect using the client app!\n");

while (1) {
int resultfd = accept(sock, NULL, NULL);
int pid = fork();
if (pid == 0)
return processConnection(resultfd, argc, argv);
else {
signal(SIGCHLD, SIG_IGN); //Dont give fuck about Zombie Children.
printf("Received connection as FD %d\n", resultfd);
close(resultfd);
}
}

return 0;
}
@@ -0,0 +1,12 @@
version: "3.7"

services:
builder:
image: 6048_builder
build:
context: Builder

server:
image: 6048_server
build:
context: Server

This file was deleted.

0 comments on commit ca3e778

Please sign in to comment.