aboutsummaryrefslogtreecommitdiff
path: root/02/src/bruteforce.c
blob: 38dfd0fff93189dd3d3508927ed614d54b671551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// src/bruteforce.c --- utility to bruteforce shell password
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// Commentary:
//
// Code:

#include <stddef.h>

#include "cracking.h"

int
main (int argc, char *argv[])
{
  if (argc != 2) {
    fprintf (stderr, "Usage: %s LOGIN\n", argv[0]);
    exit (EXIT_FAILURE);
  }

  struct shell shell = spawn_shell ();
  struct string_view login = SVCSTR (argv[1]);
  struct string_builder password = {0};
  STRING_BUILDER_APPEND_STRING_VIEW (password, SVCSTR ("A"));

  for (size_t attmept = 0;; ++attmept) {
    if (attmept % 10000 == 0)
      printf ("Trying: %.*s\n", SBFMT (password));

    if (test_credentials (shell, login, SVSB (password)))
      break;

    password_bump (&password);
  }

  printf ("Found: %.*s\n", SVFMT (SVSB (password)));

  return EXIT_SUCCESS;
}

// src/bruteforce.c ends here