Skip to content

Instantly share code, notes, and snippets.

@adililhan
Created February 16, 2021 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adililhan/090480a6244fdf9afbb2f6ec4b7fdc79 to your computer and use it in GitHub Desktop.
Save adililhan/090480a6244fdf9afbb2f6ec4b7fdc79 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <linux/seccomp.h>
#include <seccomp.h>
#include <sys/prctl.h>
void main() {
FILE *filePoint;
filePoint = fopen("/tmp/test.txt", "a");
if(filePoint == NULL) {
puts("File can not be opened");
exit(1);
}
fputs("qwe\n", filePoint);
fclose(filePoint);
filePoint = fopen("/tmp/test.txt", "a");
if(filePoint == NULL) {
puts("File can not be opened");
exit(1);
}
scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL);
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0);
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
seccomp_load(ctx);
fputs("xyz", filePoint);
fclose(filePoint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment