diff options
| author | 2026-11-11 05:31:06 +0000 | |
|---|---|---|
| committer | 2026-11-11 06:14:42 +0000 | |
| commit | 9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch) | |
| tree | 31f328747acb934d365d423adfda144818ff5ad4 /02/src/bruteforce.c | |
| download | lab-01-05-master.tar.gz | |
Diffstat (limited to '02/src/bruteforce.c')
| -rw-r--r-- | 02/src/bruteforce.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/02/src/bruteforce.c b/02/src/bruteforce.c new file mode 100644 index 0000000..38dfd0f --- /dev/null +++ b/02/src/bruteforce.c | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // src/bruteforce.c --- utility to bruteforce shell password | ||
| 2 | // | ||
| 3 | // Copyright (c) 2026 Martin Michalec <martin@michalec.dev> | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: MIT | ||
| 6 | // | ||
| 7 | // Commentary: | ||
| 8 | // | ||
| 9 | // Code: | ||
| 10 | |||
| 11 | #include <stddef.h> | ||
| 12 | |||
| 13 | #include "cracking.h" | ||
| 14 | |||
| 15 | int | ||
| 16 | main (int argc, char *argv[]) | ||
| 17 | { | ||
| 18 | if (argc != 2) { | ||
| 19 | fprintf (stderr, "Usage: %s LOGIN\n", argv[0]); | ||
| 20 | exit (EXIT_FAILURE); | ||
| 21 | } | ||
| 22 | |||
| 23 | struct shell shell = spawn_shell (); | ||
| 24 | struct string_view login = SVCSTR (argv[1]); | ||
| 25 | struct string_builder password = {0}; | ||
| 26 | STRING_BUILDER_APPEND_STRING_VIEW (password, SVCSTR ("A")); | ||
| 27 | |||
| 28 | for (size_t attmept = 0;; ++attmept) { | ||
| 29 | if (attmept % 10000 == 0) | ||
| 30 | printf ("Trying: %.*s\n", SBFMT (password)); | ||
| 31 | |||
| 32 | if (test_credentials (shell, login, SVSB (password))) | ||
| 33 | break; | ||
| 34 | |||
| 35 | password_bump (&password); | ||
| 36 | } | ||
| 37 | |||
| 38 | printf ("Found: %.*s\n", SVFMT (SVSB (password))); | ||
| 39 | |||
| 40 | return EXIT_SUCCESS; | ||
| 41 | } | ||
| 42 | |||
| 43 | // src/bruteforce.c ends here | ||
