Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NS sandbox challenges to check system vendor instead of hostname #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sandboxing/level-14/_0/babyjail_level14
Binary file not shown.
29 changes: 26 additions & 3 deletions sandboxing/level-14/_0/babyjail_level14.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@
#include <limits.h>
#include <sched.h>

char hostname[128];
long getvendor(char *name, size_t len) {
int fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY);
if (fd == -1) {
return -1;
}

long nbytes = read(fd, name, len - 1);
if (nbytes == -1) {
close(fd);
return -1;
}

name[nbytes] = '\0';

size_t read_len = strlen(name);
if (read_len > 0 && name[read_len - 1] == '\n') {
name[read_len - 1] = '\0';
}

close(fd);
return nbytes;
}

char vendor[128];

int main(int argc, char **argv, char **envp)
{
Expand All @@ -43,8 +66,8 @@ int main(int argc, char **argv, char **envp)
printf("###\n");
printf("\n");

gethostname(hostname, 128);
if (strstr(hostname, "-level") && !strstr(hostname, "vm_"))
getvendor(vendor, 128);
if (strcmp(vendor, "QEMU"))
{
puts("ERROR: in the dojo, this challenge MUST run in virtualization mode.");
puts("Please run `vm connect` to launch and connect to the Virtual Machine, then run this challenge inside the VM.");
Expand Down
Binary file modified sandboxing/level-15/_0/babyjail_level15
Binary file not shown.
29 changes: 26 additions & 3 deletions sandboxing/level-15/_0/babyjail_level15.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@
#include <limits.h>
#include <sched.h>

char hostname[128];
long getvendor(char *name, size_t len) {
int fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY);
if (fd == -1) {
return -1;
}

long nbytes = read(fd, name, len - 1);
if (nbytes == -1) {
close(fd);
return -1;
}

name[nbytes] = '\0';

size_t read_len = strlen(name);
if (read_len > 0 && name[read_len - 1] == '\n') {
name[read_len - 1] = '\0';
}

close(fd);
return nbytes;
}

char vendor[128];

int main(int argc, char **argv, char **envp)
{
Expand All @@ -43,8 +66,8 @@ int main(int argc, char **argv, char **envp)
printf("###\n");
printf("\n");

gethostname(hostname, 128);
if (strstr(hostname, "-level") && !strstr(hostname, "vm_"))
getvendor(vendor, 128);
if (strcmp(vendor, "QEMU"))
{
puts("ERROR: in the dojo, this challenge MUST run in virtualization mode.");
puts("Please run `vm connect` to launch and connect to the Virtual Machine, then run this challenge inside the VM.");
Expand Down
Binary file modified sandboxing/level-16/_0/babyjail_level16
Binary file not shown.
29 changes: 26 additions & 3 deletions sandboxing/level-16/_0/babyjail_level16.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@
#include <limits.h>
#include <sched.h>

char hostname[128];
long getvendor(char *name, size_t len) {
int fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY);
if (fd == -1) {
return -1;
}

long nbytes = read(fd, name, len - 1);
if (nbytes == -1) {
close(fd);
return -1;
}

name[nbytes] = '\0';

size_t read_len = strlen(name);
if (read_len > 0 && name[read_len - 1] == '\n') {
name[read_len - 1] = '\0';
}

close(fd);
return nbytes;
}

char vendor[128];

int main(int argc, char **argv, char **envp)
{
Expand All @@ -43,8 +66,8 @@ int main(int argc, char **argv, char **envp)
printf("###\n");
printf("\n");

gethostname(hostname, 128);
if (strstr(hostname, "-level") && !strstr(hostname, "vm_"))
getvendor(vendor, 128);
if (strcmp(vendor, "QEMU"))
{
puts("ERROR: in the dojo, this challenge MUST run in virtualization mode.");
puts("Please run `vm connect` to launch and connect to the Virtual Machine, then run this challenge inside the VM.");
Expand Down
Binary file modified sandboxing/level-17/_0/babyjail_level17
Binary file not shown.
29 changes: 26 additions & 3 deletions sandboxing/level-17/_0/babyjail_level17.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,30 @@ void print_disassembly(void *shellcode_addr, size_t shellcode_size)
#include <limits.h>
#include <sched.h>

char hostname[128];
long getvendor(char *name, size_t len) {
int fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY);
if (fd == -1) {
return -1;
}

long nbytes = read(fd, name, len - 1);
if (nbytes == -1) {
close(fd);
return -1;
}

name[nbytes] = '\0';

size_t read_len = strlen(name);
if (read_len > 0 && name[read_len - 1] == '\n') {
name[read_len - 1] = '\0';
}

close(fd);
return nbytes;
}

char vendor[128];

int main(int argc, char **argv, char **envp)
{
Expand All @@ -92,8 +115,8 @@ int main(int argc, char **argv, char **envp)
printf("###\n");
printf("\n");

gethostname(hostname, 128);
if (strstr(hostname, "-level") && !strstr(hostname, "vm_"))
getvendor(vendor, 128);
if (strcmp(vendor, "QEMU"))
{
puts("ERROR: in the dojo, this challenge MUST run in virtualization mode.");
puts("Please run `vm connect` to launch and connect to the Virtual Machine, then run this challenge inside the VM.");
Expand Down
Binary file modified sandboxing/level-18/_0/babyjail_level18
Binary file not shown.
29 changes: 26 additions & 3 deletions sandboxing/level-18/_0/babyjail_level18.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,30 @@ void print_disassembly(void *shellcode_addr, size_t shellcode_size)
#include <limits.h>
#include <sched.h>

char hostname[128];
long getvendor(char *name, size_t len) {
int fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY);
if (fd == -1) {
return -1;
}

long nbytes = read(fd, name, len - 1);
if (nbytes == -1) {
close(fd);
return -1;
}

name[nbytes] = '\0';

size_t read_len = strlen(name);
if (read_len > 0 && name[read_len - 1] == '\n') {
name[read_len - 1] = '\0';
}

close(fd);
return nbytes;
}

char vendor[128];

int main(int argc, char **argv, char **envp)
{
Expand All @@ -92,8 +115,8 @@ int main(int argc, char **argv, char **envp)
printf("###\n");
printf("\n");

gethostname(hostname, 128);
if (strstr(hostname, "-level") && !strstr(hostname, "vm_"))
getvendor(vendor, 128);
if (strcmp(vendor, "QEMU"))
{
puts("ERROR: in the dojo, this challenge MUST run in virtualization mode.");
puts("Please run `vm connect` to launch and connect to the Virtual Machine, then run this challenge inside the VM.");
Expand Down