├── .idea
├── .gitignore
├── webra1n-as-a-service.iml
├── vcs.xml
├── inspectionProfiles
│ └── profiles_settings.xml
├── modules.xml
└── misc.xml
├── .gitignore
├── bashrc
├── webra1n.service
├── checkra1n-downloader
└── checkra1n-downloader.sh
├── README.md
├── checkra1nunkillable
└── checkra1nunkillable.c
├── webra1nlauncher
└── webra1nlauncher.c
└── MAIN.sh
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
3 |
--------------------------------------------------------------------------------
/.idea/webra1n-as-a-service.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | checkra1n
2 | # ignore downloaded checkra1n binary
3 |
4 | checkra1nunkillable/checkra1nunkillable
5 | webra1nlauncher/webra1n
6 | # ignore things that we will compile
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/bashrc:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Jus de Patate - 2020 - jusdepatate@protonmail.com (github:jusdepatate)
3 | # This script is part of Webra1n As a Service (github:jusdepatate/webra1n-as-a-service)
4 | # It was meant to be the .bashrc of the user `checkra1n` created aftr running the script
5 |
6 | sudo /usr/bin/checkra1nunkillable
7 |
--------------------------------------------------------------------------------
/webra1n.service:
--------------------------------------------------------------------------------
1 | [Service]
2 | Description=Webra1n
3 | After=network.target
4 | StartLimitIntervalSec=0
5 | Type=simple
6 | Restart=always
7 | RestartSec=1
8 | StandardInput=tty
9 | TTYPath=/dev/tty2
10 | TTYReset=yes
11 | TTYVHangup=yes
12 | User=root
13 | ExecStart=/usr/bin/webra1n --port 80
14 | ExecStop=/bin/kill $(/bin/pidof webra1n)
15 |
16 | [Install]
17 | WantedBy=multi-user.target
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/checkra1n-downloader/checkra1n-downloader.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Jus de Patate - 2020 - jusdepatate@protonmail.com (github:jusdepatate)
3 | # This script is part of Webra1n As a Service (github:jusdepatate/webra1n-as-a-service)
4 | # Script that downloads checkra1n for your arch
5 |
6 | fatal() {
7 | echo -e "$*"
8 | exit 1
9 | }
10 |
11 | links=$(curl -sL "https://checkra.in/releases" | grep 'class="download-btn"' | sed -n 's/.*href="\(.*\)".*/\1/p' | grep -Eo '(http|https)://(.*)checkra1n' || fatal "Unable to get download links")
12 | # here we get all download link, might get broken if web designer change the way links are made
13 |
14 | arch=$(uname -m)
15 | # here we get arch
16 |
17 | if [ "$(echo "$links" | grep "$arch")" ]; then
18 | link=$(echo "$links" | grep "$arch")
19 | else
20 | fatal "Looks like we can't download checkra1n for you architecture ($arch)"
21 | fi
22 |
23 | link=$(echo "$links" | grep "$arch")
24 | # here we have the link corresponding to machine's arch
25 |
26 | wget "$link" -O "checkra1n"
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Webra1n As a Service
2 | Installer for headless devices that will install Checkra1n and add Webra1n As a Service on the system.
3 |
4 | ## How to run
5 | ```bash
6 | git clone https://github.com/jusdepatate/webra1n-as-a-service
7 | cd webra1n-as-a-service
8 | bash MAIN.sh
9 | ```
10 |
11 | ### Now what ?
12 | - You can access Webra1n (port `80` by default, you can edit the port by editing the [`webra1n.service`](/webra1n.service) at line 13)
13 | - You can access Checkra1n on SSH (port `22` by default, default user/password is `checkra1n`/`checkra1n` and is sudoer for all checkra1n-related executables)
14 |
15 | ### How to uninstall
16 | `bash MAIN.sh uninstall`
17 |
18 | ## To be done
19 | - [~~Checkra1n Downloader~~ ✅](/checkra1n-downloader/checkra1n-downloader.sh)
20 | - [~~Webra1n Service file~~ ✅](/webra1n.service)
21 | - Access point creator
22 | - [~~user creator for using `checkra1n` over SSH instead of HTTP~~ ✅](/MAIN.sh)
23 | - Raspberry Pi image
24 |
25 | ## Warning
26 | - **There is only support for Systemd**
27 | - I am absolutely not a pro, feel free to examinate code, open an issue or a PR if you have any type of idea.
28 |
--------------------------------------------------------------------------------
/checkra1nunkillable/checkra1nunkillable.c:
--------------------------------------------------------------------------------
1 | // Jus de Patate - 2020 - jusdepatate@protonmail.com (github:jusdepatate)
2 | // This script is part of Webra1n As a Service (github:jusdepatate/webra1n-as-a-service)
3 | // It was meant to run checkra1n on a user through ssh without being able to kill it unless we are root
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | void SIGhandler(int);
12 |
13 | int main(void) {
14 | signal(SIGINT, SIGhandler);
15 | signal(SIGQUIT, SIGhandler);
16 |
17 | struct winsize w;
18 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
19 |
20 | while (1) {
21 | if (( w.ws_col <= 80 || w.ws_row <= 24)) {
22 | // if terminal size is less than 80x24 (minimum required by checkra1n), use it in CLI mode instead of TUI
23 | fprintf(stderr, "\033[0;31mYour terminal is too small to start checkra1n in TUI mode, using CLI mode instead.\033[0m\nYou can resize and use CTRL+C to use TUI mode\n");
24 | system("/usr/bin/checkra1n --cli");
25 |
26 | } else {
27 | system("/usr/bin/checkra1n --tui");
28 | }
29 | }
30 | return 0;
31 | }
32 |
33 | void SIGhandler(int sig) {
34 | char c;
35 | signal(sig, SIG_IGN);
36 | printf("You tried");
37 | }
38 |
--------------------------------------------------------------------------------
/webra1nlauncher/webra1nlauncher.c:
--------------------------------------------------------------------------------
1 | // Jus de Patate - 2020 - jusdepatate@protonmail.com (github:jusdepatate)
2 | // This shit is part of Webra1n As a Service (github:jusdepatate/webra1n-as-a-service)
3 | // It was made to deal with Checkra1n requiring Ncurses and sending wrong status code
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | int main(int argc, char *argv[]) {
10 | if (argc > 1) {
11 | // if there are at least 1 argument
12 |
13 | char *PORT = "--port";
14 | char *P = "-p";
15 | char *arg1 = argv[1];
16 |
17 | int arg2 = 65536;
18 |
19 | char command[100];
20 |
21 | if ((strcmp(arg1, PORT) == 0 || strcmp(arg1, P) == 0)) {
22 | // if argument is "--port" or "-p" (strange way to do but fml took me a whole day to figure out.)
23 |
24 | if (argc >= 3) {
25 | arg2 = atoi(argv[2]);
26 | }
27 | // if there is a port specified, use it
28 |
29 | if ((arg2 >= 1 && arg2 <= 65535)) {
30 | // checking if specified port is correct
31 | sprintf(command, "/usr/bin/checkra1n --wui 0.0.0.0 %d", arg2);
32 | system(command);
33 | } else {
34 | fprintf(stderr, "\033[0;31mSpecified port is invalid.\033[0m\n");
35 | }
36 | } else {
37 | printf("Webra1n Launcher - Jus de Patate - 2020\n\n");
38 | printf("Accepted arguments:\n");
39 | printf("-p [1-65535] | select a port for webra1n between 1 and 65535\n");
40 | return 0;
41 | }
42 |
43 | } else {
44 | system("/usr/bin/checkra1n --wui 0.0.0.0 80");
45 | }
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/MAIN.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Jus de Patate - 2020 - jusdepatate@protonmail.com (github:jusdepatate)
3 | # This script is part of Webra1n As a Service (github:jusdepatate/webra1n-as-a-service)
4 | # It was meant to be the script to run to install everything
5 |
6 | fatal() {
7 | echo "$*"
8 | exit 1
9 | }
10 |
11 | if [ ! "$(whoami)" = "root" ]; then fatal "Please execute this script as root"; fi
12 | # Make sure the user is root, if not exit
13 |
14 | if [[ -z "$1" ]] || [[ "$1" = "install" ]]; then
15 | ./checkra1n-downloader/checkra1n-downloader.sh || fatal "Checkra1n-Download.sh failed"
16 | chmod +x checkra1n || fatal "Looks like we can't edit permissions of checkra1n executable"
17 | cp checkra1n /usr/bin/checkra1n || fatal "Couldn't move checkra1n in /usr/bin"
18 | # run Checkra1n downloader and install checkra1n, if it works we should have a file named `checkra1n` in the working directory and in /usr/bin/
19 |
20 | gcc webra1nlauncher/webra1nlauncher.c -o webra1nlauncher/webra1n || fatal "webra1nlauncher compilation failed"
21 | chmod +x webra1nlauncher/webra1n || fatal "Looks like we can't edit permissions of webra1n launcher"
22 | cp webra1nlauncher/webra1n /usr/bin/webra1n || fatal "Couldn't move webra1n in /usr/bin"
23 | # compilate the webra1n launcher
24 | # Why do I need a launcher for webra1n ?
25 | # Because checkra1n isn't that good and give bad success code to system which makes systemd to think that its dead
26 |
27 | gcc checkra1nunkillable/checkra1nunkillable.c -o checkra1nunkillable/checkra1nunkillable || fatal "checkra1nunkillable compilation failed"
28 | chmod +x checkra1nunkillable/checkra1nunkillable || fatal "Looks like we can't edit permissions of checkra1nunkillable executable"
29 | cp checkra1nunkillable/checkra1nunkillable /usr/bin/checkra1nunkillable || fatal "Couldn't move checkra1nunkillable in /usr/bin"
30 | # compilates checkra1nunkillable
31 | # it will simply make the checkra1n process un-^-C-able so that we can jail ssh connections to checkra1n
32 |
33 | useradd -m checkra1n -p "sayCaPlF0Sac." || fatal "Couldn't create user checkra1n"
34 | # add user 'checkra1n' to system with password 'checkra1n' (crypted with `perl -e 'print crypt("checkra1n", "salt")'`)
35 |
36 | cp /etc/sudoers /etc/sudoers.beforewebra1n || fatal "Couldn't backup /etc/sudoers"
37 | echo "checkra1n ALL = NOPASSWD: /usr/bin/checkra1nunkillable, /usr/bin/checkra1n, /usr/bin/webra1n" | sudo EDITOR='tee -a' visudo || fatal "Couldn't add checkra1n to sudoers for /usr/bin/checkra1n"
38 | # here we give permissions to user checkra1n to run `checkra1nunkillable`, `checkra1n` and `webra1n` as root without typing password
39 |
40 | chsh --shell /bin/bash checkra1n || fatal "Couldn't change checkra1n's shell to /bin/bash"
41 | cp bashrc ~checkra1n/.bashrc || fatal "Couldn't put .bashrc in ~checkra1n"
42 | # here we change checkra1n's shell and put our bashrc inside it
43 |
44 | cp webra1n.service /etc/systemd/system/webra1n.service || fatal "Couldn't put webra1n.service in /etc/systemd/system/"
45 | systemctl daemon-reload
46 | systemctl enable webra1n
47 | systemctl start webra1n
48 | # add webra1n.service to systemd services and enable it (=start it at reboots)
49 |
50 | elif [[ "$1" = "uninstall" ]] || [[ "$1" = "remove" ]]; then
51 | systemctl stop webra1n
52 | systemctl disable webra1n
53 | rm /etc/systemd/system/webra1n.service
54 | systemctl daemon-reload
55 | # remove systemd service
56 |
57 | cp /etc/sudoers.beforewebra1n /etc/sudoers || fatal "Couldn't use /etc/sudoers backup"
58 | deluser checkra1n
59 | # remove checkra1n user
60 |
61 | rm /usr/bin/checkra1n
62 | rm /usr/bin/webra1n
63 | rm /usr/bin/checkra1nunkillable
64 | # remove compilated executable from PATH
65 |
66 | rm checkra1n
67 | rm checkra1nunkillable/checkra1nunkillable
68 | rm webra1nlauncher/webra1n
69 | # remove compilated executable from here
70 | else
71 | echo "Webra1n-As-a-Service"
72 | echo "Jus de Patate - 2020 - jusdepatate@protonmail.com"
73 | echo ""
74 | echo "The only accepted arguments are:"
75 | echo "install - To install webra1n"
76 | echo "unistall - To remove webra1n"
77 | fi
--------------------------------------------------------------------------------